The blog added 50X monitor Restart script, finally to 502 and 504 errors have some control, but today there is a friend response to the "Database connection error" information, by troubleshooting Kern.log, found the following information,
8 02:01:05 Vmvps kernel: [232387.072765] out of Memory:kill process 1896 (mysqld) score 265 or sacrifice child
8 02:01:05 Vmvps kernel: [232387.093931] killed process 1896 (mysqld) total-vm:966156kb, ANON-RSS:134124KB, File-rss: 0kB
Obviously, because the memory is not enough, so Linux killed the MySQL process. Of course, restart the natural will be solved, but "symptoms do not cure."
The micro-demon thought for a moment and decided on an "unwise decision", hoping to be of some help to the 512M configuration of Aliyun. Why do you call it "unwise"? It is mainly because of the reading speed: physical memory >swap partition >swap file; The way this article creates the swap file is the next step, but the benefits are obvious and no additional zoning is required.
By the way Aliyun this 512M package configuration, memory on the real enough, I hope you start with a lot of caution, in fact, memory is not expensive ...
Add swap files for VPS (available for Aliyun)
1. Create a swap file (two methods, recommend the former, because it will be slow to create with DD!) )
Fallocate-l 1024m/swapfile
Or
DD If=/dev/zero of=/swapfile bs=1m count=1024
2. Set Swap permissions
chmod 600/swapfile
3. format file as Swap
Mkswap/swapfile
4. Activate swap file
Swapon/swapfile
5. Edit the/etc/fstab file to automatically mount the swap file after the system restarts
/swapfile None swap defaults 0 0
You can test it with free-m.
Before creating swap
Total used free shared buffers Cached
mem:494 488 6 21 51 208
-/+ buffers/cache:227 267
swap:0 0 0
After you create a swap
Total used free shared buffers Cached
mem:494 483 11 21 68 96
-/+ buffers/cache:318 176
swap:1023 0 1023
Delete a swap file
1. Turn off swap
Swapoff-a
2. Delete the swap file
Rm-f/swapfile
This method has no use of the micro-demon is still in the state of onlookers, the visual of a long time swap did not occupy, the specific effect of the future and you share it ~
Updated January 9, 2015
Increase the use level of swap
After the enthusiastic tips of the downstairs netizens
1. View the current system use Swap level (0-100), 0 means that only when the last resort will use swap, and 100 will often use swap
Cat/proc/sys/vm/swappiness
The number returned by the micro-demon is 0, which is why it says swap is not used.
2. Set Swap usage level (10 for example)
Sysctl vm.swappiness=10
3. Set the Power-on automatic setting
modifying/etc/sysctl.conf files
vm.swappiness=10