お金をかけずにサーバーの勉強をしよう

Zabbixインストール(前編)

2022年7月28日

メニューへ戻る

サーバー管理者ならその名をきっと聞いたことがあるはずです。

色々なコンピューターリソースを監視する Zabbixを導入しましょう。

本家サイトはこちら。
ZABBIX

先日までまだ Ubuntu 22.04に対応していなかったので待っておりましたが、2022年7月27日時点で対応ができているようなので、満を持してインストールしたいと思います。

環境は Ubuntu Server 22.04を使います。

ダウンロードとインストールの方法はこちら。
Download and install Zabbix

上記のサイトで、インストール対象環境を選ぶと、それに従ってインストールのためのコマンドが表示されるようになっています。
上記URLは以下の選択をした際のものになっています。

ZABBIXバージョン 6.2
OSディストリビューションUbuntu
OSバージョン22.04 (Jammy)
データベースMySQL
Web ServerNGINX

※どうやら MySQL/NGiNX/PHPなど結構他の OSSの環境を要求するようです。
インストール時に既存で入っているパッケージをアップデートしてしまう可能性があるので、Zabbixは他のサーバー機能と共存させず Zabbixオンリーの OS環境を用意したほうが良い気がします。
どうしても他の機能と相乗りさせるときは、Dockerを使ったほうが良いでしょう。
色々なタイプのイメージがこちらにあります。
Zabbix Docker Component Repositories

では、上記URLに出てきた手順でインストールをしていきます。
※root権限が必要なコマンドに sudoを使っています。

a. Install Zabbix repository の手順

Zabbixのリポジトリを登録します。

subro@UbuntuServer2204:~$ wget https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-1+ubuntu22.04_all.deb
--2022-07-27 17:44:25--  https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-1+ubuntu22.04_all.deb
repo.zabbix.com (repo.zabbix.com) をDNSに問いあわせています... 2604:a880:2:d0::2062:d001, 178.128.6.101
repo.zabbix.com (repo.zabbix.com)|2604:a880:2:d0::2062:d001|:443 に接続しています... 失敗しました: 接続を拒否されました.
repo.zabbix.com (repo.zabbix.com)|178.128.6.101|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 3656 (3.6K) [application/octet-stream]
‘zabbix-release_6.2-1+ubuntu22.04_all.deb’ に保存中

zabbix-release_6.2-1+ubuntu22.04_all.deb  100%[===================================================================================>]   3.57K  --.-KB/s    in 0s

2022-07-27 17:44:25 (268 MB/s) - ‘zabbix-release_6.2-1+ubuntu22.04_all.deb’ へ保存完了 [3656/3656]

subro@UbuntuServer2204:~$ sudo dpkg -i zabbix-release_6.2-1+ubuntu22.04_all.deb
以前に未選択のパッケージ zabbix-release を選択しています。
(データベースを読み込んでいます ... 現在 118895 個のファイルとディレクトリがインストールされています。)
zabbix-release_6.2-1+ubuntu22.04_all.deb を展開する準備をしています ...
zabbix-release (1:6.2-1+ubuntu22.04) を展開しています...
zabbix-release (1:6.2-1+ubuntu22.04) を設定しています ...

subro@UbuntuServer2204:~$ sudo apt update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu jammy InRelease
取得:2 http://jp.archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
取得:5 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [384 kB]
取得:6 http://jp.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [177 kB]
取得:7 https://repo.zabbix.com/zabbix-agent2-plugins/1/ubuntu jammy InRelease [4,946 B]
ヒット:8 https://deb.nodesource.com/node_16.x jammy InRelease
取得:9 https://repo.zabbix.com/zabbix/6.2/ubuntu jammy InRelease [4,958 B]
取得:10 https://repo.zabbix.com/zabbix-agent2-plugins/1/ubuntu jammy/main Sources [661 B]
取得:11 https://repo.zabbix.com/zabbix-agent2-plugins/1/ubuntu jammy/main amd64 Packages [472 B]
取得:12 https://repo.zabbix.com/zabbix/6.2/ubuntu jammy/main Sources [1,243 B]
取得:13 https://repo.zabbix.com/zabbix/6.2/ubuntu jammy/main amd64 Packages [5,147 B]
903 kB を 1秒 で取得しました (712 kB/s)
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
パッケージはすべて最新です。

