易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 4290|回复: 1
收起左侧

pacemaker+corosync/heartbeat 软件架构

[复制链接]
发表于 2019-4-29 17:31:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
pacemaker+corosync/heartbeat 软件架构9 g  Y' P" u2 n# S* y, ?
1、Pacemaker - 集群资源管理器(CRM),负责启动和停止服务,而且保证它们是一直运行着的以及某个时刻某服务只在一个节点上运行(避免多服务同时操作数据造成的混乱),利用集群基础构建提供的信息和成员管理能力,探测并恢复节点以及在其控制下的资源的失效切换,以实现高可用性。
2、Corosync - 消息层组件,管理成员关系、消息和仲裁。
3、Resource Agents - 资源代理,用来控制服务启停,监控服务状态的脚本集合,这些脚本将被LRM调用从而实现各种资源启动、停止、监控等等。任何资源代理都要使用同一种风格,接收四个参数:{start|stop|restart|status},包括配置IP地址的也是。
corosync和heartbeat对比
/ {5 A& ~3 h, T* B
(1)共同点:6 n' X0 `$ |# M' q) h' ^
  都属于消息网络层,对外提供服务和主机的心跳检测,在监控的主服务被发现当机之后,即时切换到从属的备份节点,保证系统的可用性.
. O' D! v, m! z" w7 [(2)不同点:
2 d) Y' F$ F" O9 y
  •    社区活跃度:
    & X' b+ I" q% Y* J* W2 d+ w  J5 `
Heartbeat从2010年之后,就不再继续维护,而Corosync则仍然处于活跃期! L2 f+ f0 N' ?% Z+ s5 Z* _
  • 配置复杂度:$ Z2 }! s7 O4 w( e
Heartbeat非常容易进行配置,第一次配置可能只需要几分钟,而Corosync由于有一定的复杂度则需要一点耐心. a, \8 X& W8 m# p) B* _
  • 管理资源的灵活性:9 F9 M* e; U( H" M0 L+ O' u
Heartbeat只能为所有的资源配置一个主服务,而corosync则允许为不同的资源组配置不同的主服务。- k3 o+ y) i1 l* Q- G
  • Resource stickiness:: W+ _4 @  ~/ D) \
Heartbeat在主服务server1当机之后,切换到从服务节点server2;还会把之前的主节点server1继续放入从属节点列表之内。而corosync则不会存在这个情况。! Y9 k! Q& @- ?% {, b' d
  • 配置文件的版本管理:  z6 e% v5 i. R/ h
在corosync中,其会自行处理配置文件的同步问题,heartbeat则无此功能。  ^+ o4 G- Z( K. V6 k
  • 分组管理( ?4 H+ Z, f- e- h* y! k
Heartbeat只支持2个节点,而corosync则支持多个节点的集群,支持把资源进行分组,按照组进行资源的管理,设置主服务,自行进行启停
7 p. U& d! V" x* b" V9 y    故此可见,一般来说都是选择corosync来进行心跳的检测,搭配pacemaker的资源管理系统来构建高可用的系统。
. S. W. K! R4 S' G
4 m2 N! F4 A( ~' iCorosync
. H- O/ I) T' ^8 r0 [+ U% P5 `8 Z  l2 s; g* `# x* R
+ ^* U3 j$ o$ g3 \

* q* j9 _$ k9 H. \5 b! |

6 x2 F4 m9 v7 m' W) c                               
登录/注册后可看大图

6 L- h( k$ r" K# i& O2 T- z关于心跳的基本概念:
% ~9 b' H# Q: l5 W
  • 心跳:就是将多台服务器用网络连接起来,而后每一台服务器都不停的将自己依然在线的信息使用很简短很小的通告给同一个网络中的其它主机,告诉它们自己依然在线,其它服务器收到这个心跳信息就认为它是在线的,尤其是主服务器。
  • 心跳信息怎么发送,由谁来收,其实就是进程间通信。两台主机是没法通信的,只能利用网络功能,通过进程监听在某一套接字上,实现数据发送,数据请求,所以多台服务器就得运行同等的进程,这两个进程不停的进行通信,主节点(主服务器)不停的向对方同等的节点发送自己的心跳信息,那这个软件就叫高可用的集群的基准层次,也叫心跳信息传递层以及事物信息的传递层,这是运行在集群中的各节点上的进程,这个进程是个服务软件,关机后需要将其启动起来,主机间才可以传递信息的,一般是主节点传给备节点9 x" B0 r/ k: L+ f
资源代理(Resource Agent - RA)
    一个 RA 是管理一个集群资源的可执行程序,没有固定其实现的编程语言,但是大部分RA都是用 shell 脚本实现的,Pacemaker 使用 RA 来和受管理资源进行交互,Pacemaker 支持三种类型的 RA: LSB Resource Agents、OCF Resource Agents、Legacy Heartbeat Resource Agents。
    主流的 RA 都是 OCF 类型的。RA 支持的主要操作包括: start、stop、monitor、meta-data、status
    (CIB 是个分布式的XML 文件,有用户添加配置 Pacemaker 和 Corosync 根据 CIB 控制 LRMD 的行为 LRMD 通过调用 RA 的接口控制各资源的行为)

% N6 @- u4 {, U
 楼主| 发表于 2019-5-6 15:25:54 | 显示全部楼层
1 i  q; f7 e+ A  |
pacemaker+corosync实现zabbix高可用集群
# c; i4 a' {8 ?
; T7 y1 r& T: y2 f8 T# Q( ?

    8 B  a$ T) J8 s4 e9 v7 ^' x
  • 一、pacemaker 是什么" K3 w9 J7 _# ^! s7 Z/ {  \0 U
      7 X0 y: F+ g6 q8 ], \9 ]
        
    • 1.pacemaker 简单说明
      3 d; E* o) T* G$ T1 ^2 O; \, z6 }# Q  
    • 2.pacemaker 由来
      + J8 l; M0 H! Q, J/ }
  • 二、pacemaker 特点
    & ?5 S- i9 m2 {) B2 V) b
  • 三、pacemaker 内部结构/ P6 D% m* y9 v) N$ u* t8 v  @

      ! O* ?6 d, [$ l8 ^7 L* [* I  
    • 1.群集组件说明:
      2 g4 |2 O1 P- n: D6 {2 x6 J  
    • 2.功能概述   
      6 |' G. H* v! O' U5 k
  • 四、centos6.x+pacemaker+corosync实现zabbix高可用
    + {  j9 p  v5 t
      9 W+ F) Z( k" n$ {8 \' I% |
        
    • 1、环境说明
      5 T' @6 P6 R- e3 c1 C+ X
  • 五、安装pacemakercorosync(各个节点均要运行)
    " f8 N+ G$ r2 F% [, T  V
      9 }% g3 N/ w2 E# o6 e
        
    • 1、前提条件各个节点完成主机解析工作。
      & M3 R  K/ ?# m8 `' B" `  
    • 2、各个节点的时间同步
      5 H; N7 s1 b) O. p( e: [  
    • 3、各个节点完成互信工作7 G. _% f# ?  k) k! C. z7 z
        
    • 4、关闭防火墙与SELinux  t" K$ [4 ?: N! d( ~# F
        
    • 5、安装pacemaker+corosync+pcs- L& G- \& J, `! Y
  • 六、配置corosync
      w$ {3 ?6 f/ @0 L; X

      ( y  g8 i, l/ b% [2 x$ K" M  
    • 1、设置变量. J3 S1 j& r9 U4 I
        
    • 2、更改corosync配置文件
      ( [9 D2 P1 ~1 m  
    • 3.生成密钥文件
      ' _% n/ O1 c  T' {. M! t3 Z
  • 七、安装和配置cman/ h2 W% |# n( x& M
  • 八、编辑cluster.conf   
    / x) |9 G/ {8 t3 L# r" T  D: z
  • 九、检查配置文件并开机自启  [/ ?! T: k( J6 P2 `
  • 十、资源配置; d. B# o8 u7 o+ K4 s2 t
  • 十一、验证5 Z' s1 d* a' V0 Q9 m( G
  • 十二、常用命令6 F+ q5 }, u0 h) o7 }3 O
  • 十三、zabbix启动脚本# D* K# B+ b" R7 P" ~! c

! Q' g4 {* M3 q& I7 U

; I0 v  a* G' H# ^; D1 h: e
一、pacemaker 是什么

4 c  X/ }: @! m1 A
1.pacemaker 简单说明
  P) \- D* h1 {4 |8 Z. Q! G
  pacemaker(直译:心脏起搏器),是一个群集资源管理器。它实现最大可用性群集服务(亦称资源管理)的节点和资源级故障检测和恢复使用您的首选集群基础设施(OpenAIS的或Heaerbeat)提供的消息和成员能力。
/ C' J  o9 @5 S' X- s; v) L
   它可以做乎任何规模的集群,并配备了一个强大的依赖模型,使管理员能够准确地表达群集资源之间的关系(包括顺序和位置)。几乎任何可以编写脚本,可以管理作为心脏起搏器集群的一部分。

