zabbix監控客戶端mysql用自帶的模板

1)首先在客戶端的mysql裏添加權限,即本機使用zabbix賬號連接本地的mysql
(都是客戶端裏面的mysql,也可以不用設置用root的mysql用戶比如 root 密碼123456則忽略這步驟)

mysql> grant all on *.* to zabbix@'localhost' identified by "123456”;
mysql> flush privileges;

2)在zabbix_agent服務目錄下創建.my.cnf 連接文件(一定要看清楚是 .my.cnf 有點的)
線上的zabbix安裝目錄是/etc/zabbix

[root@ff_db_master1 ~]# cd /etc/zabbix
[root@ff_db_master1 etc]# vi .my.cnf 
[client]
user=zabbix
password=123456

注意:
如果在數據庫grant授權時,針對的是localhost,這個.my.cnf裏面就不用加host參數了【如上配置】
但如果grant授權時針對的是本機的ip(如172.18.25.51),那麼在.my.cnf文件裏就要加上host參數進行指定了
即在.my.cnf文件就要加上:

[client]
host=172.18.25.51
socket=/Data/app/mysql5.6.25/var/mysql.sock 【這一行可以不用加上,默認會找到的,我就沒加】
user=root
password=123456

3)配置MySQL的key文件

[root@/etc/zabbix/zabbix_agentd.d ]# ls
userparameter_mysql.conf
然後查看 userparameter_mysql.conf 文件,看到類似 HOME=/var/lib/zabbix 的路徑設置,把路徑全都替換爲 /etc/zabbix/,也就是上面的.my.cnf文件所在的目錄路徑。
另外,注意userparameter_mysql.conf 文件裏的mysql命令路徑(提前做好mysql的系統環境變量,以防mysql命令不被系統識別)
如下:
[root@ff_db_master1 zabbix_agentd.conf.d]# cat userparameter_mysql.conf 
# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.
# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix/ mysql -N | awk '{print $$2}'
# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
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=/etc/zabbix/ mysql -N'
UserParameter=mysql.ping,HOME=/etc/zabbix/ mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

4)按照上面修改完之後檢查一下,然後重啓zabbix_agent

[ root@node2 ~ ]# systemctl restart zabbix-agent

再到zabbix的web頁面把mysql監控模版導入進去就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章