Zabbixのリポジトリが追加されました。

b. Install Zabbix server, frontend, agent の手順

関連パッケージのインストールです。

subro@UbuntuServer2204:~$ sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  apache2 apache2-bin apache2-data apache2-utils bzip2 fontconfig-config fonts-dejavu fonts-dejavu-core fonts-dejavu-extra fping libapache2-mod-php8.1 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libdeflate0 libevent-2.1-7 libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libltdl7 liblua5.3-0
  libmodbus5 libmysqlclient21 libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream
  libnginx-mod-stream-geoip2 libodbc2 libonig5 libopenipmi0 libsensors-config libsensors5 libsnmp-base libsnmp40 libtiff5 libwebp7 libxpm4 mailcap mime-support
  mysql-client mysql-client-8.0 mysql-client-core-8.0 mysql-common nginx nginx-common nginx-core php php-bcmath php-common php-fpm php-gd php-ldap php-mbstring
  php-mysql php-xml php8.1 php8.1-bcmath php8.1-cli php8.1-common php8.1-fpm php8.1-gd php8.1-ldap php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline
  php8.1-xml snmpd ssl-cert
提案パッケージ:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser bzip2-doc php-pear libgd-tools odbc-postgresql tdsodbc lm-sensors snmp-mibs-downloader
  fcgiwrap nginx-doc snmptrapd zabbix-apache-conf virtual-mysql-server
以下のパッケージが新たにインストールされます:
  apache2 apache2-bin apache2-data apache2-utils bzip2 fontconfig-config fonts-dejavu fonts-dejavu-core fonts-dejavu-extra fping libapache2-mod-php8.1 libapr1
  libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libdeflate0 libevent-2.1-7 libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libltdl7 liblua5.3-0
  libmodbus5 libmysqlclient21 libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream
  libnginx-mod-stream-geoip2 libodbc2 libonig5 libopenipmi0 libsensors-config libsensors5 libsnmp-base libsnmp40 libtiff5 libwebp7 libxpm4 mailcap mime-support
  mysql-client mysql-client-8.0 mysql-client-core-8.0 mysql-common nginx nginx-common nginx-core php php-bcmath php-common php-fpm php-gd php-ldap php-mbstring
  php-mysql php-xml php8.1 php8.1-bcmath php8.1-cli php8.1-common php8.1-fpm php8.1-gd php8.1-ldap php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline
  php8.1-xml snmpd ssl-cert zabbix-agent zabbix-frontend-php zabbix-nginx-conf zabbix-server-mysql zabbix-sql-scripts
アップグレード: 0 個、新規インストール: 79 個、削除: 0 個、保留: 0 個。
35.9 MB のアーカイブを取得する必要があります。
この操作後に追加で 182 MB のディスク容量が消費されます。
続行しますか? [Y/n] Y
取得:1 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 libapr1 amd64 1.7.0-8build1 [107 kB]
取得:2 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 libaprutil1 amd64 1.6.1-5ubuntu4 [92.4 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-5ubuntu4 [11.3 kB]

〜〜〜 中略 〜〜〜

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

インストールできたようです。

c. Create initial database の手順

データベースに初期データを投入します。

ここで問題が!
Make sure you have database server up and running.
と書いてありますが、ここまでの手順では MySQLサーバーが立ち上がってません…。

subro@UbuntuServer2204:~$ apt list --installed mysql*
Listing... Done
mysql-client-8.0/jammy-updates,now 8.0.29-0ubuntu0.22.04.3 amd64 [installed,automatic]
mysql-client-core-8.0/jammy-updates,now 8.0.29-0ubuntu0.22.04.3 amd64 [installed,automatic]
mysql-client/jammy-updates,now 8.0.29-0ubuntu0.22.04.3 all [installed,automatic]
mysql-common/jammy,now 5.8+1.0.8 all [installed,automatic]

mysql-serverが入ってませんよと…。

こちらに Ubuntu Server 22.04への MySQLサーバーのインストールについて書いてありますので、インストールして (MySQLの)rootユーザーのパスワード設定までやって下さい…。
MySQLインストール

初期化が完了した所で戻ってきて下さい。

では続きを。

subro@UbuntuServer2204:~$ mysql -uroot -p
Enter password: MySQLのrootユーザーのパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.29-0ubuntu0.22.04.3 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.00 sec)

