安装
#!/bin/sh
DIR=`pwd`
KEEPALIVED_USR_DIR=/usr/local/keepalived
KEEPALIVED_DIR=/usr/local/keepalived-1.2.18
CONF=/etc/keepalived/keepalived.conf
CONF_BAK=/etc/keepalived/keepalived.conf.bak
CHECK=/etc/keepalived/onos_check.sh
CHECK_BAK=/etc/keepalived/onos_check.sh.bak
CHECK_REQ=/etc/keepalived/onos_check_req.sh
CHECK_REQ_BAK=/etc/keepalived/onos_check_req.sh.bak
echo "-----------------------------------install keepalived-------------------------------"
if [ -d $KEEPALIVED_DIR ]; then
echo "keepalived has installed"
# 替换配置文件
## 备份原来的文件和检查脚本
mv -f $CONF $CONF_BAK
mv -f $CHECK $CHECK_BAK
mv -f $CHECK_REQ $CHECK_REQ_BAK
## 拷贝新文件
cd $DIR
cp -f ./keepalived/keepalived.conf $CONF
chmod 777 ./keepalived/onos_check.sh
chmod 777 ./keepalived/onos_check_req.sh
# cp -f ./keepalived/onos_check.sh $CHECK
# 重启数据库
service keepalived restart
exit 3
fi
## 解压keepalived.tar.gz
cd $DIR
mkdir -p $KEEPALIVED_DIR
tar -vxf keepalived-1.2.18.tar.gz -C $KEEPALIVED_DIR --strip-components 1
## 编译keepalived
cd $KEEPALIVED_DIR && ./configure --prefix=$KEEPALIVED_USR_DIR
make && make install
## 将keepalived制作成系统服务
### 首先创建文件夹,将keepalived配置文件进行复制
mkdir -p /etc/keepalived
cd $DIR
### 复制配置文件
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp -f ./keepalived/keepalived.conf /etc/keepalived/
### 检查脚本复制
chmod 777 ./keepalived/onos_check.sh
#### 先不把检查脚本复制,等onos启动之后再复制过去
#cp onos_check.sh $CHECK
### 然后复制keepalived脚本文件
cp -f /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp -f /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -sf /usr/local/sbin/keepalived /usr/sbin/
ln -sf /usr/local/keepalived/sbin/keepalived /sbin/
### 设置开机启动
chkconfig keepalived on
### 解决启动报错
cd /usr/sbin/
rm -f keepalived
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
echo "-----------------------------------install keepalived success-------------------------------"
service keepalived start
cd $DIR
卸载
#!/bin/sh
service keepalived stop
rm -rf /usr/local/keepalived
rm -rf /usr/local/keepalived-1.2.18
rm -rf /etc/keepalived
rm -rf /etc/init.d/keepalived
rm -rf /etc/sysconfig/keepalived
rm -rf /usr/local/sbin/keepalived
rm -rf /usr/sbin/keepalived
rm -rf /sbin/keepalived