Zabbix Server 自帶模板監控有密碼MySQL數據庫
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
一.Zabbix-agent端的配置
1>.為數據庫設置密碼
[root@node102 ~]# mysql -uroot -pyinzhengjie #看見沒?默認是不需要密碼就可以登錄的!我們想要設置密碼的話,就得進行授權操作! ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@node102 ~]# [root@node102 ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 227 Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> GRANT ALL ON *.* TO root@'localhost' IDENTIFIED BY 'yinzhengjie'; #創建授權用戶 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES; #刷新權限 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> MariaDB [(none)]> quit Bye [root@node102 ~]# [root@node102 ~]# mysql -uroot -pyinzhengjie #驗證創建的用戶是否可用正常登錄! Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 254 Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> quit Bye [root@node102 ~]# [root@node102 ~]#
2>.修改zabbix-agent端的數據庫配置文件並重啟服務
[root@node102 ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf | egrep -v '^#|^$' UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -uroot -pyinzhengjie -N | awk '{print $$2}' #這里需要修改一些 UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/var/lib/zabbix mysql -N' UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping -uroot -pyinzhengjie | grep -c alive #除了修改第一個,我們還需要修改這一行,把上面的配置的用戶和密碼加入進去! UserParameter=mysql.version,mysql -V [root@node102 ~]# [root@node102 ~]# [root@node102 ~]# systemctl restart zabbix-agent [root@node102 ~]# [root@node102 ~]#
二.Zabbix Server監控Agent端的數據庫
服務端配置大同小異,可參考:https://www.cnblogs.com/yinzhengjie/p/10404028.html。