클라우드플레어 무료 플랜을 사용중입니다.
서버는 단독서버이며 우분투18.04 nginx php7.0 innodb 가 돌아가고 있습니다.
서버상에 사이트가 4개가 돌아가며 4개의 전체접속자는 일방문 5만이 안되는 유머사이트들입니다.
며칠전 매월 서버비용을 감당할 수 없어 사이트를 서버 하나로 모두 모아 이전하였습니다.
오늘 오후부터 사이트 접속을 하니 nginx 500에러와 클라우드플레어 502 bad gateway가 뜨면서 에러가 나네요.
nginx 에러로그는 아래처럼 초당 로그를 찍어내고
24: Too many open files 관련하여 해결법들을
https://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/
위 처럼 적용해도 해결이 되지 않습니다.
2020/01/08 17:16:25 [crit] 2297#2297: accept4() failed (24: Too many open files)
2020/01/08 17:16:25 [crit] 2302#2302: accept4() failed (24: Too many open files)
2020/01/08 17:16:25 [crit] 2299#2299: accept4() failed (24: Too many open files)
2020/01/08 17:16:25 [crit] 2305#2305: accept4() failed (24: Too many open files)
2020/01/08 17:16:25 [crit] 2303#2303: accept4() failed (24: Too many open files)
2020/01/08 17:16:25 [crit] 2304#2304: accept4() failed (24: Too many open files)
2020/01/08 17:16:25 [crit] 2301#2301: accept4() failed (24: Too many open files)
2020/01/08 17:16:25 [crit] 2300#2300: accept4() failed (24: Too many open files)
2020/01/08 17:16:28 [crit] 2300#2300: accept4() failed (24: Too many open files)
2020/01/08 17:16:28 [crit] 2301#2301: accept4() failed (24: Too many open files)
2020/01/08 17:16:29 [crit] 2304#2304: accept4() failed (24: Too many open files)
그래서 혹시나 해서 가장 접속자가 많은 사이트를
클라우드플레어쪽에 디도스방어기능으로 5초이후 접속하는 기능을 온 했더니
다른곳 다 사이트 접속과 글읽기등이 문제없이 되네요.
php7.0-fpm.log 로그입니다.
[08-Jan-2020 17:24:59] WARNING: [pool tab10] server reached pm.max_children setting (50), consider raising it
[08-Jan-2020 17:26:59] WARNING: [pool tab10] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 42 total children
[08-Jan-2020 17:27:00] WARNING: [pool tab10] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 47 total children
[08-Jan-2020 17:27:01] WARNING: [pool tab10] server reached pm.max_children setting (50), consider raising it
[08-Jan-2020 17:27:46] WARNING: [pool tab10] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 42 total children
[08-Jan-2020 17:27:47] WARNING: [pool tab10] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 47 total children
[08-Jan-2020 17:27:48] WARNING: [pool tab10] server reached pm.max_children setting (50), consider raising it
[08-Jan-2020 17:29:27] WARNING: [pool tab10] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 42 total children
[08-Jan-2020 17:29:28] WARNING: [pool tab10] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 47 total children
[08-Jan-2020 17:29:29] WARNING: [pool tab10] server reached pm.max_children setting (50), consider raising it
서버사양이며 Xeon E3-1246v3
메모리 16 GB
하드 240 GB SSD
대역폭 50 TB - 1 Gbps
아래는 php pool.d 설정파일 입니다. 서버 내 4개의 사이트 모두 동일한 설정을 줬습니다.
[tab10]
user = tab10
group = tab10
listen = /run/php/tab10.sock
listen.owner = tab10
listen.group = www-data
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
php_admin_value[session.cookie_httponly] = 1
php_admin_value[session.use_strict_mode] = 1
; save std error to /var/log/php7.3-fpm.log
catch_workers_output = yes
; save slow process
slowlog = /var/log/php-fpm.tab10.slow.log
request_slowlog_timeout = 10
; php only timeout
php_admin_value[max_execution_time] = 30
; all timeout (php+mysql+exec+fopen+...) (use it carefully.)
;request_terminate_timeout = 90
;php_admin_value[post_max_size] = 25M
;php_admin_value[upload_max_filesize] = 25M
;php_admin_value[session.name] = "MY_SESSION_ID"
;php_value[session.save_path] = /home/myuser1/.php-session
;access.log = /var/log/php-fpm.tab10.access.log
;access.format = "%t %{REMOTE_ADDR}e \"%m %r%Q%q\" %s %f TIME:%{mili}dms MEM:%{kilo}MK CPU:%C%%"
;php_admin_flag[log_errors] = on
;php_admin_value[error_log] = /var/log/php-fpm.tab10.error.log
;php_admin_value[memory_limit] = 128M
;php_admin_value[max_input_time] = 90
my.cnf 설정파일 일부입니다.
# * Fine Tuning
#
max_connections = 2048
connect_timeout = 200
wait_timeout = 300
max_allowed_packet = 16M
thread_cache_size = 128
sort_buffer_size = 4M
bulk_insert_buffer_size = 16M
tmp_table_size = 32M
max_heap_table_size = 32M
transaction-isolation = READ-COMMITTED
# * MyISAM
#
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched. On error, make copy and try a repair.
myisam_recover_options = BACKUP
key_buffer_size = 128M
#open-files-limit = 2000
table_open_cache = 400
myisam_sort_buffer_size = 512M
concurrent_insert = 2
read_buffer_size = 2M
read_rnd_buffer_size = 1M
default_storage_engine = InnoDB
innodb_buffer_pool_size = 12G
innodb_log_buffer_size = 256M
innodb_file_per_table = 1
innodb_open_files = 800
innodb_io_capacity = 1000
innodb_flush_method = O_DIRECT
Xeon E3-1246v3
메모리 16 GB
하드 240 GB SSD
대역폭 50 TB - 1 Gbps
위 서버의 사양으로 일접속자 500명에서 3만명까지 토탈 일 4만정도의
사이트를 4개 돌리고 있습니다. (php 설정 모두 동일하게 각각의 conf파일)
클라우드플레어의 디도스어택 페이지를 실행하면 우선 에러는 멈추는데요.
이것이 서버세팅의 문제인지, 한서버에 과도하게 많은 사이트를 운영중인건지
실제 디도스공격인건지가 좀 궁금합니다. 해결책이 있을지도요...
free -m 결과입니다. (서버구매시는 16기가로 적혀있었는데 32기가인거 같네요;;)
total used free shared buff/cache available
Mem: 32127 2395 23041 24 6690 29253
Swap: 7811 0 7811
일단 nginx 에러이므로 php-fpm이나 my.cnf 쪽은 보실 필요 없습니다. (pm.max_children을 늘리라는 메시지는 무시하는 것이 정석입니다.)
링크하신 글은 10년 전에 작성된 것이어서 우분투 18.04 버전의 systemd 환경에 맞지 않고, 편집하라고 하는 설정파일 경로들도 모두 틀린 것 같습니다. 2018년 이후에 작성된 자료를 찾아보셔야 할 거예요. 리눅스는 종류별 버전별 차이가 크기 때문에, 사용하시는 특정 버전을 위해 작성된 튜토리얼 외에는 모두 패스하셔야 합니다.
그것과 무관하게, 클플에서 I'm under attack 모드를 켰더니 문제가 해결되었다면 인간이 아닌 접속자가 꽤 많이 들어와서 문제를 일으키고 있다는 뜻일 수도 있습니다. 누군가가 님 사이트의 유머글을 긁어가고 있거나, 쓸데없는 검색로봇들이 많거나... 디도스는 아닙니다. 만약 디도스라면 에러화면도 안 뜨고 그냥 뻗습니다.