yum 安装模式
yum install keepalived -y
主节点配置
[root@sjyd4 keepalived-1.2.2]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from
smtp_server smtp.ytxt.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script Monitor_Nginx {
script "/home/app/bin/monitor_nginx"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
Monitor_Nginx
}
virtual_ipaddress {
192.168.10.75
}
}
从节点需要改 state BACKUP 和priority就可以
state MASTER #//负载均衡器的角色
interface eth0 #//承载VIP地址的物理接口
virtual_router_id 1 #//虚拟路由器的ID号,每个热备组保持相同
priority 101 #//竞选优先级,数字越大优先级越高
advert_int 1 #//通告间隔秒数(心跳频率)
authentication { #//本VRRP组的认证信息
virtual_ipaddress { #//热备所针对的虚拟地址(VIP),可以有多行
192.168.10.75
使用命令 ip addr 可以查看vip地址起来了
创建lvsrs 脚本,放到/etc/init.d/下
#!/bin/bash
# 配置虚拟IP,取消arp应答
VIP=211.147.11.8
. /etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP up
/sbin/route add -host $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 $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
virtual_router_id 取值在0-255之间,用来区分多个instance的VRRP组播。
同一网段中virtual_router_id的值不能重复,否则会出错
可以用这条命令来查看该网络中所存在的vrid:tcpdump -nn -i any net 224.0.0.0/8
阅读(2652) | 评论(0) | 转发(0) |