推荐-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 20:47
下一篇 2016-04-05 22:39

相关推荐

  • AOP面向方面编程

    1.引言         软件开发的目标是要对世界的部分元素或者信息流建立模型,实现软件系统的工程需要将系统分解成可以创建和管理的模块。于是出现了以系统模块化特性的面向对象程序设计技术。模块化的面向对象编程极度极地提高了软件系统的可读性、复用性和可扩展性。向对象方法的焦点在于选择对象作为模块的主要单元,并将对象与系统的…

    Linux干货 2015-04-07
  • 用PHP编写Hadoop的MapReduce程序

    Hadoop流 虽然Hadoop是用java写的,但是Hadoop提供了Hadoop流,Hadoop流提供一个API, 允许用户使用任何语言编写map函数和reduce函数.Hadoop流动关键是,它使用UNIX标准流作为程序与Hadoop之间的接口。因此,任何程序只要可以从标准输入流中读取数据,并且可以把数据写入标准输出流中,那么就可以通过Hadoop流使…

    Linux干货 2015-04-13
  • Code Review中的几个提示

    Code Review应该是软件工程最最有价值的一个活动,之前,本站发表过《简单实用的Code Review工具》,那些工具主要是用来帮助更有效地进行这个活动,这里的这篇文章,我们主要想和大家分享一下Code Review代码审查的一些心得。 首先,我们先来看看Code Reivew的用处: Code reviews 中,可以通过大家的建议增进代码的质量。 …

    Linux干货 2015-04-03
  • yum用法第一篇-简介及常见用法使用总结

    一、简介     yum( 全称为:Yellow dog Updater, Modified),是红帽(RedHat)家族(RedHat、Fedora、CentOS)中的前端shell的软件包管理器,主要基于对RPM包的管理,能够根据配置文件(类似于svn资源库配置文件)从指定的服务器自动下载RPM包进行安装,其最大的优势就是可…

    Linux干货 2015-09-22
  • vim、crontab、bash for循环练习

    1、复制/etc/rc.d/init.d/functions文件至/tmp目录,将/tmp/functions文件中的以至少一个空白字符开头的行的行首加#。 vim中支持全文查找替换功能且在查找时支持正则表达式,在替换时进行引用。先使用vim /tmp/functions,然后在vim编辑模式中输入:%s/\(^[[:space:]]\+\)/#\1/g再回…

    系统运维 2016-12-03
  • Bash 的配置文件

    有时候,在定义了别名 alilas cls=clear  , 或者定义了 umask=033 等等,在logout 用户后再登录,会失效,因为这些本地变量,仅对当前shell生效。而要保留配置,使其永久生效,就需要将这些定义的写入配置文件中保存。下面介绍下bash的配置文件:  Bash的配置文件可以分为: profile类: /etc/…

    Linux干货 2015-04-04

评论列表(1条)

  • stanley
    stanley 2016-04-05 22:27

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