Zabbix-agent使用自带模板监控 MySQL

1、rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

 

2、yum install -y zabbix zabbix-agent


3、cd /etc/zabbix

4、vi /etc/zabbix/zabbix_agentd.conf

修改 server为服务器ip

修改hostname为服务器设置的hostname

修改serveractive 为服务器ip:port

保存,退出

5、添加

    vi .my.cnf

# Zabbix Agent

[mysql]
host=localhost
user=zabbix
password=@Zabbix..0
socket=/data/mysql/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=@Zabbix..0
socket=/data/mysql/mysql.sock

# mysql.sock文件通过find / -name mysql.sock找出路径

6、# 修改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文件所在目录


7、加入开机启动

chkconfig zabbix-agent on


8、#重启zabbix-agentd

zabbix_agent restart
9、安装zabbix_get

yum list all |grep zabbix

返回一个列表,表中出现 zabbix-get.x86_84

.yum install zabbix-get.x86_64


10、#测试

# zabbix_get -s 127.0.0.1 -p 10050 -k mysql.ping


# /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命令的路径,使用绝对路径。

11、Zabbix-web页面设置

#Configuration—Hosts—Zabbix server—Tempaltes,搜索MySQL,添加弹出的模板,然后更新

 





#Monitoring—Graphs,选择组,然后选择host及展示的图形

 





#利用Zabbix自带模板监控MySQL完成。

posted @ 2016-12-20 10:18  lanfeng2291564  阅读(3790)  评论(0编辑  收藏  举报