[步骤] Linux 虚拟内存 (交换分区) swap 的设置

步骤一:理解 Linux 虚拟内存 (交换分区) swap 使用优先级的设置机制

Linux 的 swappiness 参数用于控制虚拟内存 (交换分区) swap 的使用。
swappiness 参数的默认值是 60,也就是说当物理内存使用率达到 40 时,开始使用虚拟内存 (交换分区) swap。
当 swappiness 参数的值是 0 时,则只有当物理机内存耗尽了以后才会使用虚拟内存 (交换分区) swap。
当 swappiness 参数的值是 100 时,则立刻使用虚拟内存 (交换分区) swap。

步骤二:Linux 虚拟内存 (交换分区) swap 开关的设置

2.1 查看虚拟内存 (交换分区) swap

# swapon -s

2.2 开启虚拟内存 (交换分区) swap

# swapon -a

2.3 关闭虚拟内存 (交换分区) swap

# swapoff -a

2.4 重启虚拟内存 (交换分区) swap

# swapoff -a && swapon -a

步骤三:Linux 虚拟内存 (交换分区) swap 使用优先级的设置

3.1 临时设置虚拟内存 (交换分区) swap 使用优先级的设置

# sysctl -p swappiness=60

或者:

# sysctl vm.swappiness=60

或者:

# echo 60 > /proc/sys/vm/swappiness

(补充:这里以把 swappiness 的值设置成 60 为例)


注意:
1) 临时设置重启后失效
2) 临时设置了以后不会马上生效,只有当系统重新调用内存以后才会生效

3.2 永久设置虚拟内存 (交换分区) swap 使用优先级的设置

3.2.1 修改 /etc/sysctl.conf 文件
# vim /etc/sysctl.conf

添加以下内容:

......
vm.swappiness=60

(补充:这里以把 swappiness 的值设置成 60 为例)

3.2.2 让刚刚修改的 /etc/sysctl.conf 文件生效
# sysctl -p

3.3 查看虚拟内存 (交换分区) swap 使用优先级的设置

3.3.1 通过 /proc/sys/vm/swappiness 文件查看
# cat /proc/sys/vm/swappiness
3.3.2 通过 sysctl vm.swappiness 命令查看
# sysctl vm.swappiness

Several situations of Linux automatically reboot without reboot logs in the /var/log/messages

Situation One

This Linux server is a virtual server. If we reboot it though its virtual software, there is no relevant logs in the /var/log/messages.

Situation Two

This Linux server is a member of a pacemaker cluster. If the pacemaker cluster software fences this server for protecting the whole cluster, there is no relate logs in the /var/log/messages.

Situation Three

This Linux server has critical problems in its system or hardware. Core panic of Linux and hardware problem both can reboot the system automatically without any reboot logs in the /var/log/messages.