前几天,在管理系统的时候遇到一个奇怪的问题, 今天才有机会安装好MySQL环境来重现此问题,由于不是最原始的环境, 所以未必能够完全重现, 我只能努力重现关键问题了.. 我觉得此问题有点特别, 故在此大概的回想下当时的情景..
工作时, 执行了一个su – mysql 的命令, 遇到了下面这样一个错误..
[root@dbmain ~]# su - mysql
su: cannot set user id: Resource temporarily unavailable
- 1.
- 2.
这是一个Shell中由于资源不足引起的问题, 当时下意识的先运行ulimit,看看ulimit的基本限制.
[root@dbmain ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 25600
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 25600
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
又看了看,/etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft memlock 12582912
oracle hard memlock 12582912
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft memlock 12582912
grid hard memlock 12582912
mysql soft nproc 500
mysql hard nproc 500
mysql soft nofile 1024
mysql hard nofile 65536
mysql soft memlock 12582912
mysql hard memlock 12582912
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
经过分析,怀疑也只有process/file这两个出现资源紧张的概率比较大.. 因此就先ps -ef 看系统中该用户的进程数量..
[root@dbmain ~]# ps -ef | grep mysql
root 4733 1 0 10:30 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/dbmain.pid
mysql 4788 4733 0 10:30 ? 00:00:04 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --log-error=/var/lib/mysql/dbmain.err --pid-file=/var/lib/mysql/dbmain.pid
root 15171 17507 0 13:26 pts/2 00:00:00 mysql -uroot -p
root 20792 17163 0 15:30 pts/1 00:00:00 grep mysql
- 1.
- 2.
- 3.
- 4.
- 5.
从这个输出,,我们暂时排除nproc超标的可能性.
由此, 就根据此进程的pid进入其proc目录查看当前打开的文件数量..
发现有大量socket的文件连接.. 但是其数量远远未达到文件数的限制, 由此怀疑可能是MySQL的线程也会消耗掉Linux系统的nproc基数, 因此尝试调整/etc/security/limits.conf文件的nproc参数的值.
发现调整过后, su – mysql 确实可以成功执行了,,后面又将此参数改回, 重新执行su – mysql,,此问题又再次重现..由此确认,,使用MySQL的系统, 在设置MySQL的参数max_connections之外, 还需要考虑设置/etc/security/limits.conf文件的大小, MySQL是线程模式执行的, 其线程数也会被统计在nproc中, 这可能掩盖或造成对此问题的误判..
【编辑推荐】