Oracl LinuxでZabbix環境を構築する手順を記載します。DBはMySQL8.0、PHP7.2で構築しています。Oracle Linux独自の手順はリポジトリの箇所くらいかと思います。
Zabbixサーバを構築してそこにZabbixエージェントも設定します。またJavaアプリケーションを監視する場合、zabbix-java-gatewayが必要になるので最後にインストール、設定しています。
またZabbixDBについてバックアップスクリプトとリストアテストを別記事で紹介しています。
前提
・Oracle Linux Server release 7.6で構築。
・OS初期設定が完了していること(yum update,selinux無効化,firewalld無効化、timezone設定など)。
・必要なポートを開放しておくこと。
Zabbixサーバ → Zabbixエージェント 10050
Zabbixエージェント → Zabbixサーバ 10051
Zabbixサーバ構築手順
※rootのコマンドには行頭に # が、root以外は $ が付いています。
MySQL8.0
リポジトリ設定
# curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle https://yum.oracle.com/RPM-GPG-KEY-oracle-ol7
# curl -o /etc/yum.repos.d/public-yum-ol7.repo http://yum.oracle.com/public-yum-ol7.repo
# vi /etc/yum.repos.d/public-yum-ol7.repo
※以下を変更
[ol7_MySQL80]
enabled=0 ⇒ 1
[ol7_developer_EPEL]
enabled=0 ⇒ 1
[ol7_developer_php72]
enabled=0 ⇒ 1
インストール
# yum install mysql-community-server mysql-community-devel
設定ファイル作成
# cp -p /etc/my.cnf /etc/my.cnf.org
# ll /etc/my.cnf*
# vi /etc/my.cnf
※以下を記載
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
default_password_lifetime = 0
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
default-authentication-plugin=mysql_native_password
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
innodb_dedicated_server = ON
innodb_io_capacity = 1000
innodb_io_capacity_max = 4000
innodb_max_dirty_pages_pct = 90
※default-authentication-plugin について
mysql8.0デフォルトの認証方式、caching_sha2_passwordはzabbixにまだ対応していないです。
そのため以下2つのどちらかが必要となります。
1,my.cnfに以下の設定を記載(今回の手順はこちら)。
default-authentication-plugin=mysql_native_password
2,SQLでzabbixユーザだけネイティブ認証に変更。
alter user zabbix@'localhost' identified with mysql_native_password by 'パスワード';
※innodb関連の設定について
・innodb_dedicated_server
自動的に以下innodbのメモリ、パラメータ設定をする
innodb_buffer_pool_size
innodb_log_file_size
innodb_flush_method
・innodb_io_capacity
innodb_io_capacityが小さいとバックグラウンド処理がたまってしまう。
以下指標があるがとりあえず1000、maxを4000としておく。
デフォルト値:200
RAID:500 ~ 1000
SSD:2000 ~ 5000
IO-Drive2:10000 ~ 50000
・innodb_max_dirty_pages_pct
InnoDBバッファプールを占めるダーティな領域(更新された領域)が90%を超えると、
強制的に(他の処理をブロックして)チェックポイントが行われる。
最適値が不明なのでとりあえずデフォルトの90にしておく。
データディレクトリ作成
# mkdir -p /var/lib/mysql
起動設定
# systemctl start mysqld
# systemctl status mysqld
# systemctl enable mysqld
確認
# mysql --version
初期パスワード確認
# grep 'A temporary password' /var/log/mysqld.log
例: JD2IdIJ34v#Z
初期設定 (パスワードは例)
# mysql_secure_installation
→Enter password for user root:JD2IdIJ34v#Z (上記表示されたパスワード入力)
→New password:(変更後のパスワード入力)
→Re-enter new password:(変更後のパスワード入力)
→Change the password for root ? ((Press y|Y for Yes, any other key for No) :N
→Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
→Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
→Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
→Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
DB作成
mysql -uroot -p
mysql> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
DBユーザ作成
mysql> create user zabbix@'localhost' identified by 'パスワード';
mysql> grant all on zabbix.* to zabbix@'localhost';
mysql> flush privileges;
mysql> quit
PHP
※ OracleLinuxの用意するPHP7.2では「zabbix-web-mysql」が入らないため、REMIリポジトリからPHP7.2を取得。
EPEL,REMI
# rpm -ivh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
リポジトリ有効化 (PHP7.3も有効化できるようになっているので、/etc/yum.repos.d/remi-php73.repoの[remi-php73]を試してもいいかも。)
# vi /etc/yum.repos.d/remi-php72.repo
※以下変更
[remi-php72]
enabled=0 ⇒ 1
emi-safeリポジトリ無効 (これを無効にしないとPHPインストールを邪魔するらしいので念の為無効化)
# vi /etc/yum.repos.d/remi-safe.repo
※以下変更
[remi-safe]
enabled=1 ⇒ 0
インストール
※PHPのバージョン7.2.XXのいくつかから、php-mbstringのインストールに鬼車5(正規表現のライブラリ)が
必要になるためインストールしておく。
# yum --enablerepo=remi install oniguruma5
# yum install php php-gd php-bcmath php-xml php-mbstring php-pecl-mysql
確認
# php -v
Zabbix4.0
リポジトリ
# rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
インストール
# yum install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese zabbix-agent zabbix-get sendmail
データ流し込み
流し込むデータ(zabbix-server-mysql-4.X.X)のバージョン確認
# ls -ld /usr/share/doc/zabbix-server-mysql*
4.X.Xの箇所を編集
# cd /usr/share/doc/zabbix-server-mysql-4.X.X
パスワード入力流し込み(1,2分かかる)
# zcat create.sql.gz | mysql -u zabbix -p zabbix
設定
# cp -p /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.org
# vi /etc/zabbix/zabbix_server.conf
※以下編集
# DBPassword=
↓
DBPassword=<ZabbixDBのパスワード>
# DBHost=localhost
↓
DBHost=localhost
※DBNameとDBUserはデフォのまま
確認
# egrep "^DBPassword=|^DBHost=|^DBName=|^DBUser=|^DBPassword" /etc/zabbix/zabbix_server.conf
php.ini設定
# cp -p /etc/php.ini /etc/php.ini.org
# sed -i 's/\;date\.timezone\ \=/date\.timezone\ \=\ Asia\/Tokyo/g' /etc/php.ini
# grep "^date.timezone" /etc/php.ini
Apache設定
# cp -p /etc/httpd/conf.d/zabbix.conf /etc/httpd/conf.d/zabbix.conf.org
# sed -i 's/<IfModule mod_php5\.c>/<IfModule mod_php7\.c>/g' /etc/httpd/conf.d/zabbix.conf
# sed -i -e "s/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Tokyo/g" /etc/httpd/conf.d/zabbix.conf
# egrep "mod_php|date.timezone" /etc/httpd/conf.d/zabbix.conf
起動、自動起動設定
# systemctl start zabbix-server
# systemctl enable zabbix-server
# systemctl start httpd
# systemctl enable httpd
・ブラウザでインストール作業
http://ZabbixサーバのGIP/zabbix/
⇒ Zabbixの初期設定はこちらを参考に。
メールサービス起動
# systemctl start sendmail
# systemctl enable sendmail
Zabbixエージェント設定
zabbix-agent設定
# vi /etc/zabbix/zabbix_agentd.conf
※ 環境に合わせて変更。
Server=ZabbixサーバのIP(ここでは127.0.0.1のままでよい)
ServerActive=ZabbixサーバのIP(ここでは127.0.0.1のままでよい)
Hostname=このサーバのホスト名(zabbixコンソール上でホスト名を記載するときはここと一致させること。)
監視用設定変更
※こいつは僕の好みも入ってます。
# sed -i -e "s/# RefreshActiveChecks=120/RefreshActiveChecks=120/g" /etc/zabbix/zabbix_agentd.conf
# sed -i -e "s/# AllowRoot=0/AllowRoot=1/g" /etc/zabbix/zabbix_agentd.conf
# sed -i -e "s/# EnableRemoteCommands=0/EnableRemoteCommands=1/g" /etc/zabbix/zabbix_agentd.conf
# sed -i -e "s/# =3/Timeout=3/g" /etc/zabbix/zabbix_agentd.conf
※"HostnameItem","HostMetadata"など設定すればコンソール上でホストを追加しなくても、ホストをzabbixサーバに自動登録することができる(https://qiita.com/rotekxyz/items/79d289853145c855cd47 )。
どういう運用にするかは運用者に任せるので、ここでは設定しない。
サービス再起動、自動起動設定
# systemctl enable zabbix-agent
# systemctl start zabbix-agent
# systemctl status zabbix-agent
JMX監視設定
おまけ的なものですが、TomcatなどJavaアプリケーションを監視する場合、zabbix-java-gatewayというものが必要になりますのでインストールしておきます。
zabbix-java-gatewayインストール
# yum install zabbix-java-gateway
# systemctl start zabbix-java-gateway
# systemctl enable zabbix-java-gateway
設定編集
# vi /etc/zabbix/zabbix_server.conf
※以下項目を修正
JavaGateway=127.0.0.1
JavaGatewayPort=10052
StartJavaPollers=3
サービス再起動
# systemctl restart zabbix-server
# systemctl restart zabbix-java-gateway
監視項目の設定
ダッシュボード上でZabbixサーバに対し以下標準テンプレートを設定する。
・Template OS Linux
・Template Module ICMP Ping
メール送信テスト
こちらを参考に、自分の個人アドレスを使ってメール配信設定をする。Zabbixサーバのzabbix-agent停止してみて、メール通知がされるかを確認する。