Lvs NAT mode

Front server:
 OS: CentOS 5.6
 ip:
   eth0 192.168.1.17  netmask 255.255.255.0
   eth0:0  10.0.0.1   netmask 255.255.255.0
   Gateway: 192.168.1.1

Rear Server:
 OS: CentOS 5.6
  server one: 10.0.0.101 netmask 255.255.255.0
  server two: 10.0.0.102 netmask 255.255.255.0
  server three: 10.0.0.103 netmask 255.255.255.0
  Gateway: 10.0.0.1

Front server configuration
1. Configure the front server as gateway server, run the following script.
#!/bin/bash

/sbin/modprobe ip_tables
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_conntrack_ftp
/sbin/iptables -F
/sbin/iptables -F -t nat
/sbin/iptables -X
/sbin/iptables -Z
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables -P OUTPUT ACCEPT

echo "1" > /proc/sys/net/ipv4/ip_forward

######### eth0 wlan ##########
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -s 0/0 -d 0/0 -j ACCEPT

2. Install ipvsadm/apache on front server
linuxdba -->yum install ipvsadm
linuxdba -->yum install httpd

3. setup lvs
linuxdba -->vi /etc/init.d/lvs
#!/bin/bash
#LVS script (NAT)
VIP=192.168.1.17
RIP1=10.0.0.101
RIP2=10.0.0.102
RIP3=10.0.0.103
case "$1" in
 start)
  echo "1">/proc/sys/net/ipv4/ip_forward
  /sbin/iptables -F
  /sbin/ipvsadm -C
  /sbin/ipvsadm -A -t $VIP:80 -s rr
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP1 -m
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP2 -m
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP3 -m
  /sbin/ipvsadm
  ;;
 stop)
  echo "0">/proc/sys/net/ipv4/ip_forward
  /sbin/ipvsadm -C
  ;;
 *)
  echo "Usage: $0 {start|stop}"
  exit 1
esac


4. run lvs script
linuxdba -->/etc/init.d/lvs start
 
Rear server configuration
1. Install/start apache service on each server
one -->yum install httpd
one -->service httpd start
two -->yum install httpd
two -->service httpd start
three -->yum install httpd
three -->service httpd start

 

2. Write test script on each server
server one:
one -->vi /var/www/html/index.html
10.0.0.101 one
server two:
two -->vi /var/www/html/index.html
10.0.0.102 two
server three:
three -->vi /var/www/html/index.html
10.0.0.103 three


Test
open the following test site on the web browser and refresh for some times:
http://192.168.1.17
view the results:
linuxdba --> ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  linuxdba.org:http rr
  -> three.org:http               Masq    1      0          3        
  -> two.org:http                 Masq    1      0          3        
  -> one.org:http                 Masq    1      0          3        
linuxdba -->

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值