推荐-Corosync + Pacemaker 搭建高可用Httpd服务

Corosync + Pacemaker 搭建高可用Httpd服务


实验描述

1.两个测试节点,分别为node5.redhat.comnode6.redhat.com地址分别为172.16.100.5172.16.100.6
2.集群服务为httpd,利用nfs做共享存储,NFS地址为172.16.0.254,NFS已经共享出了一个/www/htdocs目录并且里面有index.html文件。
3.VIP地址为172.16.100.100
4.两个节点系统全部为CentOS7.2
5.由于本人还需要上班,所以时间紧张,描述的有点马虎,请多见谅。如有错误的地方,还请提出改正。


配置步骤

1.在所有节点安装pcs,并启动相应的pcsd进程

[root@node5 ~]# yum install pcs -y
[root@node5 ~]# systemctl start pcsd.service

[root@node6 ~]# yum install pcs -y
[root@node6 ~]# systemctl start pcsd.service

2.给所有节点上的hacluster用户设置一个密码。

[root@node5 ~]# echo “redhat” | passwd –stdin hacluster

[root@node6 ~]# echo “redhat” | passwd –stdin hacluster

3.在一个节点上验证两个节点

[root@node5 ~]# pcs cluster auth node5.redhat.com node6.redhat.com
Username: hacluster
Password: 这里输入的密码默认不会显示
node5.redhat.com: Authorized
node6.redhat.com: Authorized

4.将两个节点加入集群

[root@node5 ~]# pcs cluster setup –name mycluster node5.redhat.com node6.redhat.com
添加节点的输出信息
Shutting down pacemaker/corosync services…
Redirecting to /bin/systemctl stop pacemaker.service
Redirecting to /bin/systemctl stop corosync.service
Killing any remaining services…
Removing all cluster configuration files…
node5.redhat.com: Succeeded
node6.redhat.com: Succeeded
Synchronizing pcsd certificates on nodes node5.redhat.com, node6.redhat.com…
node5.redhat.com: Success
node6.redhat.com: Success

Restaring pcsd on the nodes in order to reload the certificates…
node5.redhat.com: Success *显示添加成功*
node6.redhat.com: Success *显示添加成功*

5.两个节点同时启动corosyncpacemaker进程

[root@node5 ~]# systemctl start corosync.service
[root@node5 ~]# systemctl start pacemaker.service

[root@node6 ~]# systemctl start corosync.service
[root@node6 ~]# systemctl start pacemaker.service

6.在两个节点上安装httpd进程并设置为开机启动

root@node5 ~]# yum install httpd -y
systemctl enable httpd.service

root@node6 ~]# yum install httpd -y
systemctl enable httpd.service

7.在两个节点上安装nft-utils以实现支持挂载nfs共享

[root@node5 ~]# yum install nfs-utils

[root@node6 ~]# yum install nfs-utils

8.安装crmsh,CentOS7默认不带crmsh,需要去网上下载rpm包,我用的是crmsh-2.2.0-7.1.noarch.rpmcrmsh-scripts-2.2.0-7.1.noarch.rpmpython-parallax-1.0.1-10.1.noarch.rpm

[root@node5 ~]# yum install crmsh-2.2.0-7.1.noarch.rpm crmsh-scripts-2.2.0-7.1.noarch.rpm python-parallax-1.0.1-10.1.noarch.rpm -y

[root@node6 ~]# yum install crmsh-2.2.0-7.1.noarch.rpm crmsh-scripts-2.2.0-7.1.noarch.rpm python-parallax-1.0.1-10.1.noarch.rpm -y

9.利用crmsh配置资源

[root@node5 ~]# crm configure

配置VIP资源
crm(live)configure# primitive webip ocf:heartbeat:IPaddr ip=’172.16.100.100’ op monitor interval=20s timeout=40s

配置NFS资源
crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device=’172.16.0.254:/www/htdocs’ directory=’/var/www/html’ fstype=’nfs’ op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=40s

配置WEB资源
crm(live)configure# primitive webserver systemd:httpd op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=60s

因为是两节点集群,需要关闭stonith
crm(live)configure# property stonith-enabled=false

