Tars是基于名字服务使用Tars协议的高性能RPC开发框架,同时配套一体化的服务治理平台,帮助个人或者企业快速的以微服务的方式构建自己稳定可靠的分布式应用。
官网:https://github.com/TarsCloud/Tars

本文主要参照官网中安装步骤,但是官网中使用的是Centos系统,对使用ubuntu系统的使用者来说其中很多的指令都是不一样的,本文中将介绍在ubuntu中安装的具体过程。

安装的过程主要分为以下几个部分:

1. 相关依赖库安装
2. Tars开发环境安装
3. Tars数据库环境初始化
4. Tars框架运行环境搭建
5. 安装框架普通基础服务

一、相关依赖库安装

  1. glibc-devel安装
    这个在ubuntu中对应的库名称是libc-dev,安装的命令为:
sudo apt-get install libc-dev
  1. cmake安装
sudo apt install cmake

(tars需要cmake的版本为2.8.8以上,可以用cmake –version查看版本)
3. 安装ncurses和zlib

apt-get install ncurses-dev
apt-get install zlib1g.dev
  1. mysql安装
    本人在安装mysql的时候遇到了很多的问题,一共使用了三种方法:第一种是按照官网安装,没有成功,到后面核心基础服务拉不起来;第二种是使用sudo apt-get install mysql-server安装mysql进行配置,同样的结果,发现在配完运行环境时就用不了mysql了;最后一种是安装mariadb,再安装mysql-5.6.26,这种方法成功了,所以接下来我就只具体介绍成功了的方法:
    (1) 首先安装mariadb
    参照:https://www.linuxidc.com/Linux/2017-04/142915.htm
    (2) 然后链接两个文件到/usr/local/mysql
ln -s /usr/include/mariadb /usr/local/mysql/include
ln -s /usr/lib/x86_64-linux-gnu /usr/local/mysql/lib

(3) 最后再安装编译mysql-5.6.26

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.26.tar.gz
sudo su
cd /usr/local
mkdir mysql-5.6.26
chown lz:lz ./mysql-5.6.26
ln -s /usr/local/mysql-5.6.26 /usr/local/mysql
tar zxvf mysql-5.6.26.tar.gz /usr/local/mysql-5.6.26

(如果不能解压成功,则先解压再使用cp -r来复制)
编译mysql

cd /usr/local/mysql-5.6.26
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.26 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make
make install

将 mysql 的静态库复制(或者链接)到为 Tars 基础框架准备的目录下

ln -s /home/ubuntu/mysql-5.6/libmysqlclient.a /usr/local/mysql/lib/

二 、Tars开发环境安装

1. web管理系统开发环境安装

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
source ~/.bashrc

node和带有负载功能的node应用的进程管理器pm2安装

nvm install v8.11.3
npm install -g pm2 --registry=https://registry.npm.taobao.org

2. c++开发环境安装

克隆源码:

git clone https://github.com/TarsCloud/TarsFramework
cd TarsFramework/build
chmod u+x build.sh
./build.sh prepare
sudo apt-get install protobuf-c-compiler protobuf-compiler libprotobuf-dev libprotobuf-c-dev libprotoc-dev
./build.sh all

注:我使用的protoc版本为3.1.0
安装成功后会得到如下结果:

等待编译成功。

sudo su
cd /usr/local
mkdir tars
chown lz:lz ./tars/

安装tars

cd /home/lz/TarsFramework/build/
./build.sh install

这样tars就按装到了/usr/local/tars/cpp

三、 Tars数据库环境初始化

打开mysql服务:

service mysql start
mysql -u root -p

输入密码后进入mysql:

grant all on *.* to 'tars'@'%' identified by 'tars2015' with grant option;
grant all on *.* to 'tars'@'localhost' identified by 'tars2015' with grant option;
grant all on *.* to 'tars'@'${hostname}' identified by 'tars2015' with grant option;
flush privileges;

