(ext.) zabbix3.4 monitor MySQL with Percona-monitoring-plugins

Source: Internet
Author: User
Tags install php percona egrep

Original: 79656771

Brief introduction

Before primarily using Nagios to monitor MySQL, this article mainly introduces the use of percona-monitoring-plugins monitoring Mysql,percona monitoring plug-in is PHP development, so to install PHP environment in the agent.

Configure the installation

I. zabbix-agent-side operation

1. Install software dependencies

yum install php php-mysql -y
    • 1

2. Installing the Percona Plugin

#centos 6RPM-UVH https://www.percona.com/downloads/ Percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/ Binary/redhat/6/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm #centos 7RPM-UVH https://www.percona .com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/ Binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm    
    • 1
    • 2
    • 3
    • 4

3. Copy the configuration file to the Zabbix_agent related directory

cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/#重启生效service zabbix-agent restart
    • 1
    • 2
    • 3

4. Add a read-only account to the database

grant process,super,replication client on *.* to ‘zabbix‘@‘localhost‘ identified by ‘zabbix‘;
    • 1

Since monitoring MySQL requires the use of show processlist and master-slave commands, you need to give Zabbix permissions to process,super,replication client and other permissions.

5. Modifying script parameters

vim  /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php$mysql_user = ‘zabbix‘;$mysql_pass = ‘zabbix‘;$mysql_port = 3306;$mysql_socket = ‘/tmp/mysql.sock‘;$mysql_flags = 0;
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

The above parameters need to be completed according to the actual

6. Modify Log Permissions

chown -R zabbix.zabbix /tmp/localhost-mysql_cacti_stats.txt 
    • 1

7. Testing

#在zabbix agent上测试MySQL.Threads-connected[root@test83 scripts]# bash /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iu77#在zabbix server上测试[root@test250 ~]# /App/zabbix/bin/zabbix_get -s 10.10.5.83 -k MySQL.Threads-connected77
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

If the output is normal, the Percona-monitoring-plugins configuration is successful. Next we need to install the template.

Two. Zabbix-server-side operation
1. Import the Monitoring template

Import "Zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml" report as above error, cause the original template in 3.x using a problem, you need to import the template into 2.4 and everywhere.
2. To add a template to the client, we do not have more instructions here.

Solution:

Manually modify the template file to resolve the error is more troublesome, it was mentioned that you can import this template into the Zabbix 2.X series, and then export to Zabbix 3.0.
Here we directly use the ready-made Zabbix 3.X percona-zabbix-templates
Zbx_percona_mysql_template.xml Template Address

Three. Monitor MySQL master and slave
To operate on the slave node:
1. Permission needs to be improved

#若只分配select权限,需进一步提升权限grant process,super,replication client on *.* to ‘zabbix‘@‘localhost‘ identified by ‘zabbix‘;
    • 1
    • 2

2. Modify the Script

vim/ var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.shres= ' home=~zabbix MySQL- Uzabbix-pzabbix-e  ' SHOW SLAVE status\g ' | egrep  (slave_io_ Running| slave_sql_running): ' | Awk-f:  ' {print $} ' | tr  ' \ n '  ', ' Span class= "hljs-comment" > #修改后测试 [Root @test83 ~]# bash/var/ lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slavewarning:using A Password on the command line interface can be Insecure. 1               
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

We see the output "warning:using a password on the command line interface can be insecure."
So we need to add the following in/ETC/MY.CNF:

[client]port            = 3306socket = /tmp/mysql.sockuser = zabbixpassword = zabbix
    • 1
    • 2
    • 3
    • 4
    • 5

Then change the script again to:

vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.shRES=`HOME=~zabbix mysql -e ‘SHOW SLAVE STATUS\G‘ | egrep ‘(Slave_IO_Running|Slave_SQL_Running):‘ | awk -F: ‘{print $2}‘ | tr ‘\n‘ ‘,‘`#测试[root@test83 ~]# bash /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave1
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

After the change, Zabbix will monitor MySQL master and slave, of course, we need to on the master node on the slave of the monitoring items in the template is disabled so that only the slave node synchronization can be monitored.

(GO) zabbix3.4 using Percona-monitoring-plugins to monitor MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.