Apache가 AH00144에서 떨어졌기 때문에 해결한 이야기

심야에 프로덕션 시스템이 다운되었다는 연락이 있었다.

BtoB의 웹 서비스가 열리지 않는다! ! !
다음날 비즈니스 아워까지 고군분투로 해결해야 한다는 위가 아파지는 사안에 긴급 대처했기 때문에 그 정보 공유이다.

환경



Amazon EC2 Ubuntu 16.04에서 실행되는 웹 사이트.
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

$ apache2 -v
Server version: Apache/2.4.18 (Ubuntu)

오류 로그



서버에 로그인 해 보면 Apache가 오류를 토해 죽었습니다.
Fatal error라는 문자열을 보면 순식간에 술에 취해요.
$ tail /var/log/apache2/error.log
[Tue Aug 25 20:51:54.215281 2020] [mpm_prefork:emerg] [pid 930] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Tue Aug 25 20:51:54.215369 2020] [mpm_prefork:emerg] [pid 929] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Tue Aug 25 20:51:54.216849 2020] [mpm_prefork:emerg] [pid 933] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Tue Aug 25 20:51:54.217182 2020] [mpm_prefork:emerg] [pid 931] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Tue Aug 25 20:51:54.218350 2020] [mpm_prefork:emerg] [pid 928] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Tue Aug 25 20:51:54.218757 2020] [mpm_prefork:emerg] [pid 1336] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Tue Aug 25 20:51:55.040404 2020] [core:alert] [pid 1287] AH00050: Child 928 returned a Fatal error... Apache is exiting!
[Tue Aug 25 20:58:05.444208 2020] [mpm_prefork:emerg] [pid 1333] (22)Invalid argument: AH00146: couldn't release the accept mutex
AH00144: couldn't grab the accept mutex가 프로세스 수만큼 출력됩니다.

우선 AH00144로 구그 해 보면,
htps : // 히로세 31. 하테나 bぉg. jp/엔트리/2020/03/10/190010
라는 뛰어난 블로그를 발견!

이 환경에서도 여러 상황에 따라 비 시스템 사용자 (uid가 1000 이상)로 Apache를 시작했습니다.
재현 방법도 훌륭하게 일치하고 있다.

대처



절차는 간단합니다.

/etc/apache2/apache2.conf
#Mutex file:${APACHE_LOCK_DIR} default

의 코멘트를 제거하고 reboot했다.

혹은, /etc/apache2/conf-available/mutex-file.conf 같은 파일을 만들어, a2enconf mutex-file 라고 해도 좋을지도 모른다.

세마포어 확인



다음과 같이 대책 전후에서 아파치가 세마포어를 만들지 않았음을 확인할 수 있다면 정의는 반영된다.

대책 전
$ ipcs -a

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 0          root       644        80         2
0x00000000 32769      root       644        16384      2
0x00000000 65538      root       644        280        2

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x000000a7 0          root       600        1
0x00000000 131073     testuser   600        1
0x00000000 163842     testuser   600        1
0x00000000 98307      testuser   600        1

대책 후
$ ipcs -a

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 0          root       644        80         2
0x00000000 32769      root       644        16384      2
0x00000000 65538      root       644        280        2

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x000000a7 0          root       600        1

좋은 웹페이지 즐겨찾기