* G* d/ K2 I- D( d* |# C; T7 g
   我再次说明一下,pacemaker是个资源管理器,不是提供心跳信息的,因为它似乎是一个普遍的误解,也是值得的。pacemaker是一个延续的CRM(亦称Heartbeat V2资源管理器),最初是为心跳,但已经成为独立的项目。
& R' r  B. `% M
2.pacemaker 由来

! ~/ {, h" ^0 e3 @% b4 X* ~2 X
大家都知道,Heartbeat 到了V3版本后,拆分为多个项目,其中pacemaker就是拆分出来的资源管理器。
& M7 d7 D6 p# e  e; s
    . f0 `# o, A- i& F- G, a7 n/ ]
  • Heartbeat 3.0拆分之后的组成部分:: [' ~* s/ p& y
  • Heartbeat:将原来的消息通信层独立为heartbeat项目,新的heartbeat只负责维护集群各节点的信息以及它们之前通信;
    $ q9 _  x. N& y5 F. T8 x' w$ v
  • Cluster Glue:相当于一个中间层,它用来将heartbeatpacemaker关联起来,主要包含2个部分,即为LRMSTONITH4 @( R4 W7 D1 C2 A5 l
  • Resource Agent:用来控制服务启停,监控服务状态的脚本集合,这些脚本将被LRM调用从而实现各种资源启动、停止、监控等等。
    6 C/ y; }, b  B- c2 p: E
  • Pacemaker : 也就是Cluster Resource Manager (简称CRM),用来管理整个HA的控制中心,客户端通过pacemaker来配置管理监控整个集群。* e7 H/ q7 S2 F% B3 v, |
' j* Q; T. x! ~) J+ v
二、pacemaker 特点

/ r/ @" @* w0 j+ P. ~  J8 M

    7 Y5 _' T# \7 ?$ L: M# E
  • 主机和应用程序级别的故障检测和恢复1 J7 X+ I, L4 q
  • 几乎支持任何冗余配置
    * a: t: |9 J4 x
  • 同时支持多种集群配置模式* N; K8 f' n: v: O
  • 配置策略处理法定人数损失(多台机器失败时)
    + i2 c& {8 w6 X0 h& o# @
  • 支持应用启动/关机顺序( `/ x. f0 M/ r/ u
  • 支持,必须/必须在同一台机器上运行的应用程序. {+ W9 C5 H" V& A
  • 支持多种模式的应用程序(如主/从): t4 i* i  h& l$ x2 t0 z
  • 可以测试任何故障或群集的群集状态
    $ A8 c6 o, u0 x$ N8 b8 A
6 n# t- q- t& n- ], A" u

* _7 @1 u( s3 s3 L+ `1 s8 v
三、pacemaker 内部结构
$ J% |; l* M; u& y  Y8 ?! S$ ^$ h. G/ ?
6 S& h! \- O1 D5 y
1.群集组件说明:

! L5 ^1 `3 [8 c
    5 r4 I: _0 Z; `, n' e9 A  t) b
  • stonithd:心跳系统。
    4 g% W: [2 a5 S9 ]' h" H
  • lrmd:本地资源管理守护进程。它提供了一个通用的接口支持的资源类型。直接调用资源代理(脚本)。
    1 d# P7 a& @7 F1 d$ E$ u% k
  • pengine:政策引擎。根据当前状态和配置集群计算的下一个状态。产生一个过渡图,包含行动和依赖关系的列表。
    . \7 i: ^1 E% p3 E! T: M5 N
  • CIB:群集信息库。包含所有群集选项,节点,资源,他们彼此之间的关系和现状的定义。同步更新到所有群集节点。3 I- P& I: V, O6 T* J3 s; [  E
  • CRMD:集群资源管理守护进程。主要是消息代理的PEngineLRM,还选举一个领导者(DC)统筹活动(包括启动/停止资源)的集群。
    5 ?+ _0 h% X  j$ y
  • OpenAISOpenAIS的消息和成员层。
    $ S9 A. Y: Z7 O2 d2 A: d
  • Heartbeat:心跳消息层,OpenAIS的一种替代。/ L! a: J8 G9 Z) q& g( `1 U
  • CCM:共识群集成员,心跳成员层。+ I) e2 o" t* {9 h: u& ^! x
  • CMAN是红帽RHCS套件的核心部分,CCSCMAN集群配置系统,配置cluster.conf,而cluster.conf其实就是openais的配置文件,通过CCS映射到openais9 C" D9 j, E/ X  w
; [  U+ l7 ?  Y) p
2.功能概述   
& [2 Z" q8 n" _. T! |% y5 V
CIB使用XML表示集群的集群中的所有资源的配置和当前状态。CIB的内容会被自动在整个集群中同步,使用PEngine计算集群的理想状态,生成指令列表,然后输送到DC(指定协调员)。Pacemaker 集群中所有节点选举的DC节点作为主决策节点。如果当选DC节点宕机,它会在所有的节点上, 迅速建立一个新的DC。DC将PEngine生成的策略,传递给其他节点上的LRMd(本地资源管理守护程序)或CRMD通过集群消息传递基础结构。当集群中有节点宕机,PEngine重新计算的理想策略。在某些情况下,可能有必要关闭节点,以保护共享数据或完整的资源回收。为此,Pacemaker配备了stonithd设备。STONITH可以将其它节点“爆头”,通常是实现与远程电源开关。Pacemaker会将STONITH设备,配置为资源保存在CIB中,使他们可以更容易地监测资源失败或宕机。
- X& a/ m, M' h& J! k
四、centos6.x+pacemaker+corosync实现zabbix高可用
" T* O5 P! V8 q! @" q
1、环境说明
( L& |& `( d% s3 y% X* n- B
OS:Centos 6.7x86_64  mini

2 ]' l- n3 l: m% Y) [4 k' d. X
APP: Pacemaker 1.1.15         

2 `: K2 g4 u8 v0 h$ \  M8 \* ?
        LNMP+Zabbix 3.4.1      

* N  N! z9 z4 }* k  X4 H
        corosync+pcs+cman
  B4 U! }1 z8 Y( ?7 i& Q
IPADDR:vip-192.168.8.47/20
7 N- g( [/ v0 S+ D+ }/ K
              zabbix01-192.168.8.61/20
' ?, [& ]2 y+ ]
              zabbix02-192.168.8.63/20

4 r& B4 Y& C7 a. u! }
              zabbixdb-192.168.8.120/20

  O( _! Z+ t2 @& g/ t! e2 ^, i

2 S  u/ ]- J9 M8 `6 l7 y* _
PS:IP地址需要根据个人具体环境配置,VIP和zabbix要在同一网段。
1 T4 M. a: }* Q% y( J: K6 Y
拓扑结构
8 W6 g3 L; D. T# J4 P

" v+ ^/ j# `' A/ z- ~' Z
PS:接下来会直接介绍pacemaker和corosync的安装和配置,关于zabbix+LNMP环境的部分请参考之前发表的“zabbix3.2编译安装”或“zabbix高可用”两篇文章。

+ q3 C' k8 ?. ]+ ^+ x2 h
五、安装pacemakercorosync(各个节点均要运行)
4 I& ?. \1 e8 C8 E! i5 G
1、前提条件各个节点完成主机解析工作。
3 f9 j$ X$ \  b/ l4 z* Q
vim /etc/hosts

0 |* v" l/ L+ Q( M, D' H
# cat /etc/hosts
- M5 z* y: b- ]1 i2 ?* i
127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4
9 a% ?  c6 ]2 f9 v- s
::1        localhost localhost.localdomain localhost6localhost6.localdomain6
1 x5 e/ M3 i. }+ E( y' ~
192.168.8.61zabbix01.okooo.cn zabbix01
$ s! y4 \4 h' E  g8 F
192.168.8.63zabbix02.okooo.cn zabbix02

, V- [5 J: C9 ]  T9 W
192.168.8.120zbxdb.okooo.cn zbxdb
* V9 p! Y' E: ^% F
2、各个节点的时间同步
1 c6 s. K+ H+ h- ]
ntpdate210.72.145.44
3 r0 e) O! O- V
3、各个节点完成互信工作

" b- y% b1 J! n$ N+ S! K. a* I
ssh-keygen -t rsa -f ~/.ssh/id_rsa  -P ''

4 x% X6 g/ ?. l, |4 F  f/ ]
ssh-copy-id -i.ssh/id_rsa.pub root@zabbix01/02/db.okooo.cn
0 l2 f( }+ _  d  E9 J; E$ z" D& @- v
4、关闭防火墙与SELinux

  I' b; o% r& {% h" v
