Foreword
Recently, a small partner to buy Tencent cloud of a nuclear 1G entry-level server, find the deployment of multi-service post, will be automatically stopped container some of the docker's.
Buy a new host does not provide Tencent cloud Swap partition, reason is often because the host memory usage is too high, frequent use Swap, resulting in disk IO is too high, but declined overall server performance.
Adding Swap However, users can still use the way Swap files partition.
Start swap partition
First with the free -m
view of the current situation partition, swap partition is displayed as 0
free -m
[root@VM_0_2_centos ~]# free -m
total used free shared buff/cache available
Mem: 3789 858 1579 0 1351 2638
Swap: 0 0 0
Create a new directory for the swap file, such as my directory / root / swap, create a file of a 2G
dd if=/dev/zero of=/root/swap bs=2048 count=1048576
[root@VM_0_2_centos ~]# dd if=/dev/zero of=/root/swap bs=2048 count=1048576
1048576+0 records in
1048576+0 records out
2147483648 bytes (2.1 GB) copied, 15.3681 s, 140 MB/s
This file is set to swap file
mkswap /root/swap
[root@VM_0_2_centos ~]# mkswap /root/swap
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=0d63d460-a558-4a60-9a7e-94e78be2dfc5
Modify the file permissions to 600
chmod 600 /root/swap
Enable swap file
swapon /root/swap
Boot from the start
Set boot from the start, you need to modify to modify the file / etc / fstab, add a line at the end /root/swap swap swap defaults 0 0
[root@VM_0_2_centos ~]# vi /etc/fstab
[root@VM_0_2_centos ~]# cat /etc/fstab
UUID=4b499d76-769a-40a0-93dc-4a31a59add28 / ext4 noatime,acl,user_xattr 1 1
proc /proc proc defaults 0 0
sysfs /sys sysfs noauto 0 0
debugfs /sys/kernel/debug debugfs noauto 0 0
devpts /dev/pts devpts mode=0620,gid=5 0 0
/swap swap swap defaults 0 0
/root/swap swap swap defaults 0 0
[root@VM_0_2_centos ~]#
Delete the swap partition
Delete the swap partition
swapoff /root/swap
rm -f /root/swap