LoginSignup
3
3

More than 3 years have passed since last update.

ApacheがAH00144で落ちていたので対処した話

Last updated at Posted at 2020-08-26

深夜に、本番システムがダウンしているという連絡があった。
image.png
BtoBのWebサービスが開けなくなっている!!!
翌日のビジネスアワーまでに孤軍奮闘で解決しなくてはならないという、胃が痛くなる事案に緊急対処したので、その情報共有である。

環境

Amazon EC2 の Ubuntu 16.04 で稼働するWebサイト。

$ 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 でググってみると、
https://hirose31.hatenablog.jp/entry/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としても良いかもしれない。

セマフォの確認

次の通り、対策前後で、Apacheがセマフォを作っていないことを確認できれば、定義は反映されている。

対策前
$ 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
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3