Zabbix 3.4.4 を CentOS7へインストール

メモ:  Category:centos

ネットワーク機器周りの管理を視覚化したいと思い、いろいろと調べてみたのですがもう少し大きな枠組みとして統合監視ツール(統合運用管理ツール)と呼ばれるソフトウェアーがあることがわかりました。その中から「hinemos」「Xymon」「Nagios」「Zabbix」の4つを検討した結果、とりあえず Zabbix を試してみることにします。

最終的に hinemos と Zabbix で迷ったのですが、ジョブの管理が不要だったこと、情報の多さ、GUIの見た目で Zabbix にしました。

Zabbix のサポート期間は、大きく分けて2つ用意されておりバージョン番号にLTS(Long Term Support)が付与された長期サポートと付与されてないポイントリリースに分かれます。企業で運用していく場合、サポート期間も考慮する必要があると思いますが、今回は試験運用と好奇心ですので最新版のインストールに挑戦してみます。

インストール環境;

  • CentOS 7.4.1708 (Core)
  • Apache 2.4.6
  • MariaDB 5.5.56
  • PHP 7.2
  • Zabbix 3.4.4

統合監視ツール Zabbix をインストールしログイン画面が表示されるまで

PHPとApacheのインストール

最初にEPEL及びremiリポジトリが使えるように用意します。

# yum -y install epel-release
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

ApacheとPHPをインストールしていきます。

PHPの拡張機能として必要なのがgd,bcmath,ctype,mbstringで、使用するデータベースに合わせてmysqliになります。 拡張機能も含めて PHP7.2 と Apache をインストールします。

# yum -y --enablerepo=remi-php72 install httpd php php-gd php-bcmath php-mbstring php-mysqlnd php-xml

firewalldでHTTPを許可する

クライアントのWebブラウザからアクセスできるようファイアウォールの設定を変更します。

デフォルトのソーンにhttpを許可するよう設定を追加します。

firewall-cmd --zone=public --add-service=http --permanent

追加した設定を反映させます。

# firewall-cmd --reload

httpでのアクセスが許可されたかどうかを確認します。

# firewall-cmd --zone=public --list-services
dhcpv6-client http ssh

httpと出力されていることを確認します。

MariaDB のインストール

Zabbixのドキュメントには、MySQLが要求されていますがMariaDBを使っていきたいと思います。

# yum -y install mariadb-server

MariaDBの文字コードをUTF8に設定し、照合順をutf8_binに設定します。また、データファイルをテーブル単位で扱えるようinnodb_file_per_tableに設定します。(/etc/my.cnf.d/server.conf を修正)

[mysqld]
character-set-server = utf8
collation-server     = utf8_bin
skip-character-set-client-handshake
innodb_file_per_table

MariaDBの起動と再起動後の自動起動を設定しておきます。

# systemctl start mariadb
# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

/etc/my.cnf.d/server.cnfへ設定したcharacter-setが反映されているか確認します。

MariaDBのシステム変数characterset* のうち、character_set_filesystemとcharacter_sets_dir以外の値がすべてutf8になっていることを確認します。

# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

MariaDB [(none)]> exit

MariaDBのセキュリティ向上のため、mysql_secure_installationを実行して rootパスワードの設定や不要なデータベースの削除を行います。

# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): (そのままEnterキーを押す)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:  (MariaDBのrootユーザーに新たに設定するパスワードを入力)
Re-enter new password:  (新パスワードを再入力)
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y  (匿名ユーザーを削除)
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y  (rootユーザーの接続元をlocalhostに限定)
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y  (testデータベースを削除)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y  (権限関係の変更を直ちに適用)
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

データベースとユーザの作成

Zabbixのデータを保管するデータベースとユーザを作成します。

# mysql -u root -p
MariaDB [(none)]> create database zabbix default character set utf8;
MariaDB [(none)]> grant all on zabbix.* to user_zabbix@localhost identified by 'パスワード';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

Zabbixのインストール

Zabbix のリポジトリを追加し、必要なものをインストールしていきます。 必須ではありませんが、zabbix-agent をインストールしてサーバ自身も監視対象とします。

# rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
# yum -y install zabbix-server-mysql zabbix-agent zabbix-web-mysql zabbix-web-japanese

残念ながら簡単にはインストールさせてもらえず、次のエラーが発生しインストールができません。

エラー: パッケージ: php-mysql-5.4.16-43.el7_4.x86_64 (updates)
             要求: php-pdo(x86-64) = 5.4.16-43.el7_4
            インストール: php-pdo-7.2.0-2.el7.remi.x86_64 (@remi-php72)
                php-pdo(x86-64) = 7.2.0-2.el7.remi
            利用可能: php-pdo-5.4.16-42.el7.x86_64 (base)
                php-pdo(x86-64) = 5.4.16-42.el7
            利用可能: php-pdo-5.4.16-43.el7_4.x86_64 (updates)
                php-pdo(x86-64) = 5.4.16-43.el7_4

PHP7.2を使用したのが問題なようなのでリポジトリを明示してインストールしてみます。

