六.Keepalived配置(backup)
Backup的配置与master的配置基本相同,只要修改几个方面即可,这里不再贴出完整代码,只写出差异的部分
1.将两处state MASTER 修改为state BACKUP
2.将两处priority 100 修改为priority 80
七.Keepalived,web整合配置(web1与web2均做此配置)
因为我们是使用的DR模式,所以需要对web服务器进行配置arp忽略与虚拟ip
[root@web1 ~]# ifconfig lo:0 192.168.1.100 broadcast 192.168.1.100netmask 255.255.255.255 //设置虚拟ip
[root@web1~]# echo "net.ipv4.conf.all.arp_ignore = 1" >>/etc/sysctl.conf
[root@web1~]# echo "net.ipv4.conf.lo.arp_ignore = 1" >>/etc/sysctl.conf
[root@web1~]# echo "net.ipv4.conf.all.arp_announce = 2">>/etc/sysctl.conf
[root@web1 ~]# echo "net.ipv4.conf.lo.arp_announce = 2">>/etc/sysctl.conf
八.测试
由于设定的是master为keepalived为主服务器,所以可以在master上查看是否有虚拟地址
[root@master keepalived]# ip addr
应该能找到如下内容
2: eth1:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000
link/ether 00:0c:29:70:64:a3 brdff:ff:ff:ff:ff:ff
inet 192.168.1.31/24 brd 192.168.1.255scope global eth1
inet 192.168.1.100/32 scope global eth1 //可以看到虚拟ip已经出现
inet6 fe80::20c:29ff:fe70:64a3/64 scopelink
valid_lft forever preferred_lft forever
3: eth2:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000
link/ether 00:0c:29:70:64:ad brdff:ff:ff:ff:ff:ff
inet 10.1.13.51/24 brd 10.1.13.255 scopeglobal eth2
inet 10.1.13.54/32 scope global eth2 //还有这儿的虚拟ip
inet6 fe80::20c:29ff:fe70:64ad/64 scopelink
valid_lftforever preferred_lft forever
也可以安装ipvsadm来查看配置
[root@masterkeepalived]# yum install ipvsadm
查看配置
[root@master keepalived]# ipvsadm -L
IPVirtual Server version 1.2.1 (size=4096)
ProtLocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.100:http rr
-> 192.168.1.13:http Route 1 0 2
-> 192.168.1.14:http Route 1 0 2
[root@master keepalived]#
在ip add 命令下只有主服务器才会出现虚拟vip,但是在两个keepalived主机上都会显现ipvsadm下的命令,这个不知道为什么,还要去请教高手,但是如果进行访问的话,从访问次数上来只有master下才会起作用
现在使用虚拟ip地址来查看网页
现在我们来测试一下高可用性,把master的keepalived stop,看会不会进行vip的转移
在master上关闭keepalived服务,查看backup上ip addr是否出现vip
[root@master keepalived]# servicekeepalived stop
在backup上查看
[root@backup ~]# ip addr
2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000
link/ether 00:0c:29:1f:6f:f3 brdff:ff:ff:ff:ff:ff
inet 192.168.1.32/24 brd 192.168.1.255scope global eth0
inet 192.168.1.100/32 scope global eth0 //可以看到虚拟ip
inet6 fe80::20c:29ff:fe1f:6ff3/64 scopelink
valid_lft forever preferred_lft forever
3: eth2:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen1000
link/ether 00:0c:29:1f:6f:fd brdff:ff:ff:ff:ff:ff
inet 10.1.13.52/24 brd 10.1.13.255 scopeglobal eth2
inet 10.1.13.54/32 scope global eth2
inet6 fe80::20c:29ff:fe1f:6ffd/64 scopelink
valid_lft forever preferred_lft forever
再通过浏览器查看网页
也是正常的,高可用性也是成功的.
Keepalived配置出现的问题及解决方法
错误一:
configure: error:
!!!OpenSSL is not properly installed on your system. !!!
!!!Can not include OpenSSL headers files. !!!
安装openssl-devel
yum install openssl-devel
错误二:
configure: error: Popt libraries isrequired
安装popt开发包
yum install popt-devel
错误三:
[root@master keepalived-1.2.2]# servicekeepalived start
Starting Keepalived for LVS: /bin/bash:keepalived: command not found
[FAILED]
解决方法:
[root@backup ~]# cp/usr/local/sbin/keepalived /usr/sbin/