ǰλ: > ѧϰ > >

Lvs-NATģʽ

ʱ:2020-01-04 13:35Դ:δ֪ :IT
Lvsԭ    
 
Lvs-NATģʽע   
 
Lvs-Natģʽͼ  
 
Lvs
 
ipvsadmԷ
 
ԣ
 
Lvsԭ
 
 
    ͻ˵󵽴︺ؾں˿ռʱȻᵽPREROUTING
    ں˷ݰĿĵַDZʱݰINPUT
    LVSûռipvsadmں˿ռIPVSɣipvsadmIPVSipvsadmĹIPVSINPUT,ݰINPUTʱȻᱻIPVS飬ݰĿĵַ˿ûڹ棬ôݰINPUTûռ䣬ûռĽ
    ݰĿĵַ˿ڹ棬ôݱĽ޸ĿĵַΪȶõĺ˷POSTROUTING
    POSTROUTING˷
 
 
Lvs-NATģʽע
 
RSӦʹ˽еַ    RSرָDIP DIPRIPͬһ
 
ӦĶҪDirector Server
 
ֶ֧˿ӳ RSʹϵͳ
 
ȱݣDirector ServerѹȽϴӦ辭director server  ߸سУDirector Server׳Ϊƿ
 
Lvs-Natģʽͼ
 
 
Lvs
sercer4Ϊ,,ip 172.25.100.4    ipΪ172.25.254.4
 
server8(172.25.100.8)  ָDIP172.25.100.6
 
server9(172.25.100.9)  ָDIP172.25.100.6
 
䣺ʱ,ֱifconfig鿴ֱӲ鿴£
 
һeth0ļ
 
豸ƺipַ
 
ok
 
server4Ϊ
 
·תܣʹʵԷ
 
[root@server4 ~]# vim /etc/sysctl.conf
 
net.ipv4.ip_forward = 1
 
鿴ԣ
 
[root@server4 ~]# sysctl -p
net.ipv4.ip_forward = 1   鿴Ѿ
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
 
ԣ
 
̨صĺ˷pingͨDIP172.25.254.4
 
 
 
 
servre8, server9 Ϊ˷
 
̨ʱָ
 
[root@server9 ~]# route add default gw 172.25.100.4
 
òԣ
 
[root@server4 ~]# ipvsadm -C
[root@server4 ~]# ipvsadm -A -t 172.25.254.4:80 -s wrr
[root@server4 ~]# ipvsadm -a -t 172.25.254.4:80 -r 172.25.100.6 -m -w 1
[root@server4 ~]# ipvsadm -a -t 172.25.254.4:80 -r 172.25.100.8 -m -w 1
䣺mnatģʽ-wȨ wrrȨֽе㷨
[root@server4 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  172.25.254.4:80 wrr
  -> 172.25.100.6:80              Masq    1      0          0         
  -> 172.25.100.8:80              Masq    1      0          0  
[root@server4 ~]# echo "1" >/proc/sys/net/ipv4/ip_forward  //ipת
 
//ʱsysctl -w net.ipv4.ip_forward=1
 
ipvsadmԷ
service ipvsadm save //lvs/etc/sysconfig/ipvsadm
 
󣬿service ipvsadm reloadس
 
䣺Ȼض򱣴浽κļ
 
ipvsadm -S >/etc/hi
 
 
ipvsadm -R </etc/hi
 
iptables5˽5ǵݰ̨ʱݰڷںе
 
http
 
server8server9
 
http񷢲ҳֱΪserver8‘s page ; server9's  page   
 
[root@server4 ~]# curl http://172.25.254.4
server6'page
[root@server4 ~]# curl http://172.25.254.4
server8's  page
[root@server4 ~]# curl http://172.25.254.4
server6'page
[root@server4 ~]# curl http://172.25.254.4
server8's  page
 
 
 
[root@server4 ~]# ab -n 10000 -c 200 http://172.25.254.4/index.html
 
[root@server4 ~]# ipvsadm -L -n --rate
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port                 CPS    InPPS   OutPPS    InBPS   OutBPS
  -> RemoteAddress:Port
TCP  172.25.254.4:80                    82      409      409    29237    45036
  -> 172.25.100.6:80                    41      205      205    14645    22534
  -> 172.25.100.8:80                    41      204      204    14592    22502
 
 
 
 
 
 
 
 
 



(α༭IT)
------ָ----------------------------