小內存虛擬主機上的MySql (MariaDB) 宕機緣由

原文:mysql

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

sql

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.vim

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

tail -n 100 /var/log/mariadb/mariadb.log
you may find something like this: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. rest

sudo vim /etc/my.cnf
addorm

performance_schema = off
to sectionserver

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

Open following file for editit

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/

相關文章
相關標籤/搜索