Fork me on GitHub

YApi环境配置过程

 

YApi 一个可视化接口管理工具

部署前准备:

  1. 服务器环境 Centos7, IP地址 192.168.1.18
  2. Node.js
  3. MongoDb
NodeJs
1
2
3
4
5
6
7
8
9
wget https://nodejs.org/dist/v10.15.1/node-v10.15.1-linux-x64.tar.gz 

tar -zxvf node-v10.15.1-linux-x64.tar.gz
mkdir /usr/local/nodejs
mv node-v10.15.1-linux-x64/* /usr/local/nodejs
rm -rf node-v10.15.1-linux-x64

ln -s /usr/local/nodejs/bin/node /usr/local/bin
ln -s /usr/local/nodejs/bin/npm /usr/local/bin
MongoDb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#1. 官网下载
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.6.tgz

mkdir /usr/local/mongodb
tar -zxvf mongodb-linux-x86_64-4.0.6.tgz
mv mongodb-linux-x86_64-4.0.6/* /usr/local/mongodb/
rm -rf mongodb-linux-x86_64-4.0.6

cd /usr/local/mongodb
mkdir data
mkdir logs
touch logs/mongo.log

cd /usr/local/mongodb/bin
./mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs/mongo.log --logappend --port=27017 --fork

#2. 通过 Oneinstack 安装 MongoDb
wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --db_option 15 --dbinstallmethod 1 --dbrootpwd vagrant

#创建 yapi 数据库, 并创建 yapi 用户
mongo
use admin
db.auth('root', 'vagrant')
use yapi
db.createUser({user:"yapi", pwd:"vagrant", roles:[{role:"dbOwner", db:"yapi"}]})
#创建后并不能看到 yapi 数据库, 需退出再重新登录并插入数据才行
exit
mongo
use yapi
db.auth('yapi', 'vagrant')
db.foo.insert({x:1});

#远程连接
#添加iptables 3306 端口
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
#保存iptables规则
service iptables save
#查看添加的iptables规则
iptables -nvL
YApi 安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#第一种:
npm install -g yapi-cli --registry https://registry.npm.taobao.org
yapi server

#第二种:
mkdir yapi
cd yapi
#git 或者 下载 zip 包解压到 vendors 目录
git clone https://github.com/YMFE/yapi.git vendors
cp vendors/config_example.json ./config.json
cd vendors
npm install --production --registry https://registry.npm.taobao.org
#安装程序会初始化数据库索引和管理员账号,管理员账号名可在 config.json 配置
npm run install-server
#启动服务器后,请访问 127.0.0.1:{config.json配置的端口}
node server/app.js

#若是在虚拟机,请开放3000端口
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3000 -j ACCEPT
service iptables save
问题
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#第一种安装方式的相关问题
#1.
依赖库安装完成,正在初始化数据库mongodb...
Error: internal/modules/cjs/loader.js:583 throw err; ^ Error: Cannot find module 'sha1' at Function.Module._
#解决:编辑 /usr/local/nodejs/lib/node_modules/yapi-cli/src/commands/install.js, 找到 handleNpmInstall()
将 npm install -q --production --registry https://registry.npm.taobao.org
修改为 yarn install -q --production --registry https://registry.npm.taobao.org

#2.
依赖库安装完成,正在初始化数据库mongodb...
Error: (node:9716) UnhandledPromiseRejectionWarning: MongoError: command insert requires authentication
#解决:需配置 Mongo 数据库认证, 配置用户名和密码即可


#第二种安装方式的相关问题
#1. npm install --production --registry https://registry.npm.taobao.org
npm ERR! path /data/wwwroot/private/yapi/vendors/node_modules/assert-plus/package.json.1991383012
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/data/wwwroot/private/yapi/vendors/node_modules/assert-plus/package.json.1991383012' -> '/data/wwwroot/private/yapi/vendors/node_modules/assert-plus/package.json'

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-02-20T06_05_59_862Z-debug.log
#解决
npm install -g yarn
ln -s /usr/local/nodejs/bin/yarn /usr/local/bin/
yarn install --production --registry https://registry.npm.taobao.org

#2. npm run install-server
error: MongoError: Authentication failed., mongodb Authentication failed
#解决:配置 config.json
{
"db": {
"servername": "127.0.0.1",
"DATABASE": "yapi",
"port": 27017,
"user": "yapi",
"pass": "vagrant",
"authSource": ""
}
}
posted @ 2020-10-13 10:35  stardsd  阅读(3115)  评论(0编辑  收藏  举报