Linux下搭建Haproxy+Pacemaker+Corosync集群

文章目录

[隐藏]

  • 关键应用介绍
  • 系统环境
  • 安装并配置haproxy
  • 安装集群(所有节点)
  • 配置集群(任意节点)
  • 配置资源(任意节点)

我们常常用Haproxy实现应用的高可用和负载均衡,但是也不能忽视它本身也需要高可用,于是通过Pacemeker+Corosync来实现Haproxy本身的高可用,便是一个不错的解决方案。

关键应用介绍

系统环境

主机配置

系统配置(所有主机)

systemctl disable firewalld && systemctl stop firewalld  #iptables –F  sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config  setenforce 0  echo -e "10.10.100.101 hacluster1n10.10.100.102 hacluster2n10.10.100.103 hacluster3" >> /etc/hosts  

网络配置(所有主机)

echo -e "net.ipv4.ip_nonlocal_bind = 1nnet.ipv4.ip_forward = 1" >> /etc/sysctl.conf  sysctl -p  

时钟配置(所有主机)

vi /etc/chrony.conf  
server ntp1.aliyun.com iburst  server ntp2.aliyun.com iburst  server ntp3.aliyun.com iburst  

配置免密登录(非必要)

ssh-keygen -t rsa  cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys  chmod 600 ~/.ssh/authorized_keys  for n in 2 3; do ssh-copy-id -i ~/.ssh/id_rsa.pub root@hacluster$n; done  
安装并配置haproxy

安装haproxy

yum -y install haproxy  systemctl enable haproxy  

配置haproxy

配置haproxy可参照本文另一篇文章 CentOS下通过Galera+Haproxy+Keepalived搭建MariaDB高可用集群 的haproxy部分。

以下是配置案例:

listen httpd      bind 10.10.100.100:80      balance source      option tcpka      option httpchk      option tcplog      server controller01 10.10.100.101:5000 check inter 2000 rise 2 fall 5      server controller02 10.10.100.102:5000 check inter 2000 rise 2 fall 5      server controller03 10.10.100.103:5000 check inter 2000 rise 2 fall 5  

注意:其中bind绑定的是后面将配置的集群资源的VIP。

另外:在本文中没有搭建haproxy的后端业务,各位可以自行搭建两台httpd应用服务器进行测试。

安装集群(所有节点)

安装 pcs+pacemaker+corosync

yum -y install pcs pacemaker corosync fence-agents resource-agents  

配置corosync

该配置文件会在创建集群的时候自动创建,不同集群的配置文件因此而不同。

cat /etc/corosync/corosync.conf  
totem {      version: 2      cluster_name: ha_cluster      secauth: off      transport: udpu  }    nodelist {      node {          ring0_addr: hacluster1          nodeid: 1      }        node {          ring0_addr: hacluster2          nodeid: 2      }        node {          ring0_addr: hacluster3          nodeid: 3      }  }    quorum {      provider: corosync_votequorum  }    logging {      to_logfile: yes      logfile: /var/log/cluster/corosync.log      to_syslog: yes  }  

启动 pcsd

systemctl start pcsd  systemctl enable pcsd  

配置用户

安装pcs时会自动创建hacluster用户,此时只需修改密码 (Hacluster@123):

passwd hacluster  
配置集群(任意节点)

配置节点认证

pcs cluster auth -u hacluster -p Hacluster@123 hacluster1 hacluster2 hacluster3  

创建集群

pcs cluster setup --force [ --start ] --name ha_cluster hacluster1 hacluster2 hacluster3  

启动集群

pcs cluster start --all  pcs cluster enable --all  

查看集群状态

pcs [ cluster ] status  ps aux | grep pacemaker  

检验corosync状态

corosync-cfgtool -s  corosync-cmapctl | grep members  pcs status corosync  

检查配置

crm_verify -L -V  

根据检查结果,禁用STONITH

pcs property set stonith-enabled=false  

检查无法仲裁时,设置忽略

pcs property set no-quorum-policy=ignore  

设置合适的输入处理历史记录及策略引擎生成的错误与警告

pcs property set pe-warn-series-max=1000 pe-input-series-max=1000 pe-error-series-max=1000  

基于时间驱动的方式进行状态处理

pcs property set cluster-recheck-interval=5  
配置资源(任意节点)

配置 VIP

pcs resource create vip ocf:heartbeat:IPaddr2 ip=10.10.100.100 cidr_netmask=24 nic=ens33 op monitor interval=3s  

查看集群资源

pcs resource  ip a show ens33  

添加Haproxy

pcs resource create lb-haproxy systemd:haproxy --clone  pcs resource  

绑定HAProxy和VIP必须在同一节点(建议)

pcs constraint colocation add lb-haproxy-clone with vip  

配置必须先启动VIP后再启动haproxy(建议)

pcs constraint order start vip then lb-haproxy-clone kind=Optional  

原文出处:andylouse -> https://www.andylouse.net/linux-haproxy-pacemaker-corosync-cluster

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。
超哥软件库 » Linux下搭建Haproxy+Pacemaker+Corosync集群