Centos7.7下建立无共享存储的WEB集群(pcs+pacemaker+corosync)

规划设计
操作系统安装
群集组件安装
群集节点准备
2创建VIP资源
3创建Web/Apache资源
4配置约束
5群集测试

1.准备工作(重要)

群集组件和节点的准备我在另一张博客中已经介绍,可以参考
https://blog.csdn.net/qq_45714272/article/details/106017375

[root@rs1 corosync]# crm_verify -L -V                    ## 检查配置有无错误
禁用stonish
[root@rs1 corosync]# pcs property set stonith-enabled=false

2.创建vip资源

[root@rs1 corosync]# pcs resource create VirtualIP
ocfIPaddr2 ip=192.168.43.100 cidr_netmask=24 op monitor
interval=30s
创建VIP资源如果不生效,只要禁用掉stonish设备即可
pcs property set stonith-enabled=false

[root@rs1 ~]# pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.43.100 cidr_netmask=24 op monitor interval=30s[root@rs1 ~]# pcs status
[root@rs1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:46:eb:23 brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.10/24 brd 192.168.43.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::a0b8:9a41:6d1b:7285/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
可以看出,添加的虚拟IP没有在rs1身上,我们禁用stonish设备
[root@rs1 ~]# pcs property set stonith-enabled=false
[root@rs1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:46:eb:23 brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.10/24 brd 192.168.43.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet 192.168.43.100/24 brd 192.168.43.255 scope global secondary ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::a0b8:9a41:6d1b:7285/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
成功啦!

详细介绍可以看我另一篇博客
https://blog.csdn.net/qq_45714272/article/details/106007691

开始用pcs创建资源:

创建Web/Apache资源(节点都要做)
开两台虚拟机,安装以下服务,并配置。如下:
firewall-cmd --permanent --add-service=http && firewall-cmd --reload
yum install -y httpd
echo "$(hostname)" >> /var/www/html/index.html
systemctl restart httpd
systemctl enable httpd

创建Apache状态URL(节点都要做)
vim /etc/httpd/conf.d/status.conf
<location  /server-status>
        setHandler server-status
        Order deny,allow
        deny from all
        Allow from 127.0.0.1
</location>

创建Apache资源

pcs resource create Website ocfapache
configfile=/etc/httpd/conf/httpd.conf
statusurl=“http://localhost/server-status” \ op monitor interval=1min

删除Apache资源

pcs resource delete Website

查看状态

[root@rs1 ~]# pcs status
Cluster name: cluster1
Stack: corosync
Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum
Last updated: Fri May  8 10:27:09 2020
Last change: Fri May  8 10:26:53 2020 by root via cibadmin on rs1

2 nodes configured
2 resources configured

Online: [ rs1 rs2 ]

Full list of resources:

 VIP	(ocf::heartbeat:IPaddr2):	Started rs2
 Website	(ocf::heartbeat:apache):	Starting rs1

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

无共享存储的web群集就搭建好了,我们可以通过VIP来访问web群集,一台服务器宕机,我们可以利用pcs工具对VIP进行迁移,访问另一台服务器,实现了HA

对集群进行约束

确保资源在同一节点
1.添加约束确保资源在同一节点

[root@rs1 ~]# pcs constraint
Location Constraints:
Ordering Constraints:
Colocation Constraints:
Ticket Constraints:

[root@rs1 ~]# pcs constraint colocation add Website with VirtualIP INFINITY
[root@rs1 ~]# pcs status
Cluster name: cluster1
Stack: corosync
Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum
Last updated: Fri May  8 10:51:57 2020
Last change: Fri May  8 10:51:52 2020 by root via cibadmin on rs1

2 nodes configured
2 resources configured

Online: [ rs1 rs2 ]

Full list of resources:

 VirtualIP	(ocf::heartbeat:IPaddr2):	Started rs1
 Website	(ocf::heartbeat:apache):	Starting rs1


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

2.IP飘逸

[root@rs1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:46:eb:23 brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.10/24 brd 192.168.43.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::a0b8:9a41:6d1b:7285/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
       
[root@rs1 conf.d]# pcs cluster standby rs1

[root@rs2 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:01:55:ac brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.20/24 brd 192.168.43.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet 192.168.43.100/24 brd 192.168.43.255 scope global secondary ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::a0b8:9a41:6d1b:7285/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::1777:3e7e:f136:6cf/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

[root@rs1 ~]# pcs status
Cluster name: cluster1
Stack: corosync
Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum
Last updated: Sat May  9 02:08:53 2020
Last change: Sat May  9 02:08:47 2020 by root via cibadmin on rs1

2 nodes configured
1 resource configured

Node rs1: standby
Online: [ rs2 ]

Full list of resources:

 VirtualIP	(ocf::heartbeat:IPaddr2):	Started rs2

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

恢复:

[root@rs1 ~]#  pcs cluster  unstandby rs1
[root@rs1 ~]# pcs status
Cluster name: cluster1
Stack: corosync
Current DC: rs1 (version 1.1.20-5.el7-3c4c782f70) - partition with quorum
Last updated: Sat May  9 02:11:31 2020
Last change: Sat May  9 02:11:23 2020 by root via cibadmin on rs1

2 nodes configured
1 resource configured

Online: [ rs1 rs2 ]

Full list of resources:

 VirtualIP	(ocf::heartbeat:IPaddr2):	Started rs2

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

3.先后顺序

[root@rs1 conf.d]# pcs constraint order VirtualIP then Website
Adding VirtualIP Website (kind: Mandatory) (Options: first-action=start then-action=start)
[root@rs1 conf.d]# pcs constraint
Location Constraints:
Ordering Constraints:
  start VirtualIP then start Website (kind:Mandatory)
Colocation Constraints:
Ticket Constraints:

4.优先级

[root@rs1 conf.d]# pcs constraint location Website prefers rs1=50
[root@rs1 conf.d]# pcs constraint location Website prefers rs2=100

5.指定

配置排列约束,让vip与web 资源运行在一起,分数为100
[root@node1 ~]# pcs constraint colocation add vip with web 150
[root@rs1 conf.d]# pcs constraint colocation add VirtualIP with Website 100

你可能感兴趣的:(集群)