1.keepalived 下载 地址 目前最新版本
2.安装keepalived
tar -axvf keepalived-1.2.2.tar.gz
./configure --prefix=PREFIX(指定安装路径) --with-kernel-version=VER (指定内核版本)
Keepalived configuration
------------------------
Keepalived version : 1.2.2
Compiler : gcc
Compiler flags : -g -O2 -DETHERTYPE_IPV6=0x86dd
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : No
IPVS sync daemon support : No
Use VRRP Framework : Yes
Use Debug flags : No
默认是关闭LVS的支持,如果你需要开启这个功能编译的开启即可
make
make install
3.配置 keepalived.conf文件
! Configuration File for keepalived
vrrp_instance VI_1 {
state BACKUP (状态)
interface eth0 (心跳网卡)
virtual_router_id 51 (实例,这要跟对端的名字一样)
priority 100 (优先级)
advert_int 1 (间隔时间)
nopreempt (闭闭抢站,不指这个参数默认是开启的)
authentication { (认证信息)
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.177.200 (虚拟IP地址)
}
}
4.启动keepalived
../../sbin/keepalived -f keepalived.conf (注意这种写法有有问题需要写绝对路径,这样会导致起动的时候不读配置文件)
../../sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf(这个才是正确)
5.检查
oot@192_168_177_36 keepalived-1.2.2]# ps aux|grep keepalived
root 6976 0.0 0.0 4888 568 ? Ss 13:12 0:00 ../../sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf
root 6977 0.0 0.0 4932 916 ? S 13:12 0:00 ../../sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 14:fe:b5:cf:8f:ae brd ff:ff:ff:ff:ff:ff
inet 192.168.177.36/24 brd 192.168.177.255 scope global eth0
inet 192.168.177.200/32 scope global eth0
inet6 fe80::16fe:b5ff:fecf:8fae/64 scope link
valid_lft forever preferred_lft forever
[root@192_168_177_36 keepalived-1.2.2]# tcpdump dst 224.0.0.18
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
13:23:40.947767 IP 192.168.177.37 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 110, authtype simple, intvl 1s, length 20
13:23:41.049223 IP 192_168_177_36.localdomain > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
13:23:41.948702 IP 192.168.177.37 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 110, authtype simple, intvl 1s, length 20
13:23:42.050174 IP 192_168_177_36.localdomain > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
13:23:42.949652 IP 192.168.177.37 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 110, authtype simple, intvl 1s, length 20
13:23:43.051040 IP 192_168_177_36.localdomain > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
13:23:43.950513 IP 192.168.177.37 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 110, authtype simple, intvl 1s, length 20
13:23:44.052035 IP 192_168_177_36.localdomain > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
由于keepalived 是走的 VRRP协议,组播地址是224.0.0.18 配置的时候防火墙需要放行这个地址,你用TCP dump 的时候可以看到双向的HELOO 报文。
6.其它的一些功能看配置文件里面有个实例照着做就可以了
阅读(7033) | 评论(0) | 转发(0) |