zoukankan      html  css  js  c++  java
  • Zabbix实战-简易教程(6)--Server端高可用

    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 {
         xuequn@kingsoft.com
       }
       notification_email_from zabbix@kingsoft.com
       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 {
         xuequn@kingsoft.com
       }
       notification_email_from zabbix@kingsoft.com
       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/
    [root@bgp-bjlg-zabbix-server01 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
     

    3.6 配置文件和参考文献

     
     
     
  • 相关阅读:
    世界排名第二的web前端框架bulma与Bootstrap框架的选择
    Bootstrap5中文手册翻译完毕
    RabbitMQ 学习一 了解+点对点模式
    仿京东搜索
    ES集成SpringBoot
    ElasticSearch
    权限管理整合springsecurity代码执行过程
    权限管理
    Gateway网关
    canal数据同步 客户端代码实现
  • 原文地址:https://www.cnblogs.com/skyflask/p/7501104.html
Copyright © 2011-2022 走看看