CentOS7.2にZabbix3.0を導入する

今回はCentOS 7.2上にZabbix3.0を導入してみます。
Zabbixとはオープンソースの統合監視ソフトウェアのことで、サーバ、ハードウェア、ソフトウェアに対して状況監視・障害検知・アラート通知する機能を備えています。

最新のバージョンは3.2ですが、長期サポート対象となるLTSリリースの最新バージョンは3.0です。
今回はこの3.0のZabbixをCentOS 7.2にインストールしてみます。

まずは環境情報から

VM情報

仮想化:Oracle VM VirtualBox/Vagrant
OS:CentOS Linux release 7.2.1511 (Core)
CPU:Intel(R) Core(TM) i5-4300M CPU @ 2.60GHz (1 core)
memory:2048GB

主要パッケージ情報

OSはインストール直後の状態とします。
では、実際に手順を進めていきます。

1. yumアップデート

言わずもがな、各パッケージを最新の状態にします。
プロキシ環境の場合はhttp_proxyを設定してください。

# yum update
# reboot

2. ファイアウォール設定 ※無効にしている場合は無視

Firewalldを有効にしている場合はZabbix用のポートを開けておきます。
(今回はZabbixServer用に20051番、ZabbixAgent用に20050番を使用します)

# firewall-cmd --list-all-zones
# firewall-cmd --add-port=20051/tcp --zone=public --permanent
# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --add-port=20050/tcp --zone=public --permanent
# systemctl restart firewalld

3. バックアップ用ディレクトリ作成

各種設定ファイルを退避するためのディレクトリを作成します。

# mkdir -p /var/infra/backup
# chmod -R 777 /var/infra/backup

4. SELinuxの設定 ※無効にしている場合は無視

セキュリティを考慮してSELinuxは有効にしておきます。
設定後にOSを再起動し

# getenforce
# cp -p /etc/selinux/config /var/infra/backup/`date +%Y%m%d`_`uname -n`_selinux_config
# vi /etc/selinux/config
# diff /var/infra/backup/`date +%Y%m%d`_`uname -n`_selinux_config /etc/selinux/config
# reboot
# getenforce

5. Apache HTTP Serverの導入

# yum install httpd

6. PHPの導入

remiリポジトリからPHPを入手します。

# yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# yum install yum-utils
# yum-config-manager --enable remi
# yum install php

7. PHPの設定

PHPのパラメータを変更します。

# cp -p /etc/php.ini /var/infra/backup/`date +%Y%m%d`_`uname -n`_etc_php.ini
# sed -i 's/\;date\.timezone\ \=/date\.timezone\ \=\ Asia\/Tokyo/g' /etc/php.ini
# sed -i "s/^post_max_size.*$/post\_max\_size\ \=\ 16M/g" /etc/php.ini
# sed -i "s/^max_execution_time.*$/max\_execution\_time\ \=\ 300/g" /etc/php.ini
# sed -i "s/^max_input_time.*$/max\_input\_time\ \=\ 300/g" /etc/php.ini
# sed -i "s/^memory_limit.*$/memory\_limit\ \=\ 256M/g" /etc/php.ini
# diff /var/infra/backup/`date +%Y%m%d`_`uname -n`_etc_php.ini /etc/php.ini

8. Zabbix,PostgreSQLの導入

Zabbixの各種パッケージとPostgreSQLを入手します。

# yum install http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
# yum install zabbix-agent zabbix-server-pgsql zabbix-web-pgsql zabbix-web-japanese
# yum install postgresql-server

9. PostgreSQLの設定

ZabbixDBを作成するためにPostgreSQLの設定を変更します。
今回は/pgdata/zabbixというディレクトリをデータの格納先とします。

# mkdir -p /pgdata/zabbix
# ls -lZ /pgdata/zabbix
# chown -R postgres:postgres /pgdata
# chcon -R -t postgresql_db_t /pgdata/zabbix
# ls -lZ /pgdata/zabbix
# cp -p /usr/lib/systemd/system/postgresql.service /var/infra/backup/`date +%Y%m%d`_`uname -n`_postgresql.service
# sed -i "s/^Environment.*$/Environment\=PGDATA\=\/pgdata\/zabbix/g" /usr/lib/systemd/system/postgresql.service
# systemctl daemon-reloa

10. zabbixDBの作成

PostgreSQLを起動してzabbix用のDBを作成します。
PostgreSQLの管理者ユーザならびにzabbixDBの管理者ユーザのパスワードを'password'として設定します。(パスワードは自由に設定してもらってよいです)

# postgresql-setup initdb
# systemctl start postgresql
# systemctl status postgresql
# systemctl enable postgresql
# su - postgres
$ psql -c "alter user postgres with password 'password'"
$ createuser zabbix -P -S -R -D
   ->password
   ->password
# createdb -O zabbix -E UTF8 zabbix
# exit
# su - postgres
# psql -c "GRANT ALL PRIVILEGES ON DATABASE zabbix TO zabbix"
# exi

11. zabbixDBの設定

ZabbixDBへのアクセスを設定し、ZabbixServer用のデータを挿入します。

# cp -p /pgdata/zabbix/pg_hba.conf /home/fjuser/infra/backup/`date +%Y%m%d`_`uname -n`_pg_hba.conf
# vi /pgdata/zabbix/pg_hba.conf
--以下を変更---------------------------------
2箇所trustに変更
# "local" is for Unix domain socket connections only
local   all             all                                         trust
# IPv4 local connections:
host    all             all             127.0.0.1/32       trust
----------------------------------------------

# diff /home/fjuser/infra/backup/`date +%Y%m%d`_`uname -n`_pg_hba.conf /pgdata/zabbix/pg_hba.conf
# systemctl restart postgresql
# zcat /usr/share/doc/zabbix-server-pgsql-3.0.7/create.sql.gz | psql -U zabbix zabbix -** 12. ZabbixServerの設定
ZabbixServerの待ち受けIP/ポート、DB接続情報を設定します。
# cp -p /etc/zabbix/zabbix_server.conf /home/fjuser/infra/backup/`date +%Y%m%d`_`uname -n`_zabbix_server.conf
# echo "ListenPort=20051" >> /etc/zabbix/zabbix_server.conf
# echo "ListenIP=0.0.0.0" >> /etc/zabbix/zabbix_server.conf
# echo "DBPassword=password" >> /etc/zabbix/zabbix_server.conf
# echo "DBPort=5432" >> /etc/zabbix/zabbix_server.conf
# diff /home/fjuser/infra/backup/`date +%Y%m%d`_`uname -n`_zabbix_server.conf /etc/zabbix/zabbix_server.conf
# cp -p /etc/httpd/conf.d/zabbix.conf /home/fjuser/infra/backup/`date +%Y%m%d`_`uname -n`_zabbix.conf
# sed -i "s/^.*php_value date.timezone.*$/php¥_value date¥.timezone Asia¥/Tokyo/g" /etc/httpd/conf.d/zabbix.con

13. 各種サービス起動

最後に各種サービスを起動します。
また、自動起動を有効にしておきます。

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

サービスが正常に起動してなおかつ自動設定がされていれば
以上で作業完了です。