说明
github地址:
https://github.com/YMFE/yapi
该开源软件多个你熟悉的大公司都在使用,还是很不错的。部署方式也非常多元化。
本例给出的是,docker部署方式,即docker-compose一键部署yapi
base enviroment:
python3.6.5(沙盒方案)、CentOS Linux release 7.7.1908、Docker 1.13.1、openresty/1.15.8.2
如上基础环境准备好以后,部署就非常简单了。
1.创建配置文件
# vim docker-compose.yml,依据自己的环境修改
version: '2.1'
services:
yapi:
image: mrjin/yapi:latest
# build: ./
container_name: yapi
environment:
- VERSION=1.5.6
- LOG_PATH=/tmp/yapi.log
- HOME=/home
- PORT=3000
- ADMIN_EMAIL=me@jinfeijie.cn
- DB_SERVER=mongo
- DB_NAME=yapi
- DB_PORT=27017
# restart: always
ports:
- 127.0.0.1:3000:3000
volumes:
- ~/data/yapi/log/yapi.log:/home/vendors/log # log dir
depends_on:
- mongo
entrypoint: "bash /wait-for-it.sh mongo:27017 -- entrypoint.sh"
networks:
- back-net
mongo:
image: mongo
container_name: mongo
# restart: always
ports:
- 127.0.0.1:27017:27017
volumes:
- ~/data/yapi/mongodb:/data/db #db dir
networks:
- back-net
networks:
back-net:
external: true
2.创建network
#docker network create back-net
3.启动服务
python沙盒环境下运行
#pip install docker-compose
#docker-compose up -d
PS:docker-compose需要通过pip安装,但安装时会有异常,需要调整到国内的镜像源。
4.检查是否启动成功
netstat -anp|grep 3000
5.配置防火墙
开通3000端口,允许访问firewall-cmd --zone=public
--permanent --add-port=3306/tcp
firewall-cmd --reload
6.nginx配置
官方缺少upstream部分的配置
upstream yapi{
server 127.0.0.1:3000 weight=5;
}
server {
listen 80;
server_name test.com 192.168.*.*;
keepalive_timeout 70;
location / {
proxy_pass http://yapi;
}
location ~ /\. {
deny all;
}
}
接下来就可以登录平台管理你的接口了。
7.对项目做修改,二次开发
比如去掉一些尾部
【异常】
1.pip安装docker-compose时异常
(ven) [root@localhost Yapi]# pip install docker-compose
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/docker-compose/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/docker-compose/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/docker-compose/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/docker-compose/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/docker-compose/
Could not fetch URL https://pypi.org/simple/docker-compose/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/docker-compose/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
ERROR: Could not find a version that satisfies the requirement docker-compose (from versions: none)
ERROR: No matching distribution found for docker-compose
网上好多说是更新pip安装ssl,但同样会报上面的错误,实际是因为网络的问题,需要使用国内的镜像源来加速
# pip install docker-compose -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
镜像源指向国内,异常得到解决。
来源:oschina
链接:https://my.oschina.net/guiguketang/blog/3158902