首页 > 其他分享 >部署haproxy+keepalived高可用负载均衡器

部署haproxy+keepalived高可用负载均衡器

时间:2022-10-25 18:31:51浏览次数:43  
标签:haproxy stats keepalived 192.168 etc systemctl 均衡器

尽管HAProxy非常稳定,但仍然无法规避操作系统故障、主机硬件故障、网络故障甚至断电带来的风险。所以必须对HAProxy实施高可用方案。

下面将介绍利用Keepalived实现的HAProxy热备方案。即两台主机上的两个HAProxy实例同时在线,其中权重较高的实例为MASTER,MASTER出现问题时,另一台实例自动接管所有流量。

1、地址规划

部署haproxy+keepalived高可用负载均衡器_ipad

haproxy+keepalive1
192.168.28.101
haproxy+keepalive2
192.168.28.102
VIP
192.168.28.110
harbor
192.168.28.202

1、使用yum安装软件(如果服务器不能联网,可以选择源码安装,这里为了简单,直接使用yum)

# yum install keepalived haproxy -y

部署haproxy+keepalived高可用负载均衡器_linux_02

2、关闭防火墙和selinux


关闭防火墙
iptables -F && iptables -X && iptables -Z
systemctl stop firewalld.service && systemctl disable firewalld.service

关闭Selinux
setenforce 0
echo 'sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config'| sh

3、配置时间同步

yum install chronyd -y

cat > /etc/chrony.conf <<EOF
server ntp.aliyun.com iburst
stratumweight 0
driftfile /var/lib/chrony/drift
rtcsync
makestep 10 3
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
commandkey 1
generatecommandkey
logchange 0.5
logdir /var/log/chrony
EOF

systemctl enable chronyd && systemctl start chronyd


3、配置kepalived

复制VRRP模板

cp /usr/share/doc/keepalived-1.3.5/samples/keepalived.conf.vrrp /etc/keepalived/keepalived.conf

master节点配置

修改配置如下

部署haproxy+keepalived高可用负载均衡器_linux_03

! Configuration File for keepalived

global_defs {
notification_email {
acassen
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL1
}


vrrp_instance VI_1 {
state MASTER
interface ens33
garp_master_delay 10
smtp_alert
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.28.110
}
}

backup节点配置

部署haproxy+keepalived高可用负载均衡器_linux_04


! Configuration File for keepalived

global_defs {
notification_email {
acassen
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL2
}


vrrp_instance VI_1 {
state BACKUP
interface ens33
garp_master_delay 10
smtp_alert
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.28.110
}
}

启动服务

systemctl enable keepalived  && systemctl start keepalived && systemctl status keepalived

主机:

部署haproxy+keepalived高可用负载均衡器_ipad_05

备机:

部署haproxy+keepalived高可用负载均衡器_sed_06

4、配置haproxy


hapeoxy配置如下:

主备机配置一样

scp /etc/haproxy/haproxy.cfg 192.168.28.101:/etc/haproxy/haproxy.cfg

#--------------全局配置----------------
global
log 127.0.0.1 local0 info
#log loghost local0 info
maxconn 20480
#chroot /usr/local/haproxy
pidfile /var/run/haproxy.pid
#maxconn 4000
user haproxy
group haproxy
daemon
#---------------------------------------------------------------------
#common defaults that all the 'listen' and 'backend' sections will
#use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option dontlognull
option httpclose
option httplog
#option forwardfor
option redispatch
balance roundrobin
timeout connect 10s
timeout client 10s
timeout server 10s
timeout check 10s
maxconn 60000
retries 3
#--------------统计页面配置------------------
listen admin_stats
bind 0.0.0.0:8189
stats enable
mode http
log global
stats uri /haproxy_stats
stats realm Haproxy\ Statistics
stats auth admin:admin
#stats hide-version
stats admin if TRUE
stats refresh 30s
#---------------web设置-----------------------
listen harbor-80
bind *:80
mode tcp
server server1 192.168.28.201:80 check inter 3s fall 3 rise 3


