amegonの雑なブログ

日常的なものから技術的なものまでメモの雑記

Raspberry Pi 4B に Zabbix 関連の設定をしてプロキシとして動作させる

目的

今自宅環境で Zabbix Proxy を動かしていますが、仮想環境上に構築した仮想マシンとして動いています。
この仮想環境上には Zabbix サーバーも一緒に動いていて、仮想基盤本体の再起動時など一緒に再起動しちゃうので、監視データが欠落してしまうこともありもったいない部分でした。
今回入手した Raspberry Pi 4B を Zabbix サーバーとは物理的に異なる環境で動作させる Zabbix プロキシとしたいと思います。

Zabbix Proxy のインストール

Zabbix Proxy インストール前の状態

amegon@raspberrypi:~ $ df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/root         56G   11G   42G   21% /
devtmpfs         3.6G     0  3.6G    0% /dev
tmpfs            3.9G     0  3.9G    0% /dev/shm
tmpfs            1.6G  1.2M  1.6G    1% /run
tmpfs            5.0M  4.0K  5.0M    1% /run/lock
/dev/mmcblk0p6   253M   51M  202M   20% /boot
tmpfs            782M   32K  782M    1% /run/user/1000
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ free -h
               total        used        free      shared  buff/cache   available
Mem:           7.6Gi       210Mi       6.9Gi        53Mi       529Mi       7.2Gi
Swap:           99Mi          0B        99Mi
amegon@raspberrypi:~ $

インストール実行

su になってリポジトリ追加

sudo su
# wget https://repo.zabbix.com/zabbix/5.0/raspbian/pool/main/z/zabbix-release/zabbix-release_5.0-2%2Bdebian11_all.deb
# dpkg -i zabbix-release_5.0-2+debian11_all.deb
# apt update

インストール

# apt install zabbix-proxy-mysql mariadb-server zabbix-agent

↑ 最初は zabbix-proxy-mysql だけ入れてた。ログでは1回目に zabbix-proxy-mysql だけ、2回目で 3つのモジュールをインストールしている。

# systemctl status mysql
↑ インストール後に起動していた。自動起動も有効っぽい。

DB 作成

mysql -uroot
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user 'zabbix'@'localhost' identified by 'zabbix';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql> quit;

# zcat /usr/share/doc/zabbix-proxy-mysql/schema.sql.gz | mysql -uzabbix -p zabbix

Zabbix Proxy の設定ファイル修正

# vi /etc/zabbix/zabbix_proxy.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<password>
Server=<ZabbixサーバーのIP>

Zabbix Proxy の起動と自動起動設定有効化

# systemctl start zabbix-proxy
# systemctl enable zabbix-proxy

ログで起動状況を確認

