最近总是发现站点的数据库老是连接不上,后台一块mysql已经关闭了。启动之后网站正常,但是没过几天又关闭了。
后台看mysql日志发现
2020-05-15T01:54:14.834812Z 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2020-05-15T01:54:14.834913Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2020-05-15T01:54:14.834931Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2020-05-15T01:54:14.834943Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2020-05-15T01:54:14.834979Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2020-05-15T01:54:14.840553Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-05-15T01:54:14.840582Z 0 [ERROR] Failed to initialize builtin plugins.
2020-05-15T01:54:14.840590Z 0 [ERROR] Aborting
2020-05-15T01:54:14.840606Z 0 [Note] Binlog end
2020-05-15T01:54:14.840796Z 0 [Note] Shutting down plugin 'CSV'
2020-05-15T01:54:14.845828Z 0 [Note] /www/server/mysql/bin/mysqld: Shutdown complete
百度一下,看到了好像是swap问题
ssh登录,free,查看内存
$ free
total used free shared buffers cached
Mem: 608476 565044 43432 0 1284 53996
-/+ buffers/cache: 509764 98712
Swap: 0 0 0
swap问题。适当增加swap容量
用文件作为Swap分区
1.创建要作为swap分区的文件:增加1GB大小的交换分区(原理的swap分区不变),则命令写法如下,其中的count等于想要的块的数量(bs*count=文件大小)。
# dd if=/dev/zero of=/root/swapfile bs=1M count=1024
2.格式化为交换分区文件:
# mkswap /root/swapfile #建立swap的文件系统
3.启用交换分区文件:
# swapon /root/swapfile #启用swap文件
4.使系统开机时自启用,在文件/etc/fstab中添加一行:
nano /etc/fstab
/root/swapfile swap swap defaults 0 0
观察一段时间看看情况
评论0