YApi 是高效、易用、功能强大的 api 管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。可以帮助开发者轻松创建、发布、维护 API,YApi 还为用户提供了优秀的交互体验,开发人员只需利用平台提供的接口数据写入工具以及简单的点击操作就可以实现接口的管理。
官方项目仓库 https://github.com/YMFE/yapi
本文通过docker部署YApi,docker仓库地址:https://github.com/fjc0k/docker-YApi
安装docker和docker-compose
卸载旧版本docker
apt-get remove docker docker-engine docker.io containerd runc
安装依赖包
apt-get install ca-certificates curl gnupg lsb-release
添加 Docker 的官方 GPG 密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
使用以下命令设置稳定存储库
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装 Docker和docker-compose
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose
部署YApi
mkdir /home/docker-YApi
cd /home/docker-YApi
git clone https://github.com/fjc0k/docker-YApi.git
修改一些自定义配置(修改管理员账号密码,docker映射的端口8888==》3000)
vim docker-compose.yml
version: '3'
services:
yapi-web:
image: jayfong/yapi:latest
container_name: yapi-web
ports:
- 8888:3000
environment:
- YAPI_ADMIN_ACCOUNT=管理员账号
- YAPI_ADMIN_PASSWORD=管理员密码
- 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:latest
container_name: yapi-mongo
volumes:
- ./data/db:/data/db
expose:
- 27017
restart: unless-stoppedb
部署容器
docker-compose up -d
查看运行的两个容器yapi-web和yapi-mongo
docker ps -a
配置nginx反向代理到yapi
安装nginx
以下是官方给出的 nginx 安装步骤,详情可参考这里
安装依赖程序
apt install curl gnupg2 ca-certificates lsb-release -y
导入stable nginx 安装源
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
设置安装源倾向性
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx
导入nginx官方签名
curl -o /tmp/nginx_signing.key https://nginx.org/keys/nginx_signing.key
验证下载的文件是否包含正确的密钥
gpg --dry-run --quiet --import --import-options show-only /tmp/nginx_signing.key
输出如下指纹信息则正确:573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key <signing-key@nginx.com>
最后,将密钥移动到 apt 可信密钥存储(注意“asc”文件扩展名更改):
mv /tmp/nginx_signing.key /etc/apt/trusted.gpg.d/nginx_signing.asc
安装nginx
apt update
apt install nginx -y
设置nginx开机自动启动
systemctl enable nginx
配置nginx反向代理到yapi(下面以yapi.example.com域名为例,当然您也可以通过ip访问)
vim /etc/nginx/conf.d/yapi.example.com.conf
server {
listen 80;
listen [::]:80;
server_name yapi.example.com;
access_log /var/log/nginx/yapi.example.com/access.log;
error_log /var/log/nginx/yapi.example.com/error.log;
index index.html index.htm index.php;
location / {
proxy_pass http://127.0.0.1:8888;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
创建日志存放目录并授权
mkdir /var/log/nginx/yapi.example.com/
chown -R nginx:nginx /var/log/nginx/yapi.example.com/
重启nginx
systemctl restart nginx
访问站点测试
http://yapi.example.com
文章评论