简介
有时候,一个系统既有部署在Linux上的应用,也有需要部署在Windows上的应用。它们共存的现象很常见。
在使用Tars框架时,已经部署好了Linux下的Tars框架和web,现在需要业务服务发布在Windows上,就需要把Windows部署为节点服务器(节点机)。
如果希望业务服务发布到节点服务器, 就需要将节点服务器连接到框架上, 这步操作即在节点服务器上安装tarsnode.
对于Linux下的安装,直接使用web平台上的自动安装功能就ok了,Windows目前需要手动安装。
手动部署
首先准备好Windows设备。它需要能够访问已经部署好的Tars web。
这里分为两种情况:
- 主节点Framework安装在Windows上,较简单
- 主节点Framework安装在Linux上,复杂一点
下面分别介绍。
主节点Framework安装在Windows上
此时,主节点安装的包都是可以直接用的,按照以下步骤即可:
-
在节点机打开浏览器:
http://${webhost}/get_tarsnode?ip=${localip}
- ${webhost}是web平台地址, ${localip}是节点机ip
- web平台地址需要加端口号,如192.168.1.68:3000
-
将得到的输出保存为:
install_tarsnode.sh
-
下载busybox:
http://${webhost}/files/busybox.exe
,通过其他渠道下载也可以 -
window命令行运行:
busybox.exe sh install_tarsnode.sh
,此时节点机安装完成,可以看到tarsnode进程- 该脚本会自动从web拉取tarsnode安装包,并解压安装
- 安装前会先行根据参数修改配置文件
- 使用bat脚本启动
-
windows计划任务中增加监控:
c:\tars-install\tars\tarsnode\util\monitor.bat
,确保down后自动拉起 -
在web界面的运维管理-节点管理中就可以查看到该节点机,并可以检查其连通性
-
完成安装, 缺省目录: c:\tars-install\tars
安装中如果出现以下情况,需要先安装程序运行时依赖库。百度下载安装即可。
主节点Framework安装在Linux上
此时,主节点安装的包都是Linux下的,不通直接在Windows下使用,需要按照以下步骤操作:
-
手工编译Windows下的tarsnode(我这里使用的是git bash终端,使用cmd终端时可以根据脚本内容执行)
- 下载Windows下的Framework
- 进入build目录,执行
./build.sh
可以看到help信息 - 执行
./build.sh prepare && ./build.sh all
进行编译 - 由于该脚本是为Linux下写的,make时会失败,因为cmake会生成sln而非Makefile
- 此时,执行:
cmake --build . --config RelWithDebInfo && cmake --build . --config RelWithDebInfo --target install
- 默认的安装完成后的路径为c:/tars-install, 把tarsnode拷贝到指定位置(c:/tars-install/tars/)待用
-
在节点机打开浏览器:
http://${webhost}/get_tarsnode?ip=${localip}
- ${webhost}是web平台地址, ${localip}是节点机ip
- web平台地址需要加端口号,如192.168.1.68:3000
-
将得到的输出保存为:
install_tarsnode.sh
,脚本内容大概为(webhost为192.168.1.142:3000, localip:192.168.1.62):
#!/bin/bash
#/**
# * Tencent is pleased to support the open source community by making Tars available.
# *
# * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
# *
# * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
# * in compliance with the License. You may obtain a copy of the License at
# *
# * https://opensource.org/licenses/BSD-3-Clause
# *
# * Unless required by applicable law or agreed to in writing, software distributed
# * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# * CONDITIONS OF ANY KIND, either express or implied. See the License for the
# * specific language governing permissions and limitations under the License.
# */
echo "runuser: tars, webHost:http://192.168.1.142:3000, machine_ip:192.168.1.62, registryAddress:tcp -h 192.168.1.142 -p 17890:tcp -h 192.168.1.143 -p 17890"
OSNAME=`uname`
OS=1
if [[ "$OSNAME" == "Darwin" ]]; then
OS=2
elif [[ "$OSNAME" == "Windows_NT" ]]; then
OS=3
else
OS=1
fi
if [ $OS != 3 ]; then
TARS_PATH=/usr/local/app/tars
else
TARS_PATH=c:/tars-install/tars
fi
if [ $OS != 3 ]; then
if [ ! -d "/usr/local/app" ]; then
echo "create tars base path: "
mkdir -p /data/app
ln -s /data/app /usr/local/app
fi
fi
mkdir -p ${TARS_PATH}
rm -rf tarsnode.tgz
wget http://192.168.1.142:3000/files/tarsnode.tgz
#休息1s, 避免下载的文件没有写成功
sleep 1
if [ ! -f "tarsnode.tgz" ]; then
echo "Tars node download error: http://192.168.1.142:3000/files/tarsnode.tgz"
exit
fi
if [ 'tcp -h 192.168.1.142 -p 17890:tcp -h 192.168.1.143 -p 17890' == '' ]; then
echo "registryAddress is empty."
exit
fi
if [ '192.168.1.62' == '' ]; then
echo "machine_ip is empty."
exit
fi
tar zxf tarsnode.tgz
if [ $OS != 3 ]; then
if [ -f ${TARS_PATH}/tarsnode/util/stop.sh ]; then
${TARS_PATH}/tarsnode/util/stop.sh
fi
else
if [ -f ${TARS_PATH}/tarsnode/util/stop.bat ]; then
${TARS_PATH}/tarsnode/util/stop.bat
fi
fi
cp -rf tarsnode ${TARS_PATH}/
cd ${TARS_PATH}
echo "local machine ip:[192.168.1.62] succ"
echo "tars registry:" tcp -h 192.168.1.142 -p 17890:tcp -h 192.168.1.143 -p 17890
sed -i "s/localip.tars.com/192.168.1.62/g" ${TARS_PATH}/tarsnode/conf/tars.tarsnode.config.conf
sed -i "s/registryAddress/tcp -h 192.168.1.142 -p 17890:tcp -h 192.168.1.143 -p 17890/g" ${TARS_PATH}/tarsnode/conf/tars.tarsnode.config.conf
if [ $OS != 3 ]; then
sed -i "s/registryAddress/tcp -h 192.168.1.142 -p 17890:tcp -h 192.168.1.143 -p 17890/g" ${TARS_PATH}/tarsnode/util/execute.sh
sed -i "s/localip.tars.com/192.168.1.62/g" ${TARS_PATH}/tarsnode/util/execute.sh
else
sed -i "s/registryAddress/tcp -h 192.168.1.142 -p 17890:tcp -h 192.168.1.143 -p 17890/g" ${TARS_PATH}/tarsnode/util/execute.bat
sed -i "s/localip.tars.com/192.168.1.62/g" ${TARS_PATH}/tarsnode/util/execute.bat
fi
echo "install tarsnode succ, start tarsnode"
if [ $OS != 3 ]; then
id -u tars &>/dev/null
if [ $? != 0 ]; then
useradd tars
fi
chown -R tars:tars /usr/local/app/*;
${TARS_PATH}/tarsnode/util/stop.sh
uid=`whoami`
if [ "$uid" != "tars" ] && [ "tars" != "" ]; then
echo "su $runuser: now uid:$uid, runuser:$runuser"
su - $runuser -c "sh ${TARS_PATH}/tarsnode/util/start.sh"
else
sh ${TARS_PATH}/tarsnode/util/start.sh
fi
else
${TARS_PATH}/tarsnode/util/start.bat
fi
INFO=`ps -e | grep tarsnode`
if [[ "${INFO}" != "" ]]; then
echo 'Tars node installed success'
else
echo 'Tars node installed failed'
fi
-
修改脚本相关内容:
- 注释掉48-58行,70行,82行三处,不再从web下载tarsnode,使用刚自己编译的tarsnode
-
下载busybox:
http://${webhost}/files/busybox.exe
,通过其他渠道下载也可以 -
window命令行运行:
busybox.exe sh install_tarsnode.sh
,此时节点机安装完成,可以看到tarsnode进程 -
windows计划任务中增加监控:
c:\tars-install\tars\tarsnode\util\monitor.bat
,确保down后自动拉起 -
在web界面的运维管理-节点管理中就可以查看到该节点机,并可以检查其连通性
此时,部署完成。