root@raspberrypi:/home/amegon# tail -100 /var/log/zabbix/zabbix_proxy.log
  5650:20230904:205444.684 Starting Zabbix Proxy (active) [RasPi_01]. Zabbix 5.0.37 (revision 3f4cd9bec9b).
  5650:20230904:205444.684 **** Enabled features ****
  5650:20230904:205444.685 SNMP monitoring:       YES
  5650:20230904:205444.685 IPMI monitoring:       YES
  5650:20230904:205444.685 Web monitoring:        YES
  5650:20230904:205444.685 VMware monitoring:     YES
  5650:20230904:205444.685 ODBC:                  YES
  5650:20230904:205444.685 SSH support:           YES
  5650:20230904:205444.685 IPv6 support:          YES
  5650:20230904:205444.685 TLS support:           YES
  5650:20230904:205444.685 **************************
  5650:20230904:205444.685 using configuration file: /etc/zabbix/zabbix_proxy.conf
  5650:20230904:205444.699 current database version (mandatory/optional): 05000000/05000007
  5650:20230904:205444.699 required mandatory version: 05000000
  5650:20230904:205444.723 proxy #0 started [main process]
  5655:20230904:205444.725 proxy #1 started [configuration syncer #1]
  5655:20230904:205444.765 cannot obtain configuration data from server at "192.168.3.100": empty string received
  5657:20230904:205444.826 proxy #2 started [trapper #1]
  5658:20230904:205444.827 proxy #3 started [trapper #2]
  5659:20230904:205444.828 proxy #4 started [trapper #3]
  5662:20230904:205444.830 proxy #5 started [trapper #4]
  5663:20230904:205444.831 proxy #6 started [trapper #5]
  5664:20230904:205444.833 proxy #7 started [preprocessing manager #1]
  5668:20230904:205444.836 proxy #8 started [preprocessing worker #1]
  5669:20230904:205444.836 proxy #9 started [preprocessing worker #2]
  5670:20230904:205444.838 proxy #10 started [preprocessing worker #3]
  5671:20230904:205444.839 proxy #11 started [heartbeat sender #1]
  5672:20230904:205444.840 proxy #12 started [data sender #1]
  5673:20230904:205444.842 proxy #13 started [housekeeper #1]
  5675:20230904:205444.843 proxy #14 started [http poller #1]
  5677:20230904:205444.845 proxy #15 started [discoverer #1]
  5671:20230904:205444.845 cannot send heartbeat message to server at "192.168.3.100": proxy "RasPi_01" not found
  5678:20230904:205444.846 proxy #16 started [history syncer #1]
  5682:20230904:205444.850 proxy #18 started [history syncer #3]
  5684:20230904:205444.852 proxy #19 started [history syncer #4]
  5685:20230904:205444.854 proxy #20 started [self-monitoring #1]
  5687:20230904:205444.855 proxy #21 started [task manager #1]
  5688:20230904:205444.858 proxy #22 started [poller #1]
  5690:20230904:205444.859 proxy #23 started [poller #2]
  5679:20230904:205444.861 proxy #17 started [history syncer #2]
  5691:20230904:205444.862 proxy #24 started [poller #3]
  5672:20230904:205444.862 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5695:20230904:205444.865 proxy #25 started [poller #4]
  5697:20230904:205444.866 proxy #26 started [poller #5]
  5699:20230904:205444.868 proxy #27 started [unreachable poller #1]
  5701:20230904:205444.870 proxy #28 started [icmp pinger #1]
  5672:20230904:205445.866 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205446.870 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205447.874 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205448.877 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205449.881 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5658:20230904:205450.233 cannot send list of active checks to "127.0.0.1": host [Zabbix server] not found
  5672:20230904:205450.886 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205451.890 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205452.894 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205453.898 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205454.903 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205455.908 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205456.913 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found

起動は完了。 しかし、Proxy RasPi_01 が見つからない。 Zabbix サーバー側のプロキシに同名のプロキシが登録されていないから。

Zabbix サーバー側にプロキシを追加

Zabbix サーバーの管理画面からログインして、管理 → プロキシで今回のプロキシ名を名前として追加。

Zabbix Proxy 側で以下のコマンドを実行

root@raspberrypi:/home/amegon# zabbix_proxy -R config_cache_reload
zabbix_proxy [5767]: command sent successfully
root@raspberrypi:/home/amegon#

ログを確認。

root@raspberrypi:/home/amegon# tail -f /var/log/zabbix/zabbix_proxy.log
  5672:20230904:205727.631 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205728.635 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205729.639 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205730.644 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205731.648 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205732.653 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205733.657 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
zabbix_proxy [5763]: Is this process already running? Could not lock PID file [/var/run/zabbix/zabbix_proxy.pid]: [11] Resource temporarily unavailable
  5655:20230904:205807.966 forced reloading of the configuration cache
  5655:20230904:205807.987 received configuration data from server at "192.168.3.100", datalen 3662

サーバーとの設定同期が実行され、Proxy が見つからないログは停止した。

Zabbix サーバーでプロキシのデータがとれた

最新データ受信時刻 (経過時間) が直近になっていることで、データの受信が行われていることが確認できた。

Zabbix エージェントのインストール

モジュールのインストール

プロキシのインストール時に実施済なのでここでは何もしない。

Zabbix エージェントの設定

実行コマンド

vi /etc/zabbix/zabbix_agentd.conf

編集箇所

HostName=RasPi_01

Zabbix エージェントの再起動