mysql> create user zabbix@localhost identified by 'password';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.01 sec)

mysql> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye

データベースのセッティングができました。

次はデータベースのテーブルなどを作ります。
(MySQLの)zabbixユーザーのパスワードは手順通りに password になっちゃってます。

subro@UbuntuServer2204:~$ zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix
Enter password: password

何も出力されずに終わりました。

log_bin_trust_function_creators オプションを使えなくします。

subro@UbuntuServer2204:~$ mysql -uroot -p
Enter password: MySQLのrootユーザーのパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.29-0ubuntu0.22.04.3 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye

できました。

d. Configure the database for Zabbix server の手順

/etc/zabbix/zabbix_server.conf ファイルを以下のように書き換えます。
データベースユーザーのパスワード設定ですね。

# DBPassword=
    ↓
DBPassword=password


e. Configure PHP for Zabbix frontend の手順

NGiNXはインストールされてるんでしょうか。

subro@UbuntuServer2204:~$ apt list --installed nginx
Listing... Done
nginx/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed,automatic]
N: There is 1 additional version. Please use the '-a' switch to see it

NGiNXはインストールされてるんですね。謎だ。

では手順の方を。

/etc/zabbix/nginx.conf を以下のように書き換えます。
※server_nameは皆さんの環境に合わせて適宜変えて下さい。

#        listen          8080;
#        server_name     example.com;
    ↓
         listen          8080;
         server_name     UbuntuServer2204;


f. Start Zabbix server and agent processes の手順

OS起動時に Zabbixが起動するようにします。

subro@UbuntuServer2204:~$ sudo systemctl restart zabbix-server zabbix-agent nginx php8.1-fpm

subro@UbuntuServer2204:~$ sudo systemctl enable zabbix-server zabbix-agent nginx php8.1-fpm
Synchronizing state of zabbix-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-server
Synchronizing state of zabbix-agent.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-agent
Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nginx
Synchronizing state of php8.1-fpm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable php8.1-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /lib/systemd/system/zabbix-server.service.

インストールはこれで終わりです。

g. Zabbixフロントエンドの設定の手順

WEBブラウザでアクセスしてみます。
手順には http://server_ip_or_name にアクセスするよう書いてあるので、私の環境では http://UbuntuServer2204 ってことになり、アクセス先のポートは 80番ということになります。

実際にアクセスしてみると、この画面になってしまいます。
Apache2画面

インストールの過程で NGiNXの設定ファイル /etc/nginx/conf.d/zabbix.conf (これはシンボリックリンクで実体は /etc/zabbix/nginx.conf)に、ポートを 8080番にしていしていたはずです。

そちらにアクセスすると Zabbixの画面になりました。

試しに一度 Ubuntu Serverを再起動しますと、以下の通り Apache2が上がっていて、NGiNXは 80番を取れずにエラーになっているようです。

subro@UbuntuServer2204:~$ systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-07-28 08:49:17 JST; 34min ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 959 (apache2)
      Tasks: 7 (limit: 2200)
     Memory: 19.7M
        CPU: 1.288s
     CGroup: /system.slice/apache2.service
             ├─ 959 /usr/sbin/apache2 -k start
             ├─1001 /usr/sbin/apache2 -k start
             ├─1002 /usr/sbin/apache2 -k start
             ├─1003 /usr/sbin/apache2 -k start
             ├─1007 /usr/sbin/apache2 -k start
             ├─1009 /usr/sbin/apache2 -k start
             └─1570 /usr/sbin/apache2 -k start

 7月 28 08:49:15 UbuntuServer2204 systemd[1]: Starting The Apache HTTP Server...
 7月 28 08:49:17 UbuntuServer2204 apachectl[896]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the>
 7月 28 08:49:17 UbuntuServer2204 systemd[1]: Started The Apache HTTP Server.

