天天看點

Zabbix-2.2.2監控MySQL的複制

一.zabbix agentd的安裝

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

<code>groupadd zabbix</code>

<code>useradd</code> <code>-g zabbix -G zabbix -s </code><code>/sbin/nologin</code> <code>-d </code><code>/dev/null</code> <code>zabbix</code>

<code>tar</code> <code>zxvf zabbix-2.2.2.</code><code>tar</code><code>.gz</code>

<code>cd</code> <code>zabbix-2.2.2</code>

<code>.</code><code>/configure</code> <code>--prefix=</code><code>/data/zabbix</code> <code>--sysconfdir=</code><code>/data/zabbix/conf</code> <code>--</code><code>enable</code><code>-agent</code>

<code>make</code> <code>&amp;&amp; </code><code>make</code> <code>install</code>

<code>cp</code> <code>misc</code><code>/init</code><code>.d</code><code>/fedora/core/zabbix_agentd</code> <code>/etc/init</code><code>.d/</code>

<code>chmod</code> <code>755 </code><code>/etc/init</code><code>.d</code><code>/zabbix_agentd</code>

<code> </code><code>vim </code><code>/etc/init</code><code>.d</code><code>/zabbix_agentd</code>

<code>    </code><code>修改BASEDIR=</code><code>/data/zabbix</code>

<code>vim </code><code>/data/zabbix/conf/zabbix_agentd</code><code>.conf</code>

<code>LogFile=</code><code>/data/zabbix/log/zabbix_agentd</code><code>.log    </code><code>//</code><code>日志的路徑</code>

<code>Server=zabbix.</code><code>test</code><code>.com    </code><code>//</code><code>這裡是zabbix server的位址</code>

<code>ServerActive=zabbix.</code><code>test</code><code>.com:10051  </code><code>//</code><code>同上</code>

<code>Hostname=Node1 </code>

<code>mkdir</code> <code>-p </code><code>/data/zabbix/log/</code>

<code>chown</code> <code>zabbix.zabbix </code><code>/data/zabbix/log</code>

<code>service zabbix_agentd start</code>

<code>chkconfig --level 345 zabbix_agentd on</code>

<code>檢視是否正常</code>

<code>netstat</code> <code>-an |</code><code>grep</code> <code>10050</code>

二.監控MySQL的複制

原理:利用在slave上運作show slave status擷取Slave_IO_Running和Slave_SQL_Running的值

1.在mysql上建立監控使用者

<code>grant replication client on *.* to </code><code>'zabbix'</code><code>@</code><code>'localhost'</code> <code>identified by </code><code>'zabbix'</code><code>;</code>

<code>flush privileges;</code>

2.在/data/zabbix/sbin下建立check_mysql_replication.sh腳本

<code>#!/bin/bash</code>

<code>mysql -uzabbix -pzabbix -e </code><code>"show slave status\G"</code> <code>|</code><code>grep</code> <code>-E </code><code>"Slave_IO_Running|Slave_SQL_Running"</code><code>|</code><code>awk</code> <code>'{print $2}'</code><code>|</code><code>grep</code> <code>-c Yes</code>

  給上述檔案授權

<code>chmod</code> <code>+x </code><code>/data/zabbix/sbin/check_mysql_replication</code><code>.sh</code>

3.修改<code>/data/zabbix/conf/zabbix_agentd</code><code>.conf</code>檔案

<code>UnsafeUserParameters=1</code>

<code>UserParameter=mysql.replication,</code><code>/data/zabbix/sbin/check_mysql_replication</code><code>.sh</code>

4.重新開機下zabbix_agemtd服務

<code>service zabbix_agentd restart</code>

三.配置zabbix server

1.在zabbix server上測試,這裡zabbix server是安裝在/webserver/zabbix,則運作

<code>/webserver/zabbix/bin/zabbix_get</code> <code>-s 192.168.100.223 -k </code><code>"mysql.replication"</code>

如果上面傳回的是2,那麼是正常(1.mysql的複制正常 2.zabbix_agentd是配置正常),代表Slave_IO_Running和Slave_SQL_Running兩個狀态都是Yes,這裡192.168.100.223是我的slave的IP位址

2.添加監控項目

點選“configuration”,接着點選"Host",然後找到要監控的Slave,點選它的"Items".

<a href="http://s3.51cto.com/wyfs02/M00/22/DA/wKioL1MpWQyzlt4MAALsQoddEFI601.jpg" target="_blank"></a>

2.點選“create items”

<a href="http://s3.51cto.com/wyfs02/M01/22/D9/wKiom1MpWmfBKfELAAIqaAs-wOk805.jpg" target="_blank"></a>

3.填寫監控項目内容

<a href="http://s3.51cto.com/wyfs02/M02/22/D9/wKiom1MpXQjDJOmkAAK7f8z4KuY858.jpg" target="_blank"></a>

4.建立Triggers,就是建立mysql.replication到什麼時候報警

<a href="http://s3.51cto.com/wyfs02/M01/22/D9/wKiom1MpXgvimbzbAADpWgJ4ATA226.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/22/DA/wKioL1MpXpaQyy11AAOVP2R-JLI551.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/22/DE/wKioL1MqR7GQr97QAAMRuVt3ip4150.jpg" target="_blank"></a>

這個時候我們在Slave機器上,在mysql環境下運作stop slave;

<a href="http://s3.51cto.com/wyfs02/M02/22/DE/wKioL1MqSGCyKrLbAABImjbVFn0750.jpg" target="_blank"></a>

本文轉自 rong341233 51CTO部落格,原文連結:http://blog.51cto.com/fengwan/1379787