crm(live)configure# commit

10.设置这三个服务要同时在一个节点上运行,并且启动顺序一定为VIP -> NFS -> httpd

  设置三个服务在同一节点上运行有两种方法实现,一种是将所有资源设置到同一个组里面,或者设置排列约束。当然,即设置了组,又定义为了排列约束也是可以的。设置启动顺序那么必须使用顺序约束

设置组

crm(live)configure# group webservice webip webstore webserver

或排列约束

crm(live)configure# colocation webip_with_webstore inf: webip webstore
crm(live)configure# colocation webstore_with_webserver inf: webstore webserver

顺序约束

crm(live)configure# order webip_before_webstore Mandatory: webip webstore
crm(live)configure# order webstore_before_webserver Mandatory: webstore webserver
crm(live)configure# commit


验证配置

1.首先查看集群状态

crm(live)configure# cd 退出到crmsh的主配置界面
crm(live)#status 输出status查看集群状态

Alt text1.jpg

一切正常

2.打开浏览器,输入VIP地址进行查看。

Alt text2.jpg

测试也是正常的

3.将node5节点设置为standby状态,查看服务是否转移成功。

crm(live)# node standby node5.redhat.com
crm(live)# status

Alt text3.jpg

可以看到node服务转移到了node6节点上

4.再次打开浏览器进行测试。

2.jpg

服务依旧正常,这样就实现了我们高可用的目的。


原创文章,作者:张小凡,如若转载,请注明出处:http://www.178linux.com/14207

(0)
张小凡张小凡
上一篇 2016-04-05
下一篇 2016-04-05

相关推荐

  • zabbix快速创建筛选(sql操作)

        公司由于大量业务调整,尤其是服务器功能和性能的转变,监控也跟随这变化,其中操作最为繁琐的当数zabbix筛选(相信各位从页面添加的都深感痛苦)于是有了本文。     本文采用的方法是sql操作(由于本人不会php等,无法写程序直接调用官方api,所以,嘿嘿,不解释,同时也希望各路大…

    Linux干货 2015-12-17
  • 推荐-HA专题: 编译安装并配置DRBD

    HA专题: 编译安装并配置DRBD 前言 实验环境 DRBD介绍 安装前准备工作 获取并编译安装DRBD 配置DRBD 分区 配置文件 启动并设置DRBD 格式化并挂载 验证冗余性 总结 前言 上篇我们讲到使用corosync+pacemaker实现MySQL高可用, 但是NFS容易成为单点故障从而导致数据丢失等严重问题, 我们可以使用drbd来实现MySQ…

    Linux干货 2016-04-12
  • N26_第三周作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 演示: [root@joylin test]# who|cut -d” ” -f1|uniq root gentoo [root@joylin test]# who|cut -d” ” -f1|uniq -c 5 root 1 gentoo 或者 [root@joyl…

    Linux干货 2017-02-21
  • ftp服务器介绍与配置

    一、 ftp服务,File Transfer Protocal 文件传输协议      1. ftp基于tcp协议,C/S架构          Server: wu-ftpd, proftpd ,pureftp,vsf…

    Linux干货 2015-06-21
  • 数据结构-线性表

    1. 线性表:n个数据元素的有序集合。 线性表是一种常用的数据结构。在实际应用中,线性表都是以栈、队列、字符串、数组等特殊线性表的形式来使用的。由于这些特殊线性表都具有各自的特性,因此,掌握这些特殊线性表的特性,对于数据运算的可靠性和提高操作效率都是至关重要的。  线性表是一个线性结构,它是一个含有n≥0个结点的有限序列,对于其中的结点,有且仅有一个开始结点…

    Linux干货 2015-04-07
  • 第5周

    第5周 1.显示当前系统上root,fedora或user1用户的默认shell。 [root@node1 ~]# grep -E “^(root|fedora|user1)\>” /etc/passwd | cut -d: -f 7 /bin/bash /bin/bash /bin/bash [root@node1 ~]# grep “^\(root…

    Linux干货 2017-07-27

评论列表(1条)

  • stanley
    stanley 2016-04-05 22:27

    结构清晰明白,内容详略得当,赞