"lack of free swap space"告警处理,自动挂载swap

"lack of free swap space"告警处理,自动挂载swap

[[email protected] ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           991M        636M        199M         47M        155M        174M
Swap:            0B          0B          0B
[[email protected] ~]# dd if=/dev/zero of=/tmp/vmfile bs=2M count=1024
1024+0 records in
1024+0 records out
2147483648 bytes (2.1 GB) copied, 39.5264 s, 54.3 MB/s
[[email protected] ~]# du -sh /tmp/vmfile 
2.1G    /tmp/vmfile

[[email protected] ~]# mkswap -f /tmp/vmfile 
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=28904d6d-29e8-4932-8ec2-f9c038fab25c

[[email protected] ~]# swapon /tmp/vmfile
swapon: /tmp/vmfile: insecure permissions 0644, 0600 suggested.
[[email protected] ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           991M        637M         66M         47M        287M        151M
Swap:          2.0G          0B        2.0G
[[email protected] ~]# 
[[email protected] ~]# vi /etc/fstab
/tmp/vmfile swap swap defaults 0 0

此时zabbix上的告警显示“已解决”

但是当reboot后,swap又消失了,告警再次出现

[[email protected] ~]# swapon -a	#重读/etc/fstab文件,使新swap分区挂载
swapon: /tmp/vmfile: insecure permissions 0644, 0600 suggested.
[[email protected] ~]# swapon -s
Filename                                Type            Size    Used    Priority
/tmp/vmfile                             file    2097148 0       -1

但解决不了reboot后不自动挂载

  • 解决办法如下
[[email protected] ~]# vi /etc/rc.d/rc.local 
/usr/sbin/swapon /tmp/vmfile

当在reboot后,swap将自动挂载成功

[[email protected] ~]# reboot

Last login: Sat Oct 13 15:26:03 2018 from 49.80.240.5
[[email protected] ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           991M        471M        162M         26M        358M        337M
Swap:          2.0G          0B        2.0G
[[email protected] ~]# 

"lack of free swap space"告警处理,自动挂载swap