server1 和 server2 是调度器,server3 和 server4 是服务器 【1】调度器server1 server2 关闭 keepalived 和 httpd,并打开pcsd
[root@server1 ~]# systemctl stop keepalived [root@server1 ~]# systemctl start pcsd #打开pcsd服务 [root@server1 ~]# pcs cluster start --all #激活集群【2】服务器server3 server4 打开apache
【1】实现负载均衡
server1: [root@server1 haproxy]# vim /etc/haproxy/haproxy.cfg backend app balance roundrobin #balance source server app1 172.25.15.3:80 check server app2 172.25.15.4:80 check [root@server1 haproxy]# systemctl restart haproxy server2: [root@server2 haproxy]# vim /etc/haproxy/haproxy.cfg backend app balance roundrobin #balance source server app1 172.25.15.3:80 check server app2 172.25.15.4:80 check [root@server2 haproxy]# systemctl restart haproxy实现了负载均衡
【2】实现高可用
[root@server1 ~]# pcs resource create vip ocf:heartbeat:IPaddr2 ip=172.25.0.100 op monitor interval=30s #给集群添加虚拟的VIP资源 [root@server1 ~]# pcs resource create vip ocf:heartbeat:IPaddr2 ip=172.25.15.100 op monitor interval=30s #给集群添加haproxy负载均衡服务资源 [root@server1 ~]# pcs resource create haproxy systemd:haproxy op monitor interval=60s [root@server1 ~]# pcs resource group add hagroup vip haproxy [root@server1 ~]# pcs status # 查看集群状态 此时资源都在server1中 关闭sever1的集群 server2自动开始接管,实现了高可用