Zabbix 3.0.4使用自带模板监控Mysql

客户端操作:

1,进入源码安装目录

cd /source/zabbix-3.0.4/conf/zabbix_agentd/

2,拷贝文件至zabbix客户端配置文件目录

cp userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/

3,查看mysql.sock 文件路径

ps -ef |grep mysql.sock
mysql 9727 9475 6 07:45 pts/0 00:00:01 /usr/local/mysql/bin/mysqld
--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
--plugin-dir=/usr/local/mysql/lib/plugin
--user=mysql
--log-error=/usr/local/mysql/data/localhost.localdomain.err
--pid-file=/usr/local/mysql/data/localhost.localdomain.pid
--socket=/usr/local/mysql/mysql.sock #此路径是我们要写在my.cnf文件中
--port=3306

4,添加用来关联mysql的配置文件my.cnf,并修改模板配置文件中的mysql.sock路径

cd /usr/local/zabbix/etc/
[mysql]
host=localhost
user=root
password=root
socket=/usr/local/mysql/mysql.sock
[mysqladmin]
host=localhost
user=root
password=root
socket=/usr/local/mysql/mysql.sock

5,修改userparameter_mysql.conf:修改配置文件路径为现在的

cd /usr/local/zabbix/etc/zabbix_agentd.conf.d/
sed -i 's@HOME=/var/lib/zabbix@HOME=/usr/local/zabbix/etc@g' userparameter_mysql.conf

6,修改zabbix_agentd.conf文件:下面为最终修改好的

[root@localhost ~]# cat /usr/local/zabbix/etc/zabbix_agentd.conf |grep -v "^$"|grep -v "^#"
LogFile=/tmp/zabbix_agentd.log
Server=192.168.199.150,192.168.199.151 #我这里加上本机ip才能获取到数据
ListenIP=192.168.199.151
ServerActive=192.168.199.150
Hostname=192.168.199.151
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/

7,重启zabbix 客户端,注意查看是否有报错
service zabbix_agentd restart

8,测试是否获取到值:

错误1:
[root@localhost zabbix]# /usr/local/zabbix/bin/zabbix_get -s 192.168.199.151 -p 10050 -k mysql.ping
zabbix_get [10306]: Check access restrictions in Zabbix agent configuration
解决:
Server=192.168.199.150,192.168.199.151 #修改配置文件,我这里加上本机ip才能获取到数据


错误2:
[root@localhost zabbix]# /usr/local/zabbix/bin/zabbix_get -s 192.168.199.151 -p 10050 -k mysql.ping
/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
解决:要修改mysql配置文件:
vim /etc/my.cnf
[client]
password = 你的mysql密码 #去掉注释,加上密码
port = 3306
socket = /usr/local/mysql/mysql.sock

 

9,保存重启msyql

service mysqld restart
10,再次测试获取到值
[root@localhost ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.199.151 -p 10050 -k mysql.ping
1
[root@localhost ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.199.151 -p 10050 -k mysql.version
mysql Ver 14.14 Distrib 5.6.4-m7, for Linux (x86_64) using readline 5.1

 

服务端操作:

打开zabbix web管理界面:

配置 -- 主机 -- 创建主机

Zabbix 3.0.4使用自带模板监控Mysql

Zabbix 3.0.4使用自带模板监控Mysql

模板 -- 选择Template App MySQL -- 添加 -- 更新

Zabbix 3.0.4使用自带模板监控Mysql

等待一会查看图形数据就有了


Zabbix 3.0.4使用自带模板监控MysqlZabbix 3.0.4使用自带模板监控Mysql

分享