linux高可用之corosync+packmaker详解

HA完整结构:

安装配置高可用集群:
	1、节点名称:集群每个节点的名称都得能互相解析
		/etc/hosts
		hosts中主机名的正反解析结果必须跟“uname -n”的结果保持一致;
	2、时间必须得同步
		使用网络时间服务器同步时间
	3、并非必须:各节点间能基于ssh密钥认证通信;

安装:

[[email protected] heartbeat]# yum  install corosync  -y

配置:

[[email protected] heartbeat]# cd /etc/corosync/

[[email protected] corosync]# ls
corosync.conf.example  corosync.conf.example.udpu  service.d  uidgid.d
[[email protected] corosync]# cp corosync.conf.example corosync.conf
[[email protected] corosync]# vim corosync.conf

compatibility: whitetank    #是否兼容0.8以前的版本
totem {
    version: 2    #通信协议
    secauth: on   #安全认证功能 off别人知道多波地址 就可以加入 最好开启
    threads: 0   #0表示默认  认证时候并行线程
    interface {
                      ringnumber: 0   #定义环号,防止心跳信息循环发送   就有一块网卡就用0
                      bindnetaddr: 192.168.1.0  #绑定网络地址
                      mcastaddr: 225.122.111.111  #224.0.1.0~238.255.255.255 建议用这组临时
                      mcastport: 5405 #多波端口
                      ttl:1 #只发一次 避免环路
     }
}
logging {
    fileline: off
    to_stderr: no #标准错误输出
    to_logfile: yes
    logfile: /var/log/cluster/corosync.log
    to_syslog: no   #日志开启一项即可
    debug: off
    timestamp: no  #是否记录时间戳
    logger_subsys {
                subsys: AMF
                debug: off
        }
}
amf {
    mode:disabled     #编程相关
}

安装pacemaker:

[[email protected] corosync]# yum install pacemaker -y

自动启动pacemaker:(服务不会启动,还是需要手动启动)

[[email protected] corosync]# vim corosync.conf
service {
        ver:1     #以插件方式运行pacemaker
        name:pacemaker
}
aisexec{
        user:root
        group:root
}

密钥文件:

#生产环境请手敲密钥
[[email protected] corosync]# mv /dev/random  /dev/random.bak
[[email protected] corosync]# mv /dev/urandom /dev/random

[[email protected] corosync]# corosync-keygen 

[[email protected] corosync]# mv /dev/random /dev/urandom
[[email protected] corosync]# mv /dev/random.bak  /dev/random

密钥生产:(权限400)

[[email protected] corosync]# ll
total 24
-r-------- 1 root root  128 May 31 20:54 authkey
-rw-r--r-- 1 root root  476 May 31 20:50 corosync.conf
-rw-r--r-- 1 root root 2663 May 11 06:27 corosync.conf.example
-rw-r--r-- 1 root root 1073 May 11 06:27 corosync.conf.example.udpu
drwxr-xr-x 2 root root 4096 May 11 06:27 service.d
drwxr-xr-x 2 root root 4096 May 11 06:27 uidgid.d

配置文件复制到对应节点:

[[email protected] corosync]# scp -P6789 -p authkey corosync.conf [email protected]:/etc/corosync/

crmsh安装:

[[email protected] yum.repos.d]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://download.opensuse.org/repositories/network:ha-clustering:Stable/CentOS_CentOS-6/network:ha-clustering:Stable.repo
[[email protected] yum.repos.d]# yum install crmsh -y

启动脚本:

[[email protected] corosync]# /etc/init.d/corosync start
[[email protected] corosync]# /etc/init.d/pacemaker start

#停止时候次序相反

实验服务器:marvin  sherry

初始化:

corosync默认启用了stonith,而当前集群并没有相应的stonith设备  我们里可以通过如下命令先禁用stonith:

crm(live)# configure
crm(live)configure# property stonith-enabled=false
crm(live)configure# verify
crm(live)configure# commit

设置投票

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

查看配置所有信息:

crm(live)configure# show
node marvin
node sherry
property cib-bootstrap-options: 	have-watchdog=false 	dc-version=1.1.14-8.el6-70404b0 	cluster-infrastructure="classic openais (with plugin)" 	expected-quorum-votes=2 	stonith-enabled=false
        no-quorum-policy=ignore

定义资源:

定义一个ip:

crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=192.168.1.199
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node marvin
node sherry
primitive webip IPaddr 	params ip=192.168.1.199
property cib-bootstrap-options: 	have-watchdog=false 	dc-version=1.1.14-8.el6-70404b0 	cluster-infrastructure="classic openais (with plugin)" 	expected-quorum-votes=2 	stonith-enabled=false
[[email protected] ~]# ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:0c:34:2c brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.220/24 brd 192.168.1.255 scope global eth1
    inet 192.168.1.199/24 brd 192.168.1.255 scope global secondary eth1
    inet6 fe80::20c:29ff:fe0c:342c/64 scope link 
       valid_lft forever preferred_lft forever

后期定义监控:kill后会自动启动

