Zabbix3.4.11使用自带模板监控MySQL
Zabbix默认的agentd模板里面有一个userparameter_mysql.conf配置文件,修改文件内容如下:
[root@c75 zabbix_agentd]# cat /usr/local/zabbix/conf/zabbix_agentd/userparameter_mysql.conf
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/usr/local/zabbix/conf/ mysql -N | awk '{print $$2}'
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=/usr/local/zabbix/conf/ mysql -N'
UserParameter=mysql.ping,netstat -ntpl |grep 3306 |grep mysql |wc|awk '{print $1}'
UserParameter=mysql.version,mysql -V
UserParameter=mysql.vars[*],echo "show variables where Variable_name='$1';" | HOME=/usr/local/zabbix/conf/ mysql -N | awk '{print $$2}'
做下MySQL的软连接:
ln -s /usr/local/mysql/bin/mysql /bin/
修改zabbix_agentd.conf文件,增加
Include=/usr/local/zabbix/conf/zabbix_agentd/*.conf
登陆MySQL控制台创建只读用户:
GRANT SELECT ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY 'xxxxxx';
在/usr/local/zabbix/conf创建.my.cnf文件,内容如下:
[root@c75 conf]# cat /usr/local/zabbix/conf/.my.cnf
# Zabbix Agent
[mysql]
host=localhost
user=zabbix
password="xxxxxx"
socket=/data/mysql/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password="xxxxxx"
socket=/data/mysql/mysql.sock
重启zabbix-agentd
killall -9 zabbix_agentd
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/conf/zabbix_agentd.conf
在zabbix-server机器上检测
[root@monitor ~]# zabbix_get -s 192.168.3.244 -p 10050 -k mysql.version
mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper
[root@monitor ~]# zabbix_get -s 192.168.3.244 -p 10050 -k mysql.ping
1
注意:如果测试的时候报错:sh: mysql: command not found,sh: mysqladmin: command not found,
修改userparameter_mysql.conf中mysql,mysqladmin命令的路径,使用绝对路径或者做下软连接即可;
如果报错
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.
执行的脚本中执行
chmod +s /bin/netstat
来解决chmod +s 的意思是:为了方便普通用户执行一些特权命令,SUID/SGID程序允许普通用户以root身份暂时执行该程序,并在执行结束后再恢复身份
给要监控的主机添加MySQL模板,最后效果如下图:
Tag标签:「mysql zabbix 监控 模板」更新时间:「2021-11-04 11:17:27」阅读次数:「818」