keepalived 是解决单故障节点的软件
1、 keepalived+LVS/DR
2、 任意单故障节点 的 高可用
作 分发器 的 高可用
用 keepalived 作 LVS/DR 模式 分发器 的 高可用
实验拓扑
client
node1主、node2备
webA 、webB
浮动资源有: 浮动ip、策略
IP 规划
client 192.168.4.254
node1 192.168.4.50
node2 192.168.4.55
浮动ip(vip) 192.168.4.252
webA 192.168.4.51
webB 192.168.4.52
配置步骤
#chkconfig iptables off #取消开机自起
#service iptables stop #关闭防火墙
#setenforce 0 #关闭selinux
1 配置好网络环境 所有地址的IP
#vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.4.50
NETMASK=255.255.255.0
GATEWAY=192.168.4.10
DNS1=202.106.0.20
...
#service network restart #systemctl restart NetworkManager
2 配置webA、B 服务自定义Web页面
#yum install -y httpd
#echo “192.168.4.51” > /var/www/html/index.html
#echo “192.168.4.52” > /var/www/html/index.html
#service httpd start ; chkconfig httpd on #rhel6
#systemctl start httpd;systemctl enable httpd #rhel7
配置webA、B的vip 和DR模式的网络配置
临时修改方法可写在/etc/rc.local文件里开机执行
#ifconfig lo:1 192.168.4.252/32
#echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
#echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
永久修改方法
#vim /etc/sysctl.conf
.. ..
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
#sysctl -p
在node1、node2 分别安装 keepalived 软件包
#yum -y install keepalived ipvsadm
修改配置node1
#vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.4.252
}
}
virtual_server 192.168.4.252 80 {
delay_loop 6
lb_algo rr #集群算法
lb_kind DR #DR模式
nat_mask 255.255.255.0
#persistence_timeout 50 #坚持时间同一客户端50秒内访问分配同一服务器注释掉实现实时轮询
protocol TCP
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
real_server 192.168.4.51 80 {
weight 1
}
real_server 192.168.4.52 80 {
weight 1
}
}
node2:
#vim /etc/keepalived/keepalived.conf
state MASTER
priority 150
#systemctl start keepalived
#ipvsadm -Ln
验证 254:
http://192.168.4.252/index.html
原文地址:http://blog.51cto.com/45545613/2083341