ZABBIX监控MySQL
日期:2017-09-07
使用ZABBIX自带模板监控MySQL
1.配置userparameter_mysql.conf
1)移动到zabbix解压缩路径
cd /root/zabbix-3.2.2/conf/zabbix_agentd/
2)拷贝文件到/usr/local/zabbix/etc/zabbix_agentd.conf.d/ #指定自己的zabbix安装目录
cp userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/
3)添加用来关联mysql的配置文件my.cnf,并修改模板配置文件中的mysql路径
cd /usr/local/zabbix/etc/
vim .my.cnf
#Zabbix Agent
[mysql]
host=localhost
user=zabbix
password=zabbix
socket=/var/lib/mysql/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=zabbix
socket=/var/lib/mysql/mysql.sock
# mysql.sock文件通过find / -name mysql.sock找出路径
4)修改userparameter_mysql.conf:
sed -i 's@/var/lib/zabbix@/usr/local/zabbix/etc@g' /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
# 修改完成userparameter_mysql.conf内容如下:
grep UserParameter /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/usr/local/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=/usr/local/zabbix/etc mysql -N'
UserParameter=mysql.ping,HOME=/usr/local/zabbix/etc mysqladmin ping | grep -c alive
#HOME目录为新增.my.cnf文件所在目录
5)修改zabbix_agentd.conf文件,添加下面一行
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
echo "Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/" >> /usr/local/zabbix/etc/zabbix_agentd.conf
6)重启zabbix-agentd
service zabbix_agentd restart
7)测试
# /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k mysql.ping
1
# /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k mysql.version
mysql Ver 14.14 Distrib 5.6.37, for Linux (x86_64) using EditLine wrapper
#注意:如果测试的时候报错:sh: mysql: command not found,sh: mysqladmin: command not found,修改userparameter_mysql.conf中mysql,mysqladmin命令的路径,使用绝对路径。
2.Zabbix-web页面设置
#配置,主机,点击主机名,模板,搜索MySQL,添加弹出的模板,然后更新
#监测中,图形,选择组,然后选择主机及展示的图形
上一篇:CentOS6.8部署zabbix 3.2.2
下一篇:没有了