🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# LVS+keepalived部署实践 [TOC] ## 一、部署keepalived keealived并不通过ipvsadm来管理lvs,而是自身通过配置文件直接管理lvs; keepalived三个功能:管理lvs、高可用、节点健康检查 1. 安装keepalived[lb03,lb04] ```sh yum -y install keepalived ``` 2. 全局配置 ![mark](http://noah-pic.oss-cn-chengdu.aliyuncs.com/pic/20200307/112033322.png) 3. VIP配置 ![mark](http://noah-pic.oss-cn-chengdu.aliyuncs.com/pic/20200307/112058382.png) 4. lvs的配置[两台一样] ![mark](http://noah-pic.oss-cn-chengdu.aliyuncs.com/pic/20200307/112112973.png) 5. 启动keepalived并检查 ```sh systemctl start keepalived.service systemctl status keepalived.service ``` ## 二、web服务器操作和检查 lo绑定vip ```sh ip addr add 10.0.0.13/32 dev lo ``` 修改内核参数 ```sh cat >>/etc/sysctl.conf<<EOF net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.lo.arp_announce = 2 EOF sysctl -p ``` 以上完成即可开始测试并验证了 ## 三、keepalived详细配置 ```sh [root@xxx ~]# cat /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id LVS_DEVEL-1 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.0.0.3/24 dev eth0 label eth0:1 } } #ipvsadm -A -t 10.0.0.3:80 -s wrr virtual_server 10.0.0.3 80 { delay_loop 6 lb_algo rr lb_kind DR nat_mask 255.255.255.0 persistence_timeout 50 protocol TCP #ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.7:80 -g -w 1 real_server 10.0.0.7 80 { weight 1 TCP_CHECK { connect_timeout 5 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } #ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.8:80 -g -w 1 real_server 10.0.0.8 80 { weight 1 TCP_CHECK { connect_timeout 5 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } } ``` 从注释掉的`ipvsadm ...`开始为在原配置上增加的内容 两个LB服务器,要注意修改`router_id`,`state`(主备)和`priority`(优先级) > 可以一次性配置多个VIP,virtual_server,然后再给每个virtual_server指定多个real_server