阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux高可用之Corosync+Pacemaker详解

183次阅读
没有评论

共计 8512 个字符,预计需要花费 22 分钟才能阅读完成。

HA 完整结构:

Linux 高可用之 Corosync+Pacemaker 详解

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

安装:
[root@marvin heartbeat]# yum  install corosync  -y

配置:
[root@sherry heartbeat]# cd /etc/corosync/
 
[root@sherry corosync]# ls
corosync.conf.example  corosync.conf.example.udpu  service.d  uidgid.d
[root@sherry corosync]# cp corosync.conf.example corosync.conf
[root@sherry 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:
[root@sherry corosync]# yum install pacemaker -y

自动启动 pacemaker:(服务不会启动,还是需要手动启动)
[root@sherry corosync]# vim corosync.conf
service {
        ver:1    #以插件方式运行 pacemaker
        name:pacemaker
}
aisexec{
        user:root
        group:root
}

密钥文件:
# 生产环境请手敲密钥
[root@sherry corosync]# mv /dev/random  /dev/random.bak
[root@sherry corosync]# mv /dev/urandom /dev/random
 
[root@sherry corosync]# corosync-keygen 
 
[root@sherry corosync]# mv /dev/random /dev/urandom
[root@sherry corosync]# mv /dev/random.bak  /dev/random

密钥生产:(权限 400)
[root@sherry 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

配置文件复制到对应节点:
[root@sherry corosync]# scp -P6789 -p authkey corosync.conf root@marvin:/etc/corosync/

crmsh 安装:
[root@sherry yum.repos.d]# cd /etc/yum.repos.d/
[root@sherry yum.repos.d]# wget http://download.openSUSE.org/repositories/network:ha-clustering:Stable/CentOS_CentOS-6/network:ha-clustering:Stable.repo
[root@sherry yum.repos.d]# yum install crmsh -y

启动脚本:
[root@sherry corosync]# /etc/init.d/corosync start
[root@sherry 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

[root@marvin ~]# 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

Ansible+Corosync+Pacemaker+NFS 实现 http 高可用  http://www.linuxidc.com/Linux/2016-04/130844.htm

基于 Corosync+Pacemaker+DRBD+LNMP 实现 Web 服务器高可用集群   http://www.linuxidc.com/Linux/2015-07/120576.htm

搭建基于 Corosync+DRBD 的高可用 MySQL 集群 http://www.linuxidc.com/Linux/2013-10/91386.htm

分别基于 NFS 服务和 DRBD 服务利用 Corosync 配置高可用集群 http://www.linuxidc.com/Linux/2013-09/90410.htm

Linux 高可用(HA)集群之 Corosync 详解 http://www.linuxidc.com/Linux/2013-08/88733.htm

pacemaker + Corosync 搭建高可用集群 http://www.linuxidc.com/Linux/2013-06/85972.htm

Corosync+pacemaker+RA 实现 MySQL 高可用 http://www.linuxidc.com/Linux/2012-08/67949.htm

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-06/132167.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计8512字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中