RAP2是一个可视化接口管理工具 通过分析接口结构,动态生成模拟数据,校验真实接口正确性,
围绕接口定义,通过一系列自动化工具提升我们的协作效率。数据实现的前后端分离。
本例部署RAP2,所需环境jdk、mysql、redis、node.js等服务。
[root@rap2:/root]# mkdir -p /usr/local/java/
[root@rap2:/root]# mv jdk-8u251-linux-x64.tar.gz /usr/local/java/
[root@rap2:/root]# cd /usr/local/java/
[root@rap2:/usr/local/java]# tar -xzf jdk-8u251-linux-x64.tar.gzmv
[root@rap2:/root]# vim /etc/profile
在第54行下面添加下列内容
55 export JAVA_HOME=/usr/local/java/jdk1.8.0_251
56 export JAVA_BIN=$JAVA_HOME/bin
57 export JAVA_LIB=$JAVA_HOME/lib
58 export CLASSPATH=.:$JAVA_LIB/tools.jar:$JAVA_LIB/dt.jar
59 export PATH=$JAVA_BIN:$PATH
[root@rap2:/root]# source /etc/profile
[root@rap2:/root]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
[root@rap2:/root]# yum -y install centos-release-scl
[root@rap2:/root]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
// 临时有效,退出 shell 或重启会恢复原 gcc 版本
[root@rap2:/root]# scl enable devtoolset-9 bash
// 长期有效 由于后面也需要,因此建议推荐使用此方法
[root@rap2:/root]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
[root@rap2:/root]# source /etc/profile
[root@rap2:/root]# mkdir -p /usr/local/redis/etc
[root@rap2:/root]# wget -c http://download.redis.io/releases/redis-6.0.5.tar.gz
[root@rap2:/root]# tar -xzf redis-6.0.5.tar.gz -C /usr/local/
[root@rap2:/root]# ls && cd /usr/local/redis-6.0.5/
anaconda-ks.cfg redis-6.0.5 redis-6.0.5.tar.gz
[root@rap2:/usr/local/redis-6.0.5]# cd src
[root@rap2:/usr/local/redis-6.0.5/src]# make install PREFIX=/usr/local/redis
[root@rap2:/usr/local/redis-6.0.5/src]# cd /usr/local/redis-6.0.5/
[root@rap2:/usr/local/redis-6.0.5]# mv redis.conf /usr/local/redis/etc/
#[root@rap2:/usr/local/redis/etc]# vim redis.conf
#771 requirepass coffee #修改密码,此步骤可以省略,不使用密码
[root@rap2:/usr/local/redis/etc]# cat > /etc/systemd/system/redis.service <
[Unit]
Description=Redis
After=network.target
[Service]
#Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecReload=/usr/local/redis/bin/redis-server -s reload
ExecStop=/usr/local/redis/bin/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
注意redis.service中的#Type=forking不注释掉 服务无法启动
[root@rap2:/usr/local/redis]# systemctl daemon-reload
[root@rap2:/usr/local/redis]# systemctl enable redis
[root@rap2:/usr/local/redis]# systemctl restart redis
[root@rap2:/usr/local/redis]# systemctl status redis
验证:
[root@rap2:/usr/local/redis/bin]# ./redis-cli
127.0.0.1:6379> exit
[root@rap2:/root]# wget https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3.tar.gz
[root@rap2:/root]# tar -xzf cmake-3.17.3.tar.gz
[root@rap2:/root]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@rap2:/root]# yum groupinstall "Compatibility" "Libraries Base" "Development tools" -y
[root@rap2:/root]# yum groupinstall "debugging Tools" "Dial-up Networking Support" -y
[root@rap2:/root]# yum -y install libaio-devel openssl openssl-devel
[root@rap2:/root]# cd cmake-3.15.3/
[root@rap2:/root/cmake-3.17.3]# ./configure
[root@rap2:/root/cmake-3.17.3]# gmake
[root@rap2:/root/cmake-3.17.3]# echo $? (此步骤可省略)
[root@rap2:/root/cmake-3.17.3]# gmake install
[root@rap2:/root/cmake-3.17.3]# yum install ncurses-devel ncurses -y
[root@rap2:/root/cmake-3.17.3]# cd
[root@rap2:/root]# groupadd mysql
[root@rap2:/root]# useradd -g mysql -M -s /sbin/nologin mysql
[root@rap2:/root]# id mysql
[root@rap2:/root]# mkdir -p /usr/local/mysql/data
[root@rap2:/root]# chown -R mysql:mysql /usr/local/mysql
[root@rap2:/root]# chmod -R 777 /usr/local/mysql
[root@rap2:/root]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.20.tar.gz
[root@rap2:/root]# tar -xzf mysql-boost-8.0.20.tar.gz -C /usr/local
[root@rap2:/root]# cd /usr/local/mysql-8.0.20
[root@rap2:/usr/local/mysql-8.0.20]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/mysql-8.0.20/boost
[root@rap2:/usr/local/mysql-8.0.20]# make && make install
[root@rap2:/usr/local/mysql-8.0.20]# cat > /etc/my.cnf << EOF
[mysqld]
server-id=1
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/usr/local/mysql/mysql.sock
!includedir /etc/my.cnf.d
EOF
[root@rap2:/usr/local/mysql-8.0.20]# chmod -R 1777 /tmp/
[root@rap2:/usr/local/mysql-8.0.20]# mkdir -p /var/log/mysqld
[root@rap2:/usr/local/mysql-8.0.20]# touch /var/log/mysqld/mysqld.log
[root@rap2:/usr/local/mysql-8.0.20]# chown -R mysql:mysql /var/log/mysqld/
[root@rap2:/usr/local/mysql-8.0.20]# mkdir /var/run/mysqld/
[root@rap2:/usr/local/mysql-8.0.20]# chown -R mysql:mysql /var/run/mysqld/
[root@rap2:/usr/local/mysql-8.0.20]# mkdir -p /usr/local/mysql
[root@rap2:/usr/local/mysql-8.0.20]# chmod 777 /usr/local/mysql
[root@rap2:/usr/local/mysql-8.0.20]# cd /usr/local/mysql-8.0.20/
[root@rap2:/usr/local/mysql-8.0.20]# bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
2020-07-06T07:23:32.142361Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-07-06T07:23:32.142484Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.16/runtime_output_directory/mysqld (mysqld 8.0.20) initializing of server in progress as process 28450
2020-07-06T07:23:33.237722Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: o0FAIPUduw+J
2020-07-06T07:23:33.949569Z 0 [System] [MY-013170] [Server] /usr/local/mysql-8.0.16/runtime_output_directory/mysqld (mysqld 8.0.20) initializing of server has completed
[root@rap2:/usr/local/mysql-8.0.20]# bin/mysql_ssl_rsa_setup
[root@rap2:/usr/local/mysql-8.0.20]# cp support-files/mysql.server /etc/init.d/mysqld
[root@rap2:/usr/local/mysql-8.0.20]# chmod +x /etc/init.d/mysqld
[root@rap2:/usr/local/mysql-8.0.20]# ln -s /usr/local/mysql-8.0.16 /usr/local/mysql
[root@rap2:/usr/local/mysql-8.0.20]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[root@rap2:/usr/local/mysql-8.0.20]# source /etc/profile
[root@rap2:/usr/local/mysql-8.0.20]# mysql -uroot -p
Enter password: o0FAIPUduw+J
mysql> alter user user() identified by "appleMysql";
Query OK, 0 rows affected (0.01 sec)
mysql> alter user 'root'@ 'localhost' identified by 'appleMysql';
Query OK, 0 rows affected (0.00 sec)
#创建任意ip连接root用户
mysql> create user root@'%' identified by "appleMysql";
Query OK, 0 rows affected (0.01 sec)
#授权root用户可以远程登陆
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY "appleMysql";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------
| host | user | authentication_string | plugin |
+-----------+------------------+--------------------------------------------
| % | root | $A$005$Disf%yr;8p?z6cQyi`qSy.CPLgU.VbIBSwNE2gQtlaFi1LbYec5/TBKez.M9. | caching_sha2_password |
| localhost | mysql.infoschema | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
+-----------+------------------+-------------------------------------------------
4 rows in set (0.00 sec)
mysql> exit
Bye
::不安全,授权过大,实际生产中加以限制访问范围
[root@rap2:/root]# wget -c https://nodejs.org/dist/v12.18.2/node-v12.18.2-linux-x64.tar.xz
[root@rap2:/root]# tar -xJf node-v12.18.2-linux-x64.tar.xz -C /usr/local/
[root@rap2:/usr/local]# cd /usr/local/ && mv node-v12.18.2-linux-x64 node-v12.18.2
[root@rap2:/usr/local]# vim /etc/profile
在60和61行添加下列内容:
60 export NODE_HOME=/usr/local/node-v12.18.2
61 export PATH=$PATH:$NODE_HOME/bin
或者:
[root@rap2:/usr/local]# echo 'export NODE_HOME=/usr/local/node-v12.18.2' >>/etc/profile
[root@rap2:/usr/local]# echo 'export PATH=$PATH:$NODE_HOME/bin' >>/etc/profile
[root@rap2:/usr/local]# source /etc/profile
[root@rap2:/usr/local]# node -v
v12.18.2
[root@rap2:/root/rap2-delos/src]# mysql -uroot -p"appleMysql"
mysql> CREATE DATABASE IF NOT EXISTS RAP2_DELOS_APP DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@rap2:/usr/local]# yum install git -y #没有安装git需要执行
[root@rap2:/usr/local]# git clone https://github.com/thx/rap2-delos.git
[root@rap2:/usr/local]# cd rap2-delos/src/config/
修改配置文件
进入目录rap2-delos/src/config
目录文件如下:
├── config.dev.ts
├── config.local.ts
├── config.prod.ts
└── index.ts
config.dev.ts是配置测试环境,config.prod.ts是配置准生产环境,此处为方便,将配置文件设 定成一致。主要修改DB里面的配置。后端端口此处默认8080
[root@rap2:/root/rap2-delos/src/config]# vim config.dev.ts
import { IConfigOptions } from '../types'
// 先从环境变量取配置
const config: IConfigOptions = {
version: 'v2.9.0',
serve: {
port: (process.env.SERVE_PORT && parseInt(process.env.SERVE_PORT)) || 8080,
path: '',
},
keys: ['some secret hurr'],
session: {
key: 'rap2:sess',
},
db: {
dialect: 'mysql',
host: process.env.MYSQL_URL ?? 'localhost',
port: (process.env.MYSQL_PORT && parseInt(process.env.MYSQL_PORT)) || 3306,
username: process.env.MYSQL_USERNAME ?? 'root',
password: process.env.MYSQL_PASSWD ?? 'appleMysql', #输入密码
database: process.env.MYSQL_SCHEMA ?? 'RAP2_DELOS_APP',
pool: {
max: 10,
min: 0,
idle: 10000,
},
logging: false,
dialectOptions: {
connectTimeout: 20000,
},
},
redis: {
host: process.env.REDIS_URL || 'localhost',
port: (process.env.REDIS_PORT && parseInt(process.env.REDIS_PORT)) || 6379,
},
mail: {
host: process.env.MAIL_HOST ?? 'smtphz.qiye.163.com',
port: process.env.MAIL_PORT ?? 994,
secure: process.env.MAIL_SECURE ?? true,
auth: {
user: process.env.MAIL_USER ?? '[email protected]',
pass: process.env.MAIL_PASS ?? '',
},
},
mailSender: process.env.MAIL_SENDER ?? '[email protected]',
}
export default config
[root@rap2:/root/rap2-delos/src/config] cp -p config.local.ts config.local.ts
[root@rap2:/root/rap2-delos/src/config] cp -p config.local.ts config.prod.ts
# 初始化
[root@rap2:/usr/local/rap2-delos/src/config]# cd ../..
[root@rap2:/root/rap2-delos]# npm install
# 安装 && TypeScript 编译
[root@rap2:/root/rap2-delos]# npm install -g pm2
[root@rap2:/root/rap2-delos]# npm install -g typescript
[root@rap2:/root/rap2-delos]# npm run build
# 初始化数据库 (注:如果是版本升级,数据库初始化请略过,不然会把数据库覆写了)
[root@rap2:/root/rap2-delos]# npm run create-db
.......
after after
Run create-db finished successfully.
# 执行 mocha 测试用例和 js 代码规范检查
[root@rap2:/usr/local/rap2-delos]# npm run check
> rap2-delos@2.9.0 check /usr/local/rap2-delos
> echo "Checking..." && tsc && npm run lint
Checking...
> rap2-delos@2.9.0 lint /usr/local/rap2-delos
> echo "TSLint checking..." && tslint -c tslint.json --fix 'src/**/*.ts' 'src/**/*.tsx'
TSLint checking...
# 启动开发模式的服务器 监视并在发生代码变更时自动重启
[root@rap2:/usr/local/rap2-delos]# npm run dev
> rap2-delos@2.9.0 dev /usr/local/rap2-delos
> cross-env NODE_ENV=development nodemon --watch scripts --watch dist dist/scripts/dev.js
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): scripts dist/**/*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node dist/scripts/dev.js`
Starting task: locker check
----------------------------------------
rap2-delos is running as http://localhost:8080
----------------------------------------
DATABASE √
HOST localhost
PORT 3306
DATABASE RAP2_DELOS_APP
----------------------------------------
# 后台启动服务
[root@rap2:/usr/local/rap2-delos]# npm start
[root@rap2:/usr/local/rap2-delos]# pm2 list
┌─────┬─────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼─────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ rap-server-delos │ default │ 2.9.0 │ fork │ 36994 │ 21s │ 0 │ online │ 0.8% │ 20.8mb │ root │ disabled │
└─────┴─────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[root@rap2:/usr/local/rap2-delos]# pm2 show 0
[root@rap2:/usr/local/rap2-delos]# pm2 start rap-server-delos
[PM2] Applying action restartProcessId on app [rap-server-delos](ids: [ 0 ])
[PM2] [rap-server-delos](0) ✓
[PM2] Process successfully started
┌─────┬─────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼─────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ rap-server-delos │ default │ 2.9.0 │ fork │ 37102 │ 0s │ 1 │ online │ 0% │ 11.3mb │ root │ disabled │
└─────┴─────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[root@rap2:/usr/local]# git clone https://github.com/thx/rap2-dolores.git
修改配置文件
# 文件目录如下
├── config.dev.js
├── config.prod.js
└── index.js
[root@rap2:/usr/local]# cd rap2-dolores/src/config
[root@rap2:/usr/local/rap2-dolores/src/config]# vim config.dev.ts
const config: IConfig = {
serve: `http://192.168.10.29:8080`,
keys: ['some secret hurr'],
session: {
key: 'koa:sess',
},
}
export default config
[root@rap2:/usr/local/rap2-dolores/src/config]# vim config.prod.ts
const config: IConfig = {
serve: 'http://192.168.10.29:8080',
keys: ['some secret hurr'],
session: {
key: 'koa:sess',
},
}
export default config
[root@rap2:/usr/local/rap2-dolores/src/config]# cd ../..
# 安装依赖包
[root@rap2:/usr/local/rap2-dolores]# npm install
# 编译
# 修改了项目的代码或配置文件之后一定重新编译,不然修改不起作用
# 如果报错说没有权限创建文件夹,可以在后面加上--unsafe-perm参数
# 注意:修改 cofig 文件后需要重新 npm run build 才能生效
# 编译构建build
[root@rap2:/usr/local/rap2-dolores]# npm run build
......
The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
You may serve it with a static server:
npm install -g serve
serve -s build
Find out more about deployment here:
bit.ly/CRA-deploy
[root@rap2:/usr/local/rap2-dolores]# npm install -g serve
##可以使用以下方法测试,不过我们使用nginx来代理
[root@rap2:/usr/local/rap2-dolores]# serve -s ./build -p 80
或者 # 这里启动后会阻塞会话,可以使用nohup,并且指定全路径启动
[root@rap2:/usr/local/rap2-dolores]# nohup serve -s /root/rap/build -p 80 &
nginx 网址:http://nginx.org/en/linux_packages.html
[root@rap2:/root]# cd /etc/yum.repos.d/
[root@rap2:/etc/yum.repos.d]# vim nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@rap2:/etc/yum.repos.d]# yum clean all && yum repolist && yum info nginx
[root@rap2:/root]# yum install nginx -y
[root@rap2:/root]# cat /etc/nginx/nginx.conf
[root@rap2:/root]# vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/local/rap2-dolores/build; # 这里为你rap2前端静态文件的路径
try_files $uri /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
#校验nginx是否配置成功
[root@rap2:/root]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@rap2:/root]# nginx
##nginx -s stop 为关闭
验证浏览器访问http://192.168.10.29/
Rap2在2.2之前的版本升级至Version 2.9 ;MySQL数据库存在部分区别。
区别一:
老版本数据库为12个表;Version 2.9 新增一张default_val表格;我的操作是在老的数据库上新增一张default_val表格(无数据)
mysql> show tables;
区别二:
新老版本数据库中Modules 表格中的priority的Type有区别;如下图,修改一下即可。
mysql> describe Modules;
区别三:
新老版本数据库中Properties 表格中的type和priority的Type有区别;如下图,修改一下即可。
mysql> describe Properties;
区别四:
新版本数据库的Repositories表结构中多了token ,新增一栏即可。
mysql> describe Repositories;
区别五:
新版本数据库的Repositories_members表结构中多了createdAt和updateAt ,新增即可。
mysql> describe Repositories_members;