3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

備忘録 なぜ、昨日Apacheの自動起動に失敗したのか?

Posted at

昨日、備忘録 PostgreSQL/Tomcat/Apacheを順番に自動起動というのを書きましたが、そもそもなぜApacheは自動起動に失敗したのか?
少し考えてみました。

昨日のエラーを見返す

昨日のエラーを見返してみて気付いたこと。

ログ抜粋
Apr 18 16:20:54 test01 httpd[818]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address 192.168.100.100:10080
Apr 18 16:20:54 test01 httpd[818]: no listening sockets available, shutting down
Apr 18 16:20:54 test01 httpd[818]: AH00015: Unable to open logs

IPアドレスが設定されるまえに、Apacheが起動しようとしたのが問題。

じゃあ、自分が流用したserviceファイルはそもそもどうだったのか?

/usr/lib/systemd/system/httpd.serviceを見返す

Apacheを導入したときに出来上がるhttpd.serviceファイルは以下の通り。

httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

自動的に、出来上がるファイルを利用してなぜ起動できないのか??
ここで一つのことに気付く。
Apacheを導入して、他に自動的にできるファイルは???

/etc/httpd/conf/httpd.confを見返す

Apacheが起動するときに、かならずロードされるファイルはhttpd.conf。
見返したときに気付いた!

httpd.conf抜粋
# Listen 12.34.56.78:80
# Listen 80
Listen 192.168.100.100:10080

導入直後のhttpd.confファイルは、以下の状態

httpd.conf
# Listen 12.34.56.78:80
Listen 80

Apacheは80番ポートで起動するが、このファイルではIPアドレスをListenしていない。

IPアドレスが無くてもApacheが起動できるから、httpd.serviceの中身は、After=network.targetでよかったのではないか??? と仮説

自分はIPアドレス:port番号を設定していたので、IPアドレスをはずし、以下の設定後リブート
・Listenの項目はPort番号のみ
・httpd.serviceはデフォルトの内容に変更

予想通りだった!

起動後にログを確認する。

ログ抜粋
Apr 19 17:13:22 test01 systemd[1]: Started Terminate Plymouth Boot Screen.
Apr 19 17:13:22 test01 systemd[1]: Started Wait for Plymouth Boot Screen to Quit.
Apr 19 17:13:22 test01 systemd[1]: Started Serial Getty on hvc0.
Apr 19 17:13:22 test01 systemd[1]: Starting Serial Getty on hvc0...
Apr 19 17:13:22 test01 systemd[1]: Started Getty on tty1.
Apr 19 17:13:22 test01 systemd[1]: Starting Getty on tty1...
Apr 19 17:13:22 test01 systemd[1]: Reached target Login Prompts.
Apr 19 17:13:22 test01 systemd[1]: Starting Login Prompts.
Apr 19 17:13:22 test01 startup.sh[627]: Tomcat started.
Apr 19 17:13:22 test01 systemd[1]: Started apache-tomcat-8.5.12.
Apr 19 17:13:22 test01 systemd[1]: Starting Apache 2.4.6...
Apr 19 17:13:23 test01 systemd[1]: Started Dynamic System Tuning Daemon.
Apr 19 17:13:23 test01 systemd[1]: Started Apache 2.4.6.
Apr 19 17:13:24 test01 systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 19 17:13:24 test01 systemd[1]: Dependency failed for Network Manager Wait Online.
Apr 19 17:13:24 test01 systemd[1]: Job NetworkManager-wait-online.service/start failed with result 'dependency'.
Apr 19 17:13:24 test01 systemd[1]: Starting LSB: Bring up/down networking...
Apr 19 17:13:24 test01 kernel: ip6_tables: (C) 2000-2006 Netfilter Core Team
Apr 19 17:13:24 test01 node[628]: server starting...
Apr 19 17:13:24 test01 kernel: Ebtables v2.0 registered
Apr 19 17:13:24 test01 postfix/postfix-script[799]: starting the Postfix mail system
Apr 19 17:13:24 test01 postfix/master[804]: daemon started -- version 2.10.1, configuration /etc/postfix
Apr 19 17:13:24 test01 systemd[1]: Started Postfix Mail Transport Agent.
Apr 19 17:13:24 test01 kernel: nf_conntrack version 0.5.0 (65536 buckets, 262144 max)
Apr 19 17:13:24 test01 kernel: bridge: automatic filtering via arp/ip/ip6tables has been deprecated. Update your scripts t
Apr 19 17:13:24 test01 kernel: Netfilter messages via NETLINK v0.30.
Apr 19 17:13:24 test01 kernel: ip_set: protocol 6
Apr 19 17:13:25 test01 network[718]: Bringing up loopback interface:  [  OK  ]
Apr 19 17:13:27 test01 avahi-daemon[560]: Registering new address record for fe80::444:57ff:fefd:26e on eth0.*.
Apr 19 17:13:30 test01 avahi-daemon[560]: Joining mDNS multicast group on interface eth0.IPv4 with address 10.133.207.23.
Apr 19 17:13:30 test01 avahi-daemon[560]: New relevant interface eth0.IPv4 for mDNS.
Apr 19 17:13:30 test01 avahi-daemon[560]: Registering new address record for 192.168.100.100 on eth0.IPv4.

そういうことだ。
IPアドレスをhttpd.confは必要していないから、あっさりApacheは起動できた。

これまでIBM HTTP Serverばかり触っていて、V7くらいからは、

Listen port番号

という書き方をIBM HTTP Serverは許さなくなったので、

Listen IPアドレス:port番号

と書いていたのが、まさか、こんなところで影響をうけるとは思わなかった。

結論

  • httpd.confファイルにListen IPアドレス:Port番号を記述した場合は、httpd.serviceの中では、Requires=network.targetをしなければ、Apacheは起動しない!

とりあえず解決ということにしておきましょう!
個人的には納得。

3
5
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
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?