wyh-l6

导航

实战部署keepalive+haproxy

############################################keepalive+haproxy##########################################
# apt-get update
# apt install keepalived haproxy -y
##找一个你喜欢的keeplived模板
# find / -name "keepalived*"
# cp /usr/share/doc/keepalived/samples/keepalived.conf.vrrp /etc/keepalived/keepalived.conf
##编辑文件/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
     acassen
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    garp_master_delay 10
    smtp_alert
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.213.188 label ens33:0
        192.168.213.189 label ens33:1
        192.168.213.190 label ens33:2
        192.168.213.191 label ens33:3
    }
}
}
##编辑haproxy
# vim /etc/haproxy/haproxy.cfg
##最后加上这段
listen harbor-80
  bind 192.168.213.188:80
  mode tcp
  server server1 192.168.213.222:80 check inter 3s fall 3 rise 3
listen harbor-443
  bind 192.168.213.188:443
  mode tcp
  server server1 192.168.213.222:443 check inter 3s fall 3 rise 3
##测试访问haproxy访问harbor,访问成功后,大功告成!!!!!!!!!

##解决非主节点haproxy因绑定了不存在的虚拟ip而启动不了的问题,nonlocal_bind 默认为0,需要设置为1
#查看当前值
sysctl -a | grep nonlocal_bind

#/etc/sysctl.conf末尾追加net.ipv4.ip_nonlocal_bind = 1
cat <<EOF >> /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
EOF

#立即生效
sysctl -p

posted on 2022-07-22 09:04  IT老六  阅读(107)  评论(0编辑  收藏  举报