1:在要监控的机器上执行如下:
yum -y install percona-zabbix-templates
会在/var/lib/zabbix/percona目录下生成scripts和templates两个目录!
将templates目录下的zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.xml模板导入到zabbix 机器上!
导入方法:
Configurationàtemplatesàimport,选择模板文件的位置,如图所示:
导入后如图所示:
新添加到模板如图所示:
添加监控主机:
Configuration-->Host--->Create Host 写入相关信息即可!
下面在需要监控的机器上进行相关配置:
按照percona的文档配置:
然后配置如下:
groupadd zabbix
useradd -g zabbix -M -s /sbin/nologin zabbix
tar zxvf zabbix-2.0.6.tar.gz
cd zabbix-2.0.6
./configure --enable-agent --prefix=/usr/local/zabbix
make
make install
[root@dota2 core]# pwd
/root/zabbix-2.0.6/misc/init.d/fedora/core
[root@dota2 core]# cp zabbix_agentd /etc/init.d/
vi /etc/init.d/zabbix_agentd
修改BASEDIR=/usr/local/为BASEDIR=/usr/local/zabbix
修改配置文件后配置文件如下:
[root@haproxy2 etc]# cat zabbix_agentd.conf | grep -v "#"
PidFile=/tmp/zabbix_agentd.pid
ogFile=/tmp/zabbix_agentd.log
DebugLevel=3
Server=192.168.2.203 ##监控服务器的地址
ServerActive=192.168.2.203 ##监控服务器的地址
Hostname=mysqldb1 ##和监控中显示的名称对应
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_percona_mysql.conf ##这个文件在/var/lib/zabbix/percona/templates下!
配置过程中遇到的问题:
按照文档配置后,tail -f /tmp/zabbix_agentd.log 日志中有报错:
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh: line 19: mysql: command not found
[root@haproxy2 ~]# which mysql ##其实我已经将mysql的安装路径添加到PATH里面, 但它还是找不到
/data/mysql/bin/mysql
解决方法:
cp /data/mysql/bin/mysql /usr/bin/ 或直接修改第19行,用mysql的绝对路径即可
接着报错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
修改第19行的配置:
RES=`mysql
-uroot -proot -e 'SHOW SLAVE STATUS\G' ##添加红色字体,我连接mysql的用户名和密码都是root
日志中接着报错:
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted
解决方法:
[root@haproxy2 tmp]# ll localhost-mysql_cacti_stats.txt
-rw-r--r-- 1 root root 1217 Dec 31 15:34 localhost-mysql_cacti_stats.txt
[root@haproxy2 tmp]# rm -f localhost-mysql_cacti_stats.txt
正常应该为zabbix用户的:
[root@haproxy2 tmp]# ll localhost-mysql_cacti_stats.txt
-rw-rw-r-- 1 zabbix zabbix 1242 Dec 31 15:49 localhost-mysql_cacti_stats.txt
执行
chown zabbix:
localhost-mysql_cacti_stats.tx
执行 /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
还会提示找不到/usr/bin/php 解决方法:
ln -s /usr/local/webserver/php/bin/php /usr/bin/php 即可!
再次执行;
[root@haproxy2 scripts]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg ###没有任何的显示,郁闷啊,必须输出一个数字才可以!
[root@haproxy2 scripts]# /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items gg
PHP MySQLi extension is not loaded
安装mysqli扩展,最好使用编译的php版本里面的mysqli,这样就不会有版本冲突的问题!
mysqli位于:{php解压目录}/ext下!安装完成,并加载mysqli
执行上面的命令如下:
[root@haproxy2 tmp]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
0
[root@haproxy2 tmp]# /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items gg
gg:0
到监控服务器上看看图形:
留为笔记:
虽然配置成功了,但个人认为,要监控的db上必须有php环境才可以,这样在db上就必须安装php,按照最小安装的原则,还是不大好!如果都是shell实现就好了!
阅读(6494) | 评论(0) | 转发(0) |