opensips+lvs配置(DR模式)1--lvs DR模式配置

(1).准备三个linux操作系统,虚拟机或者真机都可


IP部署如下:

                  |  Director             |  Real Server 1   |    Real Server 2

Virtual IP  | 192.168.1.1      |  192.168.1.2       |     192.168.1.3

Real IP     | 10.10.13.121    |  10.10.13.117     |     10.10.13.119


(2).配置Director机器

1.关闭防火墙和selinux(方便测试)

我的是Centos 7,

vim /etc/selinux/config

修改为SELINUX=DISABLED

chkconfig firewalld off

重启电脑


2.设置真实IP

ifconfig eth0 10.10.13.121 netmask 255.255.255.0

3.在Director机器上,编辑如下脚本lvs_dr_vip.sh,假设网卡是eth0


#!/bin/bash  
# website director vip. 
DR_VIP=10.10.13.121
DR_DIP=192.168.1.1
DR_RIP1=192.168.1.2
DR_RIP2=192.168.1.3

case "$1" in
start)
# set  vip  
ifconfig eth0:1 $DR_DIP broadcast $DR_DIP netmask 255.255.255.0
/sbin/ipvsadm -C
/sbin/ipvsadm --set 600 5 60
/sbin/ipvsadm -A -t $DR_VIP:5060 -s wrr
/sbin/ipvsadm -a -t $DR_VIP:5060 -r $DR_RIP1:5060 -g
/sbin/ipvsadm -a -t $DR_VIP:5060 -r $DR_RIP2:5060 -g
touch /var/lock/subsys/ipvsadm >/dev/null 2>&1
;;
stop)
/sbin/ipvsadm -C
/sbin/ipvsadm -Z
ifconfig eth0:1 down
rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1
echo "ipvsadm stoped"  
;;
status)
if [ ! -e /var/lock/subsys/ipvsadm ];then
echo "ipvsadm stoped"  
exit 1
else
echo "ipvsadm OK"  
fi
;;
*)
echo "Usage: $0 {start|stop|status}"  
exit 1
esac
exit 0
执行以上脚本:

sudo chmod +x lvs_dr_vip.sh

sudo ./lvs_dr_vip.sh start

若没有什么打印,便是执行成功。

注意我这里配置的端口转发规则为:

10.10.13.121:5060-----> 192.168.1.2:5060

10.10.13.121:5060-----> 192.168.1.3:5060

所以,接下来opensips的配置需要监听5060 TCP端口。


(3)配置Real Server机器(以192.168.1.2为例子)

1.设置真实IP

ifconfig eth0 10.10.13.117 netmask 255.255.255.0

2.编辑以下脚本lvs_dr_rs.sh

#!/bin/bash 
DR_VIP=10.10.13.121 
DR_RIP=192.168.1.2
 
case "$1" in  
start)
      ifconfig eth0:1 $DR_RIP netmask 255.255.255.0 broadcast $DR_RIP 
      ifconfig lo:0 $DR_VIP netmask 255.255.255.255 broadcast $DR_VIP
      /sbin/route add -host $DR_VIP dev lo:0 
      echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore 
      echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce 
      echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore 
      echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce 
      sysctl -p >/dev/null 2>&1 
      echo "RealServer Start OK" 
      ;;  
stop)
      ifconfig eth0:1 down 
      ifconfig lo:0 down
      route del $DR_VIP >/dev/null 2>&1 
      echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore 
      echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce 
      echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore 
      echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce 
      echo "RealServer Stoped" 
      ;;  
*) 
      echo "Usage: $0 {start|stop}" 
      exit 1 
esac 
exit 0 

同上,执行脚本

sudo ./lvs_dr_rs.sh start

打印RealServer Started即正常,另外一个Real Server192.168.1.3类似,只需要修改IP 即可。



你可能感兴趣的:(LVS,opensips,DR模式)