本实验以lvs-dr前提下实现环境
测试环境
Hostname |
eth0 |
DR1 |
192.168.137.100 |
DR2 |
192.168.137.101 |
RS1 |
192.168.137.111 |
RS2 |
192.168.137.122 |
准备工作:
1、ipvsadm -C setenforce 0 iptables –F
2、vip地址以192.168.137.88为例
3、DR1以及DR2上需要安装keepalived、ipvsadm
4、RS1以及RS2需要安装nginx作为测试
在DR1、DR2上修改或者加入内容:
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER #备用服务器上为 BACKUP
interface eth0
virtual_router_id 51
priority 100 #优先级,数值越大优先级越高;备用服务器上为90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.88
}
}
virtual_server 192.168.137.88 80 {
delay_loop 6 #(每隔6秒查询realserver状态,是否存活)
lb_algo wlc #(轮询算法)
lb_kind DR #(Direct Route)
persistence_timeout 0 #(同一IP的连接多少秒内被分配到同一台realserver,0表示不连接)
protocol TCP #(用TCP协议检查realserver状态)
real_server 192.168.1.111 80 {
weight 100 #(权重)
TCP_CHECK {
connect_timeout 10 #(10秒无响应超时)
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.1.122 80 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
配置完成后DR1以及DR2,运行一下命令
echo 1 > /proc/sys/net/ipv4/ip_forward
运行RS1以及RS2之前在LVS-DR文档里配置的脚本
sh /usr/local/sbin/lvs_rs.sh
先运行DR1再运行DR2的keepalived服务
/etc/init.d/keepalived start