天天看點

zabbix 使用percona監控mysql資料庫

Zabbix模闆自帶一個MySQL監控模闆,但監控的項目比較少,生産環境推薦使用percona的監控插件。

<code>https:</code><code>//www</code><code>.percona.com</code><code>/doc/percona-monitoring-plugins/1</code><code>.1</code><code>/zabbix/index</code><code>.html</code>

1.安裝percona插件(agent端):

<code>rpm -ivh http:</code><code>//www</code><code>.percona.com</code><code>/downloads/percona-release/redhat/0</code><code>.1-3</code><code>/percona-release-0</code><code>.1-3.noarch.rpm</code>

2.percona是php寫的,是以agent連接配接MySQL必須安裝php和php-mysql

<code>yum </code><code>install</code> <code>php php-mysql -y</code>

<code>yum </code><code>install</code> <code>percona-zabbix-templates -y </code>

<code>      </code> 

<code>#編輯zabbix_agent配置檔案,這步一般預設配置都完成了:</code>

<code>#vi /etc/zabbix/zabbix_agentd.conf</code>

<code>#include=/etc/zabbix_agentd.conf.d/</code>

檢視安裝的percona:

<code>rpm -ql percona-zabbix-templates</code>

<code>/var/lib/zabbix/percona</code>

<code>/var/lib/zabbix/percona/scripts</code>

<code>/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper</code><code>.sh</code>

<code>/var/lib/zabbix/percona/scripts/ss_get_mysql_stats</code><code>.php</code>

<code>/var/lib/zabbix/percona/templates</code>

<code>/var/lib/zabbix/percona/templates/userparameter_percona_mysql</code><code>.conf</code>

<code>/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2</code><code>.0.9-sver1.1.7.xml</code>

3.複制模闆到該目錄下:

<code>cp</code> <code>/var/lib/zabbix/percona/templates/userparameter_percona_mysql</code><code>.conf </code><code>/etc/zabbix/zabbix_agentd</code><code>.d/</code>

4.讓php可以連接配接到mysql上:

<code>#在mysql上授權一個賬号</code>

<code>grant </code><code>select</code><code>,process,replicationclient on *.* to jiankong@localhost identified by </code><code>"jiankong"</code><code>;</code>

<code>flush priveleges;</code>

<code>#process這個權限可以執行show processlist和kill這個指令。</code>

<code>#relicationclient權限可以檢視master和slave的狀态。</code>

<code>#編輯percona的配置檔案</code>

<code>vi</code> <code>/var/lib/zabbix/percona/scripts/ss_get_mysql_stats</code><code>.php</code>

<code>$mysql_user = </code><code>'root'</code><code>;</code>

<code>$mysql_pass = </code><code>'password'</code><code>;</code>

<code>$mysql_port = 3306;</code>

5.測試并修改監控腳本:

<code>/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper</code><code>.sh gg</code>

6.修改監控腳本,預設監控MySQL主從的,測試是否能用,如果是從庫傳回值應該為1,如果出錯的話此處需要手工修改:

<code>/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper</code><code>.sh running-slave</code>

7.導入zabbix模闆:

<code>cd</code> <code>/var/lib/zabbix/percona/templates/</code>

<code>sz zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml</code>

8.下載下傳到本地,然後在zabbix上導入

<code>Configuration -&gt; Templates-&gt; Import</code>

注意:導入模闆的時候會出錯:

解決:下載下傳個3.0的模闆導入即可解決。

<a href="https://www.ttlsa.com/wp-content/uploads/2016/07/Percona-MySQL-Server-Template.zip" target="_blank">https://www.ttlsa.com/wp-content/uploads/2016/07/Percona-MySQL-Server-Template.zip</a>

附件中我已上傳,可以直接下載下傳導入。

在生産環境中如果監控到主出現故障,則需要切換到從,則需要清除從庫的資訊。

<code>stop slave;</code>

<code>reset slave all;  </code><code>#清除從庫的連接配接資訊和二進制檔案名位置,show slave status不再有效。</code>

<a href="http://down.51cto.com/data/2366611" target="_blank">附件:http://down.51cto.com/data/2366611</a>

本文轉自 王家東哥 51CTO部落格,原文連結:http://blog.51cto.com/xiaodongge/1919521