环境要求
- nodejs(7.6+)
- mongodb(2.6+)
- git
环境准备
安装 nodejs 8+
# curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
# yum install -y nodejs
# node -v
安装 MongoDB
安装 git
yum install git
安装 yapi server
1. 创建 yapi 安装目录
# mkdir yapi
2. 进入 yapi 安装目录
# cd yapi
3. 将 yapi 源代码 clone到本地
# git clone https://github.com/YMFE/yapi.git vendors
4. 复制配置文件
# cp vendors/config_example.json ./config.json //复制完成后请修改相关配置
5. 修改配置文件
@TODO 管理员账号,MongoDB,E-mail
6. 进入源代码目录
# cd vendors
7. 注册阿里云 npm
# npm install --production --registry https://registry.npm.taobao.org
8. 初始化服务(生成管理员账号和密码,账号由config.json中来)
# npm run install-server
9. 安装 pm2
npm install pm2@latest -g
10. 编写启动脚本 start.sh,内容如下:
#!/bin/bash
pm2 start /data01/yapi/vendors/server/app.js --output ./log/out.log --error ./log/error.jog -i 2;
exit;
11. 编写重启脚本 restart.sh,内容如下:
#!/bin/bash
pm2 restart /data01/yapi/vendors/server/app.js
12. 编写关闭服务脚本 stop.sh,内容如下:
#!/bin/bash
pm2 stop all;
安装 yapi-cli
npm install -g yapi-cli
参考文档
问题
- 第一次启动时没有指定 pm2 日志输出路径,需要 delete 后加重新启动生效。