您好,登錄后才能下訂單哦!
擴(kuò)展:
haproxy+keepalived
http://blog.csdn.net/xrt95050/article/details/40926255
nginx、lvs、haproxy比較
http://www.csdn.net/article/2014-07-24/2820837
keepalived中自定義腳本 vrrp_script
http://my.oschina.net/hncscwc/blog/158746
lvs dr模式只使用一個(gè)公網(wǎng)ip的實(shí)現(xiàn)方法
http://storysky.blog.51cto.com/628458/338726
18.11 LVS DR模式搭建
1. 改回hao2 hao3機(jī)器ens33網(wǎng)卡中網(wǎng)關(guān)(.2)
[root@hao-02 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
[root@hao-03 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
2. 重啟網(wǎng)卡:
[root@hao-02 ~]# systemctl restart network
[root@hao-03 ~]# systemctl restart network
hao1 機(jī)器(dir)上操作:
1. hao1機(jī)器(dir)上,創(chuàng)建lvs_dr.sh腳本:
[root@hao-01 ~]# vim /usr/local/sbin/lvs_dr.sh
添加內(nèi)容:
#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/usr/sbin/ipvsadm
vip=192.168.211.200
rs1=192.168.211.129
rs2=192.168.211.130
#注意這里的網(wǎng)卡名字(ens33 上面設(shè)置了vip虛擬網(wǎng)卡ip)
ifdown ens33
ifup ens33
ifconfig ens33:2 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev ens33:2
$ipv -C
$ipv -A -t $vip:80 -s wrr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1
2. 執(zhí)行lvs_dr.sh腳本:
[root@hao-01 ~]# sh /usr/local/sbin/lvs_dr.sh
hao2 機(jī)器(rr)上操作:
1. hao2機(jī)器(rr)上,創(chuàng)建lvs_rs.sh腳本:
[root@hao-02 ~]# vim /usr/local/sbin/lvs_rs.sh
添加內(nèi)容:
#/bin/bash
vip=192.168.211.200
#把vip綁定在lo上,是為了實(shí)現(xiàn)rs直接把結(jié)果返回給客戶端
ifdown lo
ifup lo
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
#以下操作為更改arp內(nèi)核參數(shù),目的是為了讓rs順利發(fā)送mac地址給客戶端
#參考文檔www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html
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. 執(zhí)行lvs_rs.sh腳本:
[root@hao-02 ~]# sh /usr/local/sbin/lvs_rs.sh
hao3 機(jī)器(rr)上操作:
1. hao3機(jī)器(rr)上,創(chuàng)建lvs_rs.sh腳本:
[root@hao-03 ~]# vim /usr/local/sbin/lvs_rs.sh
添加內(nèi)容:
#/bin/bash
vip=192.168.211.200
#把vip綁定在lo上,是為了實(shí)現(xiàn)rs直接把結(jié)果返回給客戶端
ifdown lo
ifup lo
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
#以下操作為更改arp內(nèi)核參數(shù),目的是為了讓rs順利發(fā)送mac地址給客戶端
#參考文檔www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html
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. 執(zhí)行lvs_rs.sh腳本:
[root@hao-03 ~]# sh /usr/local/sbin/lvs_rs.sh
測(cè)試:
游覽器訪問(wèn)vip:192.168.211.200
18.12 keepalived lvs
hao1 機(jī)器(dir)上操作:
yum install -y keepalived
1. 編輯keepalived.conf配置文件:
[root@hao-01 ~]# vim /etc/keepalived/keepalived.conf
添加內(nèi)容:
vrrp_instance VI_1 {
#備用服務(wù)器上為 BACKUP
state MASTER
#綁定vip的網(wǎng)卡為ens33,你的網(wǎng)卡和阿銘的可能不一樣,這里需要你改一下
interface ens33
virtual_router_id 51
#備用服務(wù)器上為90
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass haomima
}
virtual_ipaddress {
192.168.211.200
}
}
virtual_server 192.168.211.200 80 {
#(每隔10秒查詢r(jià)ealserver狀態(tài))
delay_loop 10
#(lvs 算法)
lb_algo wlc
#(DR模式)
lb_kind DR
#(同一IP的連接0秒內(nèi)被分配到同一臺(tái)realserver)
persistence_timeout 0
#(用TCP協(xié)議檢查realserver狀態(tài))
protocol TCP
real_server 192.168.211.129 80 {
#(權(quán)重)
weight 100
TCP_CHECK {
#(10秒無(wú)響應(yīng)超時(shí))
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.211.130 80 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
2. 啟動(dòng)keepalived:
[root@hao-01 ~]# systemctl start keepalived
3. hao1機(jī)器(dir)上,先關(guān)閉keepalived:
[root@hao-01 ~]# systemctl stop keepalived
4. hao2機(jī)器(rr1)上,先關(guān)閉nginx,再啟動(dòng)nginx:
[root@hao-02 ~]# systemctl stop nginx
[root@hao-02 ~]# systemctl start nginx
5. hao3機(jī)器(rr2)上,先關(guān)閉nginx,再啟動(dòng)nginx:
先關(guān)閉nginx,再啟動(dòng)nginx:
[root@hao-03 ~]# systemctl stop nginx
[root@hao-03 ~]# systemctl start nginx
6. 再啟動(dòng)keepalived:
[root@hao-01 ~]# systemctl start keepalived
7. (哪個(gè)機(jī)器nginx掛了,對(duì)應(yīng)的ip就不會(huì)在這里顯示了)
[root@hao-01 ~]# ipvsadm -ln
8. hao2 hao3機(jī)器nginx都掛了,這兩個(gè)對(duì)應(yīng)的ip都不再顯示了:
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。