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

[经验分享] pacemaker搭建HTTP集群

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-9-13 10:20:20 | 显示全部楼层 |阅读模式
#以node01为例修改主机名
#node02需要同样的配置
[iyunv@node01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.5 node01
10.10.10.6 node02
#关闭防火墙以及SElinux
#node02需要同样配置

[iyunv@node01 ~]# systemctl stop firewalld
[iyunv@node01 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[iyunv@node01 ~]# setenforce 0
[iyunv@node01 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#配置pacemaker的EPEL源
#node02需要同样配置
[iyunv@node01 ~]# cat /etc/yum.repos.d/pacemaker.repo
[pacemaker]
name=pacemaker
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=0
#下载pacemaker安装包
#node02需要同样配置

[iyunv@node01 ~]#  yum install pacemaker pcs resource-agents -y
#配置节点之间认证
#node02需要同样配置

[iyunv@node01 ~]# ssh-keygen -t rsa -P ''
[iyunv@node01 ~]# ssh-copy-id node02
#修改pacemaker的用户密码(pacemaker使用的用户是hacluster,软件安装完后用户以添加)
#node02需要同样配置
[iyunv@node01 ~]# passwd hacluster

#启动pcs服务
#node02需要同样配置
[iyunv@node01 ~]# systemctl restart pcsd
#设置节点认证
#只在node01操作,所有操作会自动同步到node02
[iyunv@node01 ~]# pcs cluster auth node01 node02
Username: hacluster   
Password:
node02: Authorized
node01: Authorized
#创建一个名为mycluster的集群,并将node01和node02加入到集群节点上
#只在node01操作,所有操作会自动同步到node02
[iyunv@node01 ~]# pcs cluster setup --force --name mycluster node01 node02
Destroying cluster on nodes: node01, node02...
node01: Stopping Cluster (pacemaker)...
node02: Stopping Cluster (pacemaker)...
node01: Successfully destroyed cluster
node02: Successfully destroyed cluster

Sending cluster config files to the nodes...
node01: Succeeded
node02: Succeeded

Synchronizing pcsd certificates on nodes node01, node02...
node02: Success
node01: Success

Restarting pcsd on the nodes in order to reload the certificates...
node02: Success
node01: Success

[iyunv@node01 ~]# pcs cluster start --all
node01: Starting Cluster...
node02: Starting Cluster...
#查看集群状态
[iyunv@node01 ~]# pcs status
Cluster name: mycluster
WARNING: no stonith devices and stonith-enabled is not false
Stack: corosync
Current DC: node02 (version 1.1.15-11.el7_3.5-e174ec8) - partition with quorum
Last updated: Mon Sep 11 22:54:14 2017        Last change: Mon Sep 11 22:53:39 2017 by hacluster via crmd on node02

2 nodes and 0 resources configured

Online: [ node01 node02 ]

No resources


Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/disabled

#查看corosync的状态

[iyunv@node01 ~]# pcs status corosync

Membership information
----------------------
    Nodeid      Votes Name
         1          1 node01 (local)
         2          1 node02

#查看状态是否正常
[iyunv@node01 ~]#  crm_verify -L -V
   error: unpack_resources:    Resource start-up disabled since no STONITH resources have been defined
   error: unpack_resources:    Either configure some or disable STONITH with the stonith-enabled option
   error: unpack_resources:    NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid
**发现报错了

#关闭报错信息
[iyunv@node01 ~]#  pcs property set stonith-enabled=false


#设置VIP
#只在node01操作,所有操作会自动同步到node02
[iyunv@node01 ~]# pcs  resource create ClusterIP ocf:heartbeat:IPaddr2 nic=ens34 ip=10.10.10.8 cidr_netmask=32  op monitor interval=30s


#安装http服务
#node02需要同样配置
[iyunv@node01 ~]#  yum  -y   install  httpd

#编辑apache首页
#node02需要同样配置(node2上把node01改为node02)

[iyunv@node01 ~]# vi /var/www/html/index.html
<html>
<body>welcome to  node 1 </body>
</html>

#配置apache的URL;
#为了监视您的Apache实例的健康和恢复它如果失败,起搏器假设所使用的资源代理服务器状态的URL。

#node02需要同样配置

[iyunv@node01 ~]# vi /etc/httpd/conf/httpd.conf
<Location /server-status>
   SetHandler server-status
   Order deny,allow
   Deny from all
   Allow from 127.0.0.1
</Location>

#将apache加入集群
#只在node01操作,所有操作会自动同步到node02
[iyunv@node01 ~]# pcs resource create Web ocf:heartbeat:apache  configfile=/etc/httpd/conf/httpd.conf       statusurl="http://localhost/server-status" op monitor interval=1min


#设置apache的超时时间
##只在node01操作,所有操作会自动同步到node02
[iyunv@node01 ~]#  pcs resource op defaults timeout=240s


#将VIP和apache捆绑在一起
##只在node01操作,所有操作会自动同步到node02
[iyunv@node01 ~]# pcs constraint colocation add Web ClusterIP INFINITY

#设置启动顺序
##只在node01操作,所有操作会自动同步到node02
[iyunv@node01 ~]#  pcs constraint order ClusterIP then Web
Adding ClusterIP Web (kind: Mandatory) (Options: first-action=start then-action=start)


#查看集群状态

[iyunv@node01 ~]# pcs status
Cluster name: mycluster
Stack: corosync
Current DC: node01 (version 1.1.15-11.el7_3.5-e174ec8) - partition with quorum
Last updated: Tue Sep 12 16:06:59 2017        Last change: Tue Sep 12 16:06:49 2017 by root via cibadmin on node01

2 nodes and 2 resources configured

Online: [ node01 node02 ]

Full list of resources:

ClusterIP    (ocf::heartbeat:IPaddr2):    Started node01
Web    (ocf::heartbeat:apache):    Started node01

Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/disabled
#此时集群都在node01上。

#我们宕掉node01,在node02上查看集群状态
[iyunv@node02 ~]# pcs status
Cluster name: mycluster
Stack: corosync
Current DC: node02 (version 1.1.15-11.el7_3.5-e174ec8) - partition with quorum
Last updated: Tue Sep 12 17:02:24 2017        Last change: Tue Sep 12 17:01:57 2017 by root via cibadmin on node01

2 nodes and 2 resources configured

Online: [ node02 ]
OFFLINE: [ node01 ]

Full list of resources:

ClusterIP    (ocf::heartbeat:IPaddr2):    Started node02
Web    (ocf::heartbeat:apache):    Started node02

Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/disabled

运维网声明 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-404483-1-1.html 上篇帖子: innodb_data_file_path设置 下篇帖子: Linux的企业-高可用性High Availability
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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