今天用了一下探针,意外的发现服务器swap占用为0,因为开的docker挂上了一个基岩服务器,只要有人玩就会占用70%~80%,对我来说这是很危险的,因为上次有开了clouddreve后几天突然宕机的惨痛教训。

首先查看/etc/sysctl.conf里的配置

cat /etc/sysctl.conf
[root@Hangzhou ~]# cat /etc/sysctl.conf
vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time=120

# see details in https://help.aliyun.com/knowledge_detail/39428.html
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_announce=2

# see details in https://help.aliyun.com/knowledge_detail/41334.html
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

kernel.sysrq=1

忽然发现,根本没写物理内存占用到多少开始使用swap,默认应该60%的,也就是应该有个vm.swappiness参数写着60 ,可是我还真的没看见.....(阿里云骚操作+1 ,也许是为了使用更流畅吧......

查看当前vm.swappiness的设置是怎么样的

[root@Hangzhou ~]# sysctl -q vm.swappiness
vm.swappiness = 0

不出意外还真的是0......
如果vm.swappiness = 0 ,系统会不使用swap(我就不喝水,除非要渴死了 ~哼╭(╯^╰)╮~)。
接下来就是修改了
vim /etc/sysctl.conf ,既然没写,那就手动加上vm.swappiness = 90,也就是物理内存占用到90%就开始用swap分担内存需求压力。写个0我怕再用Cloudreve还会宕机,但是也要尽可能利用闪存,毕竟比swap快多了。
接下来reboot

[root@Hangzhou ~]# sysctl -q vm.swappiness
vm.swappiness = 90

问题解决(^▽^)

标签: none

已有 2 条评论

  1. swappiness document

    Overrides /proc/sys/vm/swappiness for the particular group. The tunable in the root cgroup corresponds to the global swappiness setting.

    Please note that unlike during the global reclaim, limit reclaim enforces that 0 swappiness really prevents from any swapping even if there is a swap storage available. This might lead to memcg OOM killer if there are no file pages to reclaim.

    vm.swappiness=0 时是根本不用。

添加新评论