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
router_id LVS_DEVEL
} vrrp_script chk_zabbix_server { script "/etc/keepalived/chk_zabbix_server.sh"
interval
weight }
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id
priority
advert_int
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
router_id LVS_DEVEL
} vrrp_script chk_zabbix_server { script "/etc/keepalived/chk_zabbix_server.sh"
interval
weight }
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id
priority
advert_int
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}" = "" ]; then /etc/init.d/zabbix-server start
sleep status2=$(ps aux|grep zabbix_server | grep -v grep | grep -v bash |wc -l)
if [ "${status2}" = "" ]; 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 配置文件和参考文献

 
 
 

Zabbix实战-简易教程(6)--Server端高可用的更多相关文章

  1. Zabbix实战-简易教程系列

    一.基础篇(安装和接入) Zabbix实战-简易教程--总流程  Zabbix实战-简易教程--整体架构图 Zabbix实战-简易教程--DB安装和表分区 Zabbix实战-简易教程--Server端 ...

  2. Zabbix实战-简易教程(4)--Server端安装

    在数据库安装完成后,接着开始安装server端了.我们这里采用yum安装. 3.2.0 安装需求 ● PHP 5.6.18 ● curl 7.47.1 ● zabbix_server (Zabbix) ...

  3. Zabbix实战-简易教程--日志类

    一.主动模式和被动模式介绍 要监控日志,必须使用主动模式,那么,什么是主动模式?什么是被动模式呢? 1.主动模式和被动模式 主动模式 主动模式通讯过程: ● Agent打开TCP连接(主动检测变成Ag ...

  4. Zabbix实战-简易教程--动作(Actions)--自动注册

    一.概述 之前已经讲述了自动发现功能,自动注册和自动发现非常类似,但是比自动发现更精确.因为自动注册,是在Agent上自定义元数据,然后Agent将元数据发送给server进行匹配,如果匹配一致,则进 ...

  5. Zabbix实战-简易教程--排错(持续收集中)

    一.安装错误 1.zabbix 安装故障之无法跳到下一步或点击下一步没反应 执行命令:chownnginx:nginx /var/lib/php/session/ -R   2.proxy上无法采集交 ...

  6. Zabbix实战-简易教程(5)--Proxy和Agent端(源码和yum方式)

    3.3.1 zabbix proxy安装(源码方式) 1.创建目录 mkdir -p /usr/local/zabbix 2.安装必要软件 yum install -y fping(若安装不成功) 或 ...

  7. Zabbix实战-简易教程--大型分布式监控系统实现Agent批量快速接入

    一.分布式架构 相信使用zabbix的大神都熟悉他的分布式架构,分布式的优势相当明显,分而治之.比如目前我的架构图如下: 那么,对将要接入监控系统的任何一个agent如何快速定位,并进行接入呢?  问 ...

  8. Zabbix实战-简易教程--WEB类--Nginx

    一.开启Nginx status状态 1.在默认主机里面加上location添加ngx_status 如下操作: server { listen 127.0.0.1:8080; server_name ...

  9. Zabbix实战-简易教程--中间件kafka监控

    一.环境准备 1.安装kafka Step 1: 下载代码 你可以登录Apache kafka 官方下载.http://kafka.apache.org/downloads.html备注:2.11-1 ...

随机推荐

  1. Elasticsearch过滤器——filter

    Elasticsearch中的所有的查询都会触发相关度得分的计算.对于那些我们不需要相关度得分的场景下,Elasticsearch以过滤器的形式提供了另一种查询功能.过滤器在概念上类似于查询,但是它们 ...

  2. 自学Zabbix3.10.1.1-事件通知Notifications upon events-媒介类型email

    自学Zabbix3.10.1.1-事件通知Notifications upon events-媒介类型email 配置媒介Email Administration→Media types->Cl ...

  3. 用Inferno代替React开发高性能响应式WEB应用

    什么是Inferno Inferno可以看做是React的另一个精简.高性能实现.它的使用方式跟React基本相同,无论是JSX语法.组件的建立.组件的生命周期,还是与Redux或Mobx的配合.路由 ...

  4. Vue-Methods中使用Filter

    1.Vue中Filter声明方式 Vue中存在两种声明Filter过滤器的方式: 1.全局过滤器 Vue.filter('testFilter1',function(val){ console.log ...

  5. Linux主机SSH免密设置解析

    为了保证一台Linux主机的安全,所以我们每个主机登录的时候一般我们都设置账号密码登录.但是很多时候为了操作方便,我们都通过设置SSH免密码登录.那么该如何设置?是不是免密码登录就不安全了呢? 一.被 ...

  6. 队列queue(1) 结构体实现队列

    前言 首先,我们先来做一道解密题:一串数列 7  6  8  6  6  7  0  4  1  ,规定一个回收站,把第一个数删除,添加到回收站里,然后把第二个数排到队伍最末尾,把第三个删除,添加到回 ...

  7. puppet配置问题统计

    一. [root@client puppet]# puppetd --test --server master.test.cominfo: Creating a new SSL key for cli ...

  8. 为什么CPU需要时钟这种概念?

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/132 最近在研究计算机里的基本逻辑电路,想到一个问题:为什么CP ...

  9. shell按行读取文件

    这工作小半年了发现以前学的那么多流弊技能都不怎么用,倒是shell用的很多,自己已经从shell小菜鸟一步步走过来,已经要变成大菜鸟=.= 经常需要用shell按行读取配置文件,自己在上面踩了很多坑, ...

  10. 599. Minimum Index Sum of Two Lists

    Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite ...