当前位置: 代码迷 >> 综合 >> linux中用pacemaker + haproxy 实现负载均衡和高可用
  详细解决方案

linux中用pacemaker + haproxy 实现负载均衡和高可用

热度:3   发布时间:2023-12-15 06:08:53.0

环境配置:
server1 server3 作为haproxy 服务器,用pacemaker实现负载均衡服务器高可用
server2 server4 作为httpd 服务器
1.server1环境配置
(1)配置yum源,

vim /etc/yum.repos.d/rhel-source.repo [rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.26.250/iso/
enabled=1
gpgcheck=0[HighAvailability]
name=HighAvailability
baseurl=http://172.25.26.250/iso/HighAvailability
gpgcheck=0[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.26.250/iso/LoadBalancer
gpgcheck=0[ResilientStorage]
name=ResilientStorage
baseurl=http://172.25.26.250/iso/ResilientStorage
gpgcheck=0[ScalableFileSystem]
name=ScalableFileSystem
baseurl=http://172.25.26.250/iso/ScalableFileSystem
gpgcheck=0

(2)服务安装与配置

yum install -y pacemaker corosync
yum install crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-5.el6.noarch.rpm
cd /etc/corosync/
ls
cp corosync.conf.example corosync.conf
vim corosync.conf# Please read the corosync.conf.5 manual page
compatibility: whitetanktotem {version: 2secauth: offthreads: 0interface {ringnumber: 0bindnetaddr: 172.25.26.0 #更改广播域mcastaddr: 226.94.1.1mcastport: 5405ttl: 1}
}logging {fileline: offto_stderr: noto_logfile: yesto_syslog: yeslogfile: /var/log/cluster/corosync.logdebug: offtimestamp: onlogger_subsys {subsys: AMFdebug: off}
}amf {mode: disabled
}
service {ver: 0name:pacemaker
}
/etc/init.d/corosync start		##开启服务

在这里插入图片描述
在这里插入图片描述
2.server3环境配置

yum install -y pacemaker corosync
rpm -ivh crmsh-1.2.6-0.rc2.2.1.x86_64.rpm --nodeps --forcecd /etc/corosync/lscp corosync.conf.example corosync.confvim corosync.conf# Please read the corosync.conf.5 manual page
compatibility: whitetanktotem {version: 2secauth: offthreads: 0interface {ringnumber: 0bindnetaddr: 172.25.26.0 #更改广播域mcastaddr: 226.94.1.1mcastport: 5405ttl: 1}
}logging {fileline: offto_stderr: noto_logfile: yesto_syslog: yeslogfile: /var/log/cluster/corosync.logdebug: offtimestamp: onlogger_subsys {subsys: AMFdebug: off}
}amf {mode: disabled
}
service {ver: 0name:pacemaker
}
/etc/init.d/corosync start##开启服务

在这里插入图片描述
在这里插入图片描述
3.在server1上(server3开启服务后)

 查看节点状态:crm status检测文件:crm_verify -VL检测如果出错:crm configure property no-quorum-policy="ignore"crm configure property stonith-enabled=false

在这里插入图片描述
添加虚拟ip:

[root@server1 corosync]# crm
crm(live)# configure
crm(live)configure# show
node server1
node server2
property $id="cib-bootstrap-options" \dc-version="1.1.10-14.el6-368c726" \cluster-infrastructure="classic openais (with plugin)" \expected-quorum-votes="2" \no-quorum-policy="ignore" \stonith-enabled="false"
crm(live)configure# primitive vip ocf:heartbeat:IPaddr2 params ip=172.25.26.100 cidr_netmask=24 op monitor interval=1min
crm(live)configure# commit
crm(live)configure# exit
bye

在这里插入图片描述
4.server3监控

crm_mon

在这里插入图片描述
关闭server1的corosync后,在server3查看,服务会自动跳到server3上
在这里插入图片描述