1、LVS安装配置
配置LVS负载均衡集群:
1、填写下列IP分配表
服务器角色 IP地址
DR 192.168.158.129
RS1 192.168.158.137
RS2 192.168.158.138
VIP 192.168.158.3
2、要配置LVS需要安装哪个软件?安装并截图。
yum install ipvsadm
3、使用LVS配置单DR集群,配置并将配置过程截图。
我在以前已经配置过啦:https://blog.csdn.net/weixin_42859280/article/details/83312326
可以参考链接文章!
主要代码:
ifconfig ens33:0 192.168.158.3 broadcast 192.168.158.3 netmask 255.255.255.255 up
route add 192.168.158.3 dev ens33:0
ipvsadm -A -t 192.168.158.3:80 -s rr
ipvsadm -a -t 192.168.158.3:80 -r 192.168.158.137:80 -g
ipvsadm -a -t 192.168.158.3:80 -r 192.168.158.138:80 -g
ifconfig ens33:0 192.168.158.3 broadcast 192.168.158.3 netmask 255.255.255.255 up
配置环回地址lo:0。就是你的VIP。虚拟IP,也是你访问另外多台服务器的跳板!
route add 192.168.158.3 dev ens33:0
添加路由,这样它们才可以相互通信!
ipvsadm -A -t 192.168.158.3:80 -s rr
添加一个虚拟服务
-A 添加一条新的虚拟服务
-t | -u TCP/UDP协议的虚拟服务
-s 配置负载均衡算法,如:rr, wrr, lc等
ipvsadm -a -t 192.168.158.3:80 -r 192.168.158.137:80 -g
-R --restore 恢复虚拟服务规则
-g | -m | -i LVS模式为:DR | NAT | TUN
ipvsadm -a -t 192.168.158.3:80 -r 192.168.158.138:80 -g
更多的内容请参考:https://www.cnblogs.com/lipengxiang2009/p/7353373.html
另外的服务器配置:
服务器1:
ifconfig lo:0 192.168.158.3 netmask 255.255.255.255 broadcast 192.168.158.3 up
route add 192.168.158.3 dev lo:0
echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo “2” > /proc/sys/net/ipv4/conf/lo/arp_announce
echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore
echo “2” > /proc/sys/net/ipv4/conf/all/arp_announce
要英文格式才可以!
服务器2:
ifconfig lo:0 192.168.158.3 netmask 255.255.255.255 broadcast 192.168.158.3 up
route add 192.168.158.3 dev lo:0
echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo “2” > /proc/sys/net/ipv4/conf/lo/arp_announce
echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore
echo “2” > /proc/sys/net/ipv4/conf/all/arp_announce
关于:arp_ignore:0 1 2 arp_announce:0 1 2 的更多介绍:
https://blog.csdn.net/weixin_42859280/article/details/83312326
4、测试LVS负载均衡截图。
OK!
2、Keepalived配置
服务器角色 IP地址
DR1 192.168.158.128
DR2 192.168.158.129
RS1 192.168.158.137
RS2 192.168.158.138
VIP 192.168.158.3
2、安装Keepalived并截图
yum install keepalived
3、配置Keepalived并截图
路径:/etc/keepalived/keepalived.conf
DR1:
! Configuration File for keepalived
global_defs {
notification_email {
#指定keepalived在发生切换时需要发送email到的对象,一行一个
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
#指定发件人
smtp_server 192.168.158.1#指定smtp服务器地址
smtp_connect_timeout 30#指定smtp连接超时时间
router_id LVS_DEVEL#运行keepalived机器的一个标识
}
vrrp_instance VI_1 {#监控多个网段的实例
state MASTER
interface eth0#vip绑定接口
virtual_router_id 51#router_id
priority 100#优先级,高优先级竞选为master
advert_int 1
authentication {#设置认证
auth_type PASS#认证方式
auth_pass 1111#认证密码
}
virtual_ipaddress {
192.168.158.3#虚拟IP地址!
}
}
virtual_server 192.168.158.3 80{#虚拟服务!
delay_loop 3#循环次数
lb_algo rr#循环方式:轮循!
lb_kind DR#DR模型
persistence_timeout 10
protocol TCP#TCP类型!
real_server 192.168.158.137 80{
weight 1#权重!
TCP_CHECK{
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80#链接端口!
}
}
real_server 192.168.158.138 80{
weight 1#权重!
TCP_CHECK{
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80#链接端口!
}
}
}
DR2:
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.158.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.158.3
}
}
virtual_server 192.168.158.3 80{
delay_loop 3
lb_algo rr
lb_kind DR
persistence_timeout 10
protocol TCP
real_server 192.168.158.137 80{
weight 1
TCP_CHECK{
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.158.138 80{
weight 1
TCP_CHECK{
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
4、测试keepalived并截图
用一个新的CENTOS进行测试
for i in {1…10};do curl 192.168.158.3;done
另外一次用:for i in {1…3333};do curl 192.168.158.3;done
期间关掉DR1观察情况。
如果关掉瞬间,立刻暂停获取网页内容,大概10秒钟后。另外一台DR工作!那么,恭喜!成功啦!