本文适用于使用源码部署的Tars框架。
具体部署请参考腾讯开源后台开发框架Tars安装。
这种方式安装的框架,其各个服务是编译出来的独立的进程,所以更新时也是独立更新。
注意:不建议单独更新某一个模块,因为各个模块的版本可能存在依赖关系,建议整套升级。
本文是笔者自行安装后的总结,具体以官方发布为准。
git clone https://github.com/TarsCloud/TarsFramework.git --recursive
如果已经有这个代码,执行’git pull’更新即可。
// 同安装流程
cd TarsFramework
git submodule update --remote --recursive
cd build
cmake ..
make -j4
框架服务的安装分两种:
tarsAdminRegistry, tarsregistry, tarsnode, tarsconfig, tarspatch
tarsstat, tarsproperty,tarsnotify, tarslog,tarsquerystat,tarsqueryproperty
编译后,所有服务的二进制可执行文件均已生成,进行服务替换即可。
单个服务的替换操作为:
// 谨慎操作,建议替换前先备份
cp -rf tarsregistry/bin/tarsregistry /usr/local/app/tars/tarsregistry/bin/tarsregistry
// 启动
/usr/local/app/tars/tarsregistry/bin/util/start.sh
可以待所有服务都替换完毕后,再重启tars框架。步骤略(可参考下节的自动升级)。
3+. 服务自动升级
每次一个一个升级会比较麻烦,我已经整理了一个脚本,可替换所有服务,最后重启Tars框架:
$ cat update.sh
#!/bin/sh
# 注意本脚本在编译后的build目录下执行
# 使用root权限
# 本脚本未做备份,建议提前备份各服务
# 输出脚本执行过程
set -x
# 定义代表服务的变量
s1="tarsnode"
s2="tarsAdminRegistry"
s3="tarsregistry"
s4="tarsconfig"
s5="tarspatch"
s6="tarsstat"
s7="tarsproperty"
s8="tarsnotify"
s9="tarslog"
s10="tarsquerystat"
s11="tarsqueryproperty"
# 定义目录
SRC="servers/"
DST="/usr/local/app/tars/"
# 开始拷贝
yes | cp -rf ${SRC}${s1}/bin/${s1} ${DST}${s1}/bin/ || echo "install ${s1} failed"
yes | cp -rf ${SRC}${s2}/bin/${s2} ${DST}${s2}/bin/ || echo "install ${s2} failed"
yes | cp -rf ${SRC}${s3}/bin/${s3} ${DST}${s3}/bin/ || echo "install ${s3} failed"
yes | cp -rf ${SRC}${s4}/bin/${s4} ${DST}${s4}/bin/ || echo "install ${s4} failed"
yes | cp -rf ${SRC}${s5}/bin/${s5} ${DST}${s5}/bin/ || echo "install ${s5} failed"
yes | cp -rf ${SRC}${s6}/bin/${s6} ${DST}${s6}/bin/ || echo "install ${s6} failed"
yes | cp -rf ${SRC}${s7}/bin/${s7} ${DST}${s7}/bin/ || echo "install ${s7} failed"
yes | cp -rf ${SRC}${s8}/bin/${s8} ${DST}${s8}/bin/ || echo "install ${s8} failed"
yes | cp -rf ${SRC}${s9}/bin/${s9} ${DST}${s9}/bin/ || echo "install ${s9} failed"
yes | cp -rf ${SRC}${s10}/bin/${s10} ${DST}${s10}/bin/ || echo "install ${s10} failed"
yes | cp -rf ${SRC}${s11}/bin/${s11} ${DST}${s11}/bin/ || echo "install ${s11} failed"
# 重启Tars框架
/usr/local/app/tars/tars-start.sh
以上脚本运行完毕后,所有服务都已更新。
后台的服务都升级完成后,还需要升级TarsWeb。
这里只介绍v2.4.7以上版本的更新。
对于新版本,tars-web由一个模块组成:tars-node-web
: tars-web主页面服务, 默认绑定3000端口, 源码对应web目录。
通过pm2 list
查看模块运行状态。如果没有这个命令,执行:source /etc/profile
配置环境变量。
web的默认安装位置在 /usr/local/app/web
,下载最新代码后,执行以下操作:
web/config/webConf.js, web/config/tars.conf
,修改db的ip为当前mysql ip, 修改tars的ip为当前环境的registry的ippm2 restart tars-node-web
关于配置文件的修改,可以在旧代码中先将那两个文件拷贝备用,下载最新代码后再覆盖回去就行了。
此时,执行pm2 list
可以看到如下输出:
刷新页面即可在右上角看到版本号。
对于使用Dcache的同学,现在方便多了,编译后,利用官方升级脚本,实现一键安装升级:
# 下载代码、编译完成后执行以下指令即可
../deploy/install.sh TARS_MYSQL_IP TARS_MYSQL_PORT TARS_MYSQL_USER TARS_MYSQL_PASSWORD DCACHE_MYSQL_IP DCACHE_MYSQL_PORT DCACHE_MYSQL_USER DCACHE_MYSQL_PASSWORD CREATE(true/false) WEB_HOST WEB_TOKEN NODE_IP
如我的机器上直接执行:
../deploy/install.sh 192.168.1.2 3306 tars tars@123456 192.168.1.2 3306 dcache dcache2019 false 192.168.1.2:3000 c63ae454524e9454dsfsaea3639ea9d1c6354221 192.168.1.2
这样公共包都安装好了。
下面就可以开始发布模块了。
这样升级是相对麻烦了点。
做过一次之后,写成脚本,再次升级时就简单了。
只需要做好备份和检查,基本没问题。
最后,建议不要升级太频繁,因为仓库版本的稳定性还是需要验证的。