centos服务器如何增加swap空间
因java加压包 耗费大量内存,且频率高,centos 服务器16G内存,完全被cached 占满。
[root@bogon home]# free
total used free shared buffers cached
Mem: 16315436 15693128 622308 64 103564 13778428
-/+ buffers/cache: 1811136 14504300
手动释命令
释放方法有三种(系统默认值是0,释放之后你可以再改回0值):
To free pagecache: echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes: echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches
手动释放后不能解决问题,且操作文件因cache被清,速度慢。
想到增加swap空间
[root@bogon home]# mkswap /home/swapfile
mkswap: /home/swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 33554428 KiB
no label, UUID=ab40acb5-66be-4b4c-b706-cd66629a9b27
[root@bogon home]# swapon /home/swapfile
[root@bogon home]# vim /etc/fstab
/home/swapfile swap swap defaults 0 0 ##添加到文件中
[root@bogon home]# mount -a
[root@bogon home]# free
total used free shared buffers cached
Mem: 16315436 15113992 1201444 64 101892 13707604
-/+ buffers/cache: 1304496 15010940
Swap: 41787384 64408 41722976
完成。