您好,登錄后才能下訂單哦!
LVS/DR 配置
準備3臺機器:
dir(192.168.220.141)
rs1(192.168. 220.143)
rs2(192.168.220.144)
vip(192.168.220.110)
Director 上 vim /usr/local/sbin/lvs_dr.sh //增加
#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/sbin/ipvsadm
vip=192.168.220.110
rs1=192.168.220.143
rs2=192.168.220.144
ifconfig eth0:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev eth0:0
$ipv -C
$ipv -A -t $vip:80 -s rr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1
兩臺rs上:vim /usr/local/sbin/lvs_dr_rs.sh
#! /bin/bash
vip=192.168.220.110
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip 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
然后director上執行: bash /usr/local/sbin/lvs_dr.sh
兩臺rs上執行: bash /usr/local/sbin/lvs_dr_rs.sh
Windows下瀏覽器測試訪問
結合keepalived
再準備一臺機器作為備用dir(192.168.220.129)
在主dir上
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.220.110
}
}
virtual_server 192.168.220.110 80 {
delay_loop 6 #(每隔10秒查詢realserver狀態)
lb_algo wlc #(lvs 算法)
lb_kind DR #(Direct Route)
persistence_timeout 60 #(同一IP的連接60秒內被分配到同一臺realserver)
protocol TCP #(用TCP協議檢查realserver狀態)
real_server 192.168.220.143 80 {
weight 100 #(權重)
TCP_CHECK {
connect_timeout 10 #(10秒無響應超時)
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.220.144 80 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
scp /etc/keepalived/keepalived.conf 192.168.220.129://etc/keepalived/keepalived.conf
在備用dir上
vim /etc/keepalived/keepalived.conf
修改以下幾處:
state MASTER -> state BACKUP
priority 100 -> priority 90
配置完keepalived后,需要開啟端口轉發(主從都要做):
echo 1 > /proc/sys/net/ipv4/ip_forward
然后,兩個rs上執行 /usr/local/sbin/lvs_dr_rs.sh 腳本
最后,兩個director上啟動keepalived服務(先主后從):
/etc/init.d/keepalived start
另外,需要注意的是,啟動keepalived服務會自動生成vip和ipvsadm規則,不需要再去執行上面提到的/usr/local/sbin/lvs_dr.sh 腳本。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。