其中{hostname}替换为你的电脑名。
退出sql编程,运行以下:

cd /home/lz/TarsFramework/sql
sed -i "s/192.168.2.131/192.168.1.117/g" `grep 192.168.2.131 -rl ./*`
sed -i "s/db.tars.com/192.168.1.117/g" `grep db.tars.com -rl ./*`
sed -i "s/10.120.129.226/192.168.1.117/g" `grep 10.120.129.226 -rl ./*`
sed -i "s/uroot/utars/g" exec-sql.sh
sed -i "s/proot@appinside/ptars2015/g" exec-sql.sh
chmod u+x exec-sql.sh
./exec-sql.sh

其中192.168.1.117为本机的IP,tars/tars2015为数据库的用户名/密码组合。

四、Tars框架运行环境搭建

1. 框架基础服务打包

准备核心基础服务:

cd /home/lz/TarsFramework/build
make framework-tar

会在当前目录生成framework.tgz 包 这个包包含了 tarsAdminRegistry, tarsregistry, tarsnode, tarsconfig, tarspatch 部署相关的文件

同时准备普通基础服务:

make tarsstat-tar
make tarsnotify-tar
make tarsproperty-tar
make tarslog-tar
make tarsquerystat-tar
make tarsqueryproperty-tar

2.安装框架核心基础服务

sudo su
mkdir -p /data/log/tars
mkdir -p /home/tarsproto
mkdir -p /usr/local/app/tars
chown -R lz:lz /usr/local/app /data/log/tars /home/tarsproto
cp /home/lz/TarsFramework/build/framework.tgz /usr/local/app/tars/
cd /usr/local/app/tars
tar xzfv framework.tgz

修改各个服务对应conf目录下配置文件,注意将配置文件中的ip地址修改为本机ip地址,如下:

sed -i "s/192.168.2.131/192.168.1.117/g" `grep 192.168.2.131 -rl ./*`
sed -i "s/db.tars.com/192.168.1.117/g" `grep db.tars.com -rl ./*`
sed -i "s/registry.tars.com/192.168.1.117/g" `grep registry.tars.com -rl ./*`
sed -i "s/web.tars.com/192.168.1.117/g" `grep web.tars.com -rl ./*`

其中,本机IP为 192.168.1.117

执行脚本,启动tars框架服务:

chmod u+x tars_install.sh
./tars_install.sh

3. 安装web管理系统

mkdir -p /home/lz/TarsFramework/TarsWeb
chown -R lz:lz /home/lz/TarsFramework/TarsWeb
cd /home/lz/TarsFramework/TarsWeb
git clone https://github.com/TarsCloud/TarsWeb.git ./
sed -i 's/db.tars.com/192.168.1.117/g' config/webConf.js
sed -i 's/registry.tars.com/192.168.1.117/g' config/tars.conf

其中,本机IP为 192.168.1.117

默认端口配置在3000上,可在config/webConf.js中修改。
启动Tars web 管理平台:

npm install --registry=https://registry.npm.taobao.org
npm run prd

调了几个node和npm的错误后终于配置成功了:

创建日志目录:

mkdir -p /data/log/tars

如果发现tarsnotify的当前状态不对,可以看后面问题解决部分,将tarsnotify服务重新发布一下。

同时你也可以用 pm2 stop tars-node-web来关闭tars web程序。

五、 安装框架普通基础服务

上面配置了三个核心基础服务,需要注意的是tarsnotify服务其实是没搭建起来的,还需要重新发布一下,直接按照官网中4.4节配置就行了,只不过还要注意tarslog服务发布的时候模板要选择tars.tarslog而不是tars.default。

最终配置好后在web上可以看到如下:

问题

1. 运行perl scripts/mysql_install_db --user=mysql时出现2018-12-28 16:16:24 18572 [ERROR] Can’t read from message file’/usr/share/mysql/english/errmsg.sys’

解决方法:

cp sql/share/english/errmsg.sys /usr/share/mysql/english

