Linux-脚本安装和卸载Keepalived

安装

#!/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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值