设为首页 收藏本站
查看: 2282|回复: 0

[经验分享] 基于Corosync和Pacemaker实现Web服务的高可用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-8-15 10:08:37 | 显示全部楼层 |阅读模式
Corosync+Pacemaker+iscsi+Httpd实现web服务的高可用

一、软件介绍

Corosync实现的是membership和可靠组通信协议
Pacemaker则基于Corosync/Linux-HA实现服务的管理

Corosync包括如下组件:
          Totem  protocol
          EVS
          CPG
          CFG
          Quorum
Extended Virtual  Synchrony算法(EVS)提供两个功能:
          组成员列表的同步;
          组消息的可靠组播。
Pacemaker层次架构
wKioL1PsOx3TLW7iAAIX50voUU8701.jpg

Pacemaker本身由四个关键组件组成:
         CIB ( 集群信息基础)
         CRMd ( 集群资源管理守护进程)
         PEngine ( PE or 策略引擎)
         STONITHd(Shoot-The-Other-Node-In-The-Head 爆其他节点的头)

wKiom1PsOgXhRkbbAAG4Wkdkpk4168.jpg
内部组件结构
二、软件的安装及web服务实现

实验环境:rhel6.5
                KVM虚拟机  关闭防火墙  selinux disabled
                两个节点node1.com  node4.com

yum install  corosync  pacemaker  -y

yum仓库不提供crm命令需要自己装
包名:crmsh-1.2.6-0.rc2.2.1.x86_64.rpm、pssh-2.3.1-2.1.x86_64.rpm
        pssh-2.3.1-4.1.x86_64.rpm、python-pssh-2.3.1-4.1.x86_64.rpm
安装crmsh依赖与pssh包,pssh若选用2.3.1-4.1还需安装python-pssh-2.3.1-4.1

配置 Corosync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
vi /etc/corosync/corosync.conf
    totem {
version: 2
secauth: off
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.122.0       //设置成实验环境的网段
mcastaddr: 226.44.1.1            //集群使用多播,各节点需要一致
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
to_syslog: yes
logfile:
/var/log/cluster/corosync.log
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}

amf {
mode: disabled
}

service {                    //添加
name: pacemaker
ver: 0            
}
//When run in version 1 mode, the plugin does not start the Pacemaker daemons.
  When run in version 0   mode, the plugin can start the Pacemaker daemons.




两个节点上配置相同
/etc/init.d/corosync start                             //启动corosync服务
使用crm_verify-LV 先校验配置文件
wKiom1PsPXmjPBKEAAECz7ZdOnk842.jpg

pacemaker默认启用了stonith,而当前集群并没有相应的stonith设备,因此此默认配置目前尚不可用,这可以通过如下命令先禁用stonith:
crm(live)configure#crm configureproperty stonith-enabled=false
再用crm_verify -LV 命令查看就没有报错了,一个节点配置所有节点同步
添加资源vip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
crm(live)configure# primitive vip ocf:heartbeat:IPaddr2 params ip=192.168.122.20 cidr_netmask=24 op
monitor interval=30s
crm(live)configure# commit
crm(live)configure# show
node node1.com
node node4.com
primitive vip ocf:heartbeat:IPaddr2
    params ip="192.168.122.20"
cidr_netmask="24"
    op monitor interval="30s"
property $id="cib-bootstrap-options"

    dc-version="1.1.10-14.el6-368c726"

    cluster-infrastructure="classic
openais (with plugin)"
    expected-quorum-votes="2"
    stonith-enabled="false"




当有半数以上的节点在线时,这个集群就认为自己拥有法定人数了,是“合法”的
1
crm(live)configure# property no-quorum-policy=ignore



    //忽略达不到法定人数的情况,继续运行资源
提交成功后就可以在另外一个节点上使用命令crm_mon  查看资源
wKioL1PsQJ7g1q8dAAEjE1CsBfc857.jpg

添加web服务资源website:
首先修改httpd配置文件
1
2
3
4
5
6
7
vi /etc/httpd/conf/httpd.conf         //各个节点服务节点均得修改,大概在921行,去掉注释
   
   SetHandler server-status
   Order deny,allow
   Deny from all
   Allow from 127.0.0.1
   



