本文共 2085 字,大约阅读时间需要 6 分钟。
安装 percona-zabbix-templates-1.1.7-2
wget https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.7-2.noarch.rpmrpm -ivh percona-zabbix-templates-1.1.7-2.noarch.rpmyum install percona-zabbix-templates php php-mysql -y
拷贝配置文件
rpm -ql percona-zabbix-templatescp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/
修改数据库链接文件
vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php$mysql_user = 'root';$mysql_pass = '';$mysql_port = 3306;$mysql_socket = NULL;$mysql_flags = 0;
导入模板(因原来的模板在3.x 使用有问题,请下载下面的模板)
https://github.com/hequan2017/zabbix-models/blob/master/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml
配置php
vim get_mysql_stats_wrapper.shCMD="/usr/local/php/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items gg
设置权限
cd /tmpchown -R zabbix.zabbix localhost-mysql_cacti_stats.txt/etc/init.d/zabbix_agentd restart
测试
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gw17603
附:
若mysql没有使用默端口3006,则还需要修改如下脚本文件
touch /tmp/localhost-mysql_cacti_stats.txt:3317chown -R zabbix.zabbix /tmp/$HOST-mysql_cacti_stats.txt:3317
修改端口脚本
vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.shCACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt "换成:CACHEFILE="/tmp/$HOST-mysql_zabbix_stats.txt:3317"
TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt`换成:TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_zabbix_stats.txt:3317`
修改mysql执行命令路径
#RES=`HOME=~zabbix mysql -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`换成:RES=`/usr/local/mysql/bin/mysql -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
监控从库: ##设置登陆的账号密码
vim /usr/local/mysql/etc/my.cnf [mysql]user=zabbixmoniterpassword=ys_ipowerlong0418socket=/usr/local/mysql/mysql.sock
sh /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave
##测试
监控项目 MySQL running slave
转载于:https://blog.51cto.com/hequan/2055492