lb及其rs配置
3.1 負載均衡器配置配置
停止路由**功能
[root@lvs01 linux]# sysctl -w net.ipv4.ip_forward=0
net.ipv4.ip_forward = 0
[root@lvs01 linux]# sysctl -w net.ipv4.conf.all.send_redirects=1
net.ipv4.conf.all.send_redirects = 1
[root@lvs01 linux]# sysctl -w net.ipv4.conf.default.send_redirects=1
net.ipv4.conf.default.send_redirects = 1
通過eth0繫結
[root@lvs01 linux]# sysctl -w net.ipv4.conf.eth0.send_redirects=1
net.ipv4.conf.eth0.send_redirects = 1
設定虛擬ip位址
[root@lvs01 linux]# ifconfig eth0:0 192.168.28.111 netmask 255.255.255.0
啟用eth0:0
[root@lvs01 linux]# ifconfig eth0:0 up
清除ipvs規則表
[root@lvs_01 ~]# ipvsadm -c
檢視集群分布
[root@lvs_01 ~]# ipvsadm -l -n
ip virtual server version 1.2.1 (size=4096)
prot localaddress:port scheduler flags
-> remoteaddress:port forward weight activeconn inactconn
為避免arp解析 增加主機路由
[root@lvs01 linux]# /sbin/route add -host 192.168.28.111 dev eth0:0
[root@lvs_01 ~]# route -n
kernel ip routing table
destination gateway genmask flags metric ref use iface
192.168.2.111 0.0.0.0 255.255.255.255 uh 0 0 0 eth0
192.168.28.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 u 0 0 0 eth0
0.0.0.0 192.168.28.2 0.0.0.0 ug 0 0 0 eth0
[root@lvs_01 ~]#
[root@lvs01 linux]# ipvsadm -a -t 192.168.28.111:80 -s rr
在lb master中增加真實伺服器
[root@lvs01 linux]# ipvsadm -a -t 192.168.28.111:80 -r 192.168.28.134 -g -w 1
[root@lvs01 linux]# ipvsadm -a -t 192.168.28.111:80 -r 192.168.28.135 -g -w 2
[root@lvs_01 ~]# ipvsadm -l -n
ip virtual server version 1.2.1 (size=4096)
prot localaddress:port scheduler flags
-> remoteaddress:port forward weight activeconn inactconn
tcp 192.168.28.111:80 rr
-> 192.168.28.135:80 route 1 0 0
-> 192.168.28.134:80 route 1 0 0
注:backup lb中安裝配置和master一致
3.2 rserver 應用真實伺服器配置
[root@rs01 ~]# sysctl -w net.ipv4.ip_forward=0
忽略arp設定
[root@rs01 ~]# sysctl -w net.ipv4.conf.lo.arp_ignore=1
設定arp宣告值
[root@rs01 ~]# sysctl -w net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.lo.arp_announce = 2
[root@rs01 ~]# sysctl -w net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_ignore = 1
[root@rs01 ~]# sysctl -w net.ipv4.conf.all.arp_announce=2
net.ipv4.conf.all.arp_announce = 2
配置rs02中vip位址
[root@rs01 ~]# /sbin/ifconfig lo:0 192.168.28.111 netmask 255.255.255.255 broadcast 192.168.28.111 up
檢視路由表
[root@localhost html]# route -n
kernel ip routing table
destination gateway genmask flags metric ref use iface
192.168.28.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 u 0 0 0 eth0
0.0.0.0 192.168.28.2 0.0.0.0 ug 0 0 0 eth0
增加主機虛擬ip
[root@rs01 ~]# /sbin/route add -host 192.168.28.111 dev lo:0
再次檢視路由表
[root@localhost html]# route -n
kernel ip routing table
destination gateway genmask flags metric ref use iface
192.168.28.111 0.0.0.0 255.255.255.255 uh 0 0 0 lo
192.168.28.0 0.0.0.0 255.255.255.0 u 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 u 0 0 0 eth0
0.0.0.0 192.168.28.2 0.0.0.0 ug 0 0 0 eth0
虛擬ip已新增進來
注:rs02 配置過程與rs01一致,參照rs01配置
lvs dr模型負載均衡
下面再說lvs dr,後端的服務php和資料庫服務完全不用改變,只需改變網路模型即可 搭建網路環境 director eno16777736 0網絡卡別名 vip 172.18.11.7 ifconfig eno16777736 0 172.18.11.7 netmask 255.255.255.2...
負載均衡 LVS DR模式
相比於nginx只能用於7層負載均衡,lvs就比較強大了,能在4層做負載均衡。而且效能和穩定性上lvs也比較佔優,畢竟是合入核心模組,不穩定肯定不行。lvs通過工作於核心的ipvs模組來實現功能,其主要工作於netfilter的input鏈上。除此之外,還需要乙個使用者態工具,ipvdadm,用於使...
Linux負載均衡軟體LVS DR模式的簡單示例
本文乙個簡單的示例演示lvs的配置 dr模式 和測試。使用的配置環境如下 director server 192.168.8.4 real server1 192.168.8.5 real server2 192.168.8.6 vip 192.168.8.200 網路topology圖如下 圖2中...