corosync+pacemaker高可用部署

OpenAIS:是实现高可用集群的一种完备解决方案;Corosync是集群管理套件的一部分,通常会与其他资源管理器一起组合使用它在传递信息的时候可以通过一个简单的配置文件来定义信息传递的方式和协议等,Pacemaker是一个集群资源管理器。它利用集群基础构件(OpenAIS 、heartbeat或corosync)提供的消息和成员管理能力来探测并从节点或资源级别的故障中恢复,以实现群集服务(亦称资源)的最大可用性。

OpenAIS:分为3个层次

    Messaging Layer:infrastructure layer

    CRM:cluster resource layer(包括local resource layer)

    RA:resource agent:管理机制:start,stop,restart,status,monitor

Messaging Layer:集群事务信息及心跳信息传播方式,unicast、broadcast、multicast

如图架构所示:

2018-07-30_185351.png


组合实现的方式

heartbeat v1 (haresources):独立实现

heartbeat v2 (crm)        :独立实现

heartbeat v3 + pacemaker

corosync + pacemaker

corosync v1 + pacemaker (plugin) )—(v1 -没有投票系统)

corosync v2 + pacemkaer (standalone service)

cman + rgmanager (RHCS)

corosync v1 + cman + pacemaker----(cman提供投票系统)

CRM:资源管理:

    资源类型:

    primitive:主资源,基本资源,在集群中只能运行在一个节点

    clone:克隆资源,在集群中可以运行多个实例,运行在多个节点

    multi-state(master/salve):多状态克隆,副本间存在主从关系

    group:组资源,将一个高可用服务所需要的所有资源组织在一起

    RA:recourse agent资源代理

    代理的类别:classes

    LSB(linux standard base):脚本文件:/etc/init.d/*、/etc/rc.d/init.d/*、(start|stop|restart|status|running,|reload)--注:不能开机自动运行

    service:(heartbeat legacy):/etc/ha.d/haresources.d/*  IPAddr(ifcfg)、IPAddr2(ip)

    OCF(Open Cluster Framework):/usr/lib/ocf/resource.d/provider,类似LSB脚本 但支持:start,stop,monitor,meta-data

                                                             provider :.isolation heartbeat openstack pacemaker

    stonish:隔离设备专用资源

    systemd:/usr/lib/systemd/system/ 注:必须设置开机能自动启动。systemctl enable *.service

    资源属性:定义格式 meta attribute=value

    priority:优先级

    target-role:started,stopped,master;如果设置为stopped,配置完后资源没有立即启动

    is-managed:是否允许crm管理此资源

    resource-stickiness:资源黏性,对当前节点的倾向性

    allow-migrate:是否允许迁移,新版本migrate改为使用move

    资源的倾向性,约束关系:

    location:位置约束,资源对当前节点倾向性

    colocation:排列约束 ,资源彼此间是否能运行在同一个节点的倾向性

    order:顺序约束,多个资源启动顺序依赖关系

安装:CentOS 7: corosync v2 + pacemaker

结构图如图:

image.png

配置HA的群集前提:

(1) 时间同步;crontab -e */5 * * * * /sbin/ntpdate 192.168.1.112 &>dev/null

    配置ntp同步服务器

(2) 基于当前正使用的主机名互相访问;严格与hostname一致

名称解析:不建议依赖于dns服务进行解析;

hostnamectl set-hostname node1.xuetong.com:立即生效并永久有效

(3)基于ssh互信

 ssh-keygen -t rsa -P ''

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

(4)  隔离设备;

各节点安装:

#yum -y install corosync  pacemaker  (可以直接安装pacemaker即可,依赖于corosync)

corosync的配置文件:/etc/corosync/corosync.conf,/etc/corosync/authkey

totem { }:通信协议,节点间通信,加密与否

interface{}:至少有一个用于监听集群信息

logging {}:日志系统,日记记录及存储

quorum {}:投票系统

nodelist {}:节点列表

pacemaker:配置文件(配置进程的运行特性):/etc/sysconfig/pacemaker  :默认即可

配置文件:

