一、keepalived lvs 集群
1、结构
2、主备修改内核参数
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
注:如果遇到提示是缺少包,yum 安装即可
3、启动keepalived
[root@iZ256w2hluuZ keepalived-1.3.5]# ./sbin/keepalived -f /usr/local/keepalived/etc/keepalived.conf
4、修改配置文件
1 > 192.168.1.109 vrrp-master-config
global_defs { #全局定义模块
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 { #vrrp 实例
state MASTER #主master
interface eth0
virtual_router_id 51
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.50 #vip 浮动的虚拟ip
}
}
virtual_server 192.168.1.50 80 { #虚拟ip
delay_loop 6 # 健康检查时间,
lb_algo wrr # 负载调度的算法为wlc
lb_kind DR #DR模式
nat_mask 255.255.255.0
persistence_timeout 0
protocol TCP
real_server 192.168.1.111 80 { # 指定real server1的IP地址
weight 3 #权值,数字越大权重越高
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.1.112 80 { # 指定real server2的IP地址
weight 3 # 权值,数字越大权重越高
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
2> 192.168.1.110 vrrp-slave-config: 把master的文件copy过来,其它不变
vrrp_instance VI_1 { #vrrp 实例要与master一致
state BACKUP #slave
interface eth0
virtual_router_id 51
priority 100 #优先级调低
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.50 #vip 浮动的虚拟ip
}
}
3> 状态
vrrp 虚拟ip飘在master 109上:
把109的keepalived kill掉,vip会飘到备机110上
二、nginx 安装
1>分别在192.168.1.111 , 192.168.1.112 上安装,安装httpd也可以
2> dr 模式需做特殊设置,创建脚本,并且start
[root@moban init.d]# cat realserver
#! /bin/bash
SNS_VIP=192.168.1.50
/etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_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 lo:0 down
route del $SNS_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
三、访问测试,实现主备
wrr 轮循
转载于:https://blog.51cto.com/keep11/2082688