收到告警:
Problem!!bohai8.8.8.64:3306
MySQL is Down,error nu:1135,err_msg:Can't create a new thread (errno 11); if you are not out
of available memory, you can consult the manual for a possible OS-dependent bug,12-01 01:30 主库!
Problem!!bohai8.8.8.28:3306
MySQL is Down,error nu:1135,err_msg:Can't create a new thread (errno 11); if you are not out
of available memory, you can consult the manual for a possible OS-dependent bug,12-01 02:02 从库!
检查mysql服务并没有down
# ps aux|grep mysqld
root 24576 0.0 0.0 106232 1396 ? S 2015 0:00 /bin/sh /opt/bohai/mysql/bin/mysqld_safe --defaults-file=my.cnf
mysql 25307 89.9 57.7 58814948 38004792 ? Sl 2015 1097429:30 /opt/bohai/mysql/bin/mysqld
--defaults-file=my.cnf --basedir=/opt/bohai/mysql --datadir=/database/mysql/data --plugin-dir=/opt/bohai/mysql/lib/plugin
--user=mysql --log-error=/database/mysql/data/error-log.err --pid-file=/database/mysql/data/mysqld.pid --socket=/opt/bohai/mysql/mysql.sock --port=3306
mysql> show variables like '%conn%';
+-----------------------------------------------+-----------------+
| Variable_name | Value |
+-----------------------------------------------+-----------------+
| max_connections | 6000 |
| max_user_connections | 3500 |
查看当前连接数:







查看Linux每个用户的最大processes数量
# ulimit -u
5000
可以从上面看出,用来限制max user processes的数量的。
但是这个user processes是什么呢?
Linux itself has a Max Processes per user limit. This feature allows us to control the number of processes an existing user on the server may be authorized to have
这个ulimit -u是用来限制每个用户的最大processes数量。如果ulimit -u进行了限制那么每个linux用户可以派生出来的process就会被限制再这个数值之内。
# ulimit -a
max user processes (-u) 5000
查看mysql 进程连接数量
# ps -eLf |grep mysql|wc -l
5473 已经超过5000
原因分析:
xxx瞬间几次把操作系统的最大连接数占满了,后来改了mysql进程的mysql用户连接数好了
昨天xxx上了很多新代码
连接数高峰大于5000,临时改变操作系统用户连接上限解决问题
# cat /database/mysql/data/mysqld.pid
25307
[[email protected] bohai]# cat /proc/25307/limits
Limit Soft Limit Hard Limit Units
Max processes 5000 5000 processes
Max open files 65535 65535 files
调整参数:
echo -n 'Max processes=6000:6000' > /proc/25307/limits
这个参数需要在mysqld启动之前调整,如果mysqld已经启动,再动态调整是无效的。(大家都知道stop start mysql是一件比较麻烦的事情,涉及线上业务就更麻烦了)
那么,有没有可以动态调整的方法呢?
echo -n ‘Max processes=SOFT_LIMITS:HARD_LIMITS’ > /proc/`pidof mysqld`/limits //例 echo -n 'Max processes=10240:10240' > /proc/`8779/limits
通过如上命令就可以动态调整已经存在的mysqld的processes限制了。
修改后:
# cat /proc/25307/limits
Limit Soft Limit Hard Limit Units
Max processes 6000 6000 processes
Max open files 65535 65535 files
之前应用链接mysql不进来,报错也是这样处理的。
更多请查褚霸的这篇blog