Deploy Compose PlayEdu
Docker-Compose 部署 PlayEdu
一. 前置环境
创建脚本,通过自定义配置文件快速生成
项目版本迭代很快,具体参数可参考 官网 来修改
- 创建目录:主要用于持久化视频文件和配置文件
- 项目代码:下载各项目文件,项目分为
api、backend、frontend、sql
- 定义配置:数据库和相关环境变量参数
| #!/bin/bash
APP_URL=`ip addr show eth0 |grep -w inet |awk '{print $2}' |awk -F '/' '{print $1}'`
APP_PATH='/opt/playedu/app'
SQL_PATH="${APP_PATH}-mysql"
URL_PATH="https://gitee.com/playeduxyz"
# 创建程序目录
mkdir -p $APP_PATH-{redis/data,mysql/{conf,data,log,dump},minio/{config,data}}
# 下载项目文件
cd /opt/playedu
git clone $URL_PATH/playedu.git playedu-api
git clone $URL_PATH/backend.git playedu-backend
git clone $URL_PATH/frontend.git playedu-frontend
cd ./playedu-api && docker build -t playedu-api:1.0-beta.6 .
cd ../playedu-backend && cp .env.example .env && echo "http://$APP_URL:9898" >> .env && docker build -t playedu-backend .
cd ../playedu-frontend && cp .env.example .env && sed -i "s/URL=/URL=http:\/\/$APP_URL:9898/g" .env && docker build -t playedu-frontend .
# 下载数据库文件并重名
wget -O $SQL_PATH/dump/playedu.sql https://gitee.com/playeduxyz/playedu/raw/main/databases/v1.0-beta.1.sql
# 替换超级管理员账密,非必须
# 修改默认账密为admin@mail.com/Admin@123
# cd $SQL_PATH/dump
# sed -i "s/超级管理员/Admin/g" $SQL_PATH/dump/playedu.sql
# sed -i "s/admin@playedu.xyz/admin@mail.com/g" `grep admin@playedu.xyz -rl playedu.sql`
# sed -i "s/d771587aa711961304fa8c1a5273f491/e324e31f2308217b874f808319f6ea95/g" `grep d771587aa711961304fa8c1a5273f491 -rl playedu.sql`
# 创建数据库配置文件
tee $SQL_PATH/conf/my.cnf<<-'EOF'
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
# 实现mysql不区分大小(开发需求,建议开启)
lower_case_table_names=1
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
default-time_zone = '+8:00'
# 更改字符集 如果想Mysql在后续的操作中文不出现乱码,则需要修改配置文件内容
symbolic-links=0
character-set-server=utf8mb4
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
EOF
|
二. 编排服务
项目代码已内置了 Dockerfile
文件,build
后直接调用镜像文件
| version: '3.8'
services:
# 缓存数据
cache:
image: redis:7.0.9-alpine3.17
container_name: playedu-redis
restart: unless-stopped
command: redis-server --requirepass 'Admin@123'
volumes:
- ./app-redis/data:/data
ports:
- 6379:6379
# 信息存储
db:
image: mysql:5.7
container_name: playedu-mysql
restart: unless-stopped
command: [
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_general_ci',
'--max_connections=3000'
]
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: Admin@123
MYSQL_USER: Admin
MYSQL_PASS: Admin123
MYSQL_DATABASE: playedu
volumes:
- ./app-mysql/conf:/etc/mysql/conf.d
- ./app-mysql/data:/var/lib/mysql
- ./app-mysql/log:/var/log/mysql
# 导入指定目录的sql文件(docker-compose导入.sql转储文件)
- ./app-mysql/dump:/docker-entrypoint-initdb.d
ports:
- 3306:3306
# 数据存储
minio:
image: minio/minio
container_name: playedu-minio
restart: unless-stopped
command: server --address ":9000" --console-address ":50000" /app-minio/data
environment:
MINIO_ACCESS_KEY: Admin
MINIO_SECRET_KEY: Admin@123
logging:
options:
max-size: "4096M"
max-file: "10"
driver: json-file
volumes:
- ./app-minio/config:/root/.minio
- ./app-minio/data:/data
- /etc/localtime:/etc/localtime:ro
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
ports:
- 9000:9000
- 50000:50000
# API接口
api:
image: playedu-api:1.0-beta.6
container_name: playedu-api
restart: unless-stopped
environment:
spring.profiles.active: prod
spring.datasource.url: "jdbc:mysql://db:3306/playedu?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false"
spring.datasource.username: root
spring.datasource.password: Admin@123
spring.data.redis.host: cache
spring.data.redis.port: 6379
spring.data.redis.password: Admin@123
# 内部调用api不生效,改为映射端口
ports:
- 9898:9898
depends_on:
- cache
- db
- minio
links:
- cache:cache
- db:db
- minio:minio
# 后台界面
backend:
image: playedu-backend
container_name: playedu-backend
restart: unless-stopped
ports:
- 8081:80
depends_on:
- api
# 学员界面
frontend:
image: playedu-frontend
container_name: playedu-frontend
restart: unless-stopped
ports:
- 8082:80
depends_on:
- api
|