小内存虚拟主机上的MySql (MariaDB) 宕机原因

原文:

MySql (MariaDB) crashes on small RAM VPS, what to do

Recently I encountered one weird problem, my MariaDB database started to crash from time to time on one of my small RAM (512mb) virtual private servers. After some short googling I found out what what is potential problem with MariaDB on small RAM machines and how to fix it.

First of all, if you have this kind of problem, check MariaDB logs

tail -n 100 /var/log/mariadb/mariadb.log
you may find something like this:

160608 12:08:05 InnoDB: Completed initialization of buffer pool
160608 12:08:05 InnoDB: Fatal error: cannot allocate memory for the buffer pool
160608 12:08:05 [ERROR] Plugin 'InnoDB' init function returned error.
160608 12:08:05 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160608 12:08:05 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
After some research I figured out that mysql require a lot resources for performance schema, and disabling it will help on small memory machines. 

sudo vim /etc/my.cnf
add

performance_schema = off
to section

[mysqld]
To ensure that database server will restart on crash, on OS with Systemd like CentOS 7 you need to do following

Open following file for edit

sudo vim /etc/systemd/system/mariadb.service
and add following lines

.include /lib/systemd/system/mariadb.service

[Service]
Restart=always
RestartSec=3
Then you need to restart reload Systemd configuration

sudo systemctl daemon-reload
and restart MariaDB service

systemctl restart mariadb
To ensure that Systemd restarts service you can do following:

ps -ef|grep maria
You will see something like this

mysql 26647 26368 0 Jun12 ? 00:06:22 /usr/libexec/mysqld ....
Try to kill the process using

kill 26647
Wait 3 seconds and check if MariaDB started again

ps -ef|grep maria

链接自:

https://vedmant.com/mysql-mariadb-crashes-small-ram-vps/

转载于:https://www.cnblogs.com/leooys/p/8667936.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值