keepalived错误 请到此处
本文为 “haproxy + keepalived 一键安装包” 的 第二篇,主要讲解 keepalived 的安装与配置!
第一篇 haproxy 安装与配置
第二篇 keepalived 安装与配置
第三篇 haproxy + keepalived 一键安装包(keepalived 为haproxy 做 HA 高可用)
第四篇 haproxy + keepalived “一键安装包” 配置与测试HOWTO
下面开始:
1 keepalived 安装需要的文件!!!
keepalived.conf #配置文档,将被keepalived_install.sh 脚本调用
keepalived_install.sh #安装脚本,有三个参数;推荐 backup 与 backup-2
----------------
sh keepalived_install.sh
Usage: keepalived_install.sh {master|backup|backup-2}
master 安装类型为: master模式
backup 安装类型为: backup 模式(优先级为 150; 有nopreempt 参数)
backup-2 安装类型为: backup 模式(优先级为 100; 没有nopreempt 参数)
keepalived.sh #keepalived 服务脚本 ,功能 启动 关闭
#keepalived 源码包
2 keepalived.conf 配置文档解释
#全局配置
global_defs { #全局定义
notification_email { #通知邮件
root@localhost #
}
notification_mail_form root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id haproxy #keepalived 机器标识
}
#vrrpd配置
vrrp_sync_group VG1 { #vrrp同步组定义
group {
VI_1 #vrrp实例 VI_1
}
}
vrrp_instance VI_1 { #vrrp实例定义
state BACKUP #实例初始化状态,还可以是master!
nopreempt #不抢占,用于state 状态中,而且优先级要高于第二个backup
interface eth0 #实例绑定的网卡
track_interface { #设定额外监控的网卡,以下任意网卡故障,状态fault
eth0
eth1
}
virtual_router_id 51 #虚拟路由id(0-255)
priority 150 #优先级,高优先级的将竞选为 MASTER
advert_int 1 #检查间隔,默认1s
authentication {
auth_type PASS #认证方式,pass
auth_pass 1111 #认证密码
}
virtual_ipaddress { #虚拟ip地址(vip 可以为多个)
10.0.1.250/24 dev eth0 scope global #虚拟ip地址 绑定在 eth0 网卡
}
}
3 启动 keepalived 日志
Dec 11 09:35:09 four Keepalived: Starting Keepalived v1.2.2 (12/10,2011)
Dec 11 09:35:09 four Keepalived_vrrp: Registering Kernel netlink reflector
Dec 11 09:35:09 four Keepalived_vrrp: Registering Kernel netlink command channel
Dec 11 09:35:09 four Keepalived_vrrp: Registering gratutious ARP shared channel
Dec 11 09:35:09 four Keepalived: Starting VRRP child process, pid=3607
Dec 11 09:35:49 four Keepalived_vrrp: Opening file '/usr/local/keepalived/keepalived.conf'.
Dec 11 09:35:49 four Keepalived_vrrp: Configuration is using : 64151 Bytes
Dec 11 09:35:49 four Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
Dec 11 09:35:49 four Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
4 vrrp包,vrid 51 ,10.0.1.251 发送vrrp包到 组播地址,224.0.0.18
tcpdump -vv vrrp
20:42:20.703999 IP (tos 0x0, ttl 255, id 8414, offset 0, flags [none], proto: VRRP (112), length: 40) 10.0.1.251 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 20, addrs: 10.0.1.250 auth "1111^@^@^@^@"
20:42:21.707222 IP (tos 0x0, ttl 255, id 8415, offset 0, flags [none], proto: VRRP (112), length: 40) 10.0.1.251 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 20, addrs: 10.0.1.250 auth "1111^@^@^@^@"
20:42:22.702427 IP (tos 0x0, ttl 255, id 8416, offset 0, flags [none], proto: VRRP (112), length: 40) 10.0.1.251 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 20, addrs: 10.0.1.250 auth "1111^@^@^@^@"
20:42:23.704223 IP (tos 0x0, ttl 255, id 8417, offset 0, flags [none], proto: VRRP (112), length: 40) 10.0.1.251 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 20, addrs: 10.0.1.250 auth "1111^@^@^@^@"
20:42:24.706683 IP (tos 0x0, ttl 255, id 8418, offset 0, flags [none], proto: VRRP (112), length: 40) 10.0.1.251 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 20, addrs: 10.0.1.250 auth "1111^@^@^@^@"
20:42:25.718362 IP (tos 0x0, ttl 255, id 8419, offset 0, flags [none], proto: VRRP (112), length: 40) 10.0.1.251 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 20, addrs: 10.0.1.250 auth "1111^@^@^@^@"
20:42:26.719005 IP (tos 0x0, ttl 255, id 8420, offset 0, flags [none], proto: VRRP (112), length: 40) 10.0.1.251 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 150, authtype simple, intvl 1s, length 20, addrs: 10.0.1.250 auth "1111^@^@^@^@"
结束
shell 脚本如有bug ,欢迎反馈!
mail:dngood@sina.com
qq群: 37275208
本文出自 “dongnan” 博客,转载请与作者联系!