#移動到zabbix解壓縮路徑
cd /usr/local/src/zabbix-3.0.3/conf/zabbix_agentd
#拷貝文件到/opt/zabbix/etc/zabbix_agentd.conf.d/ #指定自己的zabbix安裝目錄
cp userparameter_mysql.conf /opt/zabbix/etc/zabbix_agentd.conf.d/
#添加用來關聯mysql的配置文件my.cnf,並修改模板配置文件中的mysql路徑
cd /opt/zabbix/etc/
vim .my.cnf
# Zabbix Agent
[mysql][email protected]=/data/mysql/mysql.sock[mysqladmin][email protected]=/data/mysql/mysql.sock
# mysql.sock文件通過find / -name mysql.sock找出路徑
# 修改userparameter_mysql.conf:
sudo sed -i ‘s@/var/lib/zabbix@/opt/zabbix/etc@g‘ /opt/zabbix/etc/zabbix_agentd.d/userparameter_mysql.conf
# 修改完成userparameter_mysql.conf內容如下:
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/opt/zabbix/etc mysql -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=/opt/zabbix/etc mysqladmin ping | grep -c alive
#HOME目錄為新增.my.cnf文件所在目錄
# 修改zabbix_agentd.conf文件,添加下面一行
Include=/opt/zabbix/etc/zabbix_agentd.conf.d/
#重啟zabbix-agentd
/etc/init.d/zabbix_agentd restart
#測試
# /opt/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k mysql.ping1
# /opt/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k mysql.version/data/mysql/bin/mysql Ver 14.14 Distrib 5.7.12, for Linux (x86_64) using EditLine wrapper
#注意:如果測試的時候報錯:sh: mysql: command not found,sh: mysqladmin: command not found,修改userparameter_mysql.conf中mysql,mysqladmin命令的路徑,使用絕對路徑。
Zabbix-web頁面設置#Configuration—Hosts—Zabbix server—Tempaltes,搜索MySQL,添加彈出的模板,然後更新
#Monitoring—Graphs,選擇組,然後選擇host及展示的圖形
#利用Zabbix自帶模板監控MySQL完成。
本文原創地址:http://www.linuxprobe.com/monitor-mysql-with-zabbix.html
http://xxxxxx/Linuxjc/1144508.html TechArticle