# cat /etc/selinux/config

, E/ Q8 E2 n2 d) h
# This filecontrols the state of SELinux on the system.
2 C' s% J* W- K9 S
# SELINUX= cantake one of these three values:

7 b; o+ e* D$ t* {! v
#      enforcing - SELinux security policy is enforced.

  S9 d3 G# N* f+ e* x( d: g
#      permissive - SELinux prints warnings instead of enforcing.

5 U$ N( u4 y3 D2 e' v# U
#      disabled - SELinux is fully disabled.

6 n6 D# O8 i0 R: L* r1 H% y
SELINUX=disabled

9 W1 A: }: M& l
# SELINUXTYPE=type of policy in use. Possible values are:
8 f: y1 a/ T- Q) b7 d8 {
#      targeted - Only targeted network daemons are protected.
8 @! G, F- Z  v3 u" S, `
#      strict - Full SELinux protection.

; ?; `  @) N7 G' {# X% ?1 F
SELINUXTYPE=targeted

) ^; g7 R0 ]. y/ v5 J/ d

% f: j+ v8 z' L, s' Y! l
#/etc/init.d/iptables status

' O' H+ |: E: @* j; ^& a$ W4 G
iptables:Firewall is not running.

; h3 k% s! o% K1 p  u4 ]
5、安装pacemaker+corosync+pcs

3 t: w+ k2 p6 Y. a9 g
yum install -ypacemaker corosync pcs

1 D+ ^. o- D/ H, x5 _, ~2 E+ l+ z
六、配置corosync

' V4 n" e7 R. V  t) P" F- }
1、设置变量

( g% }% b0 ~* Y  d- m' O
exportais_port=4000

* P) S) G0 g0 j+ y" X7 n% u2 {
exportais_mcast=226.94.1.1
8 I7 |9 ?' C  Z  I9 D' T- b6 G
exportais_addr=192.168.15.0
# B8 e) b9 N9 {1 `" |* ^- F; X
env|grep ais

0 O$ a4 c9 ?4 o  Y: }8 z! z
2、更改corosync配置文件
3 I9 a3 {; J7 U
cp /etc/corosync/corosync.conf.example/etc/corosync/corosync.conf
# F, }, Y) Q% d4 F/ q# o$ X: s$ a
sed -i.bak“s /.*mcastaddr:。* / mcastaddr:\ $ ais_mcast /g”/etc/corosync/corosync.conf
) m* `6 p& Z* [. B- c, Hsed -i.bak“s /.* mcastport:。* / mcastport:\ $ ais_port / g”/etc/corosync/corosync.conf6 d) |' O0 u- k6 I; O: l- A4 Z8 e
sed -i.bak“s /.* bindnetaddr:。* / bindnetaddr:\ $ ais_addr / g”/etc/corosync/corosync.confcat/etc/corosync/corosync.conf

4 R( {$ A7 ~# T* G
# Please read the corosync.conf.5 manual page  

( P# f$ n, u+ T4 l
compatibility: whitetank

( D, U. b! M: q
totem {
; n% T5 L( C# L
    version: 2  
- m: B/ D. V, W: C8 N1 R- z
    secauth: on #启动认证  

1 p5 m# @- d3 [
    threads: 2  
, q2 B$ i9 @  Z3 }5 a7 V7 G+ I5 K
    interface {  

% v1 A6 E9 g6 ]$ C
        ringnumber:0  
+ |+ o( a6 E  ~* ^, }9 T
        bindnetaddr:192.168.15.0 #修改心跳线网段  
& c! U) i8 t( E- E
        mcastaddr:226.94.1.1 #组播传播心跳信息  
. c% ]8 [; {+ u# ^9 G
        mcastport:4000  

7 Q' W7 X) ]7 w7 k2 E+ ?
        ttl:1  
5 E; {6 M0 _+ a- S
    }  

4 V* D) X3 t; }& ]; r, E
}

( E! [3 R' T: q" t+ ]
logging {
( E* w4 r8 u- Q4 P% Q7 Q
    fileline: off  

% T# J' [# m' U' ^8 i4 i$ c
    to_stderr: no  

4 L9 R, W. `+ \
    to_logfile: yes  
. w" k4 P$ R1 f, S
    to_syslog: no  

; Q$ U2 G- z' ?4 c
    logfile: /var/log/cluster/corosync.log #日志位置  

9 T+ s" A! K) @
    debug: off  

) N' P; K" n$ w/ C+ g
    timestamp: on  

' _6 U) a6 i6 L( x% t& c
    logger_subsys {  

7 w% z6 }) J$ c1 S" N9 U3 H# j; Y
        subsys:AMF  
- o9 y7 c5 u3 s7 B7 }1 X' U7 S
        debug:off  
+ ?- o% s- D3 p7 ], W& d: ~6 X8 j
    }  

