之前安装失败了,只好在docker中装了。
准备环境
1.docker安装
centos7 docker 安装-CSDN博客
2.mongodb数据库docker安装
创建mongo容器目录
mkdir /data/mongo -p
docker pull mongo:4.2.21
创建一个yapi网络插件
docker network create yapi
docker run -d \
--name mongodb \
--restart always \
--net=yapi \
-p 2717:27017 \
-v /data/mongo:/data/db \
-e MONGO_INITDB_DATABASE=yapi \
-e MONGO_INITDB_ROOT_USERNAME=yapipro \
-e MONGO_INITDB_ROOT_PASSWORD=yapi2023 \
mongo:4.2.21
容器创建并启动成功
进入mongodb容器
docker exec -it 容器id /bin/bash
mongo
进入了客户端
use admin;
db.auth("yapipro", "yapi2023");
use yapi;
db.createUser({ user: 'yapi', pwd: 'yapi123456', roles: [ { role: "dbAdmin", db: "yapi" }, { role: "readWrite", db: "yapi" } ] });
退出mongo 推出容器
exit exit
2.docker 安装YApi-pro
创建YApi-pro的配置文件config.json
mkdir /data/yapi
vim /data/yapi/config.json
{
"port": "3000",
"adminAccount": "zhangxu_haha@163.com",
"timeout":120000,
"db": {
"servername": "mongo",
"DATABASE": "yapi",
"port": 27017,
"user": "yapi",
"pass": "yapi123456",
"authSource": ""
},
"mail": {
"enable": true,
"host": "smtp.163.com",
"port": 465,
"from": "*",
"auth": {
"user": "yapiadmin@163.com",
"pass": "yapiadminpassword"
}
}
}
docker pull yapipro/yapi:1.9.5
docker run -d --rm \
--name yapi-init \
--link mongodb:mongo \
--net=yapi \
-v /data/yapi/config.json:/yapi/config.json \
yapipro/yapi:1.9.5 \
server/install.js
docker run -d \
--name yapi \
--link mongodb:mongo \
--restart always \
--net=yapi \
-p 3000:3000 \
-v /data/yapi/config.json:/yapi/config.json \
yapipro/yapi:1.9.5 \
server/app.js
访问本机:3000验证一下是否部署成功
注册,登录就能用了。