리눅스 운영체제에서 top 명령어을 시용하여 운영 체제 메모리는 total, free, used로 나눈다. 만약 프로세스 메모리를 따져봐도 free가 너무 적고 used가 큰 경우가 존재한다. 이 때는 free 명령어를 이용하여 정말 메모리가 없는지 확인해야 한다.


32G 메모리 장비에서 top 명령어로 500M만 free이고 31.5G가 used로 나온다.


free로 확인하니 첫번 째 줄은 top처럼 출력하지만, buffers/cache에서는 free의 값이 17이다. (cached가 16임)


# free -g

             total       used       free     shared    buffers     cached

Mem:            31         30          0          0          0         16

-/+ buffers/cache:         14         17

Swap:            9          0          9



아래와 같이 buffers/cache 메모리를 정리하고 난 후 free로 메모리를 확인하면 다음과 같이 메모리 값이 변경된다.

전체 메모리가 0에서 17로 변경했다.  (cached는 0으로 변경했다.)


# echo 1 > /proc/sys/vm/drop_caches


# free -g

             total       used       free     shared    buffers     cached

Mem:            31         13         17          0          0          0

-/+ buffers/cache:         13         17

Swap:            9          0          9



운영체제는 파일 IO가 발생할 때, 남는 메모리를 buffer나 cache에 메모리를 할당하여 속도를 빠르게 한다.


total memory = used + free 

total memory = used + buffers + cache 



메모리 DB나 메모리만 쓰는 일래스틱서치에서 파일 백업(snapshot)을 쓸 때 이런 현상이 발생할 수 있다.

착각하지 말자. 



Posted by '김용환'
,


top에서 특정 항목으로 소팅해서 보려면, Shift + F를 선택한다.


다음과 같은 화면이 보인다. 


만약 메모리 중심으로 보려면 n 을 선택하고 화면을 보면 메모리 단위로 소팅되어 있다. 



Posted by '김용환'
,

리눅스에서 특정 프로세스의 home directory를 찾는 방법이다.


1. ps -ef | grep {pid}를 이용하여 home directory를 추측하는 방법이다.


2. /etc/{pid}/environ 을 이용하는 방식이다.


grep 'PWD' /proc/30323/environ



Posted by '김용환'
,




grep 에 --mmap 옵션을 주면 속도가 확실히 빠르다.



$ time sh -c 'grep -r TestHelper .'

real    0m19.408s

user    0m13.106s

sys     0m2.628s




$ time sh -c 'grep --mmap -r TestHelper .'

real    0m12.923s

user    0m12.509s

sys     0m0.411s

Posted by '김용환'
,


리눅스 스크립트/명령어 실행 속도를 대략 체크하기 위해서는 date 명령어를 쓸 수 있다. 


$ date; sleep 5 ; date




더 detail한 실행 정보를 알려면 time 명령어로 확인하면 된다. 


$  time sh -c 'sleep 5'


real 0m5.004s

user 0m0.002s

sys 0m0.003s


Posted by '김용환'
,


expr을 이용해서 계산기처럼 쓸 수 있다. 


 $ expr 2 + 10

12


 $ expr 2 \* 10

20


$ expr 8 \/ 2

4


 $ expr 17 \% 5

2

Posted by '김용환'
,

https://github.com/0xAX/linux-insides/tree/master/Booting

Posted by '김용환'
,


ssh 암호 물어보지 않게, 그동안 ssh pub 공개키를 복사하는 작업을 일일이 해오던 나.

이제는 ssh-copy-id 명령어를 통해서 ssh pub 공개키를 이용해서 쉽게 복사할 수 있다. 


web1 서버 

[knight@web1 ~]$ ssh-copy-id knight@web2

knight@web2's password: 

id: cannot find name for group ID knight

Now try logging into the machine, with "ssh 'knight@ web2'", and check in:


  .ssh/authorized_keys


to make sure we haven't added extra keys that you weren't expecting.



web2 서버 


[knight@web2 ~]$ ls .ssh

authorized_keys



Posted by '김용환'
,



pip install ansible 실행시 다음의 에러가 발생했다.  


 clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]


clang: note: this will be a hard error (cannot be downgraded to a warning) in the future


error: command 'cc' failed with exit status 1



나는 xcode 5.1.1 을 사용하고 있다.


확인해보니. xcode 5.1부터 unknown argument는 c 컴파일에서 에러가 나도록 바뀌었다. 


https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Introduction/Introduction.html



Xcode 5.1 Release Notes

Compiler

  • The Apple LLVM compiler in Xcode 5.1 treats unrecognized command-line options as errors. This issue has been seen when building both Python native extensions and Ruby Gems, where some invalid compiler options are currently specified.

    Projects using invalid compiler options will need to be changed to remove those options. To help ease that transition, the compiler will temporarily accept an option to downgrade the error to a warning:

    -Wno-error=unused-command-line-argument-hard-error-in-future

    To workaround this issue, set the ARCHFLAGS environment variable to downgrade the error to a warning. For example, you can install a Python native extension with:

    $ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future easy_install ExtensionName

    Similarly, you can install a Ruby Gem with:

    $ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install GemName (16214764)



문서에 있는 대로 하니 설치가 된다. (directory, file permission 이슈는 알아서 해결해야 할 듯..)


  $ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install ansible




Posted by '김용환'
,

웹 서버 인증서보기 


$ openssl s_client -connect 1.1.1.1:8000 -showcerts </dev/null 2>/dev/null|openssl x509 -outform PEM




웹 서버 인증서 저장하기


$ openssl s_client -connect 1.1.1.1:8000 -showcerts </dev/null 2>/dev/null|openssl x509 -outform PEM > www.google.com.perm



Posted by '김용환'
,