背景
上一篇详细介绍了Tars的背景、优势与架构等信息,本篇继续介绍Tars安装过程。
注:本篇采用CentOS 7(7.6)系统
环境[关闭selinux和清空防火墙规则]
[root@lisea ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@lisea ~]# uname -r
3.10.0-957.5.1.el7.x86_64
[root@lisea ~]# hostname
lisea
[root@lisea ~]# getenforce
Disabled
[root@lisea ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@lisea ~]# ifconfig
eth0: flags=4163 mtu 1500
inet 172.21.0.15 netmask 255.255.240.0 broadcast 172.21.15.255
ether 52:54:00:09:b7:6e txqueuelen 1000 (Ethernet)
RX packets 9648 bytes 9083460 (8.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5327 bytes 524204 (511.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 2 bytes 272 (272.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 272 (272.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
依赖准备
[root@lisea ~]# yum install gcc gcc-c++ -y
[root@lisea ~]# yum install bison -y
[root@lisea ~]# yum install flex -y
[root@lisea ~]# yum install cmake -y
[root@lisea ~]# yum install ncurses-devel -y
[root@lisea ~]# yum install zlib-devel -y
[root@lisea ~]# yum install glibc-devel -y
[root@lisea ~]# yum install numactl -y
[root@lisea ~]# yum install git -y
安装MySql
这里推荐mysql5.6或者5.7版本的二进制包安装方式。
本次采用5.7版本安装,MySQL5.6安装方式查看历史MySQL安装篇幅。
经测试,在安装8.0版本的MySQL,在后续无法成功编译TarsFramework。
- 切换工作路径至/usr/local/src
[root@lisea ~]# cd /usr/local/src/
- 下载MySQL
[root@lisea src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar
- 解压 MySQL 5.7 二进制包
[root@lisea src]# tar xf mysql-5.7.25-linux-glibc2.12-x86_64.tar [root@lisea src]# tar xf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
- 移动 解压好的MySQL 5.7目录至/usr/local
[root@lisea src]# mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local
- 创建MySQL软连接
[root@lisea src]# ln -s /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
- 创建 mysql 应用运行用户
[root@lisea src]# useradd -r -s /sbin/nologin mysql
- 创建 MySQL 数据存放目录
[root@lisea src]# mkdir -vp /data/mysql_data mkdir: created directory `/data' mkdir: created directory `/data/mysql_data'
- 在 MySQL 二进制包目录中创建 mysql-files 目录 [MySQL 数据导入/导出数据专放目录]
[root@lisea src]# mkdir -v /usr/local/mysql/mysql-files mkdir: created directory `/usr/local/mysql/mysql-files'
- 修改 MySQL 二进制包目录的所属用户与所属组
[root@lisea src]# chown root.mysql -R /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64
- 修改 MySQL 数据目录与 数据导入/导出专放目录的所属用户与所属组
[root@lisea src]# chown mysql.mysql /usr/local/mysql/mysql-files /data/mysql_data
- 重命名不使用系统自带 MySQL 配置文件 /etc/my.cnf [ debian类系统在 /etc/mysql/my.cnf ]
[root@lisea src]# mv /etc/my.cnf{,.old}
- 初始化
[root@lisea src]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data 2019-02-03T13:56:34.415131Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-02-03T13:56:35.563289Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-02-03T13:56:35.835511Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-02-03T13:56:35.915147Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 853b8efd-27bb-11e9-9c8d-52540009b76e. 2019-02-03T13:56:35.925540Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-02-03T13:56:35.926081Z 1 [Note] A temporary password is generated for root@localhost: wKoMdt7
-
开启 SSL 连接[可选]
[root@lisea src]# /usr/local/mysql/bin/mysql_ssl_rsa_setup -d /data/mysql_data
-
修改SSL证书文件所属用户和用户组
[root@lisea src]# chown mysql.mysql -R /data/mysql_data
- 创建mysql systemctl启动脚本[由于博客markdown语法支持问题,无法展示脚本内容,参考MySQL8.0启动脚本]
[root@lisea src]# cat /usr/lib/systemd/system/mysqld.service
- systemd加载启动配置文件
[root@lisea src]# systemctl daemon-reload
- 创建MySQL配置文件my.cnf, 指定数据目录
[root@lisea src]# cat /etc/my.cnf [mysqld] user = mysql bind_address = 0.0.0.0 character_set_server=utf8mb4 skip_name_resolve = 1 max_connections = 800 max_connect_errors = 1000 datadir = /data/mysql_data
- 启动MySQL服务
[root@lisea src]# systemctl start mysqld
- 添加MySQL bin目录至path变量,并生效环境变量
[root@lisea src]# cat /etc/profile.d/mysql.sh export MYSQL_HOME=/usr/local/mysql export PATH=$MYSQL_HOME/bin:$PATH
[root@lisea src]# source /etc/profile
* 通过mysql命令连接mysql服务,并修改默认密码(本次修改为123), 默认密码为初始化时的随机密码
```bash
[root@lisea src]# mysql -uroot -p'wKoMdt7 set password = '123';
Query OK, 0 rows affected (0.00 sec)
tars安装
- 下载TarsFramework源码
[root@lisea src]# git clone https://github.com/TarsCloud/TarsFramework.git Cloning into 'TarsFramework'... remote: Enumerating objects: 20, done. remote: Counting objects: 100% (20/20), done. remote: Compressing objects: 100% (16/16), done. remote: Total 465 (delta 6), reused 14 (delta 4), pack-reused 445 Receiving objects: 100% (465/465), 553.49 KiB | 192.00 KiB/s, done. Resolving deltas: 100% (174/174), done.
- TarsFramework编译
[root@lisea src]# cd TarsFramework/build/ [root@lisea build]# chmod u+x build.sh [root@lisea build]# ./build.sh prepare [root@lisea build]# ./build.sh all
tars数据库初始化
- 注意将${your machine ip}改为部署机器的IP
- 如果exec-sql.sh脚本执行出错,需要脚本里修改数据库用户名root对应的密码
- 脚本执行后,会创建3个数据库,分别是db_tars、tars_stat、tars_property。
- db_tars是框架运行依赖的核心数据库,里面包括了服务部署信息、服务模版信息、服务配置信息等等;
- tars_stat是服务监控数据存储的数据库;
- tars_property是服务属性监控数据存储的数据库;
- 添加数据库用户
mysql> grant all on *.* to 'tars'@'%' identified by 'tars2015' with grant option; Query OK, 0 rows affected, 1 warning (0.08 sec) mysql> grant all on *.* to 'tars'@'localhost' identified by 'tars2015' with grant option; Query OK, 0 rows affected, 2 warnings (0.00 sec) mysql> grant all on *.* to 'tars'@'172.21.0.15' identified by 'tars2015' with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec)
- 修改部署数据库的脚本ip信息[sql脚本在framework/sql目录下,修改部署的ip信息]
注:172.21.0.15是测试环境地址,修改成你们本地地址即可。[root@lisea build]# cd ../sql [root@lisea sql]# sed -i "s/192.168.2.131/172.21.0.15/g" `grep 192.168.2.131 -rl ./*` [root@lisea sql]# sed -i "s/db.tars.com/172.21.0.15/g" `grep db.tars.com -rl ./*` [root@lisea sql]# sed -i "s/10.120.129.226/172.21.0.15/g" `grep 10.120.129.226 -rl ./*`
- 修改exec-sql.sh文件数据库root密码
[root@lisea sql]# cat exec-sql.sh mysql -uroot -p123 -e "create database db_tars" mysql -uroot -p123 -e "create database tars_stat" mysql -uroot -p123 -e "create database tars_property" mysql -uroot -p123 -e "create database db_tars_web" mysql -uroot -p123 db_tars < db_tars.sql
- 创建数据库
[root@lisea sql]# chmod u+x exec-sql.sh [root@lisea sql]# ./exec-sql.sh mysql: [Warning] Using a password on the command line interface can be insecure. mysql: [Warning] Using a password on the command line interface can be insecure. mysql: [Warning] Using a password on the command line interface can be insecure. mysql: [Warning] Using a password on the command line interface can be insecure. mysql: [Warning] Using a password on the command line interface can be insecure.
tars框架运行环境搭建
框架服务的安装分两种:
- 一种是核心基础服务(必须的),必须手工部署的,
- tarsAdminRegistry
- tarsregistry
- tarsnode
- tarsconfig
- tarspatch
- 一种是普通基础服务(可选的),可以通过管理平台发布的(和普通服务一样)。
- tarsstat
- tarsproperty
- tarsnotify
- tarslog
- tarsquerystat
- tarsqueryproperty
- 准备核心基础服务安装包
会在当前目录生成framework.tgz 包 这个包包含了 tarsAdminRegistry, tarsregistry, tarsnode, tarsconfig, tarspatch 部署相关的文件[root@lisea sql]# cd ../build/ [root@lisea build]# make framework-tar
- 普通基础服务安装包准备[可选]
生成的发布包,在管理平台部署发布完成后[root@lisea build]# make tarsstat-tar [root@lisea build]# make tarsnotify-tar [root@lisea build]# make tarsproperty-tar [root@lisea build]# make tarslog-tar [root@lisea build]# make tarsquerystat-tar [root@lisea build]# make tarsqueryproperty-tar
安装核心基础服务
- 创建基础服务的工作目录
[root@lisea build]# mkdir -vp /usr/local/app/tars mkdir: created directory ‘/usr/local/app’ mkdir: created directory ‘/usr/local/app/tars’
- 将已打好的框架服务包复制到/usr/local/app/tars/,并解压
[root@lisea build]# cp framework.tgz /usr/local/app/tars/ [root@lisea build]# cd /usr/local/app/tars [root@lisea tars]# tar xf /usr/local/app/tars/framework.tgz
-
修改各个服务对应conf目录下配置文件,注意将配置文件中的ip地址修改为本机ip地址
[root@lisea tars]# cd /usr/local/app/tars [root@lisea tars]# sed -i "s/192.168.2.131/172.21.0.15/g" `grep 192.168.2.131 -rl ./*` [root@lisea tars]# sed -i "s/db.tars.com/172.21.0.15/g" `grep db.tars.com -rl ./*` [root@lisea tars]# sed -i "s/registry.tars.com/172.21.0.15/g" `grep registry.tars.com -rl ./*` [root@lisea tars]# sed -i "s/web.tars.com/172.21.0.15/g" `grep web.tars.com -rl ./*`
- 启动tars框架服务
[root@lisea tars]# chmod u+x tars_install.sh [root@lisea tars]# ./tars_install.sh
- 部署管理平台并启动web管理平台(管理平台必须和tarspatch部署在同一台服务器上)部署tarspatch
看看rsync进程是否起来了,若没有看看rsync使用的配置中的ip是否正确(即把web.tars.com替换成本机ip)[root@lisea tars]# tarspatch/util/init.sh
- tarsnode配置crontab监控[可选]
* * * * * /usr/local/app/tars/tarsnode/util/monitor.sh
安装web管理系统
- 下载tars-web
[root@lisea tars]# cd /usr/local/app [root@lisea app]# git clone https://github.com/TarsCloud/TarsWeb.git
- 修改配置文件,将配置文件中的ip地址修改为本机ip(172.21.0.15)地址
[root@lisea app]# cd TarsWeb/ [root@lisea TarsWeb]# sed -i 's/db.tars.com/172.21.0.15/g' config/webConf.js [root@lisea TarsWeb]# sed -i 's/registry.tars.com/172.21.0.15/g' config/tars.conf
- 安装npm环境
[root@lisea TarsWeb]# wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash [root@lisea TarsWeb]# source ~/.bashrc [root@lisea TarsWeb]# nvm install v8.11.3 [root@lisea TarsWeb]# npm install -g pm2 --registry=https://registry.npm.taobao.org
- 安装web管理页面依赖, 创建日志目录,启动web
[root@lisea TarsWeb]# npm install --registry=https://registry.npm.taobao.org [root@lisea TarsWeb]# mkdir -p /data/log/tars [root@lisea TarsWeb]# npm run prd