totem {

version: 2   #corosync版本

cluster_name: mycluster    #设置集群名称

crypto_cipher: aes128        #设置安全机制

crypto_hash: sha1

interface {                          #配置接口      

ringnumber: 0            #The ringnumber must start at 0

bindnetaddr: 192.168.1.0    #设置监听的IP地址

mcastaddr: 239.255.1.1    #设置多播地址

mcastport: 5405        #多播地址端口

ttl: 1

}

}

logging {                    #日志相关信息配置

fileline: off

to_stderr: no

to_logfile: yes

logfile: /var/log/cluster/corosync.log

to_syslog: yes

debug: off

timestamp: on

logger_subsys {

subsys: QUORUM

debug: off

}

}

quorum {

provider: corosync_votequorum #定义投票机制

}

nodelist {            #添加节点信息

node {

    ring0_addr: 192.168.1.120

nodeid: 1

}

node {

ring0_addr: 192.168.1.112

nodeid: 2

}

}

本次实验通过使用crmsh来管理集群事务:

可以通过http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/noarch/下载相关组件

crmsh命令使用:ls,help

command --help 

查看集群信息状态

status [<option> ...]

option:: full | bynode | inactive | ops| timing | failcounts | verbose | quiet | html | xml  |simple | tickets | noheaders  | detail | brie

配置集群CIB:configure 步骤

    配置集群属性:property

    配置资源默认属性:rsc_default

    配置集群资源:primitive、group、clone、master/slave

    配置约束:location、colacation、order

 通过help命令可以获取ra/resource/node 使用帮助:

配置集群资源:

primitive <rsc> {[<class>:[<provider>:]]<type>|@<template>}

<rsc>配置资源名称

image.png

校验编写是否存在错误:

image.png

提示错误因为没有定义stonish资源,关闭stonish设备

image.png

默认启用对称设备,这样运行在任何节点都一样

image.png

配置完成后需要commit提交才会保存生效;

image.png

测试高可用效果:让某个节点待定,查看资源迁移情况,重新上线后的结果,资源的黏性:可以强制迁移

standby [<node>] [<lifetime>] ,没指名node,表示当前节点

image.png

迁移资源:

move <rsc> [<node>] [<lifetime>] [force] {migrate之前版本} unmigrate--->clear <rsc>

mv webvip node1.xuetong.com

image.png

停止某个资源:stop <src>

配置httpd服务:

安装httpd后要确保开机能自动启动enable:systemctl enable httpd.service

查看ra资源代理是否有httpd服务

image.png

配置http资源,出现告警通过配置资源时设置:资源的operations :op op_type [attribute <timeout>]

image.png

image.png

两个资源分散均衡至不同节点,高可用实现期望一类资源运行在同一个节点,通过定义资源约束关系,在一个组服务。

把两个资源定义在同一个组:

image.png

两个资源运行在一个节点上

image.png

测试结果,并模拟节点迁移

image.png

image.png

image.png

再次让node1节点上线,资源的倾向性,因此服务运行在node3,实现资源手动迁移:

image.png

配置文件系统:filesystem,提供同样的资源:使用集中式存储nas-->NFS

yum install nfs-utils.x86_64 

vim /etc/exports

/www/html  192.168.1.0/24(rw,no_root_squash)

systemctl start nfs.server

手动测试NFS能否正常工作然后挂载使用:mount -t nfs nfsserver-ip:/www/html /var/www/html

测试正常后,通过配置资源来实现NFS部署:

image.png

重新定义group关系:group web webvip webstore webserver,这样能够简单实现nfs提供共享文件存储:

为了区分资源的启动顺序、运行在哪个节点可以通过定义约束关系:

colocation:定义资源能否运行在同一节点

        colocation <id> <score>: <rsc>[:<role>] <with-rsc>[:<role>]

coloaction webserver_with_webip inf: webserver webip:表示这两个资源必须运行在一起

order:定义资源启动先后顺序:

order <id> [{kind|<score>}:] first then [symmetrical=<bool>]

kind :: Mandatory | Optional | Serialize

order o-1 Mandatory: webip  webserver :表示先启动webip资源再到webserver资源

location:定义资源运行在哪个节点上倾向性

        location webip_pre_node1 webip 50: node1.xuetong.com

        location webip_pre_node2 webip inf: node2.xuetong.com


猜你喜欢

转载自blog.51cto.com/12580678/2152400
今日推荐