Zabbix 中使用 Percona Monitoring Plugins 監控 MySQL

來源:互聯網
上載者:User

標籤:zabbix   mysql   centos   

Zabbix 中使用 Percona Monitoring Plugins 監控 MySQL

 

1.安裝zabbix agent

[[email protected] ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.0-1.el7.x86_64.rpm[[email protected] ~]# yum install zabbix-agent

 

2.修改配置

[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.137.3

ServerActive=192.168.137.3

Hostname=szlinux01

 

3.啟動代理

[[email protected] ~]# systemctl enable zabbix-agent[[email protected] ~]# systemctl start zabbix-agent[[email protected] ~]# netstat -tunpl | grep 10050

 

4.在服務端測試資料擷取

[[email protected] ~]# zabbix_get -s 192.168.137.3 -p 10050 -k system.uptime

 

5.安裝php和php-mysql

[[email protected] ~]# yum install epel-release[[email protected] ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7[[email protected] ~]# yum install php php-mysql[[email protected] ~]# rpm -qa zabbix-agent php php-mysql

 

6.安裝配置percona-zabbix-templates

[[email protected] ~]# yum install https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.7-2.noarch.rpm[[email protected] ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/[[email protected] ~]# systemctl restart zabbix-agent

 

7.首先在被監控伺服器szlinux01的mysql裡添加許可權,即本機使用zabbix帳號串連本地的mysql

mysql> grant usage, process, replication client on *.* to ‘zabbix‘@‘localhost‘ identified by ‘[email protected]#123‘;mysql> flush privileges;

 

8.修改php檔案的mysql使用者名稱和密碼

[[email protected] ~]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php

$mysql_user = ‘zabbix‘;

$mysql_pass = ‘[email protected]#123‘;

 

9.測試指令碼

[[email protected] ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg

 

10.配置~zabbix/.my.cnf

[[email protected] ~]# vim ~zabbix/.my.cnf

[client]

user = zabbix

password = ‘[email protected]#123‘

注意:複雜密碼需要引號。

 

11.zabbix使用者測試指令碼

[[email protected] ~]# sudo -u zabbix -H /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave

 

12.匯入模板

將被監控伺服器szlinux01上的/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml下載到本地,通過Zabbix頁面匯入到模板裡。


配置->模板->匯入

650) this.width=650;" title="clip_image002" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px;" alt="clip_image002" src="http://s3.51cto.com/wyfs02/M01/96/09/wKioL1kcKvCRbrxOAACmtpCD8AI314.jpg" border="0" height="526" />

 

報錯:

650) this.width=650;" title="clip_image003" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px;" alt="clip_image003" src="http://s3.51cto.com/wyfs02/M02/96/0A/wKiom1kcKvHjFZhYAAAO3QeF2UY125.png" border="0" height="95" />

解決方案:

手動修改模板檔案解決報錯比較麻煩,有人提到可以將此模板匯入 Zabbix 2.X 系列後,再匯出到 Zabbix 3.X。

這裡直接使用現成可用的 Zabbix 3.X 的 percona-zabbix-templates

zbx_percona_mysql_template.xml模板地址

 

650) this.width=650;" title="clip_image005" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px;" alt="clip_image005" src="http://s3.51cto.com/wyfs02/M00/96/0A/wKiom1kcKvKA1RN1AABlfNKFOBQ965.jpg" border="0" height="233" />

 

13.添加主機並連結模板

650) this.width=650;" title="clip_image007" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px;" alt="clip_image007" src="http://s3.51cto.com/wyfs02/M01/96/0A/wKiom1kcKvKSUjQrAACB5cqawdc903.jpg" border="0" height="317" />

 

發現沒有最新的資料。於是,測試資料擷取:

[[email protected] ~]# zabbix_get -s 192.168.137.3 -p 10050 -k "MySQL.max-connections"

 

報錯:

rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt‘: Operation not permitted

解決方案:

在被監控伺服器szlinux01上面執行如下操作即可

[[email protected] ~]# rm -rf /tmp/localhost-mysql_cacti_stats.txt[[email protected] ~]# touch /tmp/localhost-mysql_cacti_stats.txt[[email protected] ~]# chown -R zabbix:zabbix /tmp/localhost-mysql_cacti_stats.txt

 再在zabbix上測試擷取資料:

[[email protected] ~]# zabbix_get -s 192.168.137.3 -p 10050 -k "MySQL.max-connections"[[email protected] ~]# zabbix_get -s 192.168.137.3 -p 10050 -k "MySQL.Threads-connected"[[email protected] ~]# zabbix_get -s 192.168.137.3 -p 10050 -k "MySQL.running-slave"


資料也有了,過一會,就可以看到有圖了。

本文出自 “SQL Server Deep Dive” 部落格,請務必保留此出處http://ultrasql.blog.51cto.com/9591438/1926767

Zabbix 中使用 Percona Monitoring Plugins 監控 MySQL

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.