1.部署Mariadb数据库
#安装mariadb数据库 [root@web01 ~]# yum install -y mariadb-server #启动 [root@web01 ~]# systemctl start mariadb.service #设置数据库密码 [root@web01 ~]# mysqladmin password '123456' #登录并创建zabbix用户 [root@web01 ~]# mysql -uroot -p123456 grant all privileges on *.* to zabbix@'localhost' identified by '123456';
2.安装部署percona
#安装percona
[root@web01 ~]# yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/1.0-15/percona-release-1.0-15.noarch.rpm
#安装percona模板
[root@web01 ~]# yum install -y percona-zabbix-templates
#查看脚本及模板文件
[root@web01 ~]# tree /var/lib/zabbix/percona/
/var/lib/zabbix/percona/
├── scripts
│ ├── get_mysql_stats_wrapper.sh
│ └── ss_get_mysql_stats.php
└── templates
├── userparameter_percona_mysql.conf
└── zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
#复制配置文件
[root@web01 ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
#修改连接数据库配置文件信息
[root@web01 ~]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'zabbix';
$mysql_pass = '123456';
$mysql_port = 3306;
#重启zabbix客户端
[root@web01 ~]# systemctl restart zabbix-agent
#zabbix客户端获取值测试
[root@web01 ~]# zabbix_agentd -t MySQL.Query-time-count-04
MySQL.Query-time-count-04 [t|0]
[root@web01 /server/scripts]# zabbix_agentd -t MySQL.file-fsyncs
MySQL.file-fsyncs [t|19]
#zabbix服务端获取值测试
[root@zabbix-server ~]# zabbix_get -s 172.16.1.7 -k MySQL.file-fsyncs
19
#删除不必要的缓存文件
[root@web01 ~]# rm -f /tmp/localhost-mysql_cacti_stats.txt
3.导入监控MySQL状态模板
4.被控主机关联链接模板
5.查看模板监控项状态,若有以下报错,则删除tmp不必要缓存文件
[root@web01 /tmp]# ls -l total 8 -rw-rw-r-- 1 zabbix zabbix 1296 May 21 18:01 localhost-mysql_cacti_stats.txt [root@web01 /tmp]# rm -r localhost-mysql_cacti_stats.txt rm: remove regular file ‘localhost-mysql_cacti_stats.txt’? y
6..查看监控MySQL服务的状态(等待300s左右,若有数据则成功)
多应用刷新几次,若等待时间过长,可以批量更新间隔时间





