1. 程式人生 > >pacemaker+corosync+haporxy高可用集群部署

pacemaker+corosync+haporxy高可用集群部署

-- mode balance del ystemd ipa hacluster pac 選擇

# 安裝 Corosync以及pacemaker 部署 yum install -y pacemaker pcs psmisc policycoreutils-python corosync fence-agents-all systemctl start pcsd.service systemctl enable pcsd.service # 修改密碼(全執行) echo ‘HAcluster123‘ | passwd --stdin hacluster # 驗證集群 pcs cluster auth node71.ityunv.com node72.ityunv.com node73.ityunv.com -u hacluster -p HAcluster123 --force # 創建集群 pcs cluster setup --name k8s_cluster01 node71.ityunv.com node72.ityunv.com node73.ityunv.com # 啟動集群 pcs cluster start --all # 檢查配置是否正確 crm_verify -L -V #一般情況會跳出個錯誤; pcs property set stonith-enabled=false #禁用stonith; pcs property set no-quorum-policy=ignore #無法仲裁時,選擇忽略; # 相關常用參數總結 pcs cluster enable --all #設置集群開機自動; corosync-cfgtool -s #檢查各節點通信狀態(顯示為no faults即為OK); pcs status corosync #查看coyosync狀態; pcs status crm: 是suse封裝和開發維護的一個命令工具,功能強大並強烈推薦使用,但是紅帽以及centos安裝pacemaker以及corosync是不提供的,所以需要手動安裝; cd /etc/yum.repos.d/ wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/clustering.repo yum makecache && yum -y install crmsh #二、配置haproxy實現與corosync和pacemaker結合 # 2.1 安裝並配置haproxy yum install -y haproxy mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak01 echo -e "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf sysctl -p # 2.2 修改配置文件,如下: cat > /etc/haproxy/haproxy.cfg << EOF global log 127.0.0.1 local0 log 127.0.0.1 local1 notice maxconn 4096 chroot /usr/share/haproxy user haproxy group haproxy daemon defaults log global mode tcp timeout connect 5000ms timeout client 50000ms timeout server 50000ms frontend stats-front bind *:8088 mode http default_backend stats-back backend stats-back mode http balance source stats uri /stats stats auth admin:king111 listen Kubernetes-Cluster bind 192.168.61.100:6443 balance leastconn mode tcp server k8s_71 192.168.61.71:6443 check inter 2000 fall 3 server k8s_72 192.168.61.72:6443 check inter 2000 fall 3 server k8s_73 192.168.61.73:6443 check inter 2000 fall 3 EOF # 啟動服務 systemctl restart haproxy systemctl status haproxy # 2.3 配置VIP 並 將Haproxy加入到PCS集群 # 需要Haproxy節點把開機啟動項關閉, crm 進入 PCS 命令行模式: systemctl disable haproxy #第一種方式通過CRM進行配置: crm config primitive crm-vip ocf:heartbeat:IPaddr2 params ip=192.168.61.100 cidr_netmask=24 nic=eno16777984 op start interval=0s timeout=20s op stop interval=0s timeout=20s op monitor interval=20s timeout=30s meta priority=100 primitive haproxy systemd:haproxy op start interval=0s timeout=20s op stop interval=0s timeout=20s op monitor interval=20s timeout=30s meta priority=100 target-role=Started colocation haproxy-with-vip inf: crm-vip:Started haproxy:Started verify commit exit # 查看狀態: crm status # 第二種方式通過pcs進行配置: pcs resource create pcs-vip ocf:heartbeat:IPaddr2 ip=192.168.61.100 cidr_netmask=24 nic=eno16777984 op monitor interval=15s pcs resource create haproxy systemd:haproxy op monitor interval="5s" pcs constraint colocation add pcs-vip haproxy INFINITY pcs constraint order pcs-vip then haproxy # 查看狀態: pcs status # 刪除資源 pcs resource delete haproxy pcs resource delete pcs-vip pcs resource delete crm-vip #2.4 驗證集群高可用 #可以自行試驗,重啟任意主機,看是否VIP切換到其他節點: ip a

pacemaker+corosync+haporxy高可用集群部署