LVS+keepalived实现高可用负载均衡的部署

事先准备四台虚拟机,两台做keepalived,两台做lvs

在以下部署中keeaplived 的两台机器ip分别为:192.168.76.156,192.168.76.172;lvs
的两台机器ip分别为:192.168.76.173,192.168.76.174

安装过程省略

1、keeaplived

1)配置文件

主:

! Configuration File for keepalived 
global_defs {
notification_email {
      acassen@firewall.loc
      }
      notification_email_from Alexandre.Cassen@firewall.loc
      smtp_server 127.0.0.1
      smtp_connect_timeout 30
      router_id LVS_1 
} 

vrrp_instance VI_1 {
     state MASTER   
     interface ens33
     lvs_sync_daemon_interface eth0
     virtual_router_id 51
     priority 150     
     advert_int 1
     authentication {
         auth_type PASS         
         auth_pass 1111     
    }     
    virtual_ipaddress {         
         192.168.76.201
    } 
}
 
virtual_server 192.168.76.201 80 {     
    delay_loop 6     
    lb_algo wrr     
    lb_kind DR     
    nat_mask 255.255.255.255
    persistence_timeout 300    
    protocol TCP
    real_server 192.168.76.173 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 8         
            nb_get_retry 3         
            delay_before_retry 3         
            connect_port 80 
            }    
        } 

    real_server 192.168.76.174 80 {         
        weight 1         
        TCP_CHECK {         
            connect_timeout 8         
            nb_get_retry 3         
            delay_before_retry 3         
            conect_port 80         
        }     
    } 
}

备:

! Configuration File for keepalived 
global_defs {    
    notification_email {      
        acassen@firewall.loc    
    }    
    notification_email_from Alexandre.Cassen@firewall.loc    
    smtp_server 127.0.0.1    
    smtp_connect_timeout 30   
    router_id LVS_2 
    } 

vrrp_instance VI_1 {     
    state BACKUP     
    interface ens33
    lvs_sync_daemon_interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.76.201
    } 
} 

virtual_server 192.168.76.201 80 {
   delay_loop 6
   lb_algo wrr
   lb_kind DR
   nat_mask 255.255.255.255
   persistence_timeout 300
   protocol TCP
   real_server 192.168.76.173 80 {
       weight 1
       TCP_CHECK {
           connect_timeout 8
           nb_get_retry 3
           delay_before_retry 3
           connect_port 80
       }
   }

   real_server 192.168.76.174 80 {
       weight 1
       TCP_CHECK {
           connect_timeout 8
           nb_get_retry 3
           delay_before_retry 3
           connect_port 80
       }
   }
}

2)重启服务

/etc/init.d/keepalived   start

2、两台lvs均配置

1)

 cd /etc/sysconfig/network-scripts/
  vim   ifcfg-lo:10

在这里插入图片描述

2)vim /etc/sysctl.conf

在这里插入图片描述

sysctl   -p    

3)写好http测试页面

yum  install   httpd   -y
echo  "hello,173" > /var/www/html/index.html
echo "hello,174" > /var/www/html/index/html

4)测试

IP   a

结果:主keepalived 上有浮动ip 192.168.76.201,备keepalived上没有浮动ip,页面输入192.168.76.201发现“hello,1730”,“hello,174” 轮询

关闭主keeplaived ,关闭主服务ser的httpd,备上出现浮动ip,在页面输入192.168.76.201
,出现“hello,174”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值