部署 YApi 接口管理服务
安装 Node
curl -sL https://rpm.nodesource.com/setup_8.x | bash - yum install -y nodejs
vi /etc/yum.repos.d/mongodb-org-4.0.repo [mongodb-org-4.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc sudo yum install -y mongodb-org sudo service mongod start sudo chkconfig mongod on sudo service mongod stop sudo service mongod restart
部署 YAPI
npm install -g yapi-cli --registry https://registry.npm.taobao.org yapi server
当前安装版本: v1.3.23 连接数据库成功! 开始下载平台文件压缩包... http://yapi.demo.qunar.com/publicapi/archive/v1.3.23 部署文件完成,正在安装依赖库... > dtrace-provider@0.8.6 install /opt/my-yapi/vendors/node_modules/dtrace-provider > node-gyp rebuild || node suppress-error.js make: Entering directory `/opt/my-yapi/vendors/node_modules/dtrace-provider/build' TOUCH Release/obj.target/DTraceProviderStub.stamp make: Leaving directory `/opt/my-yapi/vendors/node_modules/dtrace-provider/build' > jsonpath@1.0.0 postinstall /opt/my-yapi/vendors/node_modules/jsonpath > node lib/aesprim.js > generated/aesprim-browser.js npm WARN yapi@1.3.23 license should be a valid SPDX license expression added 345 packages from 330 contributors in 14.175s 依赖库安装完成,正在初始化数据库mongodb... > yapi@1.3.23 install-server /opt/my-yapi/vendors > node server/install.js log: mongodb load success... 初始化管理员账号成功,账号名:"test@xxx.com",密码:"ymfe.org" 部署成功,请切换到部署目录,输入: "node vendors/server/app.js" 指令启动服务器, 然后在浏览器打开 http://127.0.0.1:3000 访问
npm install pm2 -g pm2 start "vendors/server/app.js" --name yapi [root@021yun128016s my-yapi]# pm2 start "vendors/server/app.js" --name yapi [PM2] Starting /opt/my-yapi/vendors/server/app.js in fork_mode (1 instance) [PM2] Done. ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐ │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │ ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤ │ yapi │ 0 │ 1.3.23 │ fork │ 9534 │ online │ 0 │ 0s │ 0% │ 11.6 MB │ root │ disabled │ └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘ Use `pm2 show <id|name>` to get more details about an app [root@021yun128016s my-yapi]# pm2 info yapi Describing process with id 0 - name yapi ┌───────────────────┬────────────────────────────────────┐ │ status │ online │ │ name │ yapi │ │ version │ 1.3.23 │ │ restarts │ 0 │ │ uptime │ 25s │ │ script path │ /opt/my-yapi/vendors/server/app.js │ │ script args │ N/A │ │ error log path │ /root/.pm2/logs/yapi-error.log │ │ out log path │ /root/.pm2/logs/yapi-out.log │ │ pid path │ /root/.pm2/pids/yapi-0.pid │ │ interpreter │ node │ │ interpreter args │ N/A │ │ script id │ 0 │ │ exec cwd │ /opt/my-yapi │ │ exec mode │ fork_mode │ │ node.js version │ 8.12.0 │ │ node env │ N/A │ │ watch & reload │ ✘ │ │ unstable restarts │ 0 │ │ created at │ 2018-11-14T12:50:18.371Z │ └───────────────────┴────────────────────────────────────┘ Code metrics value ┌────────────────────┬────────┐ │ Event Loop Latency │ 1.36ms │ │ Active handles │ 10 │ └────────────────────┴────────┘ Add your own code metrics: http://bit.ly/code-metrics Use `pm2 logs yapi [--lines 1000]` to display logs Use `pm2 env 0` to display environement variables Use `pm2 monit` to monitor CPU and Memory usage yapi
[root@021yun128016s my-yapi]# yapi update 更新版本为v1.4.1 开始下载平台文件压缩包... http://yapi.demo.qunar.com/publicapi/archive/v1.4.1 部署文件完成,正在执行 npm install... npm WARN mongoose-auto-increment@5.0.1 requires a peer of mongoose@^4.1.12 but none is installed. You must install peer dependencies yourself. npm WARN yapi-vendor@1.4.1 license should be a valid SPDX license expression npm WARN The package moment is included as both a dev and production dependency. added 14 packages from 9 contributors, removed 11 packages and updated 10 packages in 13.291s 更新成功,请重启服务器
REFER:
https://yapi.ymfe.org/devops/index.html
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat
https://www.cnblogs.com/straycats/p/8325695.html
https://www.ddhigh.com/2017/07/31/spring-boot-pm2.html
http://www.cnblogs.com/stulzq/p/9775973.html