官方文档入口
自带模板官方文档
官方git地址1
官方git地址2
被监控mysql上创建用户
1
2
| CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '12345';
GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';
|
zabbix agent配置
参考zabbix agent安装
由于我mysql/mariadb是容器方式安装的,默认localhost走socket连接,会报错,配置host=127.0.0.1
即可
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
添加.my.cnf
1
2
3
4
5
6
7
8
9
| tee ~/zabbix/.my.cnf << EOF
[client]
host='127.0.0.1'
user='zbx_monitor'
password='12345'
EOF
# 测试上面添加的文件是否生效
HOME=$HOME/zabbix mysqladmin ping
|
修改自带userparameter_mysql.conf,mysql,mysqladmin等命令前全加上HOME变量
1
2
3
| cp ~/zabbix/conf/zabbix_agentd/userparameter_mysql.conf{,.bak} # 可选,备份文件
sed -ri "s#, (mysqladmin|mysql)#, HOME=$HOME/zabbix \1#" $HOME/zabbix/conf/zabbix_agentd/userparameter_mysql.conf
|
修改zabbix_agentd.conf
1
| echo "Include=$HOME/zabbix/conf/zabbix_agentd/userparameter_mysql.conf" >> ~/zabbix/conf/zabbix_agentd.conf
|
重启zabbix agent
1
2
| ps -ef|awk '/zabbix_agent[d] -c/{print $2}'|xargs -i kill {}
~/zabbix/sbin/zabbix_agentd -c ~/zabbix/conf/zabbix_agentd.conf
|
测试
1
2
3
| ~/zabbix/bin/zabbix_get -s 127.0.0.1 -k mysql.ping[127.0.0.1,3306]
~/zabbix/sbin/zabbix_agentd -c ~/zabbix/conf/zabbix_agentd.conf -t mysql.version[127.0.0.1,3306]
|
zabbix server配置
链接模板
容器安装的mysql/mariadb,这一步是重点
大功告成