tars平台批量部署服务脚本

官方接口文档

https://tarscloud.github.io/TarsDocs/dev/tars-web-api.html#deploy-server

由于工作原因,上不同的平台, 需要部署很多微服务,如果一个一个服务部署就很消耗体力,于是便写了一个脚本,批量部署

#!/bin/bash

#CGI 节点数量
CGINodeNum=1

#tars服务节点数量
TarsNodeNum=2

#base服务节点数量,设置是0,则自动部署到tars服务节点
BaseNodeNum=1


# 设置 tarsweb 地址  //'http://default.tarsweb.xming6.net/ 的域名 #tarsweb=default.tarsweb.xming6.net
tarsweb=default.tarsweb.xming6.net


# 设置 tarswebIP 绑定 tarsweb 的ip  
tarswebIP=192.168.102.43

# 设置 tarswebTicket 在tarsweb 用户中心生成  
tarswebTicket=d37c80dd24zz1d295bcea255c73ccd59676293PP

if [ "${tarsweb}" = "" ]; then
	echo "请设置 tarsweb 域名 !"
	exit 1
fi

if [ "${tarswebIP}" = "" ]; then
	echo "请设置 tarswebIP 地址 !"
	exit 1
fi

if [ "${tarswebTicket}" = "" ]; then
	echo "请设置 tarswebTicket !"
	exit 1
fi


## 需要处理的包
tarsSvcList=( 
    "TARS,Mmdb,tars_go,tars.cmdb.default,MainObj:10017"
    "TARS,DOOM,tars_php,tars.tarsphp.tcp,MainObj:10018|DrillTodoObj:10019"
    "HTTP,Account,tars_go,tars.go.default,Account.webObj:10075"
    "HTTP,kk,tars_nodejs,tars.nodejs.default,webObj:10076"
)


function ServantInfo(){
    AppName=$1
    AppSvc=$2
    SvcType=$3
    TemplateName=$4
    NodeName=$5
    protocol=$6
    ServantList=$7

    adapters=""
    for ServantInfo in ${ServantList[@]}
    do
        Servant=(${ServantInfo//:/ })
         if [ ${#adapters} -gt 0 ]; then
            adapters="${adapters},"
         fi
         adapters="${adapters}{\"obj_name\":\"${Servant[0]}\",\"bind_ip\":\"${NodeName}\",\"port\":\"${Servant[1]}\",\"port_type\":\"tcp\",\"protocol\":\"${protocol}\",\"thread_num\":8,\"max_connections\":200000,\"queuecap\":10000,\"queuetimeout\":60000}"

    done

    deployBody="{\"application\":\"${AppName}\",\"server_name\":\"${AppSvc}\",\"node_name\":\"${NodeName}\",\"server_type\":\"${SvcType}\",\"template_name\":\"${TemplateName}\",\"enable_set\":false,\"set_name\":\"\",\"set_area\":\"\",\"set_group\":\"\",\"adapters\":[${adapters}]}"

    echo ${deployBody}

    curl -i -x "" http://${tarswebIP}/api/deploy_server?ticket=${tarswebTicket}   -H "Host:${tarsweb}"  -H "Content-Type:application/json" -d "${deployBody}"
}



## deployBody
function deployServer(){

 AppName=$1
 AppSvc=$2
 SvcType=$3
 TemplateName=$4
 ServantString=$5
 ServantList=(${ServantString//|/ })

 if [ "TNebula" == ${AppName} ]; then

    if  [ ${BaseNodeNum} -gt 0 ] && [ "Cmdb" == ${AppSvc} -o "Cmdbx" == ${AppSvc} -o "UnifiedAccount" == ${AppSvc} -o "Task" == ${AppSvc} -o "UnifiedPrivilege" == ${AppSvc} ]; then
        for((nodeId=0;nodeId<${BaseNodeNum};nodeId++));
          do
            node_name="tars-node-base-1-${nodeId}.tars-node-svc-base-1"
            ServantInfo ${AppName} ${AppSvc} ${SvcType} ${TemplateName} ${node_name} "tars" ${ServantList}
         done
    else
      for((nodeId=0;nodeId<${TarsNodeNum};nodeId++));
           do
             node_name="tars-node-${nodeId}.tars-node-svc"
             ServantInfo ${AppName} ${AppSvc} ${SvcType} ${TemplateName} ${node_name} "tars" ${ServantList}
          done
    fi

 elif [ "TNHTTP" == ${AppName} ]; then
    for((nodeId=0;nodeId<${CGINodeNum};nodeId++));
       do
         node_name="tars-node-cgi-0-${nodeId}.tars-node-svc-cgi-0"
         ServantInfo ${AppName} ${AppSvc} ${SvcType} ${TemplateName} ${node_name} "not_tars" ${ServantList}
    done
 fi

}

for tarsSvc in ${tarsSvcList[@]}
do
  tarsSvcInfo=(${tarsSvc//,/ })
  echo ${tarsSvcInfo[1]}

  deployServer ${tarsSvcInfo[0]} ${tarsSvcInfo[1]} ${tarsSvcInfo[2]} ${tarsSvcInfo[3]} ${tarsSvcInfo[4]}

done



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值