Zabbixをインストールしてみる・もっと続き

昨日は何をやってもうまくいかなかったので…
ふと、WiresharkでWebページにアクセスした時の挙動をキャプチャ出来たら、何かわかるのではないかと思ったので、早速Wiresharkをインストールして実行。

# tshark -i eth0 -f "port 80 or port 10050 or port 10051"
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
0.000000000 192.168.0.133 -> 192.168.0.131 TCP 66 51029 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
0.252967626 192.168.0.133 -> 192.168.0.131 TCP 66 51030 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
2.997813129 192.168.0.133 -> 192.168.0.131 TCP 66 [TCP Retransmission] 51029 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
3.262967779 192.168.0.133 -> 192.168.0.131 TCP 66 [TCP Retransmission] 51030 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
9.003906364 192.168.0.133 -> 192.168.0.131 TCP 62 [TCP Retransmission] 51029 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1
9.269040062 192.168.0.133 -> 192.168.0.131 TCP 62 [TCP Retransmission] 51030 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1
21.297449263 192.168.0.133 -> 192.168.0.131 TCP 66 51031 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
24.307819017 192.168.0.133 -> 192.168.0.131 TCP 66 [TCP Retransmission] 51031 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
30.313911413 192.168.0.133 -> 192.168.0.131 TCP 62 [TCP Retransmission] 51031 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1

131(PC)からアクセスしようとしているパケットが見えるということは、Zabbixサーバにパケットが届いていないわけではないということ。しかしどういうわけか、サーバはPCにACKを返してくれないので、PC側は一定時間ACKが返ってこないためにタイムアウトと認識したと思われる。
何故サーバ(というかApacheか)はACKを返してくれないのか。原因を色々ググってたら、「それはファイアウォールが弾いてるから」という情報を見つけた。
うーん、ファイアウォールの設定は何日か前に見たし、問題ないんじゃないk

# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:zabbix-trapper
ACCEPT tcp -- anywhere anywhere tcp dpt:zabbix-agent
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http

REJECTの下にhttpを許可するルールが入ってるってことは…これはルールの優先度の関係でhttpが弾かれてしまっているのではないか?
というわけで、

[root@localhost ~]# iptables -I INPUT 5 -p tcp -m tcp --dport 80 -j ACCEPT
[root@localhost ~]# iptables -I INPUT 6 -p tcp -m tcp --dport 443 -j ACCEPT
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:zabbix-trapper
ACCEPT tcp -- anywhere anywhere tcp dpt:zabbix-agent
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http

これでWebサイトにアクセスしてみたら、500エラーに変わりまして、Apacheのログにもエラーが記録されるようになりました。

[crit] [client 192.168.0.133] configuration error: couldn't perform authentication. AuthType not set!: /zabbix

調べたところ、Apache2.2系ではhttpd.confに「Require allなんちゃら」と書くのが良くないらしい。あ、そういえばその辺の記述いじったりしてたわ。
というわけで、Require all deniedを書き換える。しかし、それでもダメ。
httpd.confは文法ミスがあってもダメらしいので、以下のコマンドを実行して、文法に問題がないか確認。

apachectl configtest
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK

文法は問題ないみたいだけど、なんか間違っているようだ。
httpd.confの「ServerName」のところにサーバのホスト名を記述しないといけないみたい(参考)
というわけでhttpd.confをこんなふうに修正しました。

265 # ServerName gives the name and port that the server uses to identify itself.
266 # This can often be determined automatically, but we recommend you specify
267 # it explicitly to prevent problems during startup.
268 #
269 # If this is not set to valid DNS name for your host, server-generated
270 # redirections will not work. See also the UseCanonicalName directive.
271 #
272 # If your host doesn't have a registered DNS name, enter its IP address here.
273 # You will have to access it by its address anyway, and this will make
274 # redirections work in a sensible way.
275 #
276 #ServerName www.example.com:80
277 ServerName localhost.localdomain:80

変化なし。うーん。
とりあえずもう1回Wiresharkでキャプチャしてみますか。

