consul 高版本升级

 

在协议兼容的情况下,先挨个升级服务端节点,完毕后,再同样操作升级客户端:
1、线上正在运行版本Consul v0.6.4 ,计划升级版本Consul v1.2.3
2、首先把Consul v1.2.3上传到每个节点服务上
3、关闭Consul v0.6.4 版本,使用 -raft-protocol=2 启动 Consul v1.2.3
4、当所有的节点服务都运行了Consul v1.2.3,则使用去掉 -raft-protocol=2参数的命令并重启,遍历重启所有Consul v1.2.3代理服务
5、consul 升级脚本

#!/bin/bash

sed -i '/consul_update\.sh/d' /etc/crontab
echo "delete crond from /etc/crontab" > /tmp/consul_update.log 
source /etc/profile

if [ ! -n "$DEPLOY_GROUP_NAME" ] ; then
echo "DEPLOY_GROUP_NAME is null, system exit!" >> /tmp/consul_update.log 
exit 1 
fi
dc_name=`echo -n $DEPLOY_GROUP_NAME | awk -F "-" '{print $1"-"$2}'`
consul_service=`ps -ef|grep "consul"|grep "bootstrap-expect"|grep -v "grep"|awk '{print $2}'`
echo "dc_name is :"$dc_name >> /tmp/consul_update.log 
overseas="s3-us-west-2.amazonaws.com/海外区存储桶"

cn_home="s3.cn-north-1.amazonaws.com.cn/国内存储桶"

if [ "$dc_name" == "test-cn1" ] || [ "$dc_name" == "test-cn" ] || [ "$dc_name" == "dev-jx1" ] || [ "$dc_name" == "test-jx1" ] || [ "$dc_name" == "prod-cn1" ] ; then
downloadurl=${cn_home}
else
downloadurl=${overseas}
fi

echo "downloadurl is :"${downloadurl} >> /tmp/consul_update.log
current_consul=$(/usr/bin/consul -v|sed -n '1p'|awk '{print $2}')
echo "befor update consul version is :"$current_consul >> /tmp/consul_update.log 
if [ -n "$current_consul" ] && [ "$current_consul" == "v0.6.4" ];then
    rm -f consul.zip
    wget https://${downloadurl}/consul/consul.zip
    unzip -o consul.zip
    mv /usr/bin/consul  /usr/bin/consulbak
    chmod 755 consul
    mv consul /usr/bin/consul

elif [ -n "$current_consul" ] && [ "$current_consul" == "v1.2.3" ];then
    rm -f consul6.zip
    wget https://${downloadurl}/consul/consul6.zip
    unzip -o consul6.zip
    mv /usr/bin/consul  /usr/bin/consulbak
    chmod 755 consul6
    mv consul6 /usr/bin/consul
else
    echo "current node not have consul .......system exit!" >> /tmp/consul_update.log
    exit 1 
fi


echo "after update  consul version is :"$(/usr/bin/consul -v|sed -n '1p'|awk '{print $2}') >> /tmp/consul_update.log 

if [ -n "$consul_service" ] && [ "$current_consul" == "v0.6.4" ];then
##sed -i "/taildir_position.json/r /tmp/flume_replace.conf" /opt/sengled/consul/consul.sh
    sed -i 's/-bootstrap-expect=5/& -raft-protocol=2/' /opt/sengled/consul/consul.sh
    echo "modify consul.sh add -raft-protocol" >> /tmp/consul_update.log 
elif [ -n "$consul_service" ] && [ "$current_consul" == "v1.2.3" ];then
    sed -i 's/-raft-protocol=2/ /g' /opt/sengled/consul/consul.sh
    echo "modify consul.sh del -raft-protocol" >> /tmp/consul_update.log 
fi

\cp consul.sh run
ps -ef|grep consul|grep config-dir|grep -v grep|awk '{print $2}'| xargs kill -9
echo "restart consul...........">> /tmp/consul_update.log 
sleep 3
/usr/bin/consul -v
/usr/bin/consul members
ps -ef|grep consul
echo "current consul cluster info:"$(/usr/bin/consul members) >> /tmp/consul_update.log 

 

posted @ 2019-02-22 14:21  老农夫  阅读(822)  评论(0编辑  收藏  举报