环境要求
nodejs(7.6+)
mongodb(2.6+)
1.安装nodejs
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum -y install nodejs
***如果没有编译环境,则需要yum install gcc-c++ make -y
2.安装配置MongoDB数据库
[@bx_70_32 /etc/yum.repos.d]# cat mongodb-org-3.6.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
[@bx_70_32 /etc/yum.repos.d]# yum -y install mongodb-org
service mongod start
***netstat -tnlp | grep 27017 确认一下MongoDB服务是否启动
***/etc/mongod.conf根据需求可自行修改路径
3.初始化MongoDB数据库
[@bx_70_32 ~]# mongo
MongoDB shell version: 2.6.12
connecting to: test
> use yapi
switched to db yapi
> db.addUser('yapi','xxxxxx')
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "yapi", "roles" : [ "dbOwner" ] }
>show dbs
admin 0.078GB
local 0.078GB
yapi 0.078GB
3.安装与配置YApi工具
[@bx_70_32 /opt/apps_install]# mkdir yapi
[@bx_70_32 /opt/apps_install]# cd yapi/
解压,压缩包可以从上述GitHub下载需要的release版本
[@bx_70_32 /opt/apps_install/yapi]# tar zxvf yapi-1.3.7.tar.gz
安装yapi工具包
[@bx_70_32 /opt/apps_install/yapi]# cd yapi-1.3.7
[@bx_70_32 /opt/apps_install/yapi/yapi-1.3.7]# npm install -g yapi-cli --registry https://registry.npm.taobao.org
/usr/bin/yapi -> /usr/lib/node_modules/yapi-cli/bin/yapi-cli
/usr/bin/yapi-cli -> /usr/lib/node_modules/yapi-cli/bin/yapi-cli
+ yapi-cli@1.2.5
added 250 packages in 15.183s
修改配置文件
[@bx_70_32 /opt/apps_install/yapi/yapi-1.3.7]# cp config_example.json config.json
[@bx_70_32 /opt/apps_install/yapi/yapi-1.3.7]# vim config.json
"port": "3000",
"adminAccount": "admin@admin.com",
"db": {
"servername": "127.0.0.1",
"DATABASE": "yapi",
"port": 27017,
"user": "yapi",
"pass": "xxxxxx"
},
"mail": {
"enable": false,
"host": "smtp.163.com",
"port": 465,
"from": "***@163.com",
"auth": {
"user": "***@163.com",
"pass": "*****"
}
}
}
[@bx_70_32 /opt/apps_install/yapi/yapi-1.3.7]# vim server/yapi.js
const config = require('../config.json');
安装node模块
[@bx_70_32 /opt/apps_install/yapi/yapi-1.3.7]# npm install --production --registry https://registry.npm.taobao.org
> dtrace-provider@0.8.6 install /opt/apps_install/yapi/yapi-1.3.7/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js
make: Entering directory `/opt/apps_install/yapi/yapi-1.3.7/node_modules/dtrace-provider/build'
TOUCH Release/obj.target/DTraceProviderStub.stamp
make: Leaving directory `/opt/apps_install/yapi/yapi-1.3.7/node_modules/dtrace-provider/build'
> jsonpath@1.0.0 postinstall /opt/apps_install/yapi/yapi-1.3.7/node_modules/jsonpath
> node lib/aesprim.js > generated/aesprim-browser.js
npm WARN yapi@1.3.7 license should be a valid SPDX license expression
added 324 packages in 53.689s
安装yapi软件
[@bx_70_32 /opt/apps_install/yapi/yapi-1.3.7]# npm run install-server
> yapi@1.3.7 install-server /opt/apps_install/yapi/yapi-1.3.7
> node server/install.js
log: mongodb load success...
初始化管理员账号成功,账号名:"admin@admin.com",密码:"ymfe.org"
启动服务
[@bx_70_32 /opt/apps_install/yapi/yapi-1.3.7]# node server/app.js &
log: the server is start at 127.0.0.1:3000
log: mongodb load success...
访问http://ip:3000即可
另附上一个谷歌浏览器插件,后续在YApi调试接口中会用到 crossRequest
链接: https://pan.baidu.com/s/1HhVH5Dr8oGEnLB6S5h546w 密码: 15d7 ---绿色无毒,放心下载
代理方式:
如果是从nginx代理,请配置nginx支持websocket
在location /添加
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://ip:port;