1 Y! \1 M% S5 U3 {; {' w  D
}

9 ?5 D& y, e" i" ?$ X' g
amf {
8 G5 }& Z9 ^  V1 i
    mode: disabled  

. ~6 l" ?. t3 ~' }
}
- d3 h/ e. @( {% a2 |( k
#启用pacemaker
9 N2 ]5 y- C/ f
service {

' T/ n/ ^( D5 j/ p  @7 o* }8 ?3 E
    ver: 0  

$ M/ }1 @+ y: q
    name: pacemaker  
+ z" L8 X- t1 v1 D. ~. w4 K/ U/ X! e
}

- a5 C( @2 u) j( z0 _8 h
aisexec {
. W8 U! ~4 \3 R- A8 I
    user: root  
. s* h& G0 S/ v! d) o9 p
    group: root  
. f: l0 v* s6 D0 p' o
}
2 F9 H2 }  L' u( G/ }  ^( N
注:用 mancorosync.conf 可以查看所有选项的意思。
3 g  R* O; \  g! A( U
3.生成密钥文件

6 E: B: p; s# Z. @1 R
注:corosync生成key文件会默认调用/dev/random随机数设备,一旦系统中断的IRQS的随机数不够用,将会产生大量的等待时间,因此,为了节约时间,我们在生成key之前讲random替换成urandom,以便节约时间。

* g. H% r+ [2 r4 r5 ~2 F
mv /dev/{random,random.bak}

, N: W. S- G) l% c) @" o' B- d
ln -s /dev/urandom /dev/random
9 T! w  U. G( a3 j1 b2 w; s; `6 E' F
corosync-keygen
6 H# F5 P, _  V0 m
PS:以上步骤要在所有节点上运行。

8 Z( ], [! g# E1 |8 t% h& {
七、安装和配置cman
2 m* g) P$ Z) |( h+ a* r
yuminstall -y cman
7 i) x* ~5 C9 e& ]' r, P
sed -i.sed"s/.*CMAN_QUORUM_TIMEOUT=.*/CMAN_QUORUM_TIMEOUT=0/g"/etc/sysconfig/cman" B0 \% o( a3 {; T+ {' b" c" \
# cat/etc/sysconfig/cman
5 l- X: `0 k6 r#CMAN_CLUSTER_TIMEOUT -- amount of time to wait to join a cluster
! n1 ?6 G$ l6 S8 s& j; m$ Z) t) d# before givingup. If CMAN_CLUSTER_TIMEOUT is positive, then we will
7 K% n5 V1 ^) F- \# waitCMAN_CLUSTER_TIMEOUT seconds before giving up and failing if
# z' h& ]9 ~. y/ i; a2 D+ _# we can't joina cluster. If CMAN_CLUSTER_TIMEOUT is zero, then we
: w& C% ^/ ]5 N6 Q# will waitindefinitely for a cluster join. If CMAN_CLUSTER_TIMEOUT is# V. a$ b% X0 D! ^
# negative, donot check to see if we have joined a cluster.9 ?. q, e3 ?, j$ O4 y
#CMAN_CLUSTER_TIMEOUT=5#CMAN_QUORUM_TIMEOUT -- amount of time to wait for a quorate cluster on
9 G4 a. r( U" ?1 X' t( A, c: A1 e+ h3 u# startup.Quorum is needed by many other applications, so we may as
& G2 c% X0 L" v) S+ h# well waithere. If CMAN_QUORUM_TIMEOUT is zero, quorum will0 D- h; }* w- P! W+ F, U
# be ignored.
7 y2 ~, V- l6 v$ @CMAN_QUORUM_TIMEOUT=0#CMAN_SHUTDOWN_TIMEOUT -- amount of time to wait for cman to become a
& E, V* _1 y7 ^* n5 Z# cluster memberbefore calling 'cman_tool' leave during shutdown.
, X5 L  ~8 \( K8 `2 e6 k: M# The default is60 seconds
0 h6 n2 D$ [2 G& M; @5 u2 ], ]/ ]#CMAN_SHUTDOWN_TIMEOUT=6#CMAN_NOTIFYD_START - control the startup behaviour for cmannotifyd,
! A' l7 r7 ]0 b7 f# the variablecan take 3 values:- j8 w5 E8 s6 P7 z
# yes | willalways start cmannotifyd
% K1 }7 a: {) ~4 T1 Q6 Y! |# no | willnever start cmannotifyd  D# P3 r+ ?7 Y0 c. t- e
# conditional(default) | will start cmannotifyd only if scriptlets. E; v7 N- @% C, V
# are found in/etc/cluster/cman-notify.d" D0 q8 `0 h7 V, H" }  ]
#CMAN_NOTIFYD_START=conditional#CMAN_SSHD_START -- control sshd startup behaviour,
; l5 F2 g" q8 [- |- h# the variablecan take 2 values:
! o0 _$ S$ }7 U; Q: s0 z8 O6 `# yes | cmanwill start sshd as early as possible# d) k! A# F  ?( i
# no (default) |cman will not start sshd1 ?" d2 ?& ]- T* v7 N# y- D% b
#CMAN_SSHD_START=no#DLM_CONTROLD_OPTS -- allow extra options to be passed to dlm_controld daemon.
  j: T8 W& p, P# i9 N, U% s: S#DLM_CONTROLD_OPTS=""#Allow tuning of DLM kernel config.
, q1 l% O4 x; A- X; G; \# l- e# do NOT changeunless instructed to do so.) g1 y' ?7 {/ \. O
#DLM_LKBTBL_SIZE=""/ l1 N- c$ d. X  p5 O1 n
#DLM_RSBTBL_SIZE=""2 @6 B: L  `8 a6 c; |
#DLM_DIRTBL_SIZE=""
: U" R+ _: O( s1 \#DLM_TCP_PORT=""#FENCE_JOIN_TIMEOUT -- seconds to wait for fence domain join to4 C( @+ A( _6 R2 \
# complete. Ifthe join hasn't completed in this time, fence_tool join
8 L# s7 M; ^8 \9 s: ^# A# exits with anerror, and this script exits with an error. To wait
/ C, `5 E* F% v  h. F' o/ P) H7 q) L# indefinitelyset the value to -1.: w5 e$ W3 l7 e2 s: k
#FENCE_JOIN_TIMEOUT=20#FENCED_MEMBER_DELAY -- amount of time to delay fence_tool join to allow
6 [, r! H- i) u5 j  x# all nodes incluster.conf to become cluster members. In seconds.+ i- o* D3 }1 n% ?
#FENCED_MEMBER_DELAY=45#FENCE_JOIN -- boolean value used to control whether or not this node
) Q, ?" V/ b5 f- ^, ~, J' F6 q# should jointhe fence domain. If FENCE_JOIN is set to "no", then
) @0 n5 n$ S% h/ \5 ~- U# the scriptwill not attempt to the fence domain. If FENCE_JOIN is
7 h/ z" [( y: P7 x" G  l# set to"yes", then the script will attempt to join the fence domain.
  v7 V% N  Z9 b4 V# If FENCE_JOINis set to any other value, the default behavior is
& P9 C$ L) @$ n# l' Y# to join thefence domain (equivalent to "yes").& H7 P& T; f6 L, @5 G2 M3 n
# When settingFENCE_JOIN to "no", it is important to also set1 k, S. @$ F& A) q& N7 h& u1 D' N
#DLM_CONTROLD_OPTS="-f0" (at least) for correct operation., M0 |& h" Z9 C
# Please notethat clusters without fencing are not( l- p9 ]+ p* s
# supported byRed Hat except for MRG installations.
% R% q. }# U. L+ t#FENCE_JOIN="yes"#FENCED_OPTS -- allow extra options to be passed to fence daemon.
, _/ L! F4 v. q" D#FENCED_OPTS=""#NETWORK_BRIDGE_SCRIPT -- script to use for xen network bridging.
1 V% u9 p& z0 c4 E- a8 y& P# This scriptmust exist in the /etc/xen/scripts directory.
! z! O& n1 q, e' O+ B9 M: L) f# The defaultscript is "network-bridge".5 e4 F9 ~( [7 n0 J$ e
#NETWORK_BRIDGE_SCRIPT="network-bridge"#CLUSTERNAME -- override clustername as specified in cluster.conf6 B" q; {  ^; m* T
#CLUSTERNAME=""#NODENAME -- specify the nodename of this node. Default autodetected.. I. ?2 ~0 y& S( k# b+ e5 b3 j
#NODENAME=""#CONFIG_LOADER -- select default config parser.' w% r6 E/ `' |' }
# This can be:  P) i8 t9 x! O( D
# xmlconfig -read directly from cluster.conf and use ricci as default
+ w" f# z# p, r$ o3 o6 m8 {# configpropagation method. (default)) h" Y  E; `% S- e6 N7 x$ E
#CONFIG_LOADER=xmlconfig#CONFIG_VALIDATION -- select default config validation behaviour.: Y. s: M' h3 U( \, ?
# This can be:
  L7 a8 K) m! _/ H! K# FAIL - Use avery strict checking. The config will not be loaded if there6 s5 s( B9 v- t, X9 D7 k
# are any kindof warnings/errors4 h. E$ ^: w9 N8 B. e
# WARN - Same asFAIL, but will allow the config to load (this is temporarily
" N1 M, F3 \2 \# the defaultbehaviour)/ ~4 I3 L8 X- G) ^8 I4 _( q6 [
# NONE - Disableconfig validation. Highly discouraged' ]: r, w- x# Q  M
#CONFIG_VALIDATION=WARN#CMAN_LEAVE_OPTS -- allows extra options to be passed to cman_tool when leave3 c1 O9 h- n) j2 ^) p
# operation isperformed.
$ k2 r: P6 S4 W#CMAN_LEAVE_OPTS=""#INITLOGLEVEL -- select how verbose the init script should be.0 ?6 I5 Q1 U9 E$ \1 n& f* D# [, g
# Possiblevalues:9 v$ y6 i- s& x' a7 e. H% `  ^( ~
# quiet - onlyone line notification for start/stop operations
0 L3 K9 W+ g2 b3 Z- s; Y) H# terse(default) - show only required activity9 M$ L0 d! n& n+ J) U. D
# full - showeverything# o. ^/ R3 t, Z  r: [; ]
#INITLOGLEVEL=terse

