标签:目的 net tcp serve 无响应 oss ace 两台 ble
一、LVS DR模式搭建在rs2机器上同样编写/usr/local/sbin/lvs_rs.sh脚本,写入如上脚本内容
[root@linux-03 ~]# vim /usr/local/sbin/lvs_rs.sh
#/bin/bash
vip=192.168.238.200
#把vip绑定在lo上,是为了实现rs直接把结果返回给客户端
ifdown lo
ifup lo
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
#以下操作为更改arp内核参数,目的是为了让rs顺利发送mac地址给客户端
#参考文档www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html
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
[root@linux-03 ~]# sh /usr/local/sbin/lvs_rs.sh //执行脚本
[root@linux-03 ~]# route -n
[root@linux-03 ~]# ip add
[root@linux-02 ~]# ip add
[root@linux-01 ~]# ip add //分别查看三台机器的网卡信息是否设置了vip=192.168.238.200
打开浏览器访问:192.168.238.200
[root@linux-01 ~]# iptables -t nat -F //清空防火墙规则
[root@linux-01 ~]# ipvsadm -ln
二、keepalived + LVS
[root@linux-01 ~]# ipvsadm -ln
[root@linux-01 ~]# vim /etc/keepalived/keepalived.conf
//配置文件内容请到https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D21Z/lvs_keepalived.conf获取,内容如下:
vrrp_instance VI_1 {
#备用服务器上为 BACKUP
state MASTER
#绑定vip的网卡为ens33,你的网卡和阿铭的可能不一样,这里需要你改一下
interface ens33
virtual_router_id 51
#备用服务器上为90
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass aminglinux
}
virtual_ipaddress {
192.168.238.200
}
}
virtual_server 192.168.238.200 80 {
#(每隔10秒查询realserver状态)
delay_loop 10
#(lvs 算法)
lb_algo wlc
#(DR模式)
lb_kind DR
#(同一IP的连接60秒内被分配到同一台realserver)
persistence_timeout 60
#(用TCP协议检查realserver状态)
protocol TCP
real_server 192.168.238.130 80 {
#(权重)
weight 100
TCP_CHECK {
#(10秒无响应超时)
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.238.131 80 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
配置完keepalived.conf配置文件,启动keepalived服务
[root@linux-01 ~]# systemctl start keepalived
[root@linux-01 ~]# ps aux |grep keep //查看keepalived进程
[root@linux-01 ~]# ipvsadm -ln
[root@linux-01 ~]# systemctl stop keepalived
[root@linux-03 ~]# systemctl start nginx //启动rs2的nginx
[root@linux-01 ~]# ip add //关掉原来的虚拟IP
[root@linux-01 ~]# ipvsadm -ln //再次查看已经没有规则了
[root@linux-01 ~]# systemctl start keepalived //再次启动keepalived
[root@linux-01 ~]# ipvsadm -ln //查看有两个规则了
说明keepalived有自动把宕机的rs剔除的功能
需要注意在两台rs机器上依然要执行/usr/local/sbin/lvs_rs.sh脚本
标签:目的 net tcp serve 无响应 oss ace 两台 ble
原文地址:http://blog.51cto.com/13669226/2138956