1. 程式人生 > >Zabbix實戰-簡易教程(6)--Server端高可用

Zabbix實戰-簡易教程(6)--Server端高可用

then lock file timeout conf 腳本 secret oot rac div

3.4 server前端高可用

至此,單臺Zabbix server環境已經搭建完成,為了達到高可用效果,我們需要通過2臺服務器之間通過HA軟件進行探測,一旦檢測到主的server掛掉後,從的server會立即頂替。我們這裏采用keepalived軟件來實現。

3.4.1 Keepalived安裝

直接yum安裝即可 Yum install keepalived

3.4.2 keepalived配置

Master上的keepalived配置如下:

【Master】 cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
 
global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 
127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_zabbix_server { script "/etc/keepalived/chk_zabbix_server.sh" interval 30 weight 2 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 60 priority 150 advert_int 1 mcast_src_ip 142.162
.196.111 authentication { auth_type PASS auth_pass ZabbixServer } track_script { chk_zabbix_server } virtual_ipaddress { 142.162.196.116 } }

【Slave】slave上的配置如下:

cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
 
global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 
127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_zabbix_server { script "/etc/keepalived/chk_zabbix_server.sh" interval 30 weight 2 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 60 priority 99 advert_int 1 mcast_src_ip 142.162.196.112 authentication { auth_type PASS auth_pass ZabbixServer } track_script { chk_zabbix_server } virtual_ipaddress { 142.162.196.116 } }

服務器上的檢測腳本如下:

cat /etc/keepalived/chk_zabbix_server.sh
#!/bin/bash
#
#
status1=$(ps aux|grep -w "zabbix_server" | grep -v grep | grep -v bash | wc -l)
 
if [ "${status1}" = "0" ]; then
 
        /etc/init.d/zabbix-server start
        sleep 3
 
        status2=$(ps aux|grep zabbix_server | grep -v grep | grep -v bash |wc -l)
        if [ "${status2}" = "0"  ]; then
                /etc/init.d/keepalived stop
        fi
fi

3.5 Zabbix master和slave文件同步

為了達到主從切換後,master和slave的文件一致,我們這裏采用了rsync進行服務端文件實時同步。 需要同步的服務器配置【Slave】:

3.5.1 rsync安裝

yum install rsync

3.5.2配置rsync,同步web文件和配置文件

cat rsync.conf ###################global config#################### uid = nobody gid = nobody use chroot = yes strict modes = yes timeout = 300 transfer logging = true log format = %h %a %o %f %u %l %m %P pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log incoming chmod = Du=rwx,Dg=rx,Do=r,Fu=rwx,Fg=rx,Fo=r exclude from = /etc/rsyncd/exclude_filelist auth users = zabbixmonitor secrets file = /etc/rsyncd/zabbixmonitor.pas hosts allow = * #####################module config################### [zabbixweb] path = /usr/share/zabbix/ comment = zabbixweb_log #ignore errors log file = /var/log/rsync/zabbixweb.log read only = no write only = no list = false uid = root gid = root #####################module config################### [zabbixconfig] path = /etc/zabbix/zabbix_server.conf comment = zabbixconfig_log #ignore errors log file = /var/log/rsync/zabbixconfig.log read only = no write only = no list = false uid = root gid = root /usr/bin/rsync --daemon --config=/etc/rsyncd/rsync.conf

3.5.3 sersync配置

被同步的服務端【Master】 被同步端采用金山周洋同學寫的sersync程序進程實施同步,這個sersync集成了rsync+inotify功能,只需在後臺開啟進程即可。 cd sersync/ [[email protected] sersync]# ll total 1780 -rwxr-xr-x 1 root root 2214 Oct 26 2011 confxml.xml -rwxr-xr-x 1 root root 1810128 Oct 26 2011 sersync2 -rwxr-xr-x 1 root root 2247 Jan 21 15:17 zabbixconfig.xml -rwxr-xr-x 1 root root 2248 Jan 21 15:44 zabbixweb.xml Zabbixweb.xml配置:
<sersync>
        <localpath watch="/usr/share/zabbix/">
            <remote ip="172.29.31.112" name="zabbixweb"/>
        </localpath>
        <rsync>
            <commonParams params="-artuz"/>
            <auth start="true" users="zabbixmonitor" passwordfile="/etc/rsyncd/zabbixmonitor.pas"/>
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <timeout start="false" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
        </rsync>
        <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
        <crontab start="false" schedule="600"><!--600mins-->
            <crontabfilter start="false">
                <exclude expression="*.php"></exclude>
                <exclude expression="info/*"></exclude>
            </crontabfilter>
        </crontab>
        <plugin start="false" name="command"/>
</sersync>

Zabbixconfig.xml配置類似。

3.5.4 啟動

./sersync2 -n 2 -o zabbixconfig.xml -d ./sersync2 -n 2 -o zabbixweb.xml -d

Zabbix實戰-簡易教程(6)--Server端高可用