困难点:zabbix5.2可用的userparameter_mysql.conf问题,一般不成功是因为监控脚本和数据库账号授权。
01 前言
zabbix内置Mysql的监控模版,因为mariadb和Mysql两者的相关性,所以这个模版也能用在mariadb services上。
02 Mysql
登陆mysql
#mysql -uroot -p |
首先要在mariadb新建一个账户,这个账户不需要有任何权限。这个账户只是用来登入mariadb获取服务状态。
GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'10.255.255.62' IDENTIFIED BY 'zabbix'; |
请将以下内容根据实际情况进行替换:
- user name >>mariadb账户名
- server ip >>mariadb服务器IP
- passwd >>mariadb密码
03 Zabbix Agent
完成mariadb的用户添加后,还要在mariadb服务器安装Zabbix Agent。通过以下文件可以得知还需要新建一个文件,并在这个文件内填入mariadb的信息:
# vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf |
# For all the following commands HOME should be set to the directory that has .my.cnf file with password information. # Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert]. # Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data]. UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive |
然后新建以下文件并进行修改,要注意的是 /var/lib/zabbix 这个路径可能并不存在,需要手动新建:
#新建文件夹
mkdir -p /var/lib/zabbix |
#修改文件
vim /etc/my.cnf |
#填入内容
# # This group is read both both by the client and the server # use it for options that affect everything # [client-server] # # include all files from the config directory # !includedir /etc/my.cnf.d
[mysqld] #skip-grant-tables [mysql] host=10.255.255.62 user=zabbix password=zabbix #socket=/var/lib/mysql/mysql.sock [mysqladmin] host=10.255.255.62 user=zabbix password=zabbix #socket=/var/lib/mysql/mysql.sock [client] host=10.255.255.62 user=zabbix password=zabbix |
#修改文件
vim /var/lib/zabbix/.my.cnf |
[mysql] user=zabbix password=zabbix host=10.255.255.62
[mysqladmin] user=zabbix password=zabbix host=10.255.255.62
[client] user=zabbix password=zabbix host=10.255.255.62 |
完成后需要通过以下命令手动重启mariadb services和zabbix agent services:
#重启mariadb
systemctl restart mariadb.service |
#重启zabbix agent
systemctl restart zabbix-agent.service |
04 Zabbix平台配置
注意,我这里以代理的方式监控
创建mysql监控组
添加监控主机
添加监控模板
查看