9 m- I8 V1 f$ m" L& f
八、编辑cluster.conf   
+ g# Z  U  l- \6 K, t
vim /etc/cluster/cluster.conf
8 F$ J! q$ W1 p0 f6 o
# cat /etc/cluster/cluster.conf' s  K/ n) P- y7 `, u
<?xmlversion="1.0"?>: b3 w/ j. T0 [7 u
<clusterconfig_version="1" name="zabbixcluster">0 {# ~7 b7 }/ R
<loggingdebug="off"/>
" W& w5 o  i' T: }0 a/ f) i5 {<clusternodes>
0 z, @! R% r4 h<clusternodename="zabbix02" nodeid="1">
6 {. w+ \( t! r. k2 _3 O% x<fence>1 h: U4 U7 A5 T. k3 h8 Q: ]. F0 b
<methodname="pcmk-redirect">7 h: K9 J* b& v& U7 |3 L
<devicename="pcmk" port="zabbix02"/>
- P: G; b2 W0 i8 G  @& W. r1 [8 }</method>
6 D6 k. v5 S4 S/ o: i' @</fence>& }% S: |, h: G* _7 h% N! M
</clusternode>: Z0 @; q% C7 t0 {6 h( B( T. O" \/ {; a
<clusternodename="zabbix01" nodeid="2">
; T) A3 o, f4 z<fence>
+ o8 ?  I  M% p4 o3 f<methodname="pcmk-redirect">$ ^5 c: X, @/ F8 [/ H8 O
<devicename="pcmk" port="zabbix01"/>- h1 |- p& v. B4 k9 T
</method>( `7 r8 G2 c' P
</fence>
2 Q2 m5 y* ^1 s</clusternode>
* {6 W: }$ X+ n+ H& ]; ^, e- a8 f9 n</clusternodes>
: a, I1 v- x2 N7 J1 V2 g<fencedevices>4 f3 o/ ~# m2 ^; u5 G# A2 G
<fencedevicename="pcmk" agent="fence_pcmk"/>- o; Y5 [' @, Z
</fencedevices>
/ X; l5 ]/ t( N6 B1 Z; Y<cman><multicast addr="226.94.1.1"/></cman> => when runningmore clusters in same network change multicast address
& N* B; L9 S& T/ Y) L2 K</cluster>
& @4 `9 G% k( Z& x
九、检查配置文件并开机自启

4 S$ j/ N' Y5 |/ r2 b# {' A
ccs_config_validate
* b0 h  I! k3 X1 g
service cman start
1 b2 B, a- P/ r9 B) c  x# h
cman_tool nodes

0 P7 _- a% {7 z5 s
service pacemaker start
3 p' v" g7 C4 H- V7 l% O
chkconfig cman on

4 n' B* w& E' F  R+ c; q
chkconfig pacemaker on
3 ^8 m/ S% a% j& d- F
0 a( k) B9 z* v+ l
十、资源配置

1 L- O/ E  Y" L8 W, l
pcs cluster auth zabbix01 zabbix02 #节点间认证

) p# s2 ?  R+ {* K8 g/ W* G; J6 }
pcs cluster start --all #启动集群中所有节点

1 v1 f: r1 v* H4 D" X3 e2 J2 Y
pcs resource create ClusterIP IPaddr2ip=192.168.8.47 cidr_netmask=32 op monitor interval=2s #创建一个名为ClusterIP,类型是IPadd2,VIP是192.168.8.47/32 每隔2秒检测一次的资源
) y% Z" B: @* H$ j
pcs property set stonith-enabled=false #因我们没有STONITH设备,所以我们先关闭这个属性
  b" N* u+ A' h7 ~; B2 j
pcs resource create zabbix-serverlsb:zabbix_server op monitor interval=5s #创建一个名为zabbix-server、标准是lsb、应用是zabbis_server,每隔5秒检测一次的资源。lsb指/etc/init.d/下的启动脚本

$ C. n! s. g% g9 C4 h) k/ G
pcs resource group add zabbix ClusterIPzabbix-server  #将ClusterIP  zabbix-server资源加入到zabbix资源组中

  i3 b% Z$ w. ?6 }) n3 `( S
pcs property setno-quorum-policy="ignore"  #忽略法定人数不足时进行仲裁
, d; D5 l9 U/ }3 y% m! }: S
pcs property setdefault-resource-stickiness="100" #资源粘性为100
$ T7 i  B( r0 I. T
pcs constraint colocation addzabbix-server ClusterIP #资源共置
! B2 |5 @+ K# k
pcs constraint order ClusterIP thenzabbix-server  #资源限制,确保VIP和service在同一个节点上运行,而且VIP要在service之前完成。

/ Z8 e" Y; V# Y3 w- Y9 q. M
pcs constraint location ClusterIPprefers zabbix01 #ClusterIP更喜欢在zabbix01节点上,可用于节点故障恢复
5 ?/ a5 d) q) q% C
pcs constraint location zabbix-serverprefers zabbix01 #zabbix-server更喜欢在zabbix01节点上,可用于故障恢复

* p  ?+ S2 F, e' A
十一、验证

( s/ ?& y) ^5 |+ E2 l+ M
1、在zabbix01上操作停止zabbix_server 服务
( [5 b+ j( a5 ~8 U4 o
: T6 |7 }5 f" @4 m1 J' i% w' @
PS:集群可以保证服务的高可用
) [/ N- h: ?8 X/ q& K# X9 u3 {
) A) P, v- L( G$ |3 z* J) b
root@zabbix01:~

! W+ G$ Z: E6 k7 ?
# pcs resource
% Y. f. u2 L, x5 f" X! l2 g
ResourceGroup: zabbix

8 X8 ~% H+ S# f1 a/ D8 R" O
    ClusterIP  (ocf::heartbeat:IPaddr2):      Started zabbix01

$ L( |* J5 w1 R5 m4 b" @% @
    zabbix-server      (lsb:zabbix_server):   Started zabbix01

- A) e) m* C0 Y2 }5 o# [
root@zabbix01:~

" W0 p$ A* z4 B& z

5 }' y% i/ f9 l- A; x# V
# ip a

' h+ ^* F8 O/ Z
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

: V" @3 w7 j4 ]. I. x, r
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

, i2 X) G( z8 H% P4 f
   inet 127.0.0.1/8 scope host lo

9 {/ x( O/ Q6 R6 q' c: O9 S) K
   inet6 ::1/128 scope host
) L! ~8 p& q# y: d' k% v9 l9 t
      valid_lft forever preferred_lft forever
( K0 P; k; S" W; x6 @' K: J
2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000

9 B! t: D! c5 \& L- K2 M7 q& \! `$ y. M
   link/ether 00:50:56:bb:68:49 brd ff:ff:ff:ff:ff:ff

( u+ K$ {9 C. [& B* n! g' F
   inet 192.168.8.61/20 brd 192.168.15.255 scope global eth0
: c* N1 y9 r) U: x; @3 w& h
   inet 192.168.8.47/32 brd 192.168.15.255 scope global eth0

( s0 B9 {* a5 l; [" ~
   inet6 fe80::250:56ff:febb:6849/64 scope link
. p2 Y  V6 t7 n$ n' b6 w4 d
      valid_lft forever preferred_lft forever
3 Q9 n. ^7 x8 w0 ?6 j
PS:此时VIP和资源均在zabbix01上运行
( m# ^+ n  J9 b3 m
) J7 p) C  `% E: l" d

, o, R2 ~% {5 ^5 n  L/ f0 `
root@zabbix01:~

% z0 |0 J, G# E9 s' v* D
# ip a

  S: z  d0 a! H
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

6 G* o9 s0 w# {( y; N
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
! ?8 C6 }) S% ^
   inet 127.0.0.1/8 scope host lo

- p- e$ Y) o( b3 D& d6 _
   inet6 ::1/128 scope host

+ H2 S) Z9 S+ q- {* g! i1 O  R; A
      valid_lft forever preferred_lft forever

" r4 C2 ~* ]0 |  D! g
2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000
' u0 w" y! [6 I' D
   link/ether 00:50:56:bb:68:49 brd ff:ff:ff:ff:ff:ff
1 g- I9 J: M2 q; N1 v# \
   inet 192.168.8.61/20 brd 192.168.15.255 scope global eth0

/ L5 e1 @6 \7 ]8 M; ^
   inet6 fe80::250:56ff:febb:6849/64 scope link
$ \. j3 h1 |% k1 G. h! `- k
      valid_lft forever preferred_lft forever
& Z5 ?) u- j, ?

6 J9 z0 G2 {* B7 v  V. m+ A  ~, j
root@zabbix01:~
  e- v5 R' ^$ E+ ]  _
# ssh zabbix02"pcs resource"
* s/ `( ]/ a+ d( P, g9 G1 g8 M
ResourceGroup: zabbix

* F& _, s( M# u1 a  q7 B
    ClusterIP  (ocf::heartbeat:IPaddr2):      Started zabbix02
6 @0 o0 v' Z  g( h
    zabbix-server      (lsb:zabbix_server):   Started zabbix02
; J8 e: |7 U0 U' Z

# E5 S% r9 _- x. L7 s
root@zabbix01:~
% Q( \: u4 d' B6 ?& Q5 o# k
# pcs clusterstart zabbix01

6 F- Q) A0 h/ L, V( T& X
zabbix01:Starting Cluster...

6 S- h4 z8 r! I
root@zabbix01:~

) A, D) E: f  r: F! e( k- \" B
# ip a
5 q* R! a' ?8 A8 h; X. i0 @! ~. H
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

# h$ _7 c  f2 M  n  K
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
; h0 i) _* d5 u. ^
   inet 127.0.0.1/8 scope host lo

$ ~) L4 c% ^) s$ y/ G
   inet6 ::1/128 scope host

3 T: D0 u, v  T
      valid_lft forever preferred_lft forever
& i* d6 a$ w1 o* p2 L. y
2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000
; d' o* \1 A& j: \
   link/ether 00:50:56:bb:68:49 brd ff:ff:ff:ff:ff:ff

/ W. a% ?. }$ i9 _' t& e( Y# K0 G
   inet 192.168.8.61/20 brd 192.168.15.255 scope global eth0
6 i0 f( q+ s* F6 k
   inet 192.168.8.47/32 brd 192.168.15.255 scope global eth0
3 L* b2 m( V4 }- H6 o
   inet6 fe80::250:56ff:febb:6849/64 scope link
4 w: Q  ?7 ]0 a& c( n0 q
      valid_lft forever preferred_lft forever
# ~& ^" m( q2 z
root@zabbix01:~
  h+ U9 X7 {7 ]; D( Y. e+ N
# pcs resource

! u% M" ~# t$ Y1 T8 u
ResourceGroup: zabbix

; }7 V8 B+ v1 y' c
    ClusterIP  (ocf::heartbeat:IPaddr2):      Started zabbix01
4 ~# @8 s6 K$ r) T3 O$ O
    zabbix-server      (lsb:zabbix_server):   Started zabbix01

% O) E* {. K2 G3 w7 O" J/ i* g( S
, d, l1 ]( G+ h3 Z/ W

/ Q4 K0 T+ J8 Z: J

) y& _7 J" Y0 {3 O: g& n8 M
PS:重启集群后资源和VIP均被zabbix02接管,但zabbix01恢复后资源与VIP又再次回到zabbix01.
% z, Z' a! S0 d
) c5 g9 ~1 L, q( c/ A
十二、常用命令
2 u4 X4 s4 b2 @' t2 L
1、查看集群状态
2 G, z- S! v8 [, A
# pcs cluster status: [) m1 m+ V9 r6 J2 U. q7 y6 T; {
Cluster Status:# X$ w: r: y$ j9 k
Stack: cman  k: \8 T7 Y3 S1 H( ~( w- S
Current DC:zabbix01 (version 1.1.15-5.el6-e174ec8) - partition with quorum2 E) q' {* z- `
Last updated:Thu Sep 21 02:13:20 2017 Last change: Wed Sep 20 09:13:10 2017 by root viacibadmin on zabbix01
2 a( P* C' \9 r( h+ S2 nodes and 2resources configured
! k' F0 W6 `# u% [9 y
PCSD Status:$ m$ F- \% K% c+ v4 N# L
zabbix01: Online
2 |% v3 _7 ~# n) B: z4 \zabbix02: Online
  l6 T5 S; }6 m2 d' v+ A8 ^* [
2、查看配置

" V( \4 g, P! X+ H: I) {: P: v
# pcs config show$ p$ V/ Z/ v0 I6 l
Cluster Name:zabbixcluster0 Y8 B4 a) j2 M6 B- O$ V' O
Corosync Nodes:
# p3 ^+ ^  V/ h& `$ dzabbix02zabbix012 S  Z. f1 G& ]& i! X# w
Pacemaker Nodes:, _. P( U+ f6 Q: \
zabbix01zabbix02

! f& {" F# m! `' I3 q! Y5 X$ y
Resources:! K' H6 V. v1 R# y; Z; Q5 p
Group: zabbix% S+ j1 f3 p3 R0 q
Resource:ClusterIP (class=ocf provider=heartbeat type=IPaddr2)  G( t3 y0 j( x2 f1 F6 l
Attributes:ip=192.168.8.47 cidr_netmask=32* C) K" r+ B% T' Z) ?2 D- p8 J9 {
Operations:start interval=0s timeout=20s (ClusterIP-start-interval-0s)
% s4 C/ g" h- b% p- xstop interval=0stimeout=20s (ClusterIP-stop-interval-0s)
4 Z" I+ x; S  a0 n: emonitorinterval=2s (ClusterIP-monitor-interval-2s)# |1 V# F! l; s& P+ p' A$ ]; n
Resource:zabbix-server (class=lsb type=zabbix_server)' e' w) H8 A: z) b
Operations:start interval=0s timeout=15 (zabbix-server-start-interval-0s)
" D" Z; p! L2 {) P3 mstop interval=0stimeout=15 (zabbix-server-stop-interval-0s)
) Y; x2 T% t5 X" Dmonitorinterval=5s (zabbix-server-monitor-interval-5s)

/ w2 L" H% Y! |7 Q7 D, i
Stonith Devices:- a( z* b7 S* |- _. u
Fencing Levels:

+ l1 K  W3 \- j
Location Constraints:
  o6 L% z0 I4 C( c' w: COrderingConstraints:
+ p4 ^0 p; w5 E) g' q& SColocationConstraints:% h7 k4 l7 i+ j7 q
TicketConstraints:
5 D8 q7 V2 H& V$ ]
Alerts:) L* e( m* m1 i; y
No alertsdefined

& J) h, o" D  z. z% v. D+ O( J
Resources Defaults:
9 r! E+ {5 l& X% j+ CNo defaults set
6 O  l& ^+ M* }' UOperationsDefaults:
6 v) `. [- p# U7 M6 l+ R2 v2 o. Ltimeout: 60s
+ {' X$ _0 i  w0 P" F# _
Cluster Properties:" Q1 u* K# `% H: C0 @- X
cluster-infrastructure:cman
2 o1 R$ L0 {+ }dc-version:1.1.15-5.el6-e174ec8
# P1 f2 [/ d$ H2 p; J+ P: u8 }default-resource-stickiness:100  T7 z$ P1 c5 S2 s. A& n' a# z. W
have-watchdog:false
7 i4 c+ F/ c# b3 M; w+ Z) f# P7 u9 Tlast-lrm-refresh:1505857479/ B9 v0 T# N6 O, l) k
no-quorum-policy:ignore
' d3 _2 [& q. d7 |4 B- R9 Cstonith-enabled:false
( L9 G0 i& l& a

- N1 l5 I8 {+ s3 R; a3 ^" e
# pcs clustercib
, h( |7 u  s  x. Z
<cibcrm_feature_set="3.0.10" validate-with="pacemaker-2.5"epoch="82" num_updates="182" admin_epoch="0"cib-last-written="Thu Sep 21 02:56:11 2017"update-origin="zabbix01" update-client="cibadmin"update-user="root" have-quorum="1" dc-uuid="zabbix02">

* p* _( B5 W% y' I
<configuration>
: \- N5 |1 h7 ?1 w/ w$ t# h  ^
   <crm_config>

1 P! `" j$ @( T. G$ n& L
     <cluster_property_set id="cib-bootstrap-options">

3 ?7 W5 }; k3 i
       <nvpair id="cib-bootstrap-options-have-watchdog"name="have-watchdog" value="false"/>

0 m+ x- ~4 e# P, X( Q: b+ \8 ?
       <nvpair id="cib-bootstrap-options-dc-version"name="dc-version" value="1.1.15-5.el6-e174ec8"/>

, E+ [! H; G3 _1 m9 X
       <nvpair id="cib-bootstrap-options-cluster-infrastructure"name="cluster-infrastructure" value="cman"/>

; M* g# @  u2 C, l1 l  ~
       <nvpair id="cib-bootstrap-options-stonith-enabled"name="stonith-enabled" value="false"/>

) H6 x) U2 R  ?/ Y& D2 a  b4 Y
       <nvpair id="cib-bootstrap-options-no-quorum-policy"name="no-quorum-policy" value="ignore"/>

& g- A! V$ H+ A! m$ v
       <nvpairid="cib-bootstrap-options-default-resource-stickiness"name="default-resource-stickiness" value="100"/>
3 r; w( N8 y7 X  K* g0 c
       <nvpair id="cib-bootstrap-options-last-lrm-refresh"name="last-lrm-refresh" value="1505857479"/>

' `! O: h$ e/ D' k- U2 l
     </cluster_property_set>
# S8 \0 e. w: L& l' m
   </crm_config>

2 N6 C: J5 \  [& z+ Y4 |
   <nodes>

% |% h1 I- t3 v% Y8 v$ i
     <node id="zabbix02" uname="zabbix02"/>
" W! x( J  ]& ~# s
     <node id="zabbix01" uname="zabbix01"/>
. M2 J$ c6 y0 p, ^
   </nodes>

4 }0 x" ~. Z/ P( F, K5 V' k! L, K- w
   <resources>
5 L- u( j" A4 B( |
     <group id="zabbix">
$ @9 _, r% L% E# k: q0 e2 G
       <primitive class="ocf" id="ClusterIP"provider="heartbeat" type="IPaddr2">

7 ]  f' K: u- [
         <instance_attributesid="ClusterIP-instance_attributes">
$ E0 ?5 p# h; u9 y% h. s
           <nvpairid="ClusterIP-instance_attributes-ip" name="ip"value="192.168.8.47"/>

5 S- ~- q5 t3 q% B* b" h( y
           <nvpair id="ClusterIP-instance_attributes-cidr_netmask"name="cidr_netmask" value="32"/>

- U4 ~8 t. j1 O0 o  W, `
         </instance_attributes>

7 O, k/ u! w2 z6 [. U7 ~* L5 ^
         <operations>

/ U( k6 q$ h9 [
           <op id="ClusterIP-start-interval-0s"interval="0s" name="start" timeout="20s"/>
& V9 _2 i# I* `. j5 c% J% @
           <op id="ClusterIP-stop-interval-0s"interval="0s" name="stop" timeout="20s"/>

& s& R* t0 q, E  O
           <op id="ClusterIP-monitor-interval-2s"interval="2s" name="monitor"/>

) H( U- N/ K$ o/ F
         </operations>

0 `' F$ B7 h& R7 c/ M$ v( B
         <meta_attributesid="ClusterIP-meta_attributes"/>

+ m0 B# W, P$ H4 G& D' O
       </primitive>

# v* D% q4 r* |2 K
       <primitive class="lsb" id="zabbix-server"type="zabbix_server">

: {' R3 F6 r. `, ]- w) U
         <instance_attributesid="zabbix-server-instance_attributes"/>

5 G9 W6 a2 Y# E6 n
         <operations>
4 p) i9 T/ R1 n# H% r- i
           <opid="zabbix-server-start-interval-0s" interval="0s"name="start" timeout="15"/>
: `/ c+ \$ g" u: N* Q; ~7 m
           <opid="zabbix-server-stop-interval-0s" interval="0s"name="stop" timeout="15"/>
$ ^2 w: y' Z* L, \- ?
           <opid="zabbix-server-monitor-interval-5s" interval="5s"name="monitor"/>
, u" Q" q9 y1 G9 [  Z; L" {9 S
         </operations>
! Q5 ~; ]" [4 B) c% s
         <meta_attributes id="zabbix-server-meta_attributes"/>

4 L9 _6 C2 [' q7 t+ E1 B" F( U
       </primitive>
& s. R: }3 T: }! O. G1 a
     </group>

$ `$ l( k: @0 Z9 }" M
   </resources>

" r- n/ E% j, |+ W# b
   <constraints>
& z6 M. i* [! e
     <rsc_colocationid="colocation-zabbix-server-ClusterIP-INFINITY"rsc="zabbix-server" score="INFINITY"with-rsc="ClusterIP"/>
* ~9 ]9 }& a5 N- o" @
     <rsc_order first="ClusterIP" first-action="start"id="order-ClusterIP-zabbix-server-mandatory"then="zabbix-server" then-action="start"/>
2 x+ u. _5 P$ ?% ?; l
     <rsc_location id="location-ClusterIP-zabbix01-INFINITY"node="zabbix01" rsc="ClusterIP"score="INFINITY"/>

8 N- _7 Q0 ]) t: {0 @. r; j9 j2 x
     <rsc_location id="location-zabbix-server-zabbix01-INFINITY"node="zabbix01" rsc="zabbix-server"score="INFINITY"/>
1 Q# n! ?! E0 y# D3 L' Y
   </constraints>
& M  j& ~0 f0 {8 l/ l9 Q
   <op_defaults>
. w% e, y0 A- h
     <meta_attributes id="op_defaults-options">
. A" U' ]1 k/ }6 S3 k
       <nvpair id="op_defaults-options-timeout"name="timeout" value="60s"/>

! B; _, L+ B+ [8 `3 s
     </meta_attributes>
# j& E+ G% o" \
   </op_defaults>
; o, u# o" z* X& m& V+ J5 K7 N
</configuration>

/ S# H  _1 L* Y  [
<status>

. v% a' p) a2 y' l
   <node_state id="zabbix01" uname="zabbix01"in_ccm="true" crmd="online"crm-debug-origin="do_update_resource" join="member"expected="member">
$ U8 i" ~, `0 L5 E! H
     <lrm id="zabbix01">
, K2 c+ M- N* S7 W& H
       <lrm_resources>
/ }3 A& [/ T, Y* W' |
         <lrm_resource id="zabbix-server"type="zabbix_server" class="lsb">

/ Q" T% p) r" H8 v
           <lrm_rsc_op id="zabbix-server_last_0"operation_key="zabbix-server_start_0" operation="start"crm-debug-origin="do_update_resource" crm_feature_set="3.0.10"transition-key="10:56:0:76f2a258-6d10-4819-8063-54875d8f896a"transition-magic="0:0;10:56:0:76f2a258-6d10-4819-8063-54875d8f896a"on_node="zabbix01" call-id="12" rc-code="0"op-status="0" interval="0" last-run="1505940302"last-rc-change="1505940302" exec-time="44"queue-time="0"op-digest="f2317cad3d54cec5d7d7aa7d0bf35cf8"/>
  _0 p5 B2 H4 |# }$ i! c" H7 \: e
           <lrm_rsc_opid="zabbix-server_monitor_5000"operation_key="zabbix-server_monitor_5000"operation="monitor" crm-debug-origin="do_update_resource" crm_feature_set="3.0.10"transition-key="11:56:0:76f2a258-6d10-4819-8063-54875d8f896a"transition-magic="0:0;11:56:0:76f2a258-6d10-4819-8063-54875d8f896a"on_node="zabbix01" call-id="13" rc-code="0"op-status="0" interval="5000"last-rc-change="1505940302" exec-time="27"queue-time="1"op-digest="873ed4f07792aa8ff18f3254244675ea"/>
6 B1 J: @+ B8 D2 G3 F1 h. i
         </lrm_resource>
0 w9 Z% P2 ^' N, F! b
         <lrm_resource id="ClusterIP"type="IPaddr2" class="ocf"provider="heartbeat">
- c6 G7 o" F+ S0 D% V
           <lrm_rsc_op id="ClusterIP_last_0"operation_key="ClusterIP_start_0" operation="start"crm-debug-origin="do_update_resource"crm_feature_set="3.0.10"transition-key="7:56:0:76f2a258-6d10-4819-8063-54875d8f896a"transition-magic="0:0;7:56:0:76f2a258-6d10-4819-8063-54875d8f896a"on_node="zabbix01" call-id="10" rc-code="0"op-status="0" interval="0" last-run="1505940302"last-rc-change="1505940302" exec-time="117"queue-time="0"op-digest="31f0afcca8f5f3ffa441c421e2c65fe1"/>
! U# u5 F. K, |8 [* K& u' o
           <lrm_rsc_op id="ClusterIP_monitor_2000"operation_key="ClusterIP_monitor_2000" operation="monitor"crm-debug-origin="do_update_resource"crm_feature_set="3.0.10"transition-key="8:56:0:76f2a258-6d10-4819-8063-54875d8f896a"transition-magic="0:0;8:56:0:76f2a258-6d10-4819-8063-54875d8f896a" on_node="zabbix01"call-id="11" rc-code="0" op-status="0"interval="2000" last-rc-change="1505940302"exec-time="160" queue-time="0"op-digest="e05b48764ef09ebc8e21989b06afa924"/>

/ m! |/ H5 u/ U5 ]: G! q, r, \$ U: v
         </lrm_resource>

& Q  U7 m6 v! F! d( E- i
       </lrm_resources>

* b+ ^- q$ P% ]7 H
     </lrm>

( D2 ~* x' Z1 x+ q) s. a% b2 H
     <transient_attributes id="zabbix01">
; v4 f8 f2 _/ y- b" X) v. \
       <instance_attributes id="status-zabbix01">
) D/ B) j; A0 ^) D9 P- J
         <nvpair id="status-zabbix01-shutdown"name="shutdown" value="0"/>
