标签:
环境信息
keepalived master 192.168.1.106
keepalived backup 192.168.1.103
vip 192.168.1.100
1,安装keepalived,我用的是1.1.17
tar -zvxf keepalived-1.1.17.tar.gz
cd keepalived-1.1.17
./configure
这一步可能会遇到缺少openssl,popt。如果缺少的话可以yum安装一下
#yum install openssl-devel
#yum install popt-devel
编译之后
make
make install
然后
/bin/cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d
/bin/cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
/bin/cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived
/bin/cp /usr/local/sbin/keepalived /usr/sbin/
修改配置文件
画线的地方backup一定不能重复
backup需要注意
1,router_id 唯一的
2,state MASTER 改成BACKUP。大写
3,priority 改成50.一般建议backup比master小50. master挂掉之后,会选择优先级最大的充当master
4,virtual_router_id 51。一定要和master一致。不然会出现裂脑
5.关于邮件部分,随便写下
backup的配置如下:
! Configuration File for keepalived 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_02 } vrrp_instance VI_2 { state BACKUP interface eth1 virtual_router_id 51 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.100/24 } }
/etc/init.d/keepalived start 启动
日志默认路径
/var/log/message
看了下日志发现日志一直刷屏,提示Can‘t initialize ipvs
这是由于ipvs模块没有加载
手动加载一下
modprobe ip_vs
modprobe ip_vs_wrr
然后重新
/etc/init.d/keepalived start
ps -ef | grep keep
会发现三个进程
[root@masters keepalived]# ps -ef | grep keep root 9276 8440 0 19:28 pts/1 00:00:00 vi keepalived.conf root 9490 1 1 19:40 ? 00:00:00 keepalived -D -d -S 0 root 9492 9490 0 19:40 ? 00:00:00 keepalived -D -d -S 0 root 9493 9490 0 19:40 ? 00:00:00 keepalived -D -d -S 0 root 9496 8440 5 19:40 pts/1 00:00:00 grep keep
怎么查看vip生效没呢
通过ip add命令
[root@masters keepalived]# ip add 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:0c:29:4a:fb:1d brd ff:ff:ff:ff:ff:ff inet 192.168.1.106/24 brd 192.168.1.255 scope global eth0 inet 192.168.1.100/24 scope global secondary eth0 inet6 fe80::20c:29ff:fe4a:fb1d/64 scope link valid_lft forever preferred_lft forever 3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN link/ether fe:c8:58:f7:2c:04 brd ff:ff:ff:ff:ff:ff
发现192.168.1.100已经被绑定到网卡上了
然后再backup上再ip add一下,结果如下
[root@slaves keepalived]# [root@slaves keepalived]# ip add 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:0c:29:25:98:10 brd ff:ff:ff:ff:ff:ff inet 192.168.1.103/24 brd 192.168.1.255 scope global eth1 inet6 fe80::20c:29ff:fe25:9810/64 scope link valid_lft forever preferred_lft forever 5: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN link/ether e2:15:b8:9d:56:eb brd ff:ff:ff:ff:ff:ff [root@slaves keepalived]#
发现vip没有绑定到网卡上,这是正常的,如果backup的vip也绑定网卡了就可能是裂脑了
然后把master上的keepalived kill掉,发现backup的vip会绑定到网卡上,这就说明keepalived配置成功
你可以在两台机器上安装下tomcat。通过192.168.1.100 访问下文件
下一篇结合nginx说下keepalived是怎么用的
标签:
原文地址:http://www.cnblogs.com/zpitbolg/p/5476978.html