上一篇詳細介紹了Tars的背景、優點與架構等信息,本篇繼續介紹Tars安裝過程。
注:本篇採用CentOS 7(7.6)系統node
[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<UP,BROADCAST,RUNNING,MULTICAST> 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<UP,LOOPBACK,RUNNING> 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
這裏推薦mysql5.6或者5.7版本的二進制包安裝方式。
本次採用5.7版本安裝,MySQL5.6安裝方式查看歷史MySQL安裝篇幅。
經測試,在安裝8.0版本的MySQL,在後續沒法成功編譯TarsFramework。mysql
[root@lisea ~]# cd /usr/local/src/
[root@lisea src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/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 [root@lisea src]# tar xf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
[root@lisea src]# mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local
[root@lisea src]# ln -s /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
[root@lisea src]# useradd -r -s /sbin/nologin mysql
[root@lisea src]# mkdir -vp /data/mysql_data mkdir: created directory `/data' mkdir: created directory `/data/mysql_data'
[root@lisea src]# mkdir -v /usr/local/mysql/mysql-files mkdir: created directory `/usr/local/mysql/mysql-files'
[root@lisea src]# chown root.mysql -R /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64
[root@lisea src]# chown mysql.mysql /usr/local/mysql/mysql-files /data/mysql_data
[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<yNor
開啓 SSL 鏈接[可選]linux
[root@lisea src]# /usr/local/mysql/bin/mysql_ssl_rsa_setup -d /data/mysql_data
修改SSL證書文件所屬用戶和用戶組c++
[root@lisea src]# chown mysql.mysql -R /data/mysql_data
[root@lisea src]# cat /usr/lib/systemd/system/mysqld.service
[root@lisea src]# systemctl daemon-reload
[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
[root@lisea src]# systemctl start mysqld
[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/profilegit
* 經過mysql命令鏈接mysql服務,並修改默認密碼(本次修改成123), 默認密碼爲初始化時的隨機密碼 ```bash [root@lisea src]# mysql -uroot -p'wKoMdt7<yNor' mysql> set password = '123'; Query OK, 0 rows affected (0.00 sec)
[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.
[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
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)
[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 ./*`
[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.
框架服務的安裝分兩種:github
[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’
[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地址web
[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 ./*`
[root@lisea tars]# chmod u+x tars_install.sh [root@lisea tars]# ./tars_install.sh
[root@lisea tars]# tarspatch/util/init.sh
* * * * * /usr/local/app/tars/tarsnode/util/monitor.sh
[root@lisea tars]# cd /usr/local/app [root@lisea app]# git clone https://github.com/TarsCloud/TarsWeb.git
[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
[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
[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