全部博文(389)
分类: Mysql/postgreSQL
2014-05-14 17:37:28
使用percona zabbix mysql-plugin 监控mysql
从percona网站下载rmp包,使用rpm 在服务器上进行安装
[root@z~]rpm -ivh percona-zabbix-templates-1.1.3-1.noarch.rpm
[root@z sql]# cd /var/lib/zabbix/percona/templates
[root@z templates]# ls
userparameter_percona_mysql.conf zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.3.xml
导入模版文xml到zabbix服务器上.
拷贝userparameter_percona_mysql.conf 文件到被监控的mysql服务器上
[root@z templates]# scp userparameter_percona_mysql.conf 192.168.233.156:/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d
password:
userparameter_percona_mysql.conf 100% 18KB 18.4KB/s 00:00
修改客户端的zabbix_agentd.conf文件,增加Include 把userparameter_percona_mysql.conf 所在的目录增加进去.
[root@o12c etc]# vi zabbix_agentd.conf
# Include=
# Include=/usr/local/etc/zabbix_agentd.userparams.conf
# Include=/usr/local/etc/zabbix_agentd.conf.d/
Include=/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/
在被监控的mysql服务器上新建目录/var/lib/zabbix/percona/scripts,并且拷贝相应的文件过去
[root@o12c zabbix_agentd.conf.d]# mkdir -p /var/lib/zabbix/percona/scripts
[root@z scripts]# scp *.sh 192.168.233.156:/var/lib/zabbix/percona/scripts
password:
get_mysql_stats_wrapper.sh
[root@z scripts]# scp *.php 192.168.233.156:/var/lib/zabbix/percona/scripts
password:
ss_get_mysql_stats.php 100% 57KB 56.7KB/s 00:00
100% 1238 1.2KB/s 00:00
[root@o12c scripts]# chmod 755 *.sh
[root@o12c scripts]# chmod 755 *.php
修改mysql客户端的执行路径,
[root@o12c scripts]#vi /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
RES=`mysql -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
修改后(具体视mysql的安装情况而定)
RES=`/usr/local/mysql/bin/mysql -uroot -proot -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
修改ss_get_mysql_stats.php
[root@o12c scripts]# vi /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = 'root';
$mysql_port = 3306;
修改/tmp/localhost-mysql_cacti_stats.txt的执行权限
[root@o12c tmp]# chown zabbix:zabbix localhost-mysql_cacti_stats.txt
被监控的mysql服务器需要安装php和php-mysql。
密码全部使用明文,可能有安全风险;在被监控的mysql服务器上需要安装php,本着尽量少安装的原则,也不是太好.