分享

企业实战|企业接口管理平台Yapi搭建

 黄爸爸好 2020-04-03

1.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:///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.

5.部署git工具

yum install git -y

6.安装部署MongoDB数据库

1)配置mongodb源

cat >> /etc/yum.repos.d/mongodb-org.repo <<EOF
> [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.

/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 ☆

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多