本實驗以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