V 3 corosync&pacemaker

简介:

一、相关概念:

补充 {

what is high Availability

A=MTBF/(MTBF+MTTR)

MTBFmean time betweenfailures平均无故障时间)

MTTRmean time to repair平均修复时间)

 

two ways improve availability

increase MTBF to very large values

reduce MTTR to very low values

 

hardware failure causes

design failurerare);randomfailurerare);infant mortalityhigh rate of failure)使用不当;wear outhigh rate of failure)用坏了

 

increase hardware MTBF

use better componentspreemptivelyreplace hardware prior to wear out在用坏前提前替换掉

 

software failure causes

implementation defectsvery common)任一软件代码超过三行都有缺陷;typicaly measured in defects per KLOC

 

increase software MTBF

experienced engineering teampeer reviewof all codesimple designcompact code foot printstatic and runtimeanalysis tools such as valgrind,lint,high compiler warning levels,coverity,lcovtestcoverage of the software

}

 

corosyncredhat6.XRHCS,比heartbeat更简单,是纯粹的message layer,每个版本都有一个名称,www.corosync.org,支持更多node,最佳16个,最多达100个,被各大linux流行版本所采用,如susedebianredhat

openaisredhat5.XRHCS,作为内核中信息通信的API,借助于CMAN完成message layer,不同版本有不同的代称,例如whitetank版本wilson版本等,使用rgmanager完成资源管理,openais是接口,一大堆的API

corosyncopenais发展到wilson版本后衍生出来的开放性集群引擎

openais9.0版本后分成两个项目,一部分是corosync(只保留了集群引擎),另一部分是openais(保留了AIS规范和corosync的一部分子功能);有时需要corosync提供AIS,这时就要安装openais插件

AISapplication interface standard,应用接口规范,是用来定义API的开放性规范的集合,这些应用程序作为中间件为应用服务提供一种开放的、高移植性的程序接口,在实现高可用过程中是亟需的)

SAFservice availability forum,服务可用性论坛是一开放性论坛,它开发并发布这些免费规范,使用AIS规范的API,可以减少应用程序的复杂性、缩短应用程序的开发时间,这些规范的主要目的就是为了提高中间组件可移植性和应用程序的高可用性)

SAF AIS(是一个开放性工程,在不断更新,而openais是基于SAF标准的集群框架的应用程序接口规范,openais提供一种集群模式(集群框架、集群成员管理、通信方式、集群监测等),能为集群软件工具提供满足AIS标准的集群接口,但没有集群资源管理的功能)

 

pacemaker(比crm特性更丰富,支持全CLI配置,也支持GUI管理工具)

HawkWeb GUI,图形界面资源管理工具,SLESsuse linux enterprise server)也使用corosync+pacemaker

LCMClinux cluster management consoleGUI

CongaRHCS,基于web的管理界面,luci是控制端,ricci是被控制端要安装在每一个node上,配置ricci成为luci的管理对象,并配置好yum源,后续的pacemakercorosync都会自动安装)

keepalivedvrrpvirtual route redundency protocol仅支持2node,在双主模型下keepalived比较理想,若多于2node只能使用heartbeatcorosync这套组件)

 

注:HA集群中节点数最好大于两个(大于两个,为奇数个,就不使用ping node或仲裁磁盘)

 

二、操作(环境redhat52.6.1832bit,两个node,同上篇):

准备软件包(http://clusterlabs.org/rpm/):

cluster-glue-1.0.6-1.6.el5.i386.rpm(让集群中各组件结合起来协同工作)

cluster-glue-libs-1.0.6-1.6.el5.i386.rpm

corosync-1.2.7-1.1.el5.i386.rpm

corosynclib-1.2.7-1.1.el5.i386.rpm

heartbeat-3.0.3-2.3.el5.i386.rpmpacemaker默认依赖heartbeat,安装上不启用即可)

heartbeat-libs-3.0.3-2.3.el5.i386.rpm

pacemaker-1.0.12-1.el5.centos.i386.rpm

pacemaker-libs-1.0.12-1.el5.centos.i386.rpm

resource-agents-1.0.3-2.6.el5.i386.rpm