# yum -y install zabbix-server-mysql zabbix-agent zabbix-web-mysql zabbix-web-japanese

次は、zabbix-web-mysql でエラーが発生しています。

エラー: パッケージ: zabbix-web-mysql-3.4.4-2.el7.noarch (zabbix)
             要求: php-mysql
            利用可能: php-mysql-5.4.16-42.el7.x86_64 (base)
                php-mysql = 5.4.16-42.el7
            利用可能: php-mysql-5.4.16-43.el7_4.x86_64 (updates)
                php-mysql = 5.4.16-43.el7_4
            利用可能: php-mysqlnd-5.4.16-42.el7.x86_64 (base)
                php-mysql = 5.4.16-42.el7
            利用可能: php-mysqlnd-5.4.16-43.el7_4.x86_64 (updates)
                php-mysql = 5.4.16-43.el7_4
            利用可能: php-pecl-mysql-1.0.0-0.17.20160812git230a828.el7.remi.7.2.x86_64 (remi-php72)
                php-mysql = 1:1.0.0
            インストール: php-mysqlnd-7.2.0-2.el7.remi.x86_64 (@remi-php72)
                見つかりません
            利用可能: php-mysqlnd-7.2.0~RC6-1.el7.remi.x86_64 (remi-php72)
                見つかりません
 問題を回避するために --skip-broken を用いることができます。
 これらを試行できます: rpm -Va --nofiles --nodigest

問題を切り分けたいので、zabbix-server-mysql と zabbix-agent をまずインストールします。

# yum -y --enablerepo=remi,remi-php72 install zabbix-server-mysql zabbix-agent

zabbix-server-mysql と zabbix-agent のパッケージは、インストールできました。が、残りはうまくいきませんでしたので個別にインストールしていきます。ここまでのエラーから font も必要そうなのでインストールしておきます。

# yum install dejavu-sans-fonts vlgothic-p-fonts
# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-web-3.4.4-2.el7.noarch.rpm
# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-web-mysql-3.4.4-2.el7.noarch.rpm
# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-web-japanese-3.4.4-2.el7.noarch.rpm
# rpm -ivh --nodeps zabbix-web-3.4.4-2.el7.noarch.rpm zabbix-web-mysql-3.4.4-2.el7.noarch.rpm zabbix-web-japanese-3.4.4-2.el7.noarch.rpm

うまくいった様ですので、データベースへテーブルと初期データを作成します。

# zcat /usr/share/doc/zabbix-server-mysql-3.4.4/create.sql.gz | mysql -u root zabbix -p

Apache の設定

Apache の設定を PHP7用に設定します。(/etc/httpd/conf.d/zabbix.conf) mod_php7.c の部分と php_value date.timezone を修正します。

<IfModule mod_php7.c>
    php_value max_execution_time 300
    php_value memory_limit 128M
    php_value post_max_size 16M
    php_value upload_max_filesize 2M
    php_value max_input_time 300
    php_value always_populate_raw_post_data -1
    php_value date.timezone Asia/Tokyo
</IfModule>

Zabbix の設定

/etc/zabbix/zabbix_server.conf の DBPassword に MariaDB に設定したパスワードを指定します。

DBPassword=PASSWORD

PHPの設定

php.ini の設定を変更します。

sed -i -e "s/post_max_size = 8M/post_max_size = 16M/g" /etc/php.ini
sed -i -e "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php.ini
sed -i -e "s/max_input_time = 60/max_input_time = 300/g" /etc/php.ini
sed -i -e "s/;date.timezone =/date.timezone = Asia\/Tokyo/g" /etc/php.ini
sed -i -e "s/;always_populate_raw_post_data/always_populate_raw_post_data/g" /etc/php.ini

各種サービスを起動します。

systemctl enable zabbix-server
systemctl start zabbix-server
systemctl enable zabbix-agent
systemctl start zabbix-agent
systemctl enable httpd
systemctl start httpd

Zabbix の初期設定

ブラウザからアクセスして次の画面が表示されれば、とりあえず第一段階クリアです。 右下の「Next step」ボタンをクリックして次へ進めます。

Wellcome to Zabbix

Zabbix の動作に必要な要件を満たしているかどうか表示されます。私の場合、xmlreader と xmlwriter と言われましたので 今回の例では php-xml をインストールしています。

動作要求の確認(エラー有り)

php-xml をインストール後、要件を満たしているか確認すると ldap に警告が出ていました。 ldap を使う予定がないので、「Next step」ボタンをクリックして次へ進めます。

動作要求の確認(ldapの警告のみ)

「Password」欄に、MariaDBに作成した user_zabbix のパスワードを入力し「Next step」をクリックします。

データベースの設定

「Next step」をクリックします。

Zabbix の詳細設定

設定した内容の確認が表示されるので問題が無ければ「Next step」をクリックします。

設定の要約

「Finish」をクリックすると、初期設定が完了します。

設定の完了

以上でインストール作業は完了です。

bluenote by BBB