1.安装keepalived(主备均安装)
cd/data/software
wgethttp://www.keepalived.org/software/keepalived-1.2.6.tar.gz
tar -zxvfkeepalived-1.2.6.tar.gz
cdkeepalived-1.2.6
./configure--prefix=/usr/local/keepalived
注:对于新服务器,在进行二进制安装时会出现几个报错,是因为系统缺少某些软件导致的
yum install openssl-*
yum install gcc popt-devel
然后再执行
./configure--prefix=/usr/local/keepalived
make
makeinstall
①建立服务启动脚本,以便使用service命令控制之
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
chmod +x /etc/init.d/keepalived
②修改/etc/init.d/keepalived寻找大约15行左右的./etc/sysconfig/keepalived, 修改为:
./usr/local/keepalived/etc/sysconfig/keepalived 即指向正确的文件位置
修改环境变量
vi /etc/profile
export PATH="$PATH:/usr/local/keepalived/sbin"
source /etc/profile
③修改/usr/local/keepalived/etc/sysconfig/keepalived文件,设置正确的服务启动参数
KEEPALIVED_OPTIONS="-D -f/usr/local/keepalived/etc/keepalived/keepalived.conf"
ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/
④经过以上修改,keepalived基本安装即可完成,启动测试之:
service keepalived start
⑤切勿忘记将此服务设置为开机启动
chkconfig keepalived on
2.配置主备模式
在这种模式下,虚拟IP在某时刻只能属于某一个节点,另一个节点作为备用节点存在。当主节点不可用时,备用节点接管虚拟IP,提供正常服务。
节点A 192.168.251.144 (主节点),
节点B 192.168.251.141 (备节点)
虚拟IP 192.168.251.150
要求默认情况下由节点A提供服务,当节点A不可用时,由节点B提供服务当节点A启动后,信号自动从节点B切换到节点A,经测试,中间切换时间小于10s
主节点A配置文件 vi /usr/local/keepalived/etc/keepalived/keepalived.conf
! Configuration File for keepalived
vrrp_script check_keepalived {
script"/usr/local/keepalived/etc/keepalived/check_keepalived.sh"
interval 5
}
global_defs {
router_idNodeA
}
vrrp_instance VI_1 {
state MASTER
interfaceeth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress{
192.168.251.150/24
}
track_script{
check_keepalived
}
}
备节点B配置文件 vi /usr/local/keepalived/etc/keepalived/keepalived.conf
! Configuration File forkeepalived
global_defs {
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.251.150/24
}
}
编写进程检测脚本check_keepalived.sh
#!/bin/bash
if [ "$(ps-ef | grep "java"| grep WowzaStreamingEngine |grep -v grep )" =="" ]
then
service keepalived stop
fi
上传至/usr/local/keepalived/etc/keepalived/下,只需要在主服务器上添加。
六、启动:
启动wowza
servicekeepalived start/stop/status