systemctl restart zabbix-agent

エージェントを監視するホストを Zabbix サーバーに作成

ホストに適用しているテンプレートは下記の画像を参照。

設定同期

zabbix_proxy -R config_cache_reload

ログを確認

  4542:20230904:210709.324 Zabbix Agent stopped. Zabbix 5.0.37 (revision 3f4cd9bec9b).
  5838:20230904:210709.382 Starting Zabbix Agent [RasPi_01]. Zabbix 5.0.37 (revision 3f4cd9bec9b).
  5838:20230904:210709.382 **** Enabled features ****
  5838:20230904:210709.382 IPv6 support:          YES
  5838:20230904:210709.382 TLS support:           YES
  5838:20230904:210709.382 **************************
  5838:20230904:210709.382 using configuration file: /etc/zabbix/zabbix_agentd.conf
  5838:20230904:210709.383 agent #0 started [main process]
  5839:20230904:210709.385 agent #1 started [collector]
  5840:20230904:210709.386 agent #2 started [listener #1]
  5841:20230904:210709.387 agent #3 started [listener #2]
  5842:20230904:210709.388 agent #4 started [listener #3]
  5843:20230904:210709.389 agent #5 started [active checks #1]
  5843:20230904:210709.399 no active checks on server [127.0.0.1:10051]: host [RasPi_01] not found
  5843:20230904:210909.428 no active checks on server [127.0.0.1:10051]: host [RasPi_01] not found
  5843:20230904:211109.459 no active checks on server [127.0.0.1:10051]: host [RasPi_01] not found

host [RasPi_01] not found のログはとまった。 また、Zabbix サーバーで監視データがとれるようになった。

Zabbix エージェントの監視データ確認

とれていた。

インストール後の状態

そんなに負荷がかかっているようにも見えない。
じゅうぶん使えそうだと期待してしまいそう。

root@raspberrypi:/home/amegon# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/root         56G   12G   42G   22% /
devtmpfs         3.6G     0  3.6G    0% /dev
tmpfs            3.9G     0  3.9G    0% /dev/shm
tmpfs            1.6G  1.2M  1.6G    1% /run
tmpfs            5.0M  4.0K  5.0M    1% /run/lock
/dev/mmcblk0p6   253M   51M  202M   20% /boot
tmpfs            782M   32K  782M    1% /run/user/1000
root@raspberrypi:/home/amegon#
root@raspberrypi:/home/amegon# free -h
               total        used        free      shared  buff/cache   available
Mem:           7.6Gi       318Mi       6.5Gi        53Mi       806Mi       7.1Gi
Swap:           99Mi          0B        99Mi
root@raspberrypi:/home/amegon#

Zabbix エージェントで mysql の監視

MySQL 関連の監視データがとれていない

template_db_mysql.conf の作成

Raspbbery Pi に以下のファイルを保存。

  • 保存ファイル: /etc/zabbix/zabbix_agentd.d/template_db_mysql.conf
  • ファイルの所有者: root
  • ファイルのパーミッション: 644
  • ファイルの内容:
UserParameter=mysql.ping[*], mysqladmin --defaults-extra-file=/var/lib/zabbix/.my.cnf 
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -N | awk '{print $$2}' 
UserParameter=mysql.get_status_variables[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sNX -e "show global status" 
UserParameter=mysql.version[*], mysqladmin --defaults-extra-file=/var/lib/zabbix/.my.cnf -s version 
UserParameter=mysql.db.discovery[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sN -e "show databases" 
UserParameter=mysql.dbsize[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'" 
UserParameter=mysql.replication.discovery[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sNX -e "show slave status" 
UserParameter=mysql.slave_status[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sNX -e "show slave status"

my.cnf の作成

Raspbbery Pi に以下のファイルを保存。

  • 保存ファイル: /var/lib/zabbix/my.cnf
  • ファイルの所有者: root
  • ファイルのパーミッション: 644
  • ファイルの内容:
[client]
user='zabbix'
password='zabbix'

Zabbix エージェントの再起動

systemctl restart zabbix-agent

Zabbix で監視アイテムの確認

とれました。