subro@UbuntuServer2204:~$ systemctl status nginx
× nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-07-28 08:49:20 JST; 33min ago
       Docs: man:nginx(8)
        CPU: 193ms

 7月 28 08:49:18 UbuntuServer2204 nginx[958]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
 7月 28 08:49:18 UbuntuServer2204 nginx[958]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
 7月 28 08:49:19 UbuntuServer2204 nginx[958]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
 7月 28 08:49:19 UbuntuServer2204 nginx[958]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
 7月 28 08:49:19 UbuntuServer2204 nginx[958]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
 7月 28 08:49:19 UbuntuServer2204 nginx[958]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
 7月 28 08:49:20 UbuntuServer2204 nginx[958]: nginx: [emerg] still could not bind()
 7月 28 08:49:20 UbuntuServer2204 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
 7月 28 08:49:20 UbuntuServer2204 systemd[1]: nginx.service: Failed with result 'exit-code'.
 7月 28 08:49:20 UbuntuServer2204 systemd[1]: Failed to start A high performance web server and a reverse proxy server.

これについて Zabbixの Q&Aに質問が上がっていました。
Why does "zabbix-nginx-conf" require apache2 ?

NGiNXを別途先にインストールしておくことで回避できるようですが、入れてしまった後言われても…なので、Apache2のサービスを立ち上がらないようにしてみました。

subro@UbuntuServer2204:~$ sudo systemctl disable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable apache2
Removed /etc/systemd/system/multi-user.target.wants/apache2.service.

これで Ubuntu Serverを再起動して、再チャレンジです。 Apache2画面
やっぱり同じ画面…。
でも、80番を使ってるのは NGiNXになりました。

subro@UbuntuServer2204:~$ sudo lsof -i:80
COMMAND PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   897     root    7u  IPv4  32593      0t0  TCP *:http (LISTEN)
nginx   897     root    8u  IPv6  32594      0t0  TCP *:http (LISTEN)
nginx   898 www-data    7u  IPv4  32593      0t0  TCP *:http (LISTEN)
nginx   898 www-data    8u  IPv6  32594      0t0  TCP *:http (LISTEN)
nginx   899 www-data    7u  IPv4  32593      0t0  TCP *:http (LISTEN)
nginx   899 www-data    8u  IPv6  32594      0t0  TCP *:http (LISTEN)

これは何かというと、Apache2と NGiNXのデフォルト DocumentRootが両方とも /var/www/html で、そこに Apache2が自分の index.html を置いてしまうからなんですね。

NGiNXが Apache2のデフォルトの index.htmlを表示している状態になっています。

これは Zabbixが提供している Debパッケージの問題なんでしょう。

本来は 80番にアクセスすると NGiNXのリバースプロキシ機能で、8080番に行くようにするんでしょうか。
ちょっとここのフロント周りの設定で何が正しいのかよく分かりませんでした。

そのうち解消されると思いますが、今は 8080番にアクセスすることで逃げようと思います。
http://UbuntuServer2204:8080 で以下の画面が出るようになりました。
Zabbix初期画面

インストールはここまでで、次回「Zabbixインストール(後編)」で監視セッティングをしてみます。


[改訂3版]Zabbix統合監視実践入門──障害通知、傾向分析、可視化による省力運用 [ 寺島 広大 ]

価格:4,048円
(2022/7/28 10:00時点)
感想(0件)

Zabbix統合監視徹底活用改訂2版 複雑化・大規模化するインフラの一元管理 (Software Design plusシリーズ) [ 池田大輔 ]

価格:3,960円
(2022/7/28 10:00時点)
感想(0件)