搭建Yapi接口文档服务

搭建Yapi接口文档服务

标签(空格分隔): linux

官方文档

https://hellosean1025.github.io/yapi/devops/index.html

系统环境配置

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

systemctl disable firewalld && systemctl stop firewalld

临时和永久关闭SElinux

setenforce 0

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

清空iptables规则

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

安装Node、Npm

下载并解压文件

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

创建链接文件

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

查看版本并切换镜像源

node -v

npm -v

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

安装Mongodb

下载包

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.2.tgz
tar zxvf mongodb-linux-x86_64-rhel70-4.4.2.tgz -C /usr/local/

mv /usr/local/mongodb-linux-x86_64-rhel70-4.4.2 /usr/local/mongodb

rm -rf mongodb-linux-x86_64-rhel70-4.4.2.tgz

cd /usr/local/mongodb/

mkdir logs data conf

cd logs/

touch mongodb.logs

cd ../conf/

vim mongodb.conf

systemLog:
quiet: false
path: /usr/local/mongodb/logs/mongodb.logs
logAppend: false
destination: file
processManagement:
fork: true
pidFilePath: /usr/local/mongodb/bin/mongodb.pid
net:
bindIp: 0.0.0.0
port: 27017
maxIncomingConnections: 65536
wireObjectCheck: true
storage:
dbPath: /usr/local/mongodb/data
journal:
enabled: true
operationProfiling:
slowOpThresholdMs: 100
mode: off

mongod 开启自启

vim /etc/systemd/system/mongodb.service

[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
RuntimeDirectory=mongodb
RuntimeDirectoryMode=0751
PIDFile=/usr/local/mongodb/bin/mongodb.pid
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.conf
ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/conf/mongodb.conf
PrivateTmp=false

[Install]
WantedBy=multi-user.target

systemctl start mongodb.service
systemctl enable mongodb.service

查看端口

ss -tunl | grep 27017

安装Git

yum install git -y

可视化部署Yapi

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

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

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

部署过程中遇到的坑

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

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

启动服务

cd /etc/my-yapi/vendors
node server/app.js

posted @ 2022-03-23 13:33  TaylorSWMM  阅读(397)  评论(0)    收藏  举报