はじめに
VirtualBoxにてCentOS7でzabbix5を構築しました
Zabbix 5.0LTS CentOS7 Server、Frontend、Agent Mysql apacheの構成です。
以下のサイトを参考に構築しました
https://www.zabbix.com/download?zabbix=5.0&os_distribution=centos&os_version=7&components=server_frontend_agent&db=mysql&ws=apache
zabbixコンポーネントのFrontendはWebのダッシュボードのことです。
frontend , server, agentでZabbix構成されています
Zabbixサーバがデータ収集も行いますが、zabbix proxyにデータ収集を任せることができる。
前提条件
VirtualBoxにてCentOS7のゲストOSを作成済みであること
手順
zabbixのリポジトリをインストールする
# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm を取得中
警告: /var/tmp/rpm-tmp.olpHdE: ヘッダー V4 RSA/SHA512 Signature、鍵 ID a14fe591: NOKEY
準備しています... ################################# [100%]
更新中 / インストール中...
1:zabbix-release-5.0-1.el7 ################################# [100%]
yumのキャッシュを削除する
# yum clean all
読み込んだプラグイン:fastestmirror
リポジトリーを清掃しています: base extras updates zabbix zabbix-non-supported
zabbixのパッケージをインストールする
yum install zabbix-server-mysql zabbix-agent
yum install centos-release-scl
ファイル /etc/yum.repos.d/zabbix.repo を編集し、zabbix-frontend リポジトリを有効にします。
vi /etc/yum.repos.d/zabbix.repo
1 [zabbix]
2 name=Zabbix Official Repository - $basearch
3 baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/
4 enabled=1
5 gpgcheck=1
6 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
7
8 [zabbix-frontend]
9 name=Zabbix Official Repository frontend - $basearch
10 baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
11 enabled=1 ← enableにする
12 gpgcheck=1
13 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
14
15 [zabbix-debuginfo]
16 name=Zabbix Official Repository debuginfo - $basearch
17 baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/debuginfo/
18 enabled=0
19 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
20 gpgcheck=1
21
22 [zabbix-non-supported]
23 name=Zabbix Official Repository non-supported - $basearch
24 baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
25 enabled=1
26 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
27 gpgcheck=1
Zabbix フロントエンド パッケージをインストールする。
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl
初期のデータベース作成する。
# mysql -uroot -p
-bash: mysql: コマンドが見つかりません
mysqlのコマンドが見つからないため、mysqlパッケージをインストールする必要があります
mysqlのリポジトリをインストールする。
rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm を取得中
警告: /var/tmp/rpm-tmp.10ftsj: ヘッダー V3 DSA/SHA1 Signature、鍵 ID 5072e1f5: NOKEY
準備しています... ################################# [100%]
更新中 / インストール中...
1:mysql57-community-release-el7-11 ################################# [100%]
[root@localhost ~]#
mysql-serverのパッケージをインストールする。
yum install mysql-server
mysqlのパスワードを確認した。
[root@localhost log]# pwd
/var/log
[root@localhost log]# cat mysqld.log | grep pass
2024-05-23T12:18:30.478471Z 1 [Note] A temporary password is generated for root@localhost: 8tsTbeJV>,jm
mysqlに接続してデータベースの設定をする
[root@localhost rpm-gpg]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44
Copyright (c) 2000, 2023, 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.
rootユーザーのパスワード変更を設定する
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'パスワード設定';
Query OK, 0 rows affected (0.00 sec)
文字列をutf8にする。
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
zabbixユーザーを作成してzabbixユーザのパスワードを設定する
mysql> create user zabbix@localhost identified by 'パスワード設定';
Query OK, 0 rows affected (0.00 sec)
zabbixユーザーに権限付与
mysql> grant all privileges on zabbix.* to zabbix@localhost;
データベースを設定変更するため1に設定する
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
Zabbix サーバー ホスト上で、初期スキーマとデータをインポートする。
[root@localhost rpm-gpg]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password:
[root@localhost rpm-gpg]#
log_bin_trust_function_creators オプションを無効にする。
[root@localhost rpm-gpg]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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
zabbixサーバーの設定ファイルにDBのパスワードを設定する
vi /etc/zabbix/zabbix_server.conf
DBPassword=password
zabbixの設定ファイルにリージョンを設定する
vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Tokyo
設定ファイルを反映させるためにサービスを再起動する
# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
VirtualBoxのため、80ポートでアクセスできる設定をする。
[root@localhost log]# firewall-cmd --permanent --add-port=80/tcp
success
[root@localhost log]#
[root@localhost log]# firewall-cmd --reload
success
[root@localhost log]#
パラメータはchatGPTに聞いてみました
Database type: MySQL
Database host: localhost(Zabbixサーバーとデータベースサーバーが同じ場合)
Database port: 3306(デフォルトのMySQLポート)
Database name: zabbix(あなたが設定したZabbixデータベース名)
User: zabbix(Zabbixデータベースユーザー)
Password: your_database_password(Zabbixデータベースユーザーのパスワード)
Nameフィールドには、Zabbixサーバーの識別名を入力する。
デフォルトのパスワードは以下です。
username Admin
Password zabbix
おまけ
zabbixにCPU負荷をかけてみました。
アラートが発報しました
zabbixサーバーにSSH接続してyesコマンドを実行した
yes > /dev/null &
yesコマンドをkillしたら復旧しました 以下がエビデンスです
まとめ
zabbixサーバーは実務でよく使われる監視サーバーです。
監視対象のホストにzabbixエージェントをインストールして監視します。
死活監視のみの場合はzabbixエージェントのインストールは不要です。
実際にハンズオンしてみて動作を確認してみることをお勧めします。