pacemaker

pacemaker
pacemaker 实验apache高可用
参考文档:笔记目录/arch/
Red_Hat_Enterprise_Linux-7-High_Availability_Add-On_Administration-en-US.pdf
Red_Hat_Enterprise_Linux-7-High_Availability_Add-On_Overview-en-US.pdf
Red_Hat_Enterprise_Linux-7-High_Availability_Add-On_Reference-zh-CN.pdf
vip:192.168.122.100
主    主
kvm虚拟机1 kvm虚拟机2
192.168.122.10 192.168.122.11
实验准备:(centos7.3平台)
1,静态ip(一定要静态ip,不要使用dhcp)
2,主机名配置和绑定
# hostnamectl set-hostname --static node1.cluster.com
# vim /etc/hosts
192.168.122.10 vm1.cluster.com node1
192.168.122.11 vm2.cluster.com node2
3,时间同步
4,关闭firewalld,selinux(开机自动不启动)
5,配置yum (本地iso镜像yum源)
6,宿主机(192.168.122.1)模拟客户端,有firefox和elinks就行
第一步:
在所有节点(node1和node2)都安装集群相关软件包
# yum install pcs pacemaker fence-agents-all
第二步:
在所有节点(node1和node2)配置hacluster用户的密码(密码一致),用于pcs管理验证,
# passwd hacluster
第三步:
在所有节点(node1和node2)启动pcsd服务
# systemctl start pcsd
# systemctl status pcsd
# systemctl enable pcsd
第四步:
验证所有节点hacluster用户的通迅
下面操作只需要在任一集群节点上做就可以(node1或node2)
# pcs cluster auth node1 node2 --这里我使用的是别名(ip,主机名都可以)
Username: hacluster --hacluster用户
Password: --密码为第二步设置的密码
node1: Authorized
node2: Authorized
# pcs cluster auth node1 node2 --在另一个节点上也操作的话,会报已经验证的信息
node1: Already authorized
node2: Already authorized
验证成功后,可以使用一个web图形界面来登录(必须要在任一节点之一上用firefox访问)
访问地址:
使用hacluster用户及其密码登录
--见图hacluster01.png (在笔记目录/arch/png/下)
第五步:
创建集群
下面操作只需要在任一集群节点上做就可以(node1或node2)
# pcs cluster setup --start --name web_ha node1 node2   
--web_ha是自定义的集群名称;node1,node2是加入集群的节点ip或主机名或别名.如果有多个节点,则后面继续加node3,node4等)
......
node1: Success
node2: Success
第六步:
设置集群开机自动启动
在所有节点(node1和node2)执行下面操作
# pcs cluster enable --all
node1: Cluster Enabled
node2: Cluster Enabled
# pcs cluster status --查看状态,所有节点上都可以操作查看
Cluster Status:
Stack: corosync
Current DC: node1 (version 1.1.15-11.el7-e174ec8) - partition with quorum
Last updated: Thu Jun 29 10:25:21 2017 Last change: Thu Jun 29 10:21:40 2017 by hacluster via crmd on node1
2 nodes and 0 resources configured
PCSD Status:
node2: Online
node1: Online
第七步:
集群创建成功后,我们需要加上高可用切换resource,查看支持的资源
# pcs resource list |wc -l --查看支持的资源
347
# pcs resource list |grep apache --apache服务是支持的
ocf:heartbeat:apache - Manages an Apache Web server instance
第八步:
在node1上操作
# yum install httpd httpd-devel wget
# echo web1 > /var/www/html/index.html
# vim /etc/httpd/conf/httpd.conf  --配置文件里最后加上下面一段,这是一段状态页面的监控
<Location /server-status>
SetHandler server-status
Require local
</Location>
在node2上操作
# yum install httpd httpd-devel wget
# echo web2 > /var/www/html/index.html
<Location /server-status>
SetHandler server-status
Require local
</Location>
第九步:
下面操作只需要在任一集群节点上做就可以(node1或node2)
# pcs resource create vip ipaddr ip=192.168.122.100 cidr_netmask=24 --group apachegroup
# pcs resource create website apache configfile="/etc/httpd/conf/httpd.conf" statusurl="http://127.0.0.1/server-status" --group apachegroup
-----------------------------------------
扩展几个小操作:
pcs resource enable 资源名 --手动启动一个资源
pcs resource disable 资源名 --手动停止一个资源
pcs resource delete 资源名 --手动删除一个资源
------------------------------------------
# pcs resource show --查看资源,都是stopped状态,手动启动也不行
Resource Group: apachegroup
website (ocf::heartbeat:apache): Stopped
vip (ocf::heartbeat:IPaddr): Stopped
原因:因为我们没有配置fence(stonish),这里可以把它相关的属性关闭先
# pcs property set stonith-enabled=false
# pcs property list --all |grep stonith-enabled
stonith-enabled: false
# pcs resource show --再次show就ok了
Resource Group: apachegroup
website (ocf::heartbeat:apache): Started node1
vip (ocf::heartbeat:IPaddr): Started node1
第十步:测试
1,把主节点模拟错误
reboot
ifconfig eth0 down
上面两个错误,都会切换到备节点
pkill httpd
ip address del 192.168.122.100/24 dev eth0
上面两个错误,不切换,但会自动再产生
---------------------------------------------------------------
其它概念
1,共享存储
2,fence stonish
3,quorum 仲裁
(参考rhel6.5的rhcs的配置文档)
posted @ 2018-06-19 22:22  Sky-wings  阅读(1131)  评论(0编辑  收藏  举报