yapi 插件_企业实战企业接口管理平台Yapi搭建

00b4e4ad6a01097d9212295db854692b.gif1.Yapi简介

Yapi是一款高效、易用、功能强大的API管理平台程序,旨在为开发、产品、测试人员提供更优雅的接口管理服务。

Yapi的功能特性:

  • 可视化接口管理

  • 数据mock

  • 自动化接口测试

  • 数据导入(各类数据,包括swagger、har、postman、json、命令行等)

  • 权限管理

  • 支持本地化部署

  • 支持插件

  • 支持二次开发

2.系统环境

OS版本:CentOS 7.6

MongoDB版本:3.2.22

Node.js版本:9.8.0

Git版本:1.8.3

3.系统环境配置

1)配置阿里yum源

cat > /etc/yum.repos.d/CentOS-Base.repo << EOF 
> [base]
> name=CentOS-$releasever - Base - mirrors.aliyun.com
> failovermethod=priority
> baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
> EOF 

2)关闭firewalld防火墙并禁止开机自启动

systemctl disable firewalld && systemctl stop firewalld

3)临时和永久关闭SElinux

setenforce 0 

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

4)清空iptables规则

iptables -X && iptables -F && iptables -Z    

4.部署Nodejs环境

1)下载并解压文件

cd /opt

wget https://nodejs.org/dist/v9.8.0/node-v9.8.0-linux-x64.tar.xz

xz -d node-v9.8.0-linux-x64.tar.xz

tar -xf node-v9.8.0-linux-x64.tar

2)创建链接文件

cd node-v9.8.0-linux-x64

ln -s /opt/node-v9.8.0-linux-x64/bin/node /usr/local/bin/node

ln -s /opt/node-v9.8.0-linux-x64/bin/npm /usr/local/bin/npm

3)查看版本并切换镜像源

node -v

npm -v

npm config set registry https://registry.npm.taobao.org

5.部署git工具

yum install git -y

6.安装部署MongoDB数据库

1)配置mongodb源

cat >> /etc/yum.repos.d/mongodb-org.repo <> [mongodb-org]
> name=MongoDB Repository
> baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/3.2/x86_64/
> gpgcheck=0
> enabled=1

2)安装mongodb

yum install -y mongodb-org

3)修改配置文件

sed -i s/127.0.0.1/0.0.0.0/g /etc/mongod.conf

4)设置服务开机自启

chkconfig mongod on

5)启动数据库

systemctl start mongod

6)查看端口信息

ss -tunl | grep 27017

7.安装部署Yapi

npm install -g yapi-cli --registry https://registry.npm.taobao.org

/opt/node-v9.8.0-linux-x64/bin/yapi server

根据命令行提示信息,在浏览器中访问部署页面

http://{IP}:{PORT}

IP:输入主机的IP地址

PORT:输入命令行中提示的端口,默认为3000

选择部署版本 -> 输入公司名称 -> 输入yapi的部署路径 -> 输入管理员邮箱 -> 输入网站端口号 ->

输入数据库地址 -> 输入数据库端口 —> 输入数据库名 -> 选择开始部署

8.错误收集与解决

如果出现以下错误,请安装如下模块文件并刷新页面重新部署

Error: Cannot find module 'fs-extra'
npm install --save fs-extra

如果出现如下错误,请安装如下模块文件并刷新页面重新部署

Error: Cannot find module 'nodemailer'
npm install nodemailer --save

如果出现如下错误,请修改添加以下路径下的db.js文件内容并刷新页面重新部署

Error: (node:687) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor
cd /etc/my-yapi/vendors/server/utils

在db.js文件的第19行处下面添加如下内容

mongoose.set('useUnifiedTopology', true);

如果出现如下错误,请根据提示删除init.py文件

node server/install.js

Error: init.lock文件已存在,请确认您是否已安装。如果需要重新安装,请删掉init.lock文件

进入/etc/my-yapi/目录

rm init.lock -y

如果重新安装,出现如下错误,请删除管理员账号信息

cd /etc/my-yapi/vendors

node server/install.js

(node:20024) UnhandledPromiseRejectionWarning: Error: 初始化管理员账号 "admin@admin.com" 失败, E11000 duplicate key error collection: yapi.user index: email_1 dup key: { : "admin@admin.com" }

进入数据库删除管理员账户信息

mongo

> use yapi;

> db.user.remove({"username":"admin"});

node server/install.js

9.启动服务并访问

根据部署日志上的提示信息,启动服务

cd /etc/my-yapi/vendors

node server/app.js

根据部署后的日志提示信息访问Yapi工具

http://{IP}:{PORT}

IP:输入主机的IP地址

PORT:输入部署时的网站端口号,默认为3000

输入node server/app.js命令行时输出的管理员账号与密码进行登录并访问

☆ END ☆

Linux云计算课程2020全新升级,云计算+安全+DevOps上线,点击查看详情。

45152f4ae58a99a802d44ad1b5f0b430.png

cf1dcd0299efb66e83e7455f797a0cc3.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值