crm(live)configure# monitor webserver 30s:15s    #删除可直接edit  30s监控一次15s延迟
crm(live)configure# verify
crm(live)configure# commit

crm(live)configure# show
primitive webserver lsb:nginx 	meta target-role=Stopped 	op monitor interval=30s timeout=15s

nfs:(定义监控) (定义正确,未提交)

crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device="sherry:/nfsshared/node1" directory="/mnt/nfs/node1"  fstype=‘nfs‘ op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s  on-fail=restart
crm(live)configure# verify

nginx:(定义监控)

crm(live)configure# primitive webserver lsb:nginx op monitor interval=30s timeout=15s  on-fail=restart  
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node marvin
node sherry
primitive webip IPaddr 	params ip=192.168.1.199
primitive webserver lsb:nginx
property cib-bootstrap-options: 	have-watchdog=false 	dc-version=1.1.14-8.el6-70404b0 	cluster-infrastructure="classic openais (with plugin)" 	expected-quorum-votes=2 	stonith-enabled=false

status:

crm(live)# status
Last updated: Wed Jun  1 20:38:32 2016		Last change: Wed Jun  1 20:36:32 2016 by root via cibadmin on sherry
Stack: classic openais (with plugin)
Current DC: marvin (version 1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes

Online: [ marvin sherry ]

Full list of resources:

 webip	(ocf::heartbeat:IPaddr):	Started marvin
 webserver	(lsb:nginx):	Started sherry

资源停止:

crm(live)# resource
crm(live)resource# stop webserver

crm(live)resource# status
 webip	(ocf::heartbeat:IPaddr):	Started
 webserver	(lsb:nginx):	(target-role:Stopped) Stopped

清理资源状态:

crm(live)resource# cleanup webserver
Cleaning up webserver on marvin, removing fail-count-webserver
Cleaning up webserver on sherry, removing fail-count-webserver

* The configuration specifies that ‘webserver‘ should remain stopped

Waiting for 2 replies from the CRMd.. OK

组操作:

先定义好资源,在加入组

crm(live)# status
Last updated: Wed Jun  1 20:38:32 2016		Last change: Wed Jun  1 20:36:32 2016 by root via cibadmin on sherry
Stack: classic openais (with plugin)
Current DC: marvin (version 1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes
Online: [ marvin sherry ]
Full list of resources:
 webip	(ocf::heartbeat:IPaddr):	Started marvin
 webserver	(lsb:nginx):	Started sherry
crm(live)# configure
crm(live)configure# group webservice webip webserver
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node marvin
node sherry
primitive webip IPaddr 	params ip=192.168.1.199
primitive webserver lsb:nginx
group webservice webip webserver
property cib-bootstrap-options: 	have-watchdog=false 	dc-version=1.1.14-8.el6-70404b0 	cluster-infrastructure="classic openais (with plugin)" 	expected-quorum-votes=2 	stonith-enabled=false

删除组:

crm(live)resource# stop webservice

crm(live)configure# delete webservice    #组下面的资源还是存在

节点操作:

节点离线:

crm(live)# node
crm(live)node# standby marvin   #资源自动转移

节点上线:

crm(live)node# online marvin

节点清理:(节点上资源信息清理)

crm(live)node# clearstate marvin

位置约束:

绑定在一起:

crm(live)configure# colocation webserver_and_webip inf: webserver webip
crm(live)configure# verify
crm(live)configure# commit

查看

crm(live)configure# show
node marvin 	attributes standby=off
node sherry
primitive webip IPaddr 	params ip=192.168.1.199
primitive webserver lsb:nginx
colocation webserver_and_webip inf: webserver webip
property cib-bootstrap-options: 	have-watchdog=false 	dc-version=1.1.14-8.el6-70404b0 	cluster-infrastructure="classic openais (with plugin)" 	expected-quorum-votes=2 	stonith-enabled=false

具体查看:

crm(live)configure# show xml
 <rsc_colocation id="webserver_and_webip" score="INFINITY" rsc="webserver" with-rsc="webip"/>  #webserver跟着webip

顺序约束:

crm(live)configure# order webip-before-webserver mandatory: webip webserver  #依次顺序
crm(live)configure# verify
crm(live)configure# commit

crm(live)configure# status
order webip-before-webserver Mandatory: webip webserver

crm(live)configure# show xml
<rsc_order id="webip-before-webserver" kind="Mandatory" first="webip" then="webserver"/>

位置约束

crm(live)configure# location webip_on_marvin webip 200: marvin
crm(live)configure# verify
crm(live)configure# commit

查看:

crm(live)# status
Last updated: Wed Jun  1 21:11:58 2016		Last change: Wed Jun  1 21:11:32 2016 by root via cibadmin on sherry
Stack: classic openais (with plugin)
Current DC: marvin (version 1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes

Online: [ marvin sherry ]

Full list of resources:

 webip	(ocf::heartbeat:IPaddr):	Started marvin
 webserver	(lsb:nginx):	Started marvin

over

时间: 2024-07-31 15:49:16

linux高可用之corosync+packmaker详解的相关文章

轻量级高可用实现工具--keepalived详解

一 .keepalived简介 keepalived:它的诞生最初是为ipvs(一些服务,内核中的一些规则)提供高可用性的,最初最主要目的是能够自主调用ipvsadm来生成规则,并且能够自动实现将用户访问的地址转移到其他节点上进行实现的. keepalived:核心包含两个ckechers和VRRP协议. ckeckers #检查服务检查reserved的健康状况的,基于脚本也可以服务本身的健康状况.这里是实现ipvs后端健康状况的检测的. VRRP # Virtual Router Redun

Hadoop 2.6.0 HA高可用集群配置详解

1 Hadoop HA架构详解 1.1 HDFS HA背景 HDFS集群中NameNode 存在单点故障(SPOF).对于只有一个NameNode的集群,如果NameNode机器出现意外情况,将导致整个集群无法使用,直到NameNode 重新启动. 影响HDFS集群不可用主要包括以下两种情况:一是NameNode机器宕机,将导致集群不可用,重启NameNode之后才可使用:二是计划内的NameNode节点软件或硬件升级,导致集群在短时间内不可用. 为了解决上述问题,Hadoop给出了HDFS的高

keepalived高可用调度器配置详解

一.VRRP概述 1.VRRP协议 虚拟路由冗余协议(Virtual Router Redundancy Protocol,简称VRRP)是由IETF提出的解决局域网中配置静态网关出现单点失效现象的路由协议,1998年已推出正式的RFC2338协议标准.VRRP广泛应用在边缘网络中,它的设计目标是支持特定情况下IP数据流量失败转移不会引起混乱,允许主机使用单路由器,以及及时在实际第一跳路由器使用失败的情形下仍能够维护路由器间的连通性. 2.vrrp术语 参考:H3C VRRP技术白皮书 虚拟路由

Linux集群——高可用集群原理详解

主备节点名称 :Active/PassivePrimary/Standby心跳 :HeartbeatHA Resource :IP ,Service ,STONITHFailOver :故障转移FailBack :服务切回资源粘性 :资源更倾向于运行于哪个节点集群内部信息传递是基于UDP的Messaging Layer资源管理器 CRM Cluster Resource ManagerDC : Designated CoordinatorPE : Policy EngineTE : Transa

高可用集群架构详解(基于corosync)

架构图 Messaging and Infrastructure Layer 第一层是messaging/infrastructure层,也就是Corosync/OpenAIS层.通过这一层发送"我还活着"的信号. Resource Allocation Layer 第二层是resource allocation layer.这一层最为复杂,包含以下组件: ClusterResource Manager (CRM) 在资源分配层,每一个动作的执行都要经过CRM.资源分配层上的其它组件(

LINUX 高可用群集之 ~Corosync~

Corosync:它属于OpenAIS(开放式应用接口规范)中的一个项目corosync一版本中本身不具 备投票功能,到了corosync 2.0之后引入了votequorum子系统也具备了投票功能了,如果我们用的是1版本的,又需要用到票数做决策时那该如何是好呢:当然,在红帽上把 cman + corosync结合起来用,但是早期cman跟pacemaker没法结合起来,如果想用pacemaker又想用投票功能的话,那就把cman当成 corosync的插件来用,把cman当成corodync的

高可用集群技术之corosync应用详解(一)

Corosync概述: Corosync是集群管理套件的一部分,它在传递信息的时候可以通过一个简单的配置文件来定义信息传递的方式和协议等.它是一个新兴的软件,2008年推出,但其实它并不是一个真正意义上的新软件,在2002年的时候有一个项目Openais , 它由于过大,分裂为两个子项目,其中可以实现HA心跳信息传输的功能就是Corosync ,它的代码60%左右来源于Openais. Corosync可以提供一个完整的HA功能,但是要实现更多,更复杂的功能,那就需要使用Openais了.Cor

Linux下使用Corosync+Pacemaker详解及安装

Corosync详解 OpenAIS概述 OpenAIS是基于SA Forum 标准的集群框架的应用程序接口规范.OpenAIS提供一种集群模式,这个模式包括集群框架,集群成员管理,通信方式,集群监测等,能够为集群软件或工具提供满足 AIS标准的集群接口,但是它没有集群资源管理功能,不能独立形成一个集群.OpenAIS组件包括AMF,CLM,CKPT,EVT,LCK,MSG,TMR,CPG,EVS等,因OpenAIS分支不同,组件略有不同.(下面介绍)OpenAIS主要包含三个分支:Picach

Linux用户态程序计时方式详解

前言 良好的计时器可帮助程序开发人员确定程序的性能瓶颈,或对不同算法进行性能比较.但要精确测量程序的运行时间并不容易,因为进程切换.中断.共享的多用户.网络流量.高速缓存访问及转移预测等因素都会对程序计时产生影响. 本文将不考虑这些影响因素(相关资料可参考<深入理解计算机系统>一书),而仅仅关注Linux系统中用户态程序执行时间的计算方式.除本文所述计时方式外,还可借助外部工具统计耗时,如<Linux调试分析诊断利器——strace>一文中介绍的strace. 本文示例代码的运行环