2. 运行service mysql start时出现:Failed to start mysql.service: Unit mysql.service not found.

解决方法:
先autoremove mariadb-server,然后在install mariadb-server

3. chkconfig:未找到命令

解决方法: 终端执行:

sudo apt install sysv-rc-conf
sudo cp /usr/sbin/sysv-rc-conf /usr/sbin/chkconfig

4. make install时出现:

/home/lz/TarsFramework/tarscpp/tools/pb2tarscpp/CppPlugin.cpp:8:45: fatal error: google/protobuf/compiler/plugin.h: 没有那个文件或目录
compilation terminated.
tarscpp/tools/pb2tarscpp/CMakeFiles/pb2tarscpp.dir/build.make:62: recipe for target 'tarscpp/tools/pb2tarscpp/CMakeFiles/pb2tarscpp.dir/CppPlugin.cpp.o' failed
make[2]: *** [tarscpp/tools/pb2tarscpp/CMakeFiles/pb2tarscpp.dir/CppPlugin.cpp.o] Error 1
CMakeFiles/Makefile2:1070: recipe for target 'tarscpp/tools/pb2tarscpp/CMakeFiles/pb2tarscpp.dir/all' failed
make[1]: *** [tarscpp/tools/pb2tarscpp/CMakeFiles/pb2tarscpp.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

解决方法:
是因为protobuf库没有装全,(感谢TARS技术交流2群的Laplace大神,他给了我解决方法),运行下面的语句:

sudo apt-get install protobuf-c-compiler protobuf-compiler libprotobuf-dev libprotobuf-c-dev libprotoc-dev

5. 运行npm install --registry=https://registry.npm.taobao.org时出现:

/usr/bin/env: "node": 没有那个文件或目录
/bin/sh: 1: node: not found
gyp: Call to 'node -e "require('nan')"' returned exit status 127 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:354:16)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 4.4.0-141-generic
gyp ERR! command "/usr/bin/nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/lz/TarsFramework/TarsWeb/node_modules/snappy
gyp ERR! node -v v4.2.6
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm WARN install:snappy@6.1.1 snappy@6.1.1 install: `prebuild-install || node-gyp rebuild`
npm WARN install:snappy@6.1.1 Exit status 1
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.2.4

解决方法:
由于Ubuntu下已经有一个名叫node的库,因此Node.js在ubuntu下默认叫nodejs,需要额外处理一下
参照 http://stackoverflow.com/questions/18130164/nodejs-vs-node-on-ubuntu-12-04

sudo ln -s /usr/bin/nodejs /usr/bin/node

6. 运行npm run prd时出现:sh: 1: pm2: not found

解决方法:

npm install -g pm2

7. 运行npm run prd时出现:Buffer.alloc is not a function

解决方法:
这是由于node的版本不匹配造成的,重装node即可:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

8. W: GPG 错误:http://ppa.launchpad.net/maarten-fonville/protobuf/ubuntu xenial InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY 4DEA8909DC6A13A3

解决方法:
https://blog.csdn.net/timekeeperl/article/details/79173793

9. apt-get -f install时出错

dpkg: 关于含有 mariadb-client-core-10.0 的 .../mariadb-client-core-10.0_10.0.37+maria-1~trusty_amd64.deb:mariadb-client-10.0 与之冲突 mysql-client-core-5.5mariadb-client-core-10.0 提供了 mysql-client-core-5.5,它将被安装。dpkg: 处理归档 /var/cache/apt/archives/mariadb-client-core-10.0_10.0.37+maria-1~trusty_amd64.deb (--unpack)时出错:软件包相互冲突 - 将不安装 mariadb-client-core-10.0
dpkg: 关于含有 mariadb-client-10.0 的 .../mariadb-client-10.0_10.0.37+maria-1~trusty_amd64.deb:mariadb-client-core-10.0 与之冲突 mysql-client-5.5mariadb-client-10.0 提供了 mysql-client-5.5,它将被安装。dpkg: 处理归档 /var/cache/apt/archives/mariadb-client-10.0_10.0.37+maria-1~trusty_amd64.deb (--unpack)时出错:软件包相互冲突 - 将不安装 mariadb-client-10.0
在处理时有错误发生:/var/cache/apt/archives/mariadb-client-core-10.0_10.0.37+maria-1~trusty_amd64.deb/var/cache/apt/archives/mariadb-client-10.0_10.0.37+maria-1~trusty_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

