第1章 安装依赖环境
node和npm有版本要求的,数据库MongoDB的安装自己百度
[root@jhkj177 ~]# node -v
v6.14.0
[root@jhkj177 ~]# npm -v
3.10.10
npm install -g yapi-cli --registry https://registry.npm.taobao.org
报错:
[root@jhkj177 ~]# yapi server
/usr/lib/node_modules/yapi-cli/src/commands/import.js:16
run: async function (argv) {
^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at /usr/lib/node_modules/yapi-cli/src/index.js:10:23
网上搜报错没找到什么解决方法,然后去官网看了一下,发现官方要求的node版本在7.6以上,于是怀疑是不是node版本太低的问题,换了符合官方要求版本的node后:
[root@jhkj66 home]# npm install -g yapi-cli --registry https://registry.npm.taobao.org
/server/tools/node-v8.11.4-linux-x64/bin/yapi -> /server/tools/node-v8.11.4-linux-x64/lib/node_modules/yapi-cli/bin/yapi-cli
/server/tools/node-v8.11.4-linux-x64/bin/yapi-cli -> /server/tools/node-v8.11.4-linux-x64/lib/node_modules/yapi-cli/bin/yapi-cli
+ yapi-cli@1.2.8
added 266 packages in 7.322s
[root@jhkj66 home]# yapi server
-bash: yapi: 未找到命令
找不到命令这个报错要看上一条命令中yapi的位置,他都会告诉你的进去以后执行命令:
[root@jhkj66 bin]# ./yapi server
在浏览器打开http://0.0.0.0:9090 访问。非本地服务器,请将0.0.0.0 替换成指定的域名或ip
在浏览器中进入安装页面
1.1报错:
查看yapi目录属主是不是root,
[root@jhkj66 node-v8.11.4-linux-x64]# chown -R root.root /server/tools/node-v8.11.4-linux-x64
删除init.lock,
清空数据库
[admin@jhkj66 mongodb]$ ./bin/mongo
MongoDB shell version: 3.2.8
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
> show dbs
local 0.000GB
yapi 0.000GB
> use yapi
switched to db yapi
> db.dropDatabase()
{ "dropped" : "yapi", "ok" : 1 }
> show dbs
local 0.000GB
1.2重新部署:
成功!
log: mongodb load success...
初始化管理员账号成功,账号名:"admin@admin.com",密码:"ymfe.org"
部署成功,请切换到部署目录,输入:"node vendors/server/app.js" 指令启动服务器, 然后在浏览器打开http://127.0.0.1:3000 访问
1.1启动yapi:
安装的目录下面会有vendors目录,进入执行一下命令启动
[root@jhkj66 vendors]# node server/app.js
log: the server is start at 127.0.0.1:3000
log: mongodb load success...
浏览器访问:
安装pm2,来管理node项目,让yapi变成守护进程
[root@jhkj66 vendors]# npm install -g pm2
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha1-QFUCsAfzGcP0cXXER0UnMA8qta0= integrity checksum failed when using sha1: wanted sha1-QFUCsAfzGcP0cXXER0UnMA8qta0= but got sha512-zr6QQnzLt3Ja0t0XI8gws2kn7zV2p0l/D3kreNvS6hFZhVU5g+uY/30l42jbgt0XGcNBEmBDGJR71J692V92tA==. (260 bytes)
npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
/server/tools/node-v8.11.4-linux-x64/bin/pm2 -> /server/tools/node-v8.11.4-linux-x64/lib/node_modules/pm2/bin/pm2
/server/tools/node-v8.11.4-linux-x64/bin/pm2-dev -> /server/tools/node-v8.11.4-linux-x64/lib/node_modules/pm2/bin/pm2-dev
/server/tools/node-v8.11.4-linux-x64/bin/pm2-docker -> /server/tools/node-v8.11.4-linux-x64/lib/node_modules/pm2/bin/pm2-docker
/server/tools/node-v8.11.4-linux-x64/bin/pm2-runtime -> /server/tools/node-v8.11.4-linux-x64/lib/node_modules/pm2/bin/pm2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ pm2@3.0.4
added 241 packages in 94.941s
现在执行启动命令会提示找不到pm2,是因为没有做软连接
[root@jhkj66 bin]# ln -s /server/tools/node-v8.11.4-linux-x64/bin/pm2 /usr/bin/
[root@jhkj66 vendors]# pm2 start server/app.js
[PM2] Starting /server/tools/node-v8.11.4-linux-x64/bin/my-yapi/vendors/server/app.js in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
│App name │id │mode │pid │status │restart │uptime │cpu │mem │user │watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
│app │0 │fork │18688 │online │0 │0s │0% │16.4 MB │root │disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app