一、安装zabbix server 略
二、安装zabbix agent 略
三、给主机套自带的模板 略
四、创建授权用户
mysql> grant all on *.* to 'zabbix'@'localhost' identified by 'musingtec2019';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
五、创建连接文件
root@[ 8.10.201.33 ]@znhjkdba:/etc/zabbix# ls
zabbix_agentd.conf zabbix_agentd.d
root@[ 8.10.201.33 ]@znhjkdba:/etc/zabbix# cat .my.cnf
[mysql]
host=localhost
user=zabbix
password=musingtec2019
socket=/tmp/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=musingtec2019
socket=/tmp/mysql.sock
六、修改模板文件
修改里面的路径为.my.cnf的路径
sed -i "s@/var/lib/zabbix@/etc/zabbix@g" /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
里面的路径如果找不到mysql 或者mysqladmin 请修改使用绝对路径。我用的就是绝对路径
root@[ 8.10.201.33 ]@znhjkdba:/etc/zabbix# cat 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 /data/mysql/bin/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 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 /data/mysql/bin/mysqladmin ping | grep -c alive
UserParameter=mysql.version,/data/mysql/bin/mysql -V
UserParameter=mysql.portNum,/usr/sbin/ss -an |grep :3306 |wc -l #这个是我自定义的
七、重启代理和测试
systemctl restart zabbix-agent
root@[zbx-srv1 8.11.8.168]@iimapp1:/root# zabbix_get -I 8.11.8.170 -s 8.10.201.33 -p 10050 -k "mysql.version"
/data/mysql/bin/mysql Ver 14.14 Distrib 5.6.44, for linux-glibc2.12 (x86_64) using EditLine wrapper
root@[zbx-srv1 8.11.8.168]@iimapp1:/root# zabbix_get -I 8.11.8.170 -s 8.10.201.33 -p 10050 -k "mysql.ping"
1
root@[zbx-srv1 8.11.8.168]@iimapp1:/root# zabbix_get -I 8.11.8.170 -s 8.10.201.33 -p 10050 -k "mysql.portNum"
124
root@[zbx-srv1 8.11.8.168]@iimapp1:/root#
八、查看服务端最新数据
九、创建触发器