Since Zabbix 2.2, Zabbix has officially supported MySQL monitoring, but MySQL monitoring is not available by default and requires additional settings before it can be used. When Kaijia switched Zabbix to a new server, the performance was more than enough, so he decided to give full play to the remaining memory and SSD performance, and also enabled monitoring of MySQL, Apache, PHP-FPM, etc.
First make sure that the Zabbix service has a MySQL monitoring template. The MySQL template is included by default in Zabbix 2.2, but if you upgraded from an older version of Zabbix, the template may not be imported. In this case, you need to visit the official Wiki page of Zabbix to download this template Template_App_MySQL-2.2.0.xml and then configure it in the front-end Web interface of the Zabbix server
The next step is to set the monitored terminal (need to install Zabbix Agent)
How to install Zabbix Agent, I will briefly explain it. Download the zabbix source file to the /tmp/install directory
./configure --enable-agent
make install
vi /usr/local/etc/zabbix_agentd.conf file
Server=192.168.153.181#Zabbix Server轮询Agent ListenPort=10050 ListenIP=0.0.0.0 ServerActive=192.168.153.181#Agent actively requests Zabbix Server
First of all, a MySQL account must be established for Zabbix Agent to log in to obtain MySQL status. This account does not require any permissions. Of course, you can log in to the MySQL of the monitored terminal and create a new account.
GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY '密码'; FLUSH PRIVILEGES;
Modify the mysql configuration file vim /etc/my.cnf (mysql is installed by default in yum, the configuration file is in /etc/my.cnf)
[client] port = 3306 socket = /var/lib/mysql/mysql.sock default-character-set=utf8 [mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock skip-locking key_buffer_size = 256M max_allowed_packet = 1M table_open_cache = 256 sort_buffer_size = 1M read_buffer_size = 1M read_rnd_buffer_size = 4M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size= 16M thread_concurrency = 8 default-character-set=utf8 log-bin=mysql-bin binlog_format=mixed server-id = 1 [mysqldump] quick max_allowed_packet = 16M #It is better to put the configuration content in /var/lib/zabbix [mysql] host=localhost user=zabbix password=zabbix socket=/var/lib/mysql/mysql.sock no-auto-rehash [myisamchk] key_buffer_size = 128M sort_buffer_size = 128M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout #It is better to put the configuration content in /var/lib/zabbix [mysqladmin] host=localhost user=zabbix password=zabbix socket=/var/lib/mysql/mysql.sock
It is recommended to create a file .my.cnf in the /var/lib/zabbix directory with the following configuration [recommended this method]
Because the directory is specified in the /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf file
UserParameter=mysql.size[*],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
[mysql] host=localhost user=zabbix password=zabbix socket=/var/lib/mysql/mysql.sock [mysqladmin] host=localhost user=zabbix password=zabbix socket=/var/lib/mysql/mysql.sock
Modify zabbix agent configuration
vim /usr/local/etc/zabbix_agentd.conf (installed from source, no --prefix is set, the configuration file directory is here)
Copy the userparameter_mysql.conf file to the /usr/local/etc/zabbix_agentd.conf.d/ directory (please modify the specific installation path according to the actual situation)
# cp /tmp/install/zabbix-2.2.9/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
Copy the service script into /etc/rc.d/init.d so that chkconfig can manage the service
cp /tmp/install/zabbix-2.2.9/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/
Start the zabbix_agent service (you must first create the zabbix user Linux user)
If it is already enabled, restart the service
service zabbix_agentd restart
Finally, don't forget to open the firewall port 10050
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
Above
Reference article
http://www.kaijia.me/2014/01/use-zabbix-monitor-mysql-server/