解决方法:

主要是几个包都没安装成功,而且相互之间有依赖关系,使用apt-get -f install无法处理这些依赖关系,所以报错,解决办法是直接用sudo dpkg -r将牵扯到的包卸载了,再使用apt-get -f install处理依赖关系即可。

10. sudo apt install mariadb-server时:

E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)

E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

解决方法:

1 终端输入 ps -aux ,列出进程。找到含有apt‘-get的进程,直接sudo kill PID。解决。
2 强制解锁,命令

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

11. npm ERR! Please include the following file with any support request: npm ERR! /home/lz/TarsFramework/TarsWeb/npm-debug.log

解决方法:
这是由于node的版本不匹配造成的,重装node即可:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

12. 配置完成后打开192.168.1.117:3000后tarsnotify服务当前状态为off


解决方法:
去查看日志文件,/usr/local/app/tars/app_log/tars/tarsnode/tars.tarsnode.log

发现有两个错误待解决!
重新配了一下还是不能解决,最后发现前面打包的服务包中,tarsnotify属于普通基础服务,并没有部署,但是部署信息已经有了,这个还是很坑,所以按照其他普通基础服务发布的方法,将tarsnotify重新发布一下:
在 web 管理系统中选择 tarsnotify 并进入“发布管理”。在列表中选中节点,并点击“发布选中节点”按钮。点击“上传发布包”,并上传 tarsnotify.tgz 文件,然后选中上传好的文件,点击“发布”按钮。回到“服务管理”列表,在 tarsnotify 后面点击“重启”。完成之后问题即解决。
这里非常感谢maq128同学的
https://github.com/maq128/temp/blob/master/kb/tars小白安装必成手册.md
看到他的博客后才恍然大悟!

13.

