zabbix监控mysql数据库

系统:Centos7

zabbix-agent版本:3.4

部署zabbix-agent

rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm

yum install -y zabbix-agent

systemctl start zabbix-agent

systemctl enable zabbix-agent

在mysql中创建监控用户

mysql> 
mysql> grant usage on *.* to zabbix@127.0.0.1 identified by 'Zabbix.2018';
Query OK, 0 rows affected, 1 warning (0.08 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.10 sec)

[root@server1 ~]# mysqladmin -uzabbix -p"Zabbix.2018" -h127.0.0.1 ping
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqld is alive #出现mysqld is alive 证明成功。

[root@server1 ~]# mysqladmin -uzabbix -p"Zabbix.2018" -h127.0.0.1 ping | grep -c alive
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
1

命令行中输入密码是不太友好的,

[root@server1 zabbix]# vim /etc/zabbix/.my.cnf

[client]
user=zabbix
host=127.0.0.1
password=Zabbix.2018

[root@server1 zabbix_agentd.d]# 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].
# 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

验证测试

[root@server1 zabbix_agentd.d]# /usr/sbin/zabbix_agentd -t mysql.ping -c /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf 
mysql.ping [t|1]

同时,在Server端也可以使用使用zabbix_get命令来测试从Server端获取指定的Client端的数据,如下:

[root@zabbix ~]# zabbix_get -s 192.168.1.94 -p 10050 -k mysql.ping
1

systemctl restart zabbix-agent

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值