CentOS 7 - Zabbix 3.0 をインストールしてみた
Zabbix 3系をインストールしたので、作業手順を残しておきます。
作業環境
サーバ(仮想:ConoHa) - OS CnetOS 7.2 - RAM 1GB - CPU 2
手順
1.MariaDBをインストール
2.Apache,PHPをインストール
3.Zabbix Serverをインストール
4.Zabbix agentをインストール
5.おまけ
1.MariaDBをインストール
Zabbix Serverには、データベースサーバが必要なのでMariaDBをインストールします。
MariaDB 10.1をインストールするのに必要なYUMのリポジトリファイルを作成します。
# vim /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.1 CentOS repository list - created 2015-11-23 16:33 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
YUMで MariaDB 10.1をインストールします。
# yum install mariadb-server mariadb mariadb-devel mariadb-libs
MariaDBを起動し、自動起動を有効にします。
# systemctl start mariadb # systemctl enable mariadb
初期設定スクリプトを使い、rootユーザのパスワードを設定します。ここで設定するrootユーザのパスワードは今後必要なるので忘れないようにしてください。
# mysql_secure_installation 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] ←Enter New password: ←パスワード入力 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] ←Enter ... 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] ←Enter ... 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] ←Enter - 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] ←Enter ... 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!
これで、MariaDBのインストールは終わり。
2.Apache,PHPをインストール
Zabbix ServerのWebUIを使うために必要なApacheとPHPをインストールします。
YUMで Apache HTTP server をインストールします。
# yum install httpd
Apacheを起動し、自動起動を有効にします。
# systemctl start httpd # systemctl enable httpd
PHP 7系をインストールするために必要なYUMのリポジトリ(EPEL,Remi)を追加します。
# yum install epel-release # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Remiリポジトリを指定し、PHP 7と必要なパッケージをインストールします。
# yum install --enablerepo=remi-php70 php php-mysqlnd php-ldap php-gd php-xml php-bcmath php-mbstring php-pecl-mysql
php.iniにタイムゾーンを設定します。
# sed -i 's/\;date\.timezone\ \=/date\.timezone\ \=\ Asia\/Tokyo/g' /etc/php.ini
php.ini にZabbix Serverの推奨値を設定します。
# 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
PHPの設定を変更した場合、Apacheを再起動します。
# systemctl restart httpd
3.Zabbix serverをインストール
Zabbix Serverのインストールに必要なYUMのリポジトリを追加します。
# rpm -Uvh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
Zabbix Serverと必要なパッケージをインストールします。
# yum install --enablerepo=remi-php70 zabbix-server zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese
MariaDBにZabbix Server用のデータベースとユーザを作成します。
ユーザ名とパスワードは、ともに「zabbix」とします。
# mysql -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.1.11-MariaDB MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> \q Bye
Zabbix Server用のデータをMariaDBにインポートします。
# cd /usr/share/doc/zabbix-server-mysql-3.0.0/ # gzip -d create.sql.gz # mysql -u zabbix -pzabbix zabbix < create.sql
Zabbix Serverの設定ファイルをリネームします。
# mv -v /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak
必要最低限の設定だけ、記述したファイルを作成します。
# vim /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 PidFile=/var/run/zabbix/zabbix_server.pid DBSocket=/var/lib/mysql/mysql.sock SNMPTrapperFile=/var/log/snmptt/snmptt.log AlertScriptsPath=/etc/zabbix/alertscripts ExternalScripts=/etc/zabbix/externalscripts DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix
Zabbix Serverを起動し、自動起動を有効にします。
# systemctl start zabbix-server # systemctl enable zabbix-server
PHPバージョンが5.6以上の場合は、下記コマンドを実行する必要があります。
# sed -i "s/PHP\_VERSION\,\ '5\.6'/PHP\_VERSION\,\ '7\.1'/g" /usr/share/zabbix/include/classes/setup/CFrontendSetup.php
Zabbix Serverのインストールを終えたら、Apacheを再起動します。
# systemctl restart httpd
ここまで手順通りに進めていれば、ブラウザからWebUIにアクセスできます。
WebUIにアクセスするには「http://サーバIPアドレス/zabbix」とブラウザに入力します。正しく接続できれば、下記の画面が表示されるはずです。
WebUIにアクセスできない場合は、Apacheの再起動かfirewalld,iptablesの設定の見直しをしてください。
4.Zabbix Agentをインストール
Zabbix Agentのインストールに必要なYUMのリポジトリを追加します。
# rpm -Uvh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
Zabbix Agentをインストールします。
# yum install zabbix-agent
Zabbix Agentの設定ファイルをリネームします。
# mv /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
必要最低限の設定だけ、記述したファイルを作成します。設定項目のServer・ServerActiveには、Zabbixサーバ or ZabbixProxy のIPアドレスを指定します。
# vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server=xxx.sabakan.red ServerActive=xxx.sabakan.red HostnameItem=system.hostname Include=/etc/zabbix/zabbix_agentd.d/
Zabbix Agentを起動し、自動起動を有効にします。
# systemctl start zabbix-agent # systemctl enable zabbix-agent
5.おまけ
文字化けを修正
WebUIでグラフを作成する際、日本語が表示されなかったり、崩れたりすることがあります。
乱暴なやり方ですが、下記方法で直せる場合があります。
まず、Zabbix Serverが使って文字フォントを調べます。
# ls -l /usr/share/zabbix/fonts/graphfont.ttf lrwxrwxrwx 1 root root 33 10月 12 12:53 /usr/share/zabbix/fonts/graphfont.ttf -> /etc/alternatives/zabbix-web-font
使用している文字フォントが「graphfont.ttf」だと分かったら、新しく日本語フォントをYUMでインストールします。
# yum install ipa-pgothic-fonts
「graphfont.ttf」のシンボリックリンクを削除します。
# rm /usr/share/zabbix/fonts/graphfont.ttf
先ほどインストールした文字フォント「ipa-pgothic-fonts」のシンボリックリンクを「graphfont.ttf」と入れ替えます。
# ln -s /usr/share/fonts/ipa-pgothic/ipagp.ttf /usr/share/zabbix/fonts/graphfont.ttf
これで、日本語の表示が正しくできるようになっているはずです。