您的位置:首页 > 数据库 > SQL

zabbix监控客户端mysql用自带的模板

2017-12-10 21:56 288 查看
1)首先在客户端的mysql里添加权限,即本机使用zabbix账号连接本地的mysql

(都是客户端里面的mysql,也可以不用设置用root的mysql用户比如 root 密码123456则忽略这步骤)

mysql> grant all on *.* to zabbix@'localhost' identified by "123456”;
mysql> flush privileges;


2)在zabbix_agent服务目录下创建.my.cnf 连接文件(一定要看清楚是 .my.cnf 有点的)

线上的zabbix安装目录是/etc/zabbix

[root@ff_db_master1 ~]# cd /etc/zabbix
[root@ff_db_master1 etc]# vi .my.cnf
[client]
user=zabbix
password=123456


注意:

如果在数据库grant授权时,针对的是localhost,这个.my.cnf里面就不用加host参数了【如上配置】

但如果grant授权时针对的是本机的ip(如172.18.25.51),那么在.my.cnf文件里就要加上host参数进行指定了

即在.my.cnf文件就要加上:

[client]
host=172.18.25.51
socket=/Data/app/mysql5.6.25/var/mysql.sock 【这一行可以不用加上,默认会找到的,我就没加】
user=root
password=123456


3)配置MySQL的key文件

[root@/etc/zabbix/zabbix_agentd.d ]# ls
userparameter_mysql.conf
然后查看 userparameter_mysql.conf 文件,看到类似 HOME=/var/lib/zabbix 的路径设置,把路径全都替换为 /etc/zabbix/,也就是上面的.my.cnf文件所在的目录路径。
另外,注意userparameter_mysql.conf 文件里的mysql命令路径(提前做好mysql的系统环境变量,以防mysql命令不被系统识别)
如下:
[root@ff_db_master1 zabbix_agentd.conf.d]# cat 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].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix/ mysql -N | awk '{print $$2}'
# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
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=/etc/zabbix/ mysql -N'
UserParameter=mysql.ping,HOME=/etc/zabbix/ mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V


4)按照上面修改完之后检查一下,然后重启zabbix_agent

[ root@node2 ~ ]# systemctl restart zabbix-agent


再到zabbix的web页面把mysql监控模版导入进去就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息