1
2
3
4
5
crm(live)configure# primitive website ocf:heartbeat:apache params configfile=/etc/httpd/conf/httpd.conf op
monitor interval=30s
crm(live)configure# commit
WARNING: website: default timeout 20s for start is smaller than the advised 40s
WARNING: website: default timeout 20s for stop is smaller than the advised 60s



1
crm(live)configure# colocation website-with-vip inf: website vip



       //将website和vip绑定在同一个节点上,不添加的话,两个资源会运行在不同的节点
1
2
crm(live)configure# location master-node website 10: node4.com   //设置master主节点
crm(live)configure# commit



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
crm(live)configure# show
node node1.com
node node4.com
primitive vip ocf:heartbeat:IPaddr2
    params ip="192.168.122.20" cidr_netmask="24"
    op monitor interval="30s"
primitive website ocf:heartbeat:apache
    params configfile="/etc/httpd/conf/httpd.conf"
    op monitor interval="30s"
    meta target-role="Started"
location master-node website 10: node4.com
colocation website-with-vip inf: website vip
property $id="cib-bootstrap-options"
    dc-version="1.1.10-14.el6-368c726"
    cluster-infrastructure="classic openais (with plugin)"
    expected-quorum-votes="2"
    stonith-enabled="false"
    no-quorum-policy="ignore"



此时可以进行测试:打开备用节点上的监控crm_mon,再关闭主节点的corosync服务,可以看到资源会切换到备用节点,若master恢复,会切换回去,即集群的高可用


添加iscsi共享存储
首先在宿主机上建立共享存储
1
2
3
4
5
6
7
vi /etc/tgt/targets.conf
<target
iqn.2014-06.com.example:server.target1>
backing-store /dev/vg_ty/ty            //宿主机使用lvm存储
initiator-address 192.168.122.24
initiator-address 192.168.122.27





$ /etc/init.d/tgtd restart
$ tgt-admin -s                                   //可以查看所有的目标主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 2147 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/vg_ty/ty
            Backing store flags:
    Account information:
    ACL information:
        192.168.122.24
        192.168.122.27



两节点(虚拟机)上连接iscsi
1
2
3
4
5
6
7
8
9
10
[iyunv@node1 ~]# iscsiadm -m discovery -p 192.168.122.1 -t st
Starting iscsid:                      [  OK  ]
192.168.122.1:3260,1 iqn.2014-06.com.example:server.target1
[iyunv@node1 ~]# iscsiadm -m node -l
Logging in to [iface: default, target:
iqn.2014-06.com.example:server.target1, portal: 192.168.122.1,3260]
(multiple)
Login to [iface: default, target:
iqn.2014-06.com.example:server.target1, portal: 192.168.122.1,3260]
successful.




fdisk  -l                                               //即可看到新添加的磁盘,进行分区

fdisk -cu  /dev/sda
mkfs.ext4  /dev/sda1             //格式化成ext4
mount  /dev/sda1  /var/www/html
echo 'node1.com' >/var/www/html/index.html
umount /dev/sda1

1
2
3
4
5
6
crm(live)configure# primitive webfs ocf:heartbeat:Filesystem params device=/dev/sda1
directory=/var/www/html fstype=ext4 op monitor interval=30s
crm(live)configure# colocation webfs-with-website inf: webfs website  
                    //将webfs和website绑定在同一个节点上
crm(live)configure# order website-after-webfs inf: webfs website
                    //设置启动顺序,先启动文件系统webfs,再启动服务website



wKioL1PsY0PxoUePAAMIk0lnUUA157.jpg
此时查看资源状况
wKioL1PsZA6DwMmyAAFcsi8v1I8652.jpg
服务运行在master node4.com上,当master宕机,资源会被备用节点node1.com接管。


</target

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-23900-1-1.html 上篇帖子: 日均百万PV架构第五弹(运维自动化) 下篇帖子: 高可用集群corosync+pacemaker+drbd+httpd----自动配置篇
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

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