开发中,接口是最常见又繁多的东西,在公司中,如果对接口不进行管理,那一定是灾难,一个好用的接口管理工具不单是能帮助管理接口,还能方便前后端的对接,提高开发效率。
这里就介绍一个好用的接口管理工具,RAP。这是阿里开源的一个接口管理工具,直接百度rap,第一个就是官网了。其本身是提供一个开源的平台免费给大家使用的,对于一些小公司的开发团队来说,省去了自己搭建服务器的麻烦,直接使用它提供的服务即可。非常方便。但是很多时候,公司对于数据的保密性等,都不太会用公共开源的服务,所以直接用官方开源的代码,搭建一个本地的RAP服务,以供公司内部使用是最好的选择。
rap目前已经有了升级版,rap2。 但是在此之前已经搭建过rap服务的公司来说,要升级到rap2,则会比较麻烦。这里我就不赘述旧版rap的部署了,直接详细说一下rap2的本地搭建以及如何讲rap中的数据导入到rap2,以达成升级。(注意:因为rap2跟rap结构架构类的相差太多,无法直接在原rap的基础上进行升级。需要重新搭建rap2,并导入之前的数据)
一: 搭建RAP2
RAP2 是前后端分离部署的,相应的它分成了两个项目,分别的github地址如下:
后端api服务:https://github.com/thx/rap2-delos
前端:https://github.com/thx/rap2-dolores
首先搭建后端api服务
① 准备工作
后端api服务的搭建需要:
Node.js 8.9.4+
MySQL 5.7+
Redis 4.0+
redis的搭建参考我之前的博《Centos7.2 Redis数据库的安装与自启动配置》
mysql需要5.7+的版本,参考我的博文《Centos7.2 通过rpm包安装Mysql5.7》
nodejs的安装也比较简单,如下:
[root@localhost node-v10.13.0-linux-x64]# vim /etc/profile
[root@localhost node-v10.13.0-linux-x64]# source /etc/profile
[root@localhost node-v10.13.0-linux-x64]# node -v
v10.13.0
[root@localhost node-v10.13.0-linux-x64]# npm -v
6.4.1
③创建数据库
mysql -e ‘CREATE DATABASE IF NOT EXISTS RAP2_DELOS_APP DEFAULT CHARSET utf8 COLLATE utf8_general_ci’
安装nginx和redis
nginx的配置
vim /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 8082;
server_name _;
root /usr/local/rap2-dolores/build;
index index.html index.htm;
location / {
try_files $uri /index.html;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
访问服务:
http://192.168.65.134:8082/
重新启动操作:
后台:
[root@localhost local]# cd rap2-delos/
[root@localhost rap2-delos]# npm start
> rap2-delos@2.9.0 start /usr/local/rap2-delos
> cross-env NODE_ENV=production pm2 start dist/dispatch.js --name=rap-server-delos
[PM2] Starting /usr/local/rap2-delos/dist/dispatch.js in fork_mode (1 instance)
[PM2] Done.
┌─────┬─────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼─────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ rap-server-delos │ default │ 2.9.0 │ fork │ 9823 │ 0s │ 0 │ online │ 0% │ 15.2mb │ root │ disabled │
前台: