最近一个月博客经常性出现无法连接到mysql,查日志是因为内存不足(1G内存)。所以想到用交换分区。
默认阿里云是没有交换分区的,估计是因为交换分区会影响磁盘IO。
[root@www ~]# free -m total used free shared buff/cache available Mem: 3790 2530 115 34 1145 953 Swap: 0 0 0
# 创建一个交换分区
[root@www ~]# dd if=/dev/zero of=/swap bs=1M count=1024 [root@www ~]# mkswap -f /swap
# 设置权限,否则 swapon 会提示 insecure permissions
[root@www ~]# chmod 600 /swap [root@www ~]# swapon /swap
# 设置开机自动挂载交换分区
[root@www ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Mon May 8 03:33:12 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=41b13286-90d7-4c0f-9afb-ba92382eda59 / ext4 defaults 1 1 /swap swap swap defaults 0 0
这几天就再也没出现过连不上mysql的情况。
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3985.html