prebuild-install WARN install EACCES: permission denied, access '/root/.npm'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/11.6.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/lz/TarsFramework/TarsWeb/node_modules/snappy/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/lz/TarsFramework/TarsWeb/node_modules/snappy/.node-gyp'
gyp ERR! System Linux 4.15.0-43-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/lz/TarsFramework/TarsWeb/node_modules/snappy
gyp ERR! node -v v11.6.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: snappy@6.1.2 (node_modules/snappy):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: snappy@6.1.2 install: `prebuild-install || node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

解决方法:

sudo npm install

参考文献:

https://github.com/TarsCloud/Tars/blob/master/Install.zh.md
https://cloud.tencent.com/developer/article/1372998
https://blog.csdn.net/weixin_40405198/article/details/79578290
https://blog.csdn.net/kdchxue/article/details/81046192
https://blog.csdn.net/yypsober/article/details/51906691
https://blog.csdn.net/tingfenyijiu/article/details/79788223
https://stackoverflow.com/questions/36499840/typeerror-buffer-alloc-is-not-a-function
http://tieba.baidu.com/p/5043173421
https://www.cnblogs.com/derek718/articles/2632154.html

NBJ原创

不得转载

ubuntu中配置tars详细教程相关推荐

  1. Ubuntu中NS2安装详细教程

    前言: NS2是指 Network Simulator version 2,NS(Network Simulator) 是一种针对网络技术的源代码公开的.免费的软件模拟平台,研究人员使用它可以很容易的 ...

  2. IDEA中配置Tomcat(详细教程)

    第一步: 下载获取Tomcat,tomcat官网 第二步: 打开IDEA,创建一个新的Project 第三步: 选择java模块 继续next 第四步:给你项目起个名字 名字起完后,点击Finish ...

  3. idea 配置mysql逆向_IDEA中Mybatis的MGB使用逆向工程配置的详细教程

    添加依赖 添加generatorConfig.xml文件 在maven的plugins中运行mybatis-generator插件 注意事项: (1).generatorConfig.xml文件需要放 ...

  4. ubuntu18.04 安装qt5.12.8及环境配置的详细教程

    这篇文章主要介绍了ubuntu18.04 安装qt5.12.8及环境配置的教程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下 环境 系统: ...

  5. VMware15中安装Linux详细教程

    VMware15中安装Linux详细教程 ======================== 一. 搭建VMware环境 1. 打开链接(https://www.vmware.com/cn.html), ...

  6. post修改服务器数据源,postgresql安装及配置超详细教程

    1. 安装 根据业务需求选择版本,官网下载 初始化数据库 执行完初始化任务之后,postgresql 会自动创建和生成两个用户和一个数据库: linux 系统用户 postgres:管理数据库的系统用 ...

  7. mysql 5.720安装_MySQL 5.7.27下载安装配置的详细教程

    前言 在安装MySQL的时候会遇到很多问题,博客上有很多解决问题的办法,在这里我附上一些链接,遇到问题的朋友们可以阅读参考哈~本文主要针对于刚接触数据库的小白,来安装MySQL数据库.目前官网上的My ...

  8. VMware虚拟机安装配置Android-x86详细教程

    VMware虚拟机 安装配置Android-x86详细教程 工作环境:cn_windows_7_ultimate_with_sp1_x86 工具:VMware Workstation 10.0 and ...

  9. Ubuntu中配置Java环境变量时,出现command not found问题解决记录

    百度出Ubuntu中配置Java环境变量时,在利用sudo gedit /etc/profile 对profile编辑后, 在terminal中输入 sudo source /etc/profile, ...

最新文章

  1. 深度学习-机器学习(5.2支持向量机SVM)
  2. clickhouse原理解析与应用实践_Hybrid App (混合应用) 技术全解析 方案原理篇
  3. explorer.exe rundll32.exe病毒解决方案
  4. 字体怎么安装到电脑上_文章还在使用电脑上的固定字体?这款字体软件超好用...
  5. 【LeetCode笔记】76. 最小覆盖子串(字符串、滑动窗口)
  6. 不了解沙特,那你就看不懂硅谷
  7. 如何打造7*24h持续交付通道?阿里高级技术专家的5点思考
  8. 单例模式中的线程安全问题
  9. MATLAB时域频域波形显示GUI
  10. IDEA使用的插件记录
  11. Android实现IOS轮效果(Android Studio)
  12. python 离散数学 判断单射 双射 满射
  13. Windows API 关于控件的自绘——文本颜色、背景颜色、字体
  14. java图片合成视频
  15. iconfont图标无法显示的问题
  16. 1、Swoole是什么?你可以通过swoole干些什么?
  17. 直线电机模组在轨道交通(地铁轻轨磁浮)行业应用和发展优势
  18. 一生总会遇到那么一个人
  19. c++学习笔记- 自制魔兽显血改键
  20. 手撕包菜php,包菜怎么做爽脆不出水,教你简单小技巧,营养健康,家里人都喜欢...

热门文章

  1. cpu如何维护自己控制权的
  2. 生物信息学【3】:相关理论方法
  3. 如何面对生活中的消极情绪?
  4. Visual Studio 2017环境cmake编译opencv 4.3.0+opencv_contrib 4.3.0(保证成功,保姆级教学,呕心沥血)
  5. 脚本语言有哪些,如JavaScript、Scala、Python
  6. 计算机范畴论(javaScript实践版)第二篇
  7. 假期,更想念我的宝宝和老婆了。
  8. 模拟CMOS集成电路设计入门学习(12)
  9. 如何玩转Fluxion
  10. 垂直翻页的Viewpager 兼容华为手机