/ P1 U0 w% d# q$ m
       </instance_attributes>
8 ~. H, E6 E0 m: _
     </transient_attributes>

" r, z( a7 B! l. F8 d8 N
   </node_state>

, ], F) L7 t( f6 `5 g% L
   <node_state id="zabbix02" uname="zabbix02"crmd="online" crm-debug-origin="do_update_resource"in_ccm="true" join="member" expected="member">
$ g* J9 c$ C5 Q$ S& @
     <transient_attributes id="zabbix02">

9 i2 W) d; r0 I( @4 O, B& S
       <instance_attributes id="status-zabbix02">

4 g  c% A7 k/ a" l) P! A
         <nvpair id="status-zabbix02-shutdown"name="shutdown" value="0"/>
; n, p+ S8 t. ^& p
       </instance_attributes>
$ f* c1 [& g  q- v* j
     </transient_attributes>

, O2 T% b' C' U( z+ m9 r$ K
     <lrm id="zabbix02">
% D, U7 |/ y, q$ @: ^& {
       <lrm_resources>

; t& l' s% n8 c+ K8 h) p3 |9 J
         <lrm_resource id="zabbix-server"type="zabbix_server" class="lsb">
% x1 R" A% r3 d* I3 I
           <lrm_rsc_op id="zabbix-server_last_0"operation_key="zabbix-server_stop_0" operation="stop"crm-debug-origin="do_update_resource"crm_feature_set="3.0.10"transition-key="9:56:0:76f2a258-6d10-4819-8063-54875d8f896a"transition-magic="0:0;9:56:0:76f2a258-6d10-4819-8063-54875d8f896a"on_node="zabbix02" call-id="39" rc-code="0"op-status="0" interval="0" last-run="1505940302"last-rc-change="1505940302" exec-time="50"queue-time="0"op-digest="f2317cad3d54cec5d7d7aa7d0bf35cf8"/>
' ^- z$ [& j; ~# t8 D4 V6 x
           <lrm_rsc_op id="zabbix-server_monitor_5000"operation_key="zabbix-server_monitor_5000"operation="monitor" crm-debug-origin="build_active_RAs"crm_feature_set="3.0.10"transition-key="9:53:0:76f2a258-6d10-4819-8063-54875d8f896a" transition-magic="0:0;9:53:0:76f2a258-6d10-4819-8063-54875d8f896a"on_node="zabbix02" call-id="37" rc-code="0"op-status="0" interval="5000"last-rc-change="1505940185" exec-time="17"queue-time="0" op-digest="873ed4f07792aa8ff18f3254244675ea"/>
) n4 p- h$ v4 V- G1 Z
         </lrm_resource>

5 ^+ ?1 n( p. q. {/ _# r# c7 W
         <lrm_resource id="ClusterIP" type="IPaddr2"class="ocf" provider="heartbeat">
( I6 @2 @7 ?9 c0 g) d/ O# o9 L
           <lrm_rsc_op id="ClusterIP_last_0"operation_key="ClusterIP_stop_0" operation="stop"crm-debug-origin="do_update_resource"crm_feature_set="3.0.10" transition-key="6:56:0:76f2a258-6d10-4819-8063-54875d8f896a"transition-magic="0:0;6:56:0:76f2a258-6d10-4819-8063-54875d8f896a"on_node="zabbix02" call-id="41" rc-code="0"op-status="0" interval="0" last-run="1505940302"last-rc-change="1505940302" exec-time="93"queue-time="0" op-digest="31f0afcca8f5f3ffa441c421e2c65fe1"/>

% p  P; M& B, m* s6 }' X  T
           <lrm_rsc_opid="ClusterIP_monitor_2000"operation_key="ClusterIP_monitor_2000" operation="monitor"crm-debug-origin="build_active_RAs" crm_feature_set="3.0.10"transition-key="6:53:0:76f2a258-6d10-4819-8063-54875d8f896a"transition-magic="0:0;6:53:0:76f2a258-6d10-4819-8063-54875d8f896a"on_node="zabbix02" call-id="35" rc-code="0"op-status="0" interval="2000"last-rc-change="1505940185" exec-time="118" queue-time="0"op-digest="e05b48764ef09ebc8e21989b06afa924"/>

5 ]' e' @- o' a7 c5 e# q
         </lrm_resource>
# I3 U  t4 K" W6 v8 d& w
       </lrm_resources>

7 v) K) m/ m9 d) ^+ V
     </lrm>

& U, c+ {0 S  {! \% a" B
   </node_state>
- p5 m% L$ ^# E0 |2 [) I& |
</status>

# Q* g# x+ T' v2 X7 O$ L% M
</cib>

* J8 N2 A+ h; Y
3、查看资源

( D3 j6 Q4 ?, O  G6 o& R" M, \
# pcs resource, w) A; l; n" T: E: f6 P3 D; r. u
Resource Group:zabbix
0 {' n: V1 `. M, X4 s) N4 R9 [5 ?0 {ClusterIP (ocf::heartbeat:IPaddr2):Started zabbix01# v! a  ]3 p( C4 @& b& W4 O- C
zabbix-server (lsb:zabbix_server):Started zabbix01

' d8 ], Y  I, K6 e
4、查看资源组

$ ]1 J; F$ g! T  h# d4 G+ ^
#pcs resourcegroup list

9 ?+ W% ^4 {/ t
zabbix:ClusterIP zabbix-server
# c$ ~( d, x; w' s2 a# Y9 a6 I8 k
# j3 E! ]1 T) n7 Y$ n: {
十三、zabbix启动脚本
* M2 J9 p4 K2 j
# cat /etc/init.d/zabbix_server
1 S6 ?4 r$ P: p" P- M# }0 S#!/bin/bash
. q: k3 Q2 z* w' E3 y3 M1 W0 ^#Location ofzabbix binary. Change path as neccessary
& A; [) m+ J3 Q4 d5 {9 h  g
DAEMON=/usr/local/zabbix/sbin/zabbix_server
- e5 D% n& Q$ ^& i: I% e" G8 O& nNAME=`basename$DAEMON`  a' d5 y: k, X- C
#Pid file ofzabbix, should be matched with pid directive in nginx config file.( V5 R4 J& C  N0 Y2 x+ r& K' F
PIDFILE=/tmp/$NAME.pid
6 G; O' n! |6 c0 `  {: s#this filelocation: T3 j+ T) T- Z- b) _
SCRIPTNAME=/etc/init.d/$NAME. L* b3 b" t& z. g& @- l4 o
#only run ifbinary can be found4 ~; X; v8 h' B5 O
test -x $DAEMON|| exit 0
" x) _7 \% _" ?3 Y8 T2 H) oRETVAL=0

* K8 h# D+ p" D
start() {
4 }7 d" m2 R- s* decho$"Starting $NAME"" h& w6 ^% b% H/ ?
$DAEMON
1 x  L" M! I3 m0 H+ h* ]3 ~7 u1 NRETVAL=07 y$ A3 J- z9 h, M1 U$ o
}

: i+ ]% j7 r5 |% f
stop() {
0 j  h3 l, n  H$ V  k6 b3 W8 Uecho$"Graceful stopping $NAME"
7 q6 U, Q- E5 k7 H# F9 N[ -s"$PIDFILE" ] && kill -QUIT `cat $PIDFILE`
" b% G4 N( n& s8 N, m) a% a& rRETVAL=0/ W7 g, ?+ W% T- U- H6 t
}
) B. s" P+ O8 l9 c7 @
forcestop() {1 U: A3 t/ }0 w& Z: Q  |
echo$"Quick stopping $NAME"+ u, q4 A# W  A: }1 R9 v/ G
[ -s"$PIDFILE" ] && kill -TERM `cat $PIDFILE`
, z* ?- v! O* K$ R& x5 {+ ARETVAL=$?
( b% w8 N$ z) C7 A5 U' M7 g9 D+ v}
$ ^6 |4 ~. t, b5 ?( m4 u) A8 W
reload() {1 h  [. ~9 V+ L1 ?
echo$"Graceful reloading $NAME configuration"
, `/ ~( q! q- k) h1 \1 x[ -s"$PIDFILE" ] && kill -HUP `cat $PIDFILE`
5 D4 [  A8 F: }7 C' LRETVAL=$?
6 O: F9 O* `7 x$ R}

* r: t* X* ]# G7 g' Y
status() {6 p, V/ S* e# }# i' O0 u: m6 J2 r
if [ -s $PIDFILE]; then
( d5 m! N) x  }  j6 v. ~8 e0 {echo $"$NAMEis running."
- R! f$ B  [3 c1 r7 ^RETVAL=09 R2 U* F5 h6 Q! b
else7 M; b3 C" O  X0 S
echo$"$NAME stopped."" w2 y( I) r, ~$ M# ?. F
RETVAL=3
7 \5 G5 L% i. {" P! Q4 D1 Lfi* i4 O9 u% X: M* t, i
}  ^  x5 N" i& l( Z) g, P
# See how wewere called.. i  S7 f5 D% @" h: h' f+ q
case"$1" in
$ E' y. R5 }# L7 F% L2 Dstart)3 {1 t  y+ Q5 L9 ?. e6 {
start
6 s+ j! Y' Y) i: o) q7 W0 @3 f;;  E; l+ m$ \- D2 e) y& q' \& B
stop)! W- r2 E1 Y7 g* _: r8 F8 O
stop. v" Z5 v0 F: ]+ S
;;7 r1 J- I) v. k
force-stop)
& F: v* M  ^  y8 dforcestop% F5 \& V. y" |0 u  Q
;;) D9 e  X/ n3 q! m
restart)0 D) i, Y0 S( c
stop0 A) k% `% y+ b, e
start5 J5 q% H$ J8 j
;;1 T7 P' E9 _4 V3 N4 l* G
reload)
; C! Y5 n3 w; U. s9 zreload
# F2 U0 ?7 T& K/ f1 v$ ];;
- k* o8 `# G- S/ s, ^status)
) T! Y( R8 g  |status: [: J$ J: a1 i, `* g+ f/ k
;;
  ?' Z! v, |) Z* ]) k*)
2 p0 I- K5 I* a. }; O# W) Iecho$"Usage: $0 {start|stop|force-stop|restart|reload|status}"3 G1 ]. Q7 ~- w+ ]! m
exit 1
8 ^% H# |: Y/ r3 U* Iesac

/ M" `% Q+ i! e  G, P5 }/ V
exit $RETVAL4 b3 n! i0 S7 S! t: J& `- q
</pre>

+ K: X; }/ I# s/ E% v% K
. p( ?( l/ L, s/ z- `2 `
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-9 01:10 , Processed in 0.198125 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表