libesmtp-1.0.4-5.el5.i386.rpm(需单独下载https://dl.fedoraproject.org/pub/epel/5/i386/repoview/letter_l.group.html

其它软件包介绍:

ldirectord-1.0.3-2.6.el5.i386.rpm(专用于ipvs,作为ipvs的补充,可帮助生成ipvs规则及后端RShealth_check,灵活地应用在高可用集群中,与corosyncheartbeat都能结合工作,用于heartbeat的包为heartbeat-ldirectord-2.1.4-11.el5.i386.rpm

openais-debuginfo-1.1.3-1.6.el5.i386.rpm(不做开发可不安装,以插件方式工作在corosync

openaislib-1.1.3-1.6.el5.i386.rpm

 

准备环境(参照集群第二篇heartbeatV2文章)有:时间同步、主机名、ssh双机互信、本地yum

注:redhat5系统使用corosync1.2.71系列的),redhat6使用2系列的

 

node1-side

将以上rpm包放至/root目录下

#cd

#scp ./*  node2:/root

#for I  in  {1..2};do ssh  node$I  ‘yum -y  --nogpgcheck  localinstall /root/*.rpm’;done

#for I  in  {1..2};do ssh  node$I  ‘yum -y  install  httpd’;done

#rpm -ql  corosync

/etc/corosync/corosync.conf.sample

/etc/init.d/corosync

/usr/sbin/corosync

/usr/sbin/corosync-keygen(生成密钥,它是从/dev/random(随机数来自熵池,磁盘中断的时间间隔和击键的时间间隔)下获取随机数,如果不够会等待,提示我们狂敲键盘让其自动生成)

注:heartbeat中的authkeys(密钥手动生成,且明文传输,要改权限为600

#cd /etc/corosync

#cp  corosync.conf.example  corosync.conf

#man  corosync.conf

totem {  }(图腾,每个node同其它node通信通过totem定义)

logging {  }

event {  }

 

#vim /etc/corosync/corosync.conf

totem {

       version: 2(配置文件的版本号,唯一合法的版本号为2,不是说我们改动过就是第一版之类的,是被corosync所支持的版本,各版本间语法不同)

       secauth: on(安全认证,为安全要开启,用HMAC/SHA1加密,会消耗系统资源)

       threads: 2(开启多个线程执行加密或多播,若secauthoff这项就没用,若为on此项才有意义)

       interface {

                ringnumber: 0(每个接口所定义的环,若仅有一个node不定义此项,若有多个node,每个node有两块网卡(冗余),定义多个node上的eth0是一个环,eth1是一环,若有多个node没定义此项,消息在网络中会形成环路一起传递下去)

               bindnetaddr: 192.168.1.0(绑定的网络地址,若一个node上有两块网卡,在哪个网络上传递信息,在哪个网络进行多播,这项定义的是网络,不能写IP,是IP所在的网络地址)

                mcastaddr: 226.94.1.1DIP,仅能使用224.0.2.0~238.255.255.255

                mcastport: 5405

        }

}

logging {

       fileline: off(定义不同的日志间打印分隔符)

       to_stderr: no(发到标准错误输出,也就是屏幕)

       to_logfile: yes(使用指定文件记录日志)

       to_syslog: no(用系统自带的syslog记录/var/log/messages,只开一项即可)

       logfile: /var/log/cluster/corosync.log(此目录不存在,记得在开启服务前要创建此目录)

       debug: off(出错时打开此项调试)

       timestamp: on(记录时间戳,能定位错误,若开启此项每记录一次日志都要获取一次当前系统时间(一次系统调用要返回用户空间,内核通过硬件获取时间),多记录一个条目会使文件体积变大)

       logger_subsys {(子系统信息)

                subsys: AMF

                debug: off

       }

}

amf {

       mode: disabled(没安装openais,未启用)

}

service {(添加此段,启动corosync时,将pacemaker也启动)

       ver: 0

       name: pacemaker

       #use_mgmtd: yes

}

aisexec {(运行openais所指定用户和组,由于未安装openais,此段忽略)

       user: root

       group: root

}      

 

#corosync-keygen(会生成authkey文件,权限400,非文本文件)

#file /etc/corosync/authkey

/etc/corosync/authkey: data

#ll !$

-r-------- 1 root root 128 Jul 10 02:28/etc/corosync/authkey

#scp -p  authkey  corosync.conf node2:/etc/corosync/

#for I  in  {1..2};do ssh  node$I  ‘mkdir  /var/log/cluster/’;done

 

#service corosync  start

#ssh node2  ‘service  corosync start’

#grep  -e  "Corosync Cluster Engine"  -e  "configuration file"  /var/log/cluster/corosync.log(查看corosync引擎是否正常启动)

#grep  TOTEM  /var/log/cluster/corosync.log(查看初始化成员节点通知是否正常发出)

#grep ERROR:  /var/log/cluster/corosync.log(查看启动过程是否有错误,此实验没有STONITH设备,会报错,执行#crm  configure  property stonith-enabled=false即可)

#grep pcmk_startup /var/log/cluster/corosync.log(查看pacemaker是否启动)

 

#crm_mon

注:没有配置ping node很有可能集群分裂

 

#crm(取代了heartbeatV2中的crm_sh,比crm_sh强大的多,进入后help,可管理resourcenodera,可查看noderesourcestatus,支持cd命令,支持命令补全等)

注:crm命令在任一node运行都行,它会自动连接DC从而使配置保存

 

crm(live)#ra

crm(live)ra# list  lsb

crm(live)ra# list  ocf

crm(live)ra# classes

heartbeat

lsb

ocf / heartbeat pacemaker

stonith

crm(live)ra# meta  [ocf:[heartbeat:]IPaddr

crm(live)ra# meta  ocf:heartbeat:Filesystem(或meta  Filesystem

crm(live)ra# providers IPaddr

heartbeat

crm(live)ra# providers Filesystem

heartbeat

crm(live)ra# providers Dummy

heartbeat pacemaker

 

crm有两种模式:

交互模式(下配置,执行commit命令后才生效);

批处理模式(下配置立即生效,例如#crm  configure  property stonith-enabled=false

crm(live)# configure

crm(live)configure# property  stonith-enabled=false(交互模式)

crm(live)configure# property  no-quorum-policy=ignore

crm(live)configure# verify(检查配置文件是否正确)

crm(live)configure# commit(在交互模式下,要提交)

crm(live)configure# show  [xml]display CIBobjects

node node1.magedu.com

node node2.magedu.com

property$id="cib-bootstrap-options" \

         dc-version="1.0.12-unknown"\

         cluster-infrastructure="openais"\

         expected-quorum-votes="2"\

         stonith-enabled="false"

         no-quorum-policy="ignore"

crm(live)configure# show  xml(打开/var/lib/heartbeat/crm/cib.xml文件)

 

crm(live)# configure

crm(live)configure# primitive webipocf:heartbeat:IPaddr params ip=192.168.41.222 nic=eth0 cidr_netmask=24 iflabel=eth0:0(打开另一终端,crm(live)configure# help primitivecrm(live)ra# meta ocf:heartbeat:IPaddr,参考语法配置正确)

crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device=192.168.41.128:/web/htdocs directory=/var/www/html fstype=nfs op start timeout=60 op stop timeout=60(这里的start timeoutstop timeout必须要定义,因为默认值是20秒,小于建议的60秒,op后指定的这些选项只能比建议的长)

crm(live)configure# primitive httpd lsb:httpd

crm(live)configure# group webservice webip webstore httpd

crm(live)configure# verify

crm(live)configure# commit

crm(live)configure# show

crm(live)configure# edit(可直接编辑配置,是在vim下配置)

crm(live)configure# cd

crm(live)#exit

[root@node1 ~]#

 

[root@node1 ~]# crm

crm(live)# node

crm(live)node# help

crm(live)node# show

crm(live)node# list

crm(live)node# standby(或#crm  node standby

crm(live)node# online(或#crm  node online

crm(live)node# clearstate node1.magedu.com

 

crm(live)# resource

crm(live)resource# help

crm(live)resource# stop webservice

crm(live)resource# start webservice

crm(live)resource# restart webservice

crm(live)resource# list

 Resource Group: webservice

    webip     (ocf::heartbeat:IPaddr)Started

    webstore        (ocf::heartbeat:Filesystem)Started

    httpd      (lsb:httpd) Started

crm(live)resource# status

crm(live)resource# cleanup webservice

Cleaning up webip on node1.magedu.com

Cleaning up webip on node2.magedu.com

Cleaning up webstore on node1.magedu.com

Cleaning up webstore on node2.magedu.com

Cleaning up httpd on node1.magedu.com

Cleaning up httpd on node2.magedu.com

Waiting for 7 replies from the CRMd.......

 

[root@node1 ~]# crm_mon(在以上noderesource上操作时,观察监控的变化)

 

以上是通过组将各资源绑在一起,以下是通过constraint将资源绑在一起

 

crm(live)# resource

crm(live)resource# stop webservice

crm(live)resource# cd

crm(live)# configure

crm(live)configure# delete webservice

crm(live)configure# show

crm(live)configure# commit

[root@node1 ~]# crm_mon(将组删除后可看到,三个资源是分散地运行在不同的node上)

============

Last updated: Thu Nov  5 23:54:54 2015

Stack: openais

Current DC: node2.magedu.com - partitionwith quorum

Version: 1.0.12-unknown

2 Nodes configured, 2 expected votes

3 Resources configured.

============

Online: [ node1.magedu.com node2.magedu.com]

httpd  (lsb:httpd):    Started node1.magedu.com

webstore        (ocf::heartbeat:Filesystem):    Startednode2.magedu.com

webip  (ocf::heartbeat:IPaddr):        Started node1.magedu.com

 

crm(live)configure# help  colocation

crm(live)configure# colocation httpd_with_webstore inf: httpd webstore

crm(live)configure# colocation webstore_with_webip inf: webstore webip

crm(live)configure# order webstore_before_httpd mandatory: httpd webstore

crm(live)configure# order webip_before_httpd mandatory: httpd webip

crm(live)configure# verify

crm(live)configure# commit

crm(live)configure# show

crm(live)configure# exit

bye

[root@node1 ~]# crm node standby(将当前node备用,并在另一终端打开#crm_mon

……

httpd  (lsb:httpd):    Startednode2.magedu.com

webstore        (ocf::heartbeat:Filesystem):    Started node2.magedu.com

webip  (ocf::heartbeat:IPaddr):       Started node2.magedu.com

[root@node1 ~]# crm node online

……

httpd  (lsb:httpd):    Startednode1.magedu.com

webstore        (ocf::heartbeat:Filesystem):    Started node1.magedu.com

webip  (ocf::heartbeat:IPaddr):       Started node1.magedu.com

 

crm(live)configure# location webip_on_node1webip rule 100: #uname eq node1.magedu.com(位置约束)

crm(live)configure# rsc_defaults resource-stickiness=200(资源粘性)

注:位置约束和资源粘性结合起来决定资源到底在哪个node运行,这两项都设置后,资源粘性(定义资源乐意运行在当前node),位置约束(倾向性,定义资源乐意运行在哪个node),若在node1#crm  node  standby,资源转移至node2,而当node1重新online后资源不会切换(若当前node1故障不能工作,资源同样转移到node2)(如果按例子中设置仅定义位置约束,则在node1standby后,会切至node2,当node1重新online后,资源又切至node1

crm(live)configure# exit

bye

[root@node1 ~]# crm_mon(当前运行在node1

……

Online: [ node1.magedu.com node2.magedu.com]

 

httpd  (lsb:httpd):    Startednode1.magedu.com

webstore        (ocf::heartbeat:Filesystem):    Started node1.magedu.com

webip  (ocf::heartbeat:IPaddr):       Started node1.magedu.com

[root@node1 ~]# service corosync stop(将node1服务停止)

Signaling Corosync Cluster Engine(corosync) to terminate: [  OK  ]

Waiting for corosync services tounload:..                 [  OK  ]

[root@node2 ~]# crm_mon(资源运行在node2上)

……

Online: [ node2.magedu.com ]

OFFLINE: [ node1.magedu.com ]

 

httpd  (lsb:httpd):    Startednode2.magedu.com

webstore        (ocf::heartbeat:Filesystem):    Started node2.magedu.com

webip  (ocf::heartbeat:IPaddr):       Started node2.magedu.com

 

 

 

本文转自 chaijowin 51CTO博客,原文链接:http://blog.51cto.com/jowin/1719779,如需转载请自行联系原作者

相关文章
|
Web App开发 网络协议 Linux
|
Shell 应用服务中间件 网络安全
|
关系型数据库 MySQL Linux

热门文章

最新文章