`
kusix
  • 浏览: 68591 次
社区版块
存档分类
最新评论

LVS-NAT实战配置

    博客分类:
  • LVS
阅读更多
今天测试redis分片集群的时候,要用到LVS做LB,由于机器不够,访问redis的客户端都部署在一台16核的机器上,所以只有用NAT模式。
LB SERVER: 10.10.224.236
REAL SERVER: 10.10.224.231:8000 - 8008 共9个端口

步骤1:
修改REAL SERVER的网关,使其指向LB SERVER的虚拟IP
修改配置
[root@esb ~]$ vi /etc/sysconfig/network

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=esb
#GATEWAY=10.10.224.1
GATEWAY=10.10.224.253

然后重启网络
/etc/init.d/network restart


步骤2:
在LB SERVER上编辑脚本lvs.sh
#!/bin/bash

#LVS script NAT

VIP=10.10.224.253

RIP=10.10.224.231

#RIP2=10.0.0.3

#./etc/rc.d/init.d/functions

case "$1" in

        start)

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

        /sbin/iptables -F

        /sbin/iptables -t nat -F

        /sbin/ifconfig eth0:0 $VIP netmask 255.255.255.0 up

        /sbin/ipvsadm -A -t $VIP:8081 -s rr             

        /sbin/ipvsadm -a -t $VIP:8081 -r 10.10.224.231:8001 -m -w 1     

        /sbin/ipvsadm -a -t $VIP:8081 -r 10.10.224.231:8002 -m -w 1
	/sbin/ipvsadm -a -t $VIP:8081 -r 10.10.224.231:8003 -m -w 1
	/sbin/ipvsadm -a -t $VIP:8081 -r 10.10.224.231:8004 -m -w 1
	/sbin/ipvsadm -a -t $VIP:8081 -r 10.10.224.231:8005 -m -w 1
	/sbin/ipvsadm -a -t $VIP:8081 -r 10.10.224.231:8006 -m -w 1
	/sbin/ipvsadm -a -t $VIP:8081 -r 10.10.224.231:8007 -m -w 1
	/sbin/ipvsadm -a -t $VIP:8081 -r 10.10.224.231:8008 -m -w 1

	/sbin/ipvsadm -A -t $VIP:8080 -s rr             

        /sbin/ipvsadm -a -t $VIP:8080 -r 10.10.224.231:8000 -m -w 1   

	

        /sbin/ipvsadm

        echo "start LVS of DirectorServer NAT"

        ;;

        stop)

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

        /sbin/ipvsadm -C

        /sbin/ifconfig eth0:0 down

        echo "stop LVS of DirectorServer NAT"

        ;;

        *)

        echo "Usage:$0{start|stop}"

        exit 1

esac


启动脚本
[root@localhost ~]# ./lvs.sh start
[root@localhost ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.10.224.253:8080 rr
  -> 10.10.224.231:8000           Masq    1      0          0         
TCP  10.10.224.253:8081 rr
  -> 10.10.224.231:8008           Masq    1      0          0         
  -> 10.10.224.231:8007           Masq    1      0          0         
  -> 10.10.224.231:8006           Masq    1      0          0         
  -> 10.10.224.231:8005           Masq    1      0          0         
  -> 10.10.224.231:8004           Masq    1      0          0         
  -> 10.10.224.231:8003           Masq    1      0          0         
  -> 10.10.224.231:8002           Masq    1      0          0         
  -> 10.10.224.231:8001           Masq    1      0          0


至此,NAT配置完毕。
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics