Zabbix 3.2.6-Mysql multi-instance Monitoring-Percona Monitoring Plugins automatically found that zabbix-percona

Source: Internet
Author: User
Tags percona egrep

Zabbix 3.2.6-Mysql multi-instance Monitoring-Percona Monitoring Plugins automatically found that zabbix-percona
Mysql multi-instance monitoring system environment: cat/etc/redhat-releaseCentOS Linux release 7.3.1611 (Core) kernel version: uname-r3.10.0-514. el7.x86 _ 64docker version: docker-vDocker version 1.12.6, build 3a094bd/1.12.6docker image version: docker. io/zabbix-web-nginx-mysql latestdocker. io/zabbix-server-mysql latestdocker. io/mysql 5.7 monitored mysql application version: mysql-5.7.17-linux-glibc2.5-x86_64Percona Monitoring Plugins version: 1.1.7-2. noarch. rpm is written at the beginning: If zabbi X server and zabbix agent have been installed in other ways. You can skip steps 1 and 2 and start from step 2. 1. The zabbix server is running in the docker container. Therefore, the server first installs the docker service yum install-y epel-releaseyum install-y docker # the command for centos6.x is yum install-y docker- io then run the docker service systemctl start dockerdocker Add the boot auto start systemctl enable docker check whether docker has successfully started systemctl status docker 2. install related containers 2.1. mysql container docker run -- name mysql-server-t \-e MYSQL_DATABASE = "zabbix" \-e MYSQL_USER = "zabbix" \-e MYSQL_PASSWORD = "ywwd.net" \-e MYSQL_ROOT_PAS SWORD = "ywwd.net" \-v/data/container/mysql/zabbix:/var/lib/mysql \-v/etc/localtime: ro \ -- restart = always \-d mysql: 5.7 \ -- character-set-server = utf8 -- collation-server = utf8_general_ci -- SQL-mode = "NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION" 2.2. zabbix-server container docker run -- name zabbix-server-mysql-t \-e DB_SERVER_HOST = "mysql-server" \-e MYSQL_DATABASE = "zabbix" \-e MYSQL_USER = "Zabbix" \-e MYSQL_PASSWORD = "ywwd.net" \-e MYSQL_ROOT_PASSWORD = "ywwd.net" \ -- link mysql-server: mysql \-p 10051: 10051 -- restart = always \-v/etc/localtime: ro \-d zabbix/zabbix-server-mysql: latest 2.3. zabbix-web Container (nginx) docker run -- name zabbix-web-nginx-mysql-t \-e DB_SERVER_HOST = "mysql-server" \-e MYSQL_DATABASE = "zabbix" \-e MYSQL_USER = "zabbix "\ -e MYSQL_PASSWORD = "ywwd. Net "\-e MYSQL_ROOT_PASSWORD =" ywwd.net "\ -- link mysql-server: mysql \ -- link zabbix-server-mysql: zabbix-server \-v/etc/localtime: /etc/localtime: ro \-p 80: 80 \ -- restart = always \-d zabbix/zabbix-web-nginx-mysql: latest Note: there is a small problem, zabbix-web-nginx-mysql STARTUP script/run_zabbix_component.sh specifies the time zone, not China's Asia/Shanghai, so we need to enter zabbix-web-nginx-mysql to modify 2.4. modify zabbix-web's Time Zone docker exec-it zabbix-web-nginx-my SQL/bin/bashTZ =$ {TZ:-"Asia/Shanghai"} changed here to Asia/Shanghai, otherwise, the zabbix-web end time will be slow for 5 hours sed-in's # Europe/Riga # Asia/Shanghai # G'/run_zabbix_component.sh after changing the time zone, you need to restart the container docker restart zabbix-web-nginx-mysql2.5. open the service port number of zabbix-server and zabbix-agent on the firewall. The port number is firewall-cmd -- permanent -- add-port = 10050-10051/tcp # -- permanent, and the port number is 10050zabbix-agent, 10051zabbix-server service port firewall-cmd -- reload # reload the firewall fi Rewall-cmd -- list-all # finally check whether the configuration takes effect so that zabbix-server has been installed. Next, we use the rpm package to install the rpm-ivh zabbix-agent-3.2.6-1.el7.x86_64.rpm and we also need to release zabbix-agent. port firewall-cmd -- permanent -- add-port = 10050/tcp firewall-cmd -- reload and configure egrep-v '^ $ | ^ #'/etc/ zabbix/zabbix_agentd.confPidFile =/var/run/zabbix/empty =/var/log/zabbix/zabbix_agentd.logServer = 10.0.0.106 # <= zabbix-server IP address S ErverActive = 10.0.0.106 # <== zabbix-server IP address, active Hostname = 10.0.0.107 # <== zabbix-agent IP address or host name Include =/etc/zabbix/zabbix_agentd.d /*. conf then add the host on the web interface of zabbix-server. 1) modify the host name, which corresponds to the Hostname in the configuration file of zabbix-agent. 2) Select the group you want to set, if the group does not exist, add it to the new group in the following column. 3) Specify the IP address or domain name of zabbix-agent (the port number is generally changed, click Add. 3. Use the Percona Monitoring Plugins plug-in for MySQL multi-instance Monitoring. 1) the script for Monitoring zabbix by percona is written in php. Therefore, you need to prepare the php runtime environment, use yum to install Can meet the requirements: yum install-y php php-mysql2) install percona-zabbix-templatesyum install-y https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/6/x86_64/percona-zabbix-templates-1.1.7-2.noarch.rpm can also be configured Percona yum repository after installation, it is recommended to configure percona yum source, as a DBA, you must use the percona toolkit. Note: I didn't use this method. I installed percona toolkit through the source code package. Yum install-y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-3.noarch.rpmyum install-y percona-zabbix-templates 4, yum installed shell for a single instance version, so we want to make relevant changes, here has been modified, we clone directly, compare, need to install gitgit clone https://github.com/lianghx7123/Mysql_Multiport_monitor_used_zabbix.git mysql_monitor 1) After comparison, we found that in the get_mysql_stats_wrapper.sh script, added the relevant parameter PORT = $2 HOST = 127.0.0.1 2) CMD = "/usr/bi N/php-q $ DIR/ss_get_mysql_stats.php -- host $ HOST -- items $ ITEM -- port $ PORT "the php path of the CMD variable must be specified correctly. Otherwise, an error is reported, we added -- port $ PORTCACHEFILE later to judge if [$ PORT = 3306]; thenCACHEFILE = "/tmp/$HOST-mysql_cacti_stats.txt" elseCACHEFILE = "/tmp/$HOST-mysql_cacti_stats.txt ": $ PORTfi 3) Modify running-slave as follows. Here, the alarm overlaps with another Slave Stopped in the template. However, this alarm is more sensitive than Slave Stopped, and the alarm is triggered about 3 minutes in advance, however, in the/etc/my. cnf and the mysql account and password added in the script. if ["$ I TEM "=" running-slave "]; then # Check for running slaveRES = 'home = ~ Zabbix/usr/local/mysql/bin/mysql-P $ PORT-h127.0.0.1-uzabbix-e 'show slave status \ G' | egrep '(Slave_IO_Running | Slave_ SQL _Running ): '| grep-I yes | wc-l' if ["$ RES"-ne 2]; thenecho 1 elseecho 0fiexit and in/etc/my. adding [mysql] password = 123456 # In cnf poses a security risk. change the cnf file attribute to 600 4) # cat $ CACHEFILE | sed's // \ n/g; s/-1/0/G' | grep $ ITEM | awk-F: '{print $2}' is changed to cat $ CACHEFILE | sed's // \ n/G' | grep $ ITEM | Awk-F: '{print $2}' or cat $ CACHEFILE | sed's // \ n/g; s/-1/1/G' | grep $ ITEM | awk-F: '{print $2}' is changed to the first one, set the alarm threshold to less than 0 on the web Side of zabbix-server or equal to 1 to the second line. You can set the alarm threshold to 1 in a unified manner, 5. Modify the automatic discovery script cat mysql_low_discovery.sh #! /Bin/bash # Fucation: mysql low-level discovery # Script_name mysql_low_discovery.shdiscovery () {port = ($ (sudo ss-tpln | awk-F "[:] + "'/[m] ysql/{print $4}') printf' {\ n' printf' \ t" data ": [\ n' for key in $ {! Port [@]} doif [["$ {# port [@]}"-gt 1 & "$ {key}"-ne "$ ($ {# port [@]}-1 )) "]; thensocket = 'ps aux | grep $ {port [$ {key}]} | grep-v grep | awk-F' = ''{print $9} '| cut-d ''-f 1' printf' \ t {\ n' printf" \ t \ "{# MYSQLPORT }\": \ "$ {port [$ {key}]} \"}, \ n "else [[" $ {key} "-eq" ($ {# port [@]}-1 )) "] socket = 'ps aux | grep $ {port [$ {key}]} | grep-v grep | awk-F' ='' {print $9} '| cut-d ''-f 1 'printf' \ t {\ n' printf" \ t \ "{# MYSQLPORT }\": \ "$ {port [$ {key}]} \"} \ n "fidoneprintf' \ t] \ n'printf'} \ n'} notice: because sudo is used here, you must add the sudo permission to the zabbix user and only run the ss Command echo 'zabbix ALL = (ALL) NOPASSWD: /usr/sbin/ss'>/etc/sudoers modify ss_get_mysql_stats.php script $ mysql_user = 'zabbix '; <===== this is the php login mysql user $ mysql_pass = 123456; <===== this is the php login mysql password $ mysql_port = NULL; <===== change port and socket to NULL $ mysql_socket = NULL; Modify userparameter_percona_mysql.c In the onf configuration file, replace comma ',' with [*], sed-in's #, # [*], # g'userparameter_percona_mysql.conf add $ 1sed-in's #$1 # G' userparameter_percona_mysql.conf to the end of each line and add the port in the first line to automatically detect the sed-in '1i UserParameter = MySQL. discovery, /bin/bash/var/lib/zabbix/percona/scripts/mysql_low_discovery.sh 'userparameter_percona_mysql.conf 6. Copy the script file and run mkdir-p/var/lib/zabbix/percona/scripts/ cp userparameter_percona_mysql.conf/etc/zabbix/za Bbix_agentd.d/cp release/var/lib/zabbix/percona/scripts/cp ss_get_mysql_stats.php/var/lib/zabbix/percona /chmod 700/var/lib/zabbix/percona/scripts/* chown-R zabbix. /var/lib/zabbix/7. At last, you must perform authorization ON all the master databases. Otherwise, you cannot obtain the metric data grant select, PROCESS, SUPER, replication client on *. * TO 'zabbix' @ 'localhost' identified by '20140901'; Flush privileges; 8. Finally, import the template Mysql_Multiport.xml to zabbix-server. All the script files used have been added to the attachment. You can download and use them. Create a trigger prototype on the zabbix-server side. Click host ==> auto discovery ==> trigger type ==> Click Create trigger prototype in the upper right corner to assign an alert level, click Add in the expression column, select a prototype, and then select MySQL. slave-stopped [# MYSQLPORT}] select the latest tvalue smaller than NN to 0 note: if cat $ CACHEFILE | sed's // \ n/g; s/-4.4/G' is specified in section 1/1, | grep $ ITEM | awk-F: '{print $2}' selects the latest T value to be 1, and then we can manually stop master-slave replication. After a moment, an alarm will be sent. The blog site does not allow attachments, so I can only put the attachment on Baidu cloud http://pan.baidu.com/s/1hrI03is reference article: https://ywwd.net/read-1271https://github.com/hc-dba/Mysql_Mu Ltiport_monitor_used_zabbixhttp: // www.ywnds.com /? P = 6199 can also be added and mail alarm, here we recommend the following blog alarm: https://www.oschina.net/news/75588/zabbix-3.0.3

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.