目录
资源清单
主机 | IP |
---|---|
Yapi节点 | 10.0.0.1 |
软件 | 版本 |
---|---|
docker | 20.10.12 |
docker-compose | 1.23.1 |
Yapi镜像 | 1.12.0 |
服务部署依赖 LDAP ,部署服务也可以不启用 LDAP 服务
一、Docker
安装
1. 使用国内 yum
源
$ yum install -y yum-utils device-mapper-persistent-data lvm2
$ yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2. 卸载旧版本的 docker
## 如果主机上已经有docker存在且不是想要安装的版本,需要先进行卸载。
$ yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
container*
3. 安装 Docker20.10
版本
$ yum -y install docker-ce-20.10.12-3.el7 docker-ce-cli-20.10.12-3.el7 vim
4. 设置镜像加速
$ mkdir /etc/docker
$ vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://xxxxxxxxx.mirror.aliyuncs.com"]
}
5. 启动 docker
$ systemctl start docker
$ systemctl enable docker
$ systemctl status docker
二、Docker-compose
安装
1. Docker-compose
安装
## github.com 可能访问超时,可以使用下面的获取下载下来后上传服务器即可
$ curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ curl -k "https://dl.cactifans.com/zabbix_docker/docker-compose" -o /usr/bin/docker-compose
$ chmod a+x /usr/bin/docker-compose
2. 查看 docker-compose
版本
$ docker-compose version
三、Yapi
安装
1. 获取 Yapi v1.12.0
版本包软件
$ wget https://codeload.github.com/YMFE/yapi/tar.gz/refs/tags/v1.12.0 -O yapi-1.12.0.tar.gz
2. 创建 Yapi
目录
$ mkdir -pv /data/yapi/{conf,log,docker-compose}
$ mv yapi-1.12.0.tar.gz /data/yapi/docker-compose/
$ cd /data/yapi/docker-compose
3. 提供镜像打包和服务配置文件等
a | Dockerfile
文件
$ cat Dockerfile
FROM node:11 as builder
RUN apt-get install -y git python make openssl tar gcc
ADD yapi-1.12.0.tar.gz /home/
RUN mkdir /api && mv /home/yapi-1.12.0 /api/vendors
RUN cd /api/vendors && \
npm install --production --registry https://registry.npm.taobao.org
FROM node:11
MAINTAINER evescn
ENV TZ="Asia/Shanghai" HOME="/"
WORKDIR ${HOME}
COPY --from=builder /api/vendors /api/vendors
EXPOSE 3000
COPY docker-entrypoint.sh /api/
RUN chmod 755 /api/docker-entrypoint.sh
ENTRYPOINT ["/api/docker-entrypoint.sh"]
b | docker-entrypoint.sh
文件
$ cat docker-entrypoint.sh
#!/bin/bash
set -eo pipefail
shopt -s nullglob
node /api/vendors/server/app.js
exec "$@"
c | docker-compose.yaml
文件
$ cat docker-compose.yaml
version: "3"
services:
# Sevice
yapi:
build:
context: ./
dockerfile: ./Dockerfile
image: harbor.evescn.com/devops/yapi:v1.12.0
container_name: yapi
environment:
- VERSION=1.12.0
- LOG_PATH=/tmp/yapi.log
ports:
- 3000:3000
volumes:
- /data/yapi/log/yapi.log:/tmp/yapi.log # log dir
- /data/yapi/conf/config.json:/api/config.json
depends_on:
- mongo
networks:
- YapiNet
# DB
mongo:
image: mongo:6.0.4
container_name: mongo
restart: always
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=Stacs@1808
volumes:
- /etc/localtime:/etc/localtime
- /data/yapi/mongodb/data:/data/db
- /data/yapi/mongodb/log:/var/log/mongodb
networks:
- YapiNet
networks:
YapiNet:
driver: bridge
d | config.json
文件
$ cat config.json
{
"port": "3000",
"adminAccount": "[email protected]",
"timeout":120000,
"db": {
"servername": "mongo",
"DATABASE": "yapi",
"port": 27017,
"user": "root",
"pass": "root123",
"authSource": "admin"
},
"mail": {
"enable": true,
"host": "smtp.163.com", //邮箱服务器
"port": 465, //端口
"from": "***@163.com", //发送人邮箱
"auth": {
"user": "***@163.com", //邮箱服务器账号
"pass": "*****" //邮箱服务器密码
}
},
"ldapLogin": {
"enable": true, // 没有 LDAP 服务,可以设置为 false ,或者不配置 ldapLogin 信息
"server": "ldap://l-ldapt1.com",
"baseDn": "CN=Admin,CN=Users,DC=test,DC=com",
"bindPassword": "password123",
"searchDn": "OU=UserContainer,DC=test,DC=com",
"searchStandard": "mail", // 自定义格式: "searchStandard": "&(objectClass=user)(cn=%s)"
"emailPostfix": "@163.com",
"emailKey": "mail",
"usernameKey": "name"
}
}
参考文档:
http://yapi.smart-xwork.cn/doc/devops/index.html
https://github.com/MyHerux/code-note/blob/master/Program/%E5%B7%A5%E5%85%B7%E7%AF%87/Yapi/%E4%BD%BF%E7%94%A8DockerCompose%E6%9E%84%E5%BB%BA%E9%83%A8%E7%BD%B2Yapi.md
4. 打包镜像
$ docker-compose build
5. 提供服务配置文件信息
$ cp config.json /data/yapi/conf/config.json
6. 启动服务
$ docker-compose up -d