以前一直都是用redhat5,redhat6也处于测试阶段,当然也遇到了很多奇奇怪怪的问题,比如之前写的一篇博客,当时候是用root启动了mysqld_unsafe,在mysql的QPS到1W以上后,会出现ERROR 1135 (HY000): Can’t create a new thread (errno 11); 当时候的解决办法是用mysql用户来启动就解决了问题。但因为在系统重启后,如果用sudo -u mysql来启动的话,脚本会被卡主。
这个问题今天得到了一个稍微深入一点的结论。
首先我们看看这个错误
view source
?
ERROR 1135 (HY000): Can’t create a new thread (errno 11);
ifyou are not out of available memory,
you can consult the manual fora possible OS-dependent bug
google类似Can’t create a new thread的错误后,得到的结论是文件描述符不够用,检查了vim /etc/security/limits.conf 的设置,是正常的 www.it1net
view source
?
vim /etc/security/limits.conf
得到的结果是
root soft nofile 65535
root hard nofile 65535
admin soft nofile 65535
admin hard nofile 65535
# End of file
mysql soft nproc 65536
mysql hard nproc 65536
mysql soft nofile 65535
mysql hard nofile 65535
但观察了sudo -u root bash -c " ulimit -a " 后,得到 max user processes (-u) 1024
view source
?
core filesize (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
filesize (blocks, -f) unlimited
pending signals (-i) 385957
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
openfiles (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-timepriority (-r) 0
stack size (kbytes, -s) 10240
cpu time(seconds, -t) unlimited
max user processes (-u) 1024
virtual memory (kbytes, -v) unlimited
filelocks (-x) unlimited
max user processes (-u) 1024 和 sudo -u root bash -c " ulimit -u " 一样,都是得到1024的结果
sudo -u root bash -c " ulimit -u "
1024
而在redhat5里面,只要在/etc/security/limits.conf 设置了root soft nofile 65535 和root hard nofile 65535,对应的uilmit -u 就会是655
和@维西v @tb天羽 搞了几个小时,依然没法成功修改root用户的 max user processes到65535 。后来发现了一篇文章 Know your limits (ulimits) ,提及到redhat6新增了/etc/security/limits.d/90-nproc.conf,里面的内容是
view source
?
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 1024
redhat6下面,root用户使用ulimit -u没法修改
* soft nproc 1024的意思是任何用户的最大max user processes为1024个,其他用户可以通过ulimit -u来修改 ,但root用户则修改不成功,我们这里看一个例子
view source
?
[yingyuan.ydh@my031226 ~]$ cat/etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 1024
[yingyuan.ydh@my031226 ~]$ ulimit-u
1024
[yingyuan.ydh@my031226 ~]$ ulimit-u 65535
[yingyuan.ydh@my031226 ~]$ ulimit-u
65535
[yingyuan.ydh@my031226 ~]$ sudo-uroot bash-c " ulimit -u 65535"
[yingyuan.ydh@my031226 ~]$ sudo-uroot bash-c " ulimit -u "
1024
很明显,在redhat6的/etc/security/limits.d/90-nproc.conf限制下,个人用户可以修改ulimit-u,但root用户没法修改。 解下来,我们把etc/security/limits.d/90-nproc.conf改掉,会看到root的ulimit -u 可以修改成功。
view source
?
[yingyuan.ydh@my031226 ~]$ sudo-uroot bash-c " ulimit -u 65535"
[yingyuan.ydh@my031226 ~]$ sudo-uroot bash-c " ulimit -u "
65535
[yingyuan.ydh@my031226 ~]$ cat/etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 65535
结果
在成功修改了root用户的max user processes后,继续使用root用户启动mysqld_safe脚本,稳定运行了一个下午,一切正常。