linux 스왑(swap) 늘리기

AWS를 이용중인 이 사이트를 최근에는 사용하기가 너무 힘들어 이것 저것 확인하던중 dmesg 에 아래와 같은 내용이 있는것을 확인.

[39212299.946048] Out of memory: Kill process 16823 (apache2) score 121 or sacrifice child
[39212299.946065] Killed process 16823 (apache2) total-vm:296504kB, anon-rss:73084kB, file-rss:0kB

가끔씩 mysql도 죽고하던 것이 생각났고, 위메시지를 보면, out of memory도 나고해서 메모리 사용량 확인.

# free -m
             total       used       free     shared    buffers     cached
Mem:           590        573         16          0          2         55
-/+ buffers/cache:        515         74
Swap:            0          0          0

swap이 하나도 없으므로, swap을 늘려보기로했다.
이미지 화일을 하나 만든다.

# dd if=/dev/zero of=/swap_file.img bs=1024k count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 15.3271 s, 35.0 MB/s

만든 이미지 화일을 swap으로 만든다.

# mkswap /swap_file.img
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=f85b6540-8374-408e-a38d-92baccf26a02

만든 swap을 추가하고 확인한다.

# swapon /swap_file.img
# free -m
             total       used       free     shared    buffers     cached
Mem:           590        574         15          0          3         56
-/+ buffers/cache:        515         74
Swap:          511          0        511

재부팅해도 문제 없도록 /etc/fstab 에 만든 swap화일을 등록한다.

# vi /etc/fstab
/swap_file.img          none    swap    sw              0 0

답글 남기기

Your email address will not be published.