YApi 是高效、易用、功能强大的API管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务
官网:https://yapi.ymfe.org/,
结合官网的教程和网上自己搜索整理的资料,最终决定使用docker部署Yapi,比较方便便捷,下面介绍具体的操作。
Docker 安装我们可以参考菜鸟教程的安装指南 → → → 戳我
Docker 使用的一些命令指南 → → → 戳我
docker pull silsuer/yapi
拉取Yapi镜像➜ ~ docker pull silsuer/yapi
Using default tag: latest
latest: Pulling from silsuer/yapi
1be7f2b886e8: Pull complete
6fbc4a21b806: Pull complete
c71a6f8e1378: Pull complete
4be3072e5a37: Pull complete
...
Digest: sha256:f5a5270feaffafcc428d76037af8ea03ca335fa4426c51e889d7c2966f916638
Status: Downloaded newer image for silsuer/yapi:latest
docker.io/silsuer/yapi:latest
docker run --name yapi -dit -p 27017:27017 -p 9090:9090 -p 3000:3000 silsuer/yapi bash
➜ ~ docker run --name yapi -dit -p 27017:27017 -p 9090:9090 -p 3000:3000 silsuer/yapi bash
8fefc0fc6a332bc4892eecb5b5beada25510cee59b1c1c61e15696d5f50c13ba
➜ ~ docker ps // 查看doker正在运行的所有容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8fefc0fc6a33 silsuer/yapi "bash" 18 hours ago Up 15 minutes 0.0.0.0:3000->3000/tcp, 0.0.0.0:9090->9090/tcp, 0.0.0.0:27017->27017/tcp yapi
➜ ~
docker attach yapi
(exit退出容器后,容器停止运行)或者 docker exec -it yapi bash
(exit退出容器后,容器依旧运行)➜ ~ docker attach yapi
root@8fefc0fc6a33:/# ----(进去容器伪终端,可以直接命令行操作了)
root@8fefc0fc6a33:/# ls
Users boot etc lib media my-yapi proc run srv tmp var
bin dev home lib64 mnt opt root sbin sys usr
root@8fefc0fc6a33:/#
当我们进去Yapi容器中后,我们就开始部署Yapi了!!!
1、 输入service mongodb start
启动MogoDB,Yapi部署需要数据库依赖
root@6181b9bbfc25:/# service mongodb start
* Starting database mongodb [ OK ]
2、因为Yapi需要git支持,输入apt-get update
先升级git源
root@6181b9bbfc25:/# apt-get update
Ign:1 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 InRelease
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
...
3、apt-get install git
安装git
root@6181b9bbfc25:/# apt-get install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libboost-filesystem1.58.0 libboost-program-options1.58.0
libboost-system1.58.0 libboost-thread1.58.0 libgoogle-perftools4 libpcap0.8
libpcrecpp0v5 libsnappy1v5 libtcmalloc-minimal4 libunwind8 libv8-3.14.5
libyaml-cpp0.5v5
...
Do you want to continue? [Y/n] y // 中途会遇到是否继续,输入y 继续
...
4、MogoDB和Git 准备就绪后, 我们就可以开始yapi部署了, 输入yapi server
开启yapi服务
root@8fefc0fc6a33:/# yapi server
在浏览器打开 http://0.0.0.0:9090 访问。非本地服务器,请将 0.0.0.0 替换成指定的域名或ip
/bin/sh: 1: xdg-open: not found
5、在浏览器打开 http://0.0.0.0:9090 ,非本地服务器,请将 0.0.0.0 替换成指定的域名或 ip 进入yapi部署页面,按照默认配置,输入公司名称点击开始部署即可。
6、部署成功后,查看命令窗口,显示如下
added 345 packages in 53.839s
依赖库安装完成,正在初始化数据库mongodb...
> [email protected] install-server /my-yapi/vendors
> node server/install.js
>
log: mongodb load success...
7、初始化完成后,请切换到部署目录,输入: node vendors/server/app.js
指令启动服务器, 然后在浏览器打开 http://127.0.0.1:3000 访问
root@6181b9bbfc25:/# ls
bin dev home lib64 mnt opt root sbin sys usr
boot etc lib media my-yapi proc run srv tmp var
root@6181b9bbfc25:/# cd my-yapi/
root@6181b9bbfc25:/my-yapi# node vendors/server/app.js
log: 服务已启动,请打开下面链接访问:
http://127.0.0.1:3000/
(node:526) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
log: mongodb load success...
8、使用默认的账号密码就可以登录了 ,账号名:“[email protected]”,密码:“ymfe.org”
ctrl + c
可以结束 yapi 进程,再执行nohup node /my-yapi/vendors/server/app.js 2>&1 &
在后台运行 yapi,如下root@3d3a94296f11:/my-yapi# node vendors/server/app.js
log: the server is start at 127.0.0.1:3000
log: mongodb load success...
root@6181b9bbfc25:/my-yapi# nohup node /my-yapi/vendors/server/app.js 2>&1 &
[1] 91
root@6181b9bbfc25:/my-yapi# nohup: ignoring input and appending output to 'nohup.out'
root@6181b9bbfc25:/my-yapi#
docker exec -ti yapi bash
方式进入的容器,输入exit就可以了,以docker attach方式进入的容器,按ctrl+p+q
(就是三个键同时按),出现下图所示就可以了log: mongodb load success...
read escape sequence
➜ ~