zabbix 4.0 Monitoring mysql

 zabbix official support for monitoring MySQL, but the direct use of the default template is not available, require additional setup before you can use. If you only need to do simple monitoring of mysql database, zabbix template comes fully able to meet the requirements

  Here are the steps to monitor mysql zabbix comes with templates.

  Environment: zabbix4.0 ubuntu16.04 LTS mysql 5.5

  1, add in the relevant host mysql the monitoring template. Template name: Template DB MySQL.

  2, the configuration of the client mysql, mysql create a user to obtain relevant data

# Set the database encoding 
the CREATE DATABASE zabbix CHARACTER the SET utf8 COLLATE utf8_bin; 
# create a new MySQL database zabbix, stores data collected # username zabbix, password 123456 GRANT ALL PRIVILEGES ON zabbix. * The TO zabbix @ ' % ' IDENTIFIED BY ' 123456 ' ; # refresh permission FLUSH pRIVILEGES;

  3, set up an account to be monitored after completion of the new terminal /etc/zabbix/.my.cnf file to provide Zabbix Agent to access the database, similar to the following:

# vim /etc/zabbix/ .my.cnf

[mysql]
host=localhost
user=zabbix
password=123456
socket=/data/mysql/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=123456
socket=/data/mysql/mysql.sock

# mysql.sock文件通过find / -name mysql.sock找出路径

  4. A profile modification agent

# Vi /etc/zabbix/zabbix_agentd.conf 

# modify server to server ip 

# modify the settings for the server hostname hostname 

# modify serveractive server ip: port

     5, modify /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf (if not created), this file is used to develop Zabbix Agent how to get MySQL data, we need all the / var / lib / zabbix modify the current .my path .cnf file / etc / zabbix. Save and restart the Zabbix Agent After the setup is complete

# 新建userparameter_mysql.conf文件
vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
#修改文件后内容如下 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=/var/lib/zabbix mysql -N' UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive UserParameter=mysql.version,mysql -V # 重启agent服务 systemctl restart zabbix-agent

  6, the configuration is complete

   Host Configuration Interface

   

   The latest data show interface

  

  

 

Guess you like

Origin www.cnblogs.com/daofaziran/p/12559948.html