1. Add MySQL template to Web page
Configuration > Hosts > Select Host or Add new host > tempaltes, search for MySQL, add popup templates, and then update
2, configuration userparameter_mysql.conf
Locate the configuration file
[Email protected] ~]# Find/-name Userparameter_mysql.conf/usr/share/doc/zabbix22-agent-2.2.16/userparameter_ Mysql.conf
Build a directory to put configuration files in/etc/zabbix
[Email protected] ~]# mkdir/etc/zabbix/zabbix_agentd.d/
Copy the configuration file to this directory
[[Email protected] ~] #cp/USR/SHARE/DOC/ZABBIX22-AGENT-2.2.16/USERPARAMETER_MYSQL.CONF/ETC/ZABBIX/ZABBIX_AGENTD.D /
Create a user to get data about MySQL
Mysql>grant USAGE on *. * to ' Zabbix ' @ ' localhost ' identified by ' 123 '; Mysql>flush privileges;
Add a configuration file to associate with MySQL MY.CNF
[Email protected] ~]# vim/etc/zabbix/.my.cnf [mysql]host = Localhostuser = Zabbixpassword = 123socket =/tmp/mysql.sock[ Mysqladmin]host = Localhostuser = Zabbixpassword = 123socket =/tmp/mysql.sock
Modify the directory where the Userparameter_mysql.conf:HOME directory is new. my.cnf files
[[email protected] ~] #sed -i ' [email protected] /var/lib/[email protected]/etc/zabbix/@g ' /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
[[email protected] ~]# grep -v "^#" /etc/zabbix/zabbix_agentd.d/userparameter_ mysql.conf userparameter=mysql.status[*],echo "show global status where variable _name= ' $ '; " | HOME=/etc/zabbix mysql -N | awk ' {print $$2} ' userparameter= mysql.size[*],bash -c ' echo "Select sum ($ (case " $ " in both|" ") echo "Data_length+index_length";; data|index) echo "$3_length";; free) echo "Data_free";;  ESAC) from information_schema.tables$ ([[ "$" = "All" | | ! "$ ]] |" | echo " where table_schema=\" $1\ "") $ ([[ "$" = "All" | | ! "$ ]] |" | echo "and table_name=\" $2\ ""); | home=/etc/zabbix mysql -n ' Userparameter=mysql.ping,home=/etc/zabbix mysqladmin ping | grep -c aliveuserparameter=mysql.version,mysql -v
Modify the zabbix_agentd.conf file to add a row for the directory where userparameter_mysql.conf resides
[Email protected] ~]# vim/etc/zabbix/zabbix_agentd.d/userparameter_mysql.confinclude=/etc/zabbix/zabbix_ agentd.conf.d/
Restart Zabbix-agentd
[[Email protected] ~]# service Zabbix-agentd restartshutting down Zabbix agent: [OK]sta rting Zabbix agent: [OK]
Test
[[Email protected] ~] #zabbix_get-S 192.168.1.102-p 10050-k mysql.ping1[[email protected] ~]# zabbix_get-s 192.168.1.10 2-p 10050-k mysql.versionmysql Ver 14.14 distrib 5.1.71, for Redhat-linux-gnu (x86_64) using ReadLine 5.1
Zabbix using your own template to monitor MySQL