lvs

lvs

實驗環境:

主機1172.25.46.1

主機2172.25.46.2

主機3172.25.46.3



主機1

# yum install -y ipvsadm

# ip addr add 172.25.46.100/24 dev eth1

eth1:

 inet 172.25.46.100/24 scope global secondary eth1

 

加載 rule

# ipvsadm -A -t 172.25.46.100:80 -s rr

# ipvsadm -a -t 172.25.46.100:80 -r 172.25.46.3:80 -g

# ipvsadm -a -t 172.25.46.100:80 -r 172.25.46.2:80 -g

# 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.46.100:80 rr

  -> 172.25.46.2:80                Route   1      0          0        

  -> 172.25.46.3:80                Route   1      0          0       

 

將以上配置保存至/etc/sysconfig/ipvsadm文件-保存 rule

# /etc/init.d/ipvsadm save

# cat /etc/sysconfig/ipvsadm

-A -t 172.25.46.100:80 -s rr

-a -t 172.25.46.100:80 -r 172.25.46.2:80 -g -w 1

-a -t 172.25.46.100:80 -r 172.25.46.3:80 -g -w 1

# /etc/init.d/ipvsadm start

 

主機2

# yum install -y httpd

# cd /var/www/html/

# ls

index.html

# cat index.html

server2.example.com

# /etc/init.d/httpd start

# netstat -antlp

tcp        0      0 :::22                       :::*                        LISTEN      1125/sshd  

# yum install -y arptables_jf

# arptables -A IN -d 172.25.46.100 -j DROP

# ip addr add 172.25.46.100/32 dev eth0

# ip addr show

eth0:

 inet 172.25.46.100/32 scope global eth0

# arptables -A OUT -s 172.25.46.100 -j mangle --mangle-ip-s 172.25.46.2

# /etc/init.d/arptables_jf save

# arptables -nL

Chain IN (policy ACCEPT)

target     source-ip            destination-ip       source-hw          destination-hw     hlen   op         hrd        pro      

           0.0.0.0/0            172.25.46.100        00/00              00/00              any    0000/0000  0000/0000  0000/0000

 

Chain OUT (policy ACCEPT)

target     source-ip            destination-ip       source-hw          destination-hw     hlen   op         hrd        pro      

mangle     172.25.46.100        0.0.0.0/0            00/00              00/00              any    0000/0000  0000/0000  0000/0000 --mangle-ip-s 172.25.46.2

 

Chain FORWARD (policy ACCEPT)

target     source-ip            destination-ip       source-hw          destination-hw     hlen   op         hrd        pro      

 

主機3

# yum install -y httpd

# cd /var/www/html/

# ls

index.html

# cat index.html

server3.example.com

# /etc/init.d/httpd start

# netstat -antlp

tcp        0      0 :::80                       :::*                        LISTEN      1479/httpd    

# yum install -y arptables_jf

# arptables -A IN -d 172.25.46.100 -j DROP

# arptables -A OUT -s 172.25.46.100 -j mangle --mangle-ip-s 172.25.46.3

# arptables -nL

Chain IN (policy ACCEPT)

target     source-ip            destination-ip       source-hw          destination-hw     hlen   op         hrd        pro      

DROP       0.0.0.0/0            172.25.46.100        00/00              00/00              any    0000/0000  0000/0000  0000/0000

 

Chain OUT (policy ACCEPT)

target     source-ip            destination-ip       source-hw          destination-hw     hlen   op         hrd        pro      

mangle     172.25.46.100        0.0.0.0/0            00/00              00/00              any    0000/0000  0000/0000  0000/0000 --mangle-ip-s 172.25.46.3

 

Chain FORWARD (policy ACCEPT)

target     source-ip            destination-ip       source-hw          destination-hw     hlen   op         hrd        pro      

# /etc/init.d/arptables_jf save

---------瀏覽器172.25.46.100,頁面在server2.example.comservre3.example.com之間轉換

 

訪問cheungssh時:http://ip/cheungssh

http://域名/cheungssh

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章