mysqld无法启动(php-fpm开启过多导致)

mysql数据库挂了,无法重启

$ service mysqld status
MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED]

$ service mysqld stop
MySQL server PID file could not be found! 

$ service mysqld start
Starting MySQL.The server quit without updating PID file (/[FAILED]er/data/iZwz9a0ptppx6qcloucmdrZ.pid).
[root@iZwz9a0ptppx6qcloucmdrZ subsys]# find / -name 'iZwz9a0ptppx6qcloucmdrZ.pid'

$ service mysqld restart
MySQL server PID file could not be found!                  [FAILED]
Starting MySQL.The server quit without updating PID file (/[FAILED]er/data/iZwz9a0ptppx6qcloucmdrZ.pid).

查看一下mysql报错日子

InnoDB: mmap(137363456 bytes) failed; errno 12
2020-05-17 22:47:14 25396 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2020-05-17 22:47:14 25396 [ERROR] Plugin 'InnoDB' init function returned error.
2020-05-17 22:47:14 25396 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-05-17 22:47:14 25396 [ERROR] Unknown/unsupported storage engine: InnoDB
2020-05-17 22:47:14 25396 [ERROR] Aborting

内存不足了,启动不了mysql,于是看一下原因,是什么导致内存不足

查看内存使用情况

free -m
             total       used       free     shared    buffers     cached
Mem:          3961       3627        333          0         60         33
-/+ buffers/cache:       3533        427
Swap:            0          0          0

剩下333M可用,肯定启动不了mysql

查看启动的php-fpm数量

ps -fe |grep "php-fpm"|grep "pool"|wc -l
143

平均一个php-fpm的内存消耗 0.5~1%,通常一个php-fpm为3M,但是随着内存的泄露后面会达到20~30M,所以一般开100个,可能就会消耗3G内存。

143-137

查看当前连接中的的php-fpm

netstat -anp|grep "php-fpm"|grep "tcp"|grep "pool"|wc -l
0

修改php-fpm.conf的配置

[global]
pid = /www/server/php/56/var/run/php-fpm.pid
error_log = /www/server/php/56/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi-56.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.status_path = /phpfpm_56_status
pm.max_children = 1000
pm.start_servers = 40
pm.min_spare_servers = 40
pm.max_spare_servers = 300
request_terminate_timeout = 2000
request_slowlog_timeout = 30
slowlog = var/log/slow.log
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 25
request_terminate_timeout = 300
request_slowlog_timeout = 30
slowlog = var/log/slow.log

重启php-fpm

service php-fpm restart
service mysqld start
Starting MySQL..                                           [  OK  ]

内存释放了,重新启动php-fpm
再启动mysql,解决正常启动

你可能感兴趣的:(mysql,centos,mysql,centos)