内网部署YApi
官网地址:https://hellosean1025.github.io/yapi/devops/index.html
环境要求
- nodejs(7.6+)
- mongodb(2.6+),安装看这篇文章:
安装,命令行部署
mkdir yapi
cd yapi
git clone https://github.com/YMFE/yapi.git vendors //或者下载 zip 包解压到 vendors 目录(clone 整个仓库大概 140+ M,可以通过 `git clone --depth=1 https://github.com/YMFE/yapi.git vendors` 命令减少,大概 10+ M)
cp vendors/config_example.json ./config.json //复制完成后请修改相关配置,主要是修改连接mongodb的库名,访问用户名和密码
cd vendors
npm install --production --registry https://registry.npm.taobao.org
npm run install-server //安装程序会初始化数据库索引和管理员账号,管理员账号名可在 config.json 配置
# 提示
# 初始化管理员账号成功,账号名:"admin@admin.com",密码:"ymfe.org"
node server/app.js //启动服务器后,请访问 127.0.0.1:{config.json配置的端口},初次运行会有个编译的过程,请耐心等候,后面使用pm2进行服务管理,这一步如果运行的话需要kill掉
在执行这一步(npm install --production --registry https://registry.npm.taobao.org)时报错如下:
npm ERR! code ETARGET
npm ERR! notarget No matching version found for dify@1.0.5.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'vendors'
npm ERR! notarget
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-02-07T07_44_03_504Z-debug.log
解决办法:
rm -rf node_modules
npm cache clean --force
rm package-lock.json
服务管理
推荐使用 pm2 管理 node 服务器启动,停止
npm install pm2 -g //安装pm2
cd {项目目录} # cd yapi
pm2 start "vendors/server/app.js" --name yapi //pm2管理yapi服务
pm2 info yapi //查看服务信息
pm2 stop yapi //停止服务
pm2 restart yapi //重启服务
升级
cd {项目目录} # cd yapi
yapi ls //查看版本号列表
yapi update //更新到最新版本
yapi update -v {Version} //更新到指定版本
测试
访问后新建一个项目,使用测试swagger.json: https://petstore.swagger.io/v2/swagger.json
安装其他插件 ==> 不建议安装
安装其他插件后,原来页面上少了swagger同步的信息
其他插件