1.禁用安装防护
[root@mysql213 ~]# vi /etc/selinux/config #关闭安装
SELINUX=disabled
2.授权zabbix监控账号
mysql -uroot -p123456
mysql> grant usage on *.* to zabbix@127.0.0.1 identified by '123456';
mysql> grant usage on *.* to zabbix@'%' identified by '123456';#不安全但是暴力
mysql> flush privileges;
3.编辑安装agent客户端(参考Linux系统-zabbix监控)
4.查看确认的信息
vi /etc/zabbix/zabbix_agentd.conf#系统自己配置可以看一下
Include=/etc/zabbix/zabbix_agentd.d/*.conf #
vi /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf #系统自动配置查看一下就可以
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema="$1"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name="$2"");" | HOME=/var/lib/zabbix mysql -N'
UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V
5.service zabbix-agent restart
systemctl restart mysqld
6.[root@mysql213 ~]# vi /etc/my.cnf #配置mysql验证 在最后添加即可
#Zabbix Agent
[mysql]
host=localhost
user=zabbix
password=123456
socket= /var/lib/mysql/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=123456
socket= /var/lib/mysql/mysql.sock
7.参数验证
zabbix_agentd -t mysql.version
zabbix_agentd -t mysql.ping
8.添加主机系统自带模板就可以 默认发现数据1分钟
大概需要一个小时,会自动发现一些监控项目