listen harbor-443
bind *:443
mode tcp
server server1 192.168.28.201:443 check inter 3s fall 3 rise 3

启动服务:

systemctl start  haproxy && systemctl enable  haproxy  && systemctl status haproxy

部署haproxy+keepalived高可用负载均衡器_linux_07

5、测试效果

正常效果

打开​​https://192.168.28.110/​​查看负载后的地址

部署haproxy+keepalived高可用负载均衡器_sed_08

master:

keepalived状态:

部署haproxy+keepalived高可用负载均衡器_ipad_09

backup:

keepalived状态:

部署haproxy+keepalived高可用负载均衡器_sed_10

关闭master

backup:

keepalived状态:

部署haproxy+keepalived高可用负载均衡器_linux_11

网页访问:

部署haproxy+keepalived高可用负载均衡器_linux_12

haproxy页面:

切换为backup PID

部署haproxy+keepalived高可用负载均衡器_linux_13

启动master

backup:

keepalived状态:

部署haproxy+keepalived高可用负载均衡器_ipad_14

master:

keepalived状态:

部署haproxy+keepalived高可用负载均衡器_sed_15

访问网页正常:

部署haproxy+keepalived高可用负载均衡器_linux_16

haproxy页面:

切换为master PID

部署haproxy+keepalived高可用负载均衡器_linux_17

由此可见,高可用负载均衡器正常使用。


标签:haproxy,stats,keepalived,192.168,etc,systemctl,均衡器
From: https://blog.51cto.com/lxycneo/5795054

相关文章

  • haproxy代理mysql
    背景在做mysql集群的时候需要一个负载均衡解决方案,以便流量可以按照需求传给mysql各个节点,以下主要记录haproxy的配置安装mysql(略)创建haproxy用户createuserifnot......
  • keepalived双主架构
    一环境规划节点IP功能VIPnode-01192.168.174.120keepalivedmaster/slave192.168.174.20node-02192.168.174.121keepalivedslave/master192.168.174.21二设置node-01节点......
  • keepalived主从架构
    一环境规划节点IP功能VIPnode-01192.168.174.120keepalivedmaster192.168.174.20node-02192.168.174.121keepalivedslave192.168.174.20二抢占模式抢占模式,即当高优先级......
  • ubuntu20.04部署keepalived
    一环境准备1.1设置时间同步root@node-01:~#apt-yinstallchronyroot@node-01:~#systemctlenablechrony二在线安装2.1查看keepalived软件版本root@node-01:~#apt-......
  • Nginx+Keepalived(双机热备)介绍已经搭建高可用负载均衡环境
    图文教程,Nginx+Keepalived(双机热备)介绍已经搭建高可用负载均衡环境阿飞云已于2022-03-2717:31:34修改1577收藏7分类专栏:Nginx_OpenResty文章标签:网络javali......
  • keepalived实现nginx负载均衡机高可用
    keepalived实现nginx负载均衡机高可用目录keepalived实现nginx负载均衡机高可用配置web界面配置nginx负载均衡配置keepalived高可用编写脚本配置keepalived加入监控脚本的......
  • Keepalived高可用、四层负载均衡
    目录Keepalived高可用高可用简介常用的工具问题名称解释VRRP协议部署keepalived下载安装Keepalived配置保证nginx配置一样解决keepalived的脑裂问题keepalived的非抢占式四......
  • CentOS 8.2 k8s 集群安装 Keepalived-2.2.7
    一、Keepalived集群安装地址https://www.keepalived.orgNginx和Keepalived是配套使用的,如果有其他负载均衡器就不需要再安装这两个服务。安装依赖yuminstall......
  • LVS+Keepalived+httpd安装及配置
    LVS+Keepalived+httpd安装及配置目录1环境...12安装LVS软件(分别在LVS-Master和LVS-Backup中)...11.1.查看是否有IPVS模块...11.2.安装IPVS管理工具...13安装keepal......
  • Keepalived高可用集群
    目录​​Keepalived​​​​Keepalived实现主备网站​​KeepalivedKeepalived软件起初是专为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务器节点的状态,后来又......