# tshark -i eth0 -f "port 80 or port 10050 or port 10051"
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
0.000000000 192.168.0.133 -> 192.168.0.131 TCP 66 54519 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1
0.000081295 192.168.0.131 -> 192.168.0.133 TCP 66 http > 54519 [SYN, ACK] Seq=0 Ack=1 Win=14520 Len=0 MSS=1452 SACK_PERM=1 WS=32
0.000894249 192.168.0.133 -> 192.168.0.131 TCP 60 54519 > http [ACK] Seq=1 Ack=1 Win=66560 Len=0
0.110881690 192.168.0.133 -> 192.168.0.131 HTTP 405 GET /zabbix HTTP/1.1
0.110925550 192.168.0.131 -> 192.168.0.133 TCP 54 http > 54519 [ACK] Seq=1 Ack=352 Win=15616 Len=0
0.111732078 192.168.0.131 -> 192.168.0.133 HTTP 859 HTTP/1.1 500 Internal Server Error (text/html)
0.111815609 192.168.0.131 -> 192.168.0.133 TCP 54 http > 54519 [FIN, ACK] Seq=806 Ack=352 Win=15616 Len=0
0.113006264 192.168.0.133 -> 192.168.0.131 TCP 60 54519 > http [ACK] Seq=352 Ack=807 Win=65792 Len=0
0.429702657 192.168.0.133 -> 192.168.0.131 TCP 60 54519 > http [FIN, ACK] Seq=352 Ack=807 Win=65792 Len=0
0.429745400 192.168.0.131 -> 192.168.0.133 TCP 54 http > 54519 [ACK] Seq=807 Ack=353 Win=15616 Len=0
0.429779203 192.168.0.133 -> 192.168.0.131 TCP 60 54519 > http [RST, ACK] Seq=353 Ack=807 Win=0 Len=0

サーバがACKを返してくれるようになった。エラー出てるけど。
このあとiptablesのchain outputに設定入れてみたり(多分意味ない)してみたけど、うまくいかず。
「AuthType not set!」というからには認証の設定に問題があるのか…手動でApacheにそんな設定入れなきゃダメなんだっけ?と調べていた時に見た文言。

ZabbixのApacheの設定は/etc/httpd/conf.d/zabbix.confに記述されています(うろ)

…いや、まさか…そんなことはないよね…と、/etc/httpd/conf.d/zabbix.confを開く。

7 <Directory "/usr/share/zabbix">
8 Options FollowSymLinks
9 AllowOverride None
10 Require all granted
11
12
13 php_value max_execution_time 300
14 php_value memory_limit 1024M
15 php_value post_max_size 16M
16 php_value upload_max_filesize 2M
17 php_value max_input_time 300
18 # php_value date.timezone Europe/Riga
19 php_value date.timezone Asia/Tokyo
20

………

7 <Directory "/usr/share/zabbix">
8 Options FollowSymLinks
9 AllowOverride None
10 Order allow,deny
11 Allow from all
12
13 php_value max_execution_time 300
14 php_value memory_limit 1024M
15 php_value post_max_size 16M
16 php_value upload_max_filesize 2M
17 php_value max_input_time 300
18 # php_value date.timezone Europe/Riga
19 php_value date.timezone Asia/Tokyo
20

httpdをリブート。そして何度目かのWebアクセス。

f:id:BladeCatcher:20190221221012j:plain
キタ━(゚∀゚)━!!
というわけでZabbixのセットアップやるよ!!
まず上記の画面で「Next Step」をクリック。

f:id:BladeCatcher:20190221221013p:plain
え?なんかエラー出ましたね。
こちらの情報によると、

デフォルトの設定であれば、PHP.iniでalways_populate_raw_post_dataの設定がコメントアウトされているので、セミコロンを外して設定を有効にするだけです。

なので/etc/php.iniを見てみたら、確かにコメントアウトされていた。

700 ; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is
701 ; to disable this feature and it will be removed in a future version.
702 ; If post reading is disabled through enable_post_data_reading,
703 ; $HTTP_RAW_POST_DATA is *NOT* populated.
704 ; http://php.net/always-populate-raw-post-data
705 ;always_populate_raw_post_data = -1

というわけで、コメントアウトを外してみる。するとエラーが消えました。

f:id:BladeCatcher:20190221221014p:plain
このまま「Next Step」で進むと、
Zabbix用のDBを設定する画面が表示されます。
/etc/zabbix/zabbix_server.confに入力した情報を入れれば良いです。

f:id:BladeCatcher:20190221221015p:plain
「Name」のところは任意でいいらしいです。
「Host」はどっちでもいいみたいだけど、今回はIPアドレスにしました。

f:id:BladeCatcher:20190221221017p:plain
これでインストールしますよ的な画面。問題なければ「Next Step」でインストール完了です。Finishを押すと、Zabbixのログイン画面が出てきます。

f:id:BladeCatcher:20190221221018p:plain

初期ログインID・パスワードは「admin:zabbix」
デフォルトは英語のUIだけど、右上の人型アイコンをクリックし、「language」のところで日本語を選択すれば日本語化できる。

f:id:BladeCatcher:20190221221019p:plain