centos 6.x max process 값 튜닝 for mysql
centos 6.4 에서 ulimit 으로 인한 max connection 에러가 발생해서
확인한 부분 공유 드립니다.
( 대부분 아시는 내용일텐데 cent 6.4 에서 max user process default 설정이 조금 변경되어서 헤메었던 상황이라 공유 드립니다. ㅎ)
일단 제가 잘못 알고 있었던 부분은 mysql 이 multi thread 기반이라 max connection 에 영향을 주는 os limit 이 nofile 만 인 걸로 생각했었는데
noproc 도 영향을 받네요…
그리고 cent6.4 에서 root를 제외한 계정의 noproc soft limit default 가 1024 이고
/etc/security/limits.d/90-nproc.conf 라는 파일에 아래와 같이 default 로 설정 되어 있습니다.
그래서 cent 5.x 에서 하듯이 /etc/security/limits.conf 에 설정을 해도 nproc soft limit 은 계속 1024 로
변경이 되지 않았습니다.
( 운영시 설정 변경할 때 limits.d 아래에 파일을 만들어서 6.4 방식으로 하던지 아니면 없애고
/etc/security/limits.conf 파일에 설정하던지 해야 할 거 같습니다. )
아래 보면 root는 unlimited 이지만 그외 계정들은 1024 이기 때문에 mysqld 까지 root 로 띄우지 않으면
1024 의 제한을 받게 됩니다.
[root@testvm2 limits.d]# pwd /etc/security/limits.d [root@testvm2 limits.d]# ls -lrt total 4 -rw-r--r--. 1 root root 191 Feb 22 2013 90-nproc.conf [root@testvm2 limits.d]# cat 90-nproc.conf # Default limit for number of user's processes to prevent # accidental fork bombs. # See rhbz #432903 for reasoning. * soft nproc 1024 root soft nproc unlimited |
##### limit 변경 전
1) Mysqld 의 pid 확인
[svcop@y-db01 ~]$ ps -ef | grep mysql
root 5392 1 0 2013 ? 00:00:00 /bin/sh /usr1/mariadb/5.5.34/bin/mysqld_safe --datadir=/usr1/mariadb/DBSpace_y-db01/DATA --pid-file=/tmp/mysqld.pid
mysql 6549 5392 0 2013 ? 00:55:27 /usr1/mariadb/5.5.34/bin/mysqld --basedir=/usr1/mariadb/5.5.34 --datadir=/usr1/mariadb/DBSpace_y-db01/DATA --plugin-dir=/usr1/mariadb/5.5.34/lib/plugin --user=mysql --log-error=/usr1/mariadb/5.5.34/admin/log/error.log --open-files-limit=40960 --pid-file=/tmp/mysqld.pid --socket=/tmp/mysql.sock --port=19336
svcop 17215 17149 0 09:59 pts/1 00:00:00 grep mysql
2) 해당 process 의 limit 확인
[root@y-db01 ~]# cat /proc/6549/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 10485760 unlimited bytes
Max core file size 0 0 bytes
Max resident set unlimited unlimited bytes
Max processes 1024 unlimited processes <---------- soft limit이 1024로 되어 있음
Max open files 50005 50005 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 255493 255493 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
3) Mysql connection 테스트
- 1024 개 이상으로 connection 시도
- Error 발생
[root@y-db01 ~]# mysql -u root -p
Enter password:
ERROR 1135 (HY000): 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
4) Connection 에러 발생시에 Mysql process 개수 확인
[root@y-db01 ~]# pstree
init─┬─agetty
├─auditd───{auditd}
├─crond
├─dbus-daemon
├─2*[dhclient]
├─6*[mingetty]
├─mysqld_safe───mysqld───1023*[{mysqld}]
├─nmon
├─ntpd
├─rsyslogd───3*[{rsyslogd}]
├─snmpd
├─sshd─┬─sshd───sshd───bash───sudo───su───bash───tail
│ └─sshd───sshd───bash───sudo───su───bash───pstree
├─udevd───2*[udevd]
└─xe-daemon───sleep
### Noproc Limit 변경
- /etc/security/limits.d/90-nproc.conf 파일 삭제
- /etc/security/limits.conf 에 설정
* soft nproc unlimited * hard nproc unlimited * soft nofile 65536 * hard nofile 65536 * soft fsize unlimited * hard fsize unlimited * soft stack unlimited * hard stack unlimited |
5) Mysqld 재시작
service mysqld stop
service mysqld start
6) Limit 정상 적용 여부 확인
[root@y-db01 log]# ps -ef | grep mysql
root 2999 1 0 11:08 pts/0 00:00:00 /bin/sh /usr1/mariadb/5.5.34/bin/mysqld_safe --datadir=/usr1/mariadb/DBSpace_y-db01/DATA --pid-file=/tmp/mysqld.pid
mysql 4144 2999 3 11:08 pts/0 00:00:04 /usr1/mariadb/5.5.34/bin/mysqld --basedir=/usr1/mariadb/5.5.34 --datadir=/usr1/mariadb/DBSpace_y-db01/DATA --plugin-dir=/usr1/mariadb/5.5.34/lib/plugin --user=mysql --log-error=/usr1/mariadb/5.5.34/admin/log/error.log --open-files-limit=40960 --pid-file=/tmp/mysqld.pid --socket=/tmp/mysql.sock --port=19336
root 4265 32576 0 11:10 pts/0 00:00:00 grep mysql
[root@y-db01 log]# cat /proc/4144/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size unlimited unlimited bytes
Max core file size 0 0 bytes
Max resident set unlimited unlimited bytes
Max processes unlimited unlimited processes ß----- 변경 되었음 …
Max open files 50005 50005 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 255493 255493 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
7) Mysql connection test 이상 없음
이 작성자의 게시글더보기
|
- 2014/01/16 10:47
예전에 Cent6에서 이 문제로 커넥션이 1000개 이상 못갔었던 기억이 나네요. ^^ㅋ
진짜로 MySQL 데몬한테 적용이 되었는지는 아래로 한 방에 확인할 수 있어요. ㅎ
ps -u mysql | grep mysql | awk '{print $1}' | xargs -i cat /proc/{}/limits - 2014/02/13 22:55
sudo su -
cat /proc/`ps -ef | grep mysql | grep port | awk -F' ' '{print $2}'`/limits
cat /etc/security/limits.d/90-nproc.conf
vi /etc/security/limits.d/90-nproc.conf
================================================================================
...
* - nofile 65536
* - nproc unlimited
================================================================================
cat /etc/security/limits.d/90-nproc.conf
sudo su - mysql
service mysqld restart
cat /proc/`ps -ef | grep mysql | grep port | awk -F' ' '{print $2}'`/limits
pstree