0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Zabbix5.0】 における MySQL監視設定手順

Last updated at Posted at 2024-04-15

環境

監視する・される2台ともVagrantで構築

  • 監視サーバー側
    • CentOS7
    • zabbix-server 5.0
  • 監視ホスト側
    • CentOS7
    • MySQL 8.0
    • zabbix-agent 5.0

監視ホスト側の設定

要するにこちらを参照。
https://github.com/zabbix/zabbix/blob/release/5.0/conf/zabbix_agentd/userparameter_mysql.conf

Zabbix用のMySQLユーザー作成

# mysql -u root -p<password_root>

mysql> CREATE USER 'zabbix'@'localhost' IDENTIFIED WITH mysql_native_password BY <password_zbx>;
Query OK, 0 rows affected (0.16 sec)

mysql> 
mysql> 
mysql> GRANT ALL ON *.* TO 'zabbix'@'localhost';
Query OK, 0 rows affected (0.02 sec)

mysql> 
mysql> 
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

※【注意】このとき、ユーザーが接続するhostを'%'で作成してしまうと
  MySQLの接続元ホスト探しの仕組み上、匿名アカウント'@localhost'に接続されてしまう。

MySQLはまず最初に接続元ホストの検証を行います。"user1@localhost"の要求に対してて"''@localhost"と"user1@%"を比較する際、ホスト名が最長マッチする"''@localhost"が優先されるのです。

## 必要ファイル設定

  • /var/lib/zabbix/.my.cnf
[client]
user=zabbix #zabbix用に接続するユーザー
password=<password_zbx>

  • /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
    Zabbixから叩くコマンドの読み替えを記載している。
    $1, $2 といった引数はZabbix側で指定する。
UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
~                                                                                  
  • Zabbix Agent サービス再起動
# systemctl restart zabbix-agent

# Zabbixサーバーでの設定

  • Configuration > Hosts > 当該ホスト > Templates
    スクリーンショット 2024-04-16 0.34.34.png

  • Configuration > Hosts > 当該ホスト > Macros
    スクリーンショット 2024-04-16 0.35.14.png


これで拾えるはず。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?