一、YApi介绍
1.YApi简介
YApi旨在为开发、产品、测试人员提供更优雅的接口管理服务。可以帮助开发者轻松创建、发布、维护 API。
2.YApi功能
YApi 成熟的团队管理扁平化项目权限配置满足各类企业的需求。
基于 websocket 的多人协作接口编辑功能和类 postman 测试工具,让多人协作成倍提升开发效率。
易用的 Mock Server,再也不用担心 mock 数据的生成了。
完善的接口自动化测试,保证数据的正确性。
支持导入 swagger, postman, har 数据格式,方便迁移旧项目。
强大的插件机制,满足各类业务需求。
二、检查docker环境
1.检查docker版本
[root@docker ~]# docker -v
Docker version 20.10.18, build b40c2f6
2.检查docker状态
[root@docker ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-10-21 13:52:55 CST; 9h ago
Docs: https://docs.docker.com
Main PID: 9813 (dockerd)
Tasks: 36
Memory: 535.9M
CGroup: /system.slice/docker.service
├─ 9813 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
├─13425 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3000 -container-ip 172.20.0.2 -container-port 3...
├─13453 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3000 -container-ip 172.20.0.2 -container-port 3000
├─48329 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8011 -container-ip 172.19.0.2 -container-port 8...
└─48334 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8011 -container-ip 172.19.0.2 -container-port 80
Oct 21 13:52:39 docker dockerd[9813]: time="2022-10-21T13:52:39.865044855+08:00" level=info msg="ClientConn switching ba...le=grpc
Oct 21 13:52:41 docker dockerd[9813]: time="2022-10-21T13:52:41.471511161+08:00" level=info msg="[graphdriver] using pri...erlay2"
Oct 21 13:52:45 docker dockerd[9813]: time="2022-10-21T13:52:45.234684184+08:00" level=info msg="Loading containers: start."
Oct 21 13:52:47 docker dockerd[9813]: time="2022-10-21T13:52:47.414394139+08:00" level=info msg="Default bridge (docker0...ddress"
Oct 21 13:52:54 docker dockerd[9813]: time="2022-10-21T13:52:54.698122310+08:00" level=info msg="Loading containers: done."
Oct 21 13:52:54 docker dockerd[9813]: time="2022-10-21T13:52:54.973240663+08:00" level=info msg="Docker daemon" commit=e...0.10.18
Oct 21 13:52:54 docker dockerd[9813]: time="2022-10-21T13:52:54.973328839+08:00" level=info msg="Daemon has completed in...zation"
Oct 21 13:52:55 docker systemd[1]: Started Docker Application Container Engine.
Oct 21 13:52:55 docker dockerd[9813]: time="2022-10-21T13:52:55.682450266+08:00" level=info msg="API listen on /var/run/...r.sock"
Oct 21 15:26:05 docker dockerd[9813]: time="2022-10-21T15:26:05.202485181+08:00" level=info msg="ignoring event" contain...Delete"
Hint: Some lines were ellipsized, use -l to show in full.
[root@docker ~]#
三、安装MongoDB数据库
1.创建MongoDB数据卷
[root@docker ~]# docker volume create yapi_db
yapi_db
2.创建MongoDB容器
[root@docker ~]# docker run -d --name mongo-yapi -v yapi_db:/data/db mongo:4.4.9
Unable to find image 'mongo:4.4.9' locally
4.4.9: Pulling from library/mongo
f3ef4ff62e0d: Pull complete
b1a49f973a13: Pull complete
a94d4dd6d900: Pull complete
f6e410f3a61f: Pull complete
84513ed7bcb6: Pull complete
c81f961faa63: Pull complete
a4146772698c: Pull complete
7d67abd2e683: Pull complete
0930c7be04e9: Pull complete
c583d7bc3a62: Pull complete
Digest: sha256:f5a4e5d7dea0f7d3abe14c8f24ed0f62d91d26b4eb56c14a817b8f04dd335aec
Status: Downloaded newer image for mongo:4.4.9
c21a142b5ac83816d55a5d417354c607cadce478a428385ed8530bbb21fd5029
3.查看MongoDB容器状态
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c21a142b5ac8 mongo:4.4.9 "docker-entrypoint.s…" About a minute ago Up About a minute 27017/tcp mongo-yapi
四、安装Yapi
1.下载Yapi镜像
[root@docker ~]# docker pull registry.cn-hangzhou.aliyuncs.com/anoy/yapi
Using default tag: latest
latest: Pulling from anoy/yapi
e7c96db7181b: Pull complete
72484f09da35: Pull complete
86bee4bed5f2: Pull complete
f9e983f0fe2c: Pull complete
60b427281623: Pull complete
148cae4613db: Pull complete
Digest: sha256:a34daaf6cf64c55fb849d92452009ff312636c05365cf02965f6871b8fbff0c5
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/anoy/yapi:latest
registry.cn-hangzhou.aliyuncs.com/anoy/yapi:latest
2.Yapi初始化
[root@docker ~]# docker run -it --rm --link mongo-yapi:mongo --entrypoint npm --workdir /api/vendors registry.cn-hangzhou.aliyuncs.com/anoy/yapi run install-server
> yapi-vendor@1.8.5 install-server /api/vendors
> node server/install.js
log: mongodb load success...
初始化管理员账号成功,账号名:"admin@admin.com",密码:"ymfe.org"
3.启动Yapi服务
[root@docker data]# docker run -d --name yapi --link mongo-yapi:mongo --workdir /api/vendors -p 3000:3000 registry.cn-hangzhou.aliyuncs.com/anoy/yapi server/app.js
32a37816967e940854b4f2adcbc16f386d617bea6e78d74cdf45007a4896035f
4.查看容器状态
[root@docker data]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32a37816967e registry.cn-hangzhou.aliyuncs.com/anoy/yapi "node server/app.js" 55 seconds ago Up 54 seconds 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp yapi
c21a142b5ac8 mongo:4.4.9 "docker-entrypoint.s…" 12 minutes ago Up 12 minutes 27017/tcp mongo-yapi
5.登录Yapi
admin@admin.com
ymfe.org
五、使用docker-compose部署Yapi容器
1.下载Yapi镜像
[root@docker yapi]# docker pull jayfong/yapi:latest
latest: Pulling from jayfong/yapi
cbdbe7a5bc2a: Pull complete
8f3938f7d3bd: Pull complete
6e3c12f5dc10: Pull complete
ce0cb7a9eeee: Pull complete
33778c009b63: Pull complete
0a69a898b7c7: Pull complete
Digest: sha256:163e5d6219107c9eae0e0cd5d2cdbb78d7ef82d992850b1d7c920d8ee0371f9b
Status: Downloaded newer image for jayfong/yapi:latest
docker.io/jayfong/yapi:latest
2.编辑docker-compose.yaml
[root@docker yapi]# cat docker-compose.yaml
version: '3'
services:
yapi-web:
image: jayfong/yapi:latest
container_name: yapi-web
ports:
- 40001:3000
environment:
- YAPI_ADMIN_ACCOUNT=admin@docker.yapi
- YAPI_ADMIN_PASSWORD=adm1n
- YAPI_CLOSE_REGISTER=true
- YAPI_DB_SERVERNAME=yapi-mongo
- YAPI_DB_PORT=27017
- YAPI_DB_DATABASE=yapi
- YAPI_MAIL_ENABLE=false
- YAPI_LDAP_LOGIN_ENABLE=false
- YAPI_PLUGINS=[]
depends_on:
- yapi-mongo
links:
- yapi-mongo
restart: unless-stopped
yapi-mongo:
image: mongo:4.4.9
container_name: yapi-mongo
volumes:
- ./data/db:/data/db
expose:
- 27017
restart: unless-stopped
3.安装Yapi容器
[root@docker yapi]# docker-compose up -d
Creating network "yapi_default" with the default driver
Creating yapi-mongo ... done
Creating yapi-web ... done
4.查看YApi容器状态
[root@docker yapi]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a12933e54d4 jayfong/yapi:latest "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:40001->3000/tcp, :::40001->3000/tcp yapi-web
d229e2652dbd mongo:4.4.9 "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 27017/tcp
5.进入YApi登录页
6.进入YApi首页
admin@docker.yapi
adm1n