天天看點

負載均衡的高可用叢集(9)-haproxy負載均衡+pacemaker高可用

haproxy負載均衡+pacemaker高可用

實驗環境

server1(172.25.254.1)(hapoxy+pacemaker) 安裝hapoxy+pacemaker
server2(172.25.254.2)(hapoxy+pacemaker) 安裝hapoxy+pacemaker
server4(172.25.254.4)apache 後端伺服器
server5(172.25.254.5)apache 後端伺服器

pacemaker

server1 和server2的haproxy配置一樣,能實作負載均衡

[[email protected] ~]# vim /etc/haproxy/haproxy.cfg
           
負載均衡的高可用叢集(9)-haproxy負載均衡+pacemaker高可用

負載均衡測試:

負載均衡的高可用叢集(9)-haproxy負載均衡+pacemaker高可用

server1 和server2的 pacemaker配置

systemctl  start pcsd     開啟pcsd服務
  pcs cluster start --all   激活叢集 
  pcs status         檢視叢集狀态      
  pcs  resource create vip ocf:heartbeat:IPaddr2 ip=172.25.0.100 op monitor  interval=30s  給叢集添加虛拟的VIP資源
 pcs resource create haproxy systemd:haproxy op monitor  interval=60s給叢集添加haproxy負載均衡服務資源
 pcs resource group add hagroup vip haproxy  添加資源組
           

測試  

關掉sever1  的叢集 server2自動開始接管 實作了高可用

[[email protected] ~]# pcs cluster stop  server1
server1: Stopping Cluster (pacemaker)...
server1: Stopping Cluster (corosync)...
           
[[email protected] ~]# pcs status
Cluster name: mycluster
Stack: corosync
Current DC: server2 (version 1.1.19-8.el7-c3c624ea3d) - partition with quorum
Last updated: Mon Aug 10 17:43:04 2020
Last change: Mon Aug 10 17:18:57 2020 by root via cibadmin on server1

2 nodes configured
2 resources configured

Online: [ server2 ]
OFFLINE: [ server1 ]

Full list of resources:

 Resource Group: hagroup
     vip	(ocf::heartbeat:IPaddr2):	Started server2
     haproxy	(systemd:haproxy):	Started server2

Failed Actions:
* haproxy_monitor_60000 on server2 'not running' (7): call=42, status=complete, exitreason='',
    last-rc-change='Mon Aug 10 17:38:34 2020', queued=0ms, exec=0ms


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