使用Zabbix自带MySQL模板监控MySQL
1. 安装zabbix agent
[[email protected] ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.0-1.el7.x86_64.rpm [[email protected] ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [[email protected] ~]# yum install zabbix-agent
2. 修改配置
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf Server=192.168.137.5 ServerActive=192.168.137.5 Hostname=szlinux02
3. 启动代理
[[email protected] ~]# systemctl enable zabbix-agent [[email protected] ~]# systemctl start zabbix-agent [[email protected] ~]# netstat -tunpl | grep 10050
4. 在服务端测试数据获取
[[email protected] ~]# zabbix_get -s 192.168.137.4 -p 10050 -k system.uptime
5. 在zabbix页面添加Linux主机
配置->主机->创建主机
6. 为主机连接模板
点击选择,勾选Template App MySQL和Template OS Linux,点击添加。
7. 为Template App MySQL在客户端配置
首先在客户端的mysql里添加权限,即本机使用zabbix账号连接本地的mysql
mysql> grant usage, process, replication client on *.* to ‘zabbix‘@‘localhost‘ identified by ‘[email protected]#123‘; mysql> flush privileges;
添加.my.cnf
vi .my.cnf
# Zabbix Agent
[mysql]
host=localhost
user=zabbix
password=’[email protected]#123’
socket=/usr/local/mysql/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=’[email protected]#123’
socket=/usr/local/mysql/mysql.sock
8. 修改userparameter_mysql.conf的HOME为新增.my.cnf文件所在目录
sed -i ‘[email protected]/var/lib/[email protected]/etc/[email protected]‘ /etc/zabbix /zabbix_agentd.d/userparameter_mysql.conf
9. 重启zabbix-agent
systemctl restart zabbix-agent
10. 在zabbix服务端测试获取mysql监控指标数据
zabbix_get -s 192.168.137.4 -p 10050 -k mysql.ping
注意:
- 如果测试的时候报错:sh: mysql: command not found,sh: mysqladmin: command not found,修改userparameter_mysql.conf中mysql,mysqladmin命令的路径,使用绝对路径,然后重启zabbix-agent,再测试。
- password居然要加引号才能读到。
11. 在Web页面查看最新数据和图形
检测中->最新数据或图形
时间: 2024-11-20 05:40:51