From 78131eae9bbd72942db606109862df316a875473 Mon Sep 17 00:00:00 2001 From: Toyas Date: Thu, 27 Mar 2025 23:55:46 +0800 Subject: [PATCH] docs(test): Add development environment smoke test notes --- ...ŽSpring Cloud的高可用在线视频平台项目架构.md | 989 ++++++++++++++++++ docs/开发环境搭建.md | 90 ++ sql/init.sql | 4 +- .../src/main/resources/application.yml | 4 +- 4 files changed, 1083 insertions(+), 4 deletions(-) create mode 100644 docs/基于Spring Cloud的高可用在线视频平台项目架构.md create mode 100644 docs/开发环境搭建.md diff --git a/docs/基于Spring Cloud的高可用在线视频平台项目架构.md b/docs/基于Spring Cloud的高可用在线视频平台项目架构.md new file mode 100644 index 0000000..c29ba87 --- /dev/null +++ b/docs/基于Spring Cloud的高可用在线视频平台项目架构.md @@ -0,0 +1,989 @@ +# 基于Spring Cloud的高可用在线视频平台项目架构 + +## 技术栈选型 + +根据2024年最新技术栈和Spring Cloud Alibaba 2023.0.1.0版本,选用以下组件: + +- **框架基础**: + - Spring Boot 3.2.4 + - Spring Cloud 2023.0.1 + - Spring Cloud Alibaba 2023.0.1.0 + +- **核心组件**: + - Nacos 2.3.2 (服务注册与配置中心) + - Sentinel 1.8.6 (流量控制) + - Seata 2.0.0 (分布式事务) + - RocketMQ 5.1.4 (消息队列) + +- **其他组件**: + - Spring Cloud Gateway (API网关) + - OpenFeign (服务调用) + - Spring Security + OAuth2 + JWT (安全认证) + - MySQL 8.0 (主数据库) + - Redis 7.0 (缓存) + - MinIO (分布式文件存储) + - FFmpeg (视频处理) + - Prometheus + Grafana (监控) + - Docker + DockerCompose (容器化部署) + +## IntelliJ IDEA 创建步骤 + +### 1. 创建父工程 (Maven项目) + +1. 打开IntelliJ IDEA,选择"File" -> "New" -> "Project" +2. 选择"Maven",点击"Next" +3. 填写项目信息: + - GroupId: `com.nuaa.video` + - ArtifactId: `video-platform` + - Version: `1.0.0` +4. 点击"Finish"创建项目 + +5. 修改父工程pom.xml: + +```xml + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.4 + + + + com.nuaa.video + video-platform + 1.0.0 + pom + video-platform + 基于Spring Cloud的高可用在线视频平台 + + + 17 + UTF-8 + UTF-8 + 2023.0.1 + 2023.0.1.0 + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + + + video-common + video-gateway + video-auth + video-user + video-content + video-comment + video-recommend + video-admin + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + + + + +``` + +### 2. 创建公共模块 (video-common) + +1. 右键父工程 -> New -> Module +2. 选择"Maven",点击"Next" +3. 填写模块信息: + - Name: `video-common` + - Parent: `com.nuaa.video:video-platform` +4. 点击"Finish" + +5. 修改video-common的pom.xml: + +```xml + + + + video-platform + com.nuaa.video + 1.0.0 + + 4.0.0 + + video-common + + + + + org.projectlombok + lombok + true + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-validation + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.5 + + + + + mysql + mysql-connector-java + 8.0.33 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + io.minio + minio + 8.5.7 + + + + + cn.hutool + hutool-all + 5.8.26 + + + + + io.jsonwebtoken + jjwt-api + 0.12.3 + + + io.jsonwebtoken + jjwt-impl + 0.12.3 + runtime + + + io.jsonwebtoken + jjwt-jackson + 0.12.3 + runtime + + + +``` + +### 3. 创建API网关模块 (video-gateway) + +1. 右键父工程 -> New -> Module +2. 选择"Maven",点击"Next" +3. 填写模块信息: + - Name: `video-gateway` + - Parent: `com.nuaa.video:video-platform` +4. 点击"Finish" + +5. 修改video-gateway的pom.xml: + +```xml + + + + video-platform + com.nuaa.video + 1.0.0 + + 4.0.0 + + video-gateway + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + com.alibaba.cloud + spring-cloud-alibaba-sentinel-gateway + + + + + org.springframework.boot + spring-boot-starter-actuator + + + +``` + +6. 创建application.yml: + +```yaml +server: + port: 9000 + +spring: + application: + name: video-gateway + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + namespace: public + group: DEFAULT_GROUP + gateway: + discovery: + locator: + enabled: true + lower-case-service-id: true + routes: + - id: video-auth + uri: lb://video-auth + predicates: + - Path=/auth/** + filters: + - StripPrefix=1 + - id: video-user + uri: lb://video-user + predicates: + - Path=/user/** + filters: + - StripPrefix=1 + - id: video-content + uri: lb://video-content + predicates: + - Path=/content/** + filters: + - StripPrefix=1 + - id: video-comment + uri: lb://video-comment + predicates: + - Path=/comment/** + filters: + - StripPrefix=1 + - id: video-recommend + uri: lb://video-recommend + predicates: + - Path=/recommend/** + filters: + - StripPrefix=1 + - id: video-admin + uri: lb://video-admin + predicates: + - Path=/admin/** + filters: + - StripPrefix=1 + sentinel: + transport: + dashboard: localhost:8080 + port: 8719 + eager: true + scg: + fallback: + mode: response + response-body: '{"code":500,"message":"服务不可用,请稍后再试"}' + +management: + endpoints: + web: + exposure: + include: '*' +``` + +7. 创建主启动类`GatewayApplication.java`: + +```java +package com.nuaa.video.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class GatewayApplication { + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } +} +``` + +### 4. 创建认证服务模块 (video-auth) + +1. 右键父工程 -> New -> Module +2. 选择"Maven",点击"Next" +3. 填写模块信息: + - Name: `video-auth` + - Parent: `com.nuaa.video:video-platform` +4. 点击"Finish" + +5. 修改video-auth的pom.xml: + +```xml + + + + video-platform + com.nuaa.video + 1.0.0 + + 4.0.0 + + video-auth + + + + com.nuaa.video + video-common + ${project.version} + + + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + + + + + org.springframework.security + spring-security-oauth2-authorization-server + 1.2.1 + + + +``` + +6. 创建application.yml: + +```yaml +server: + port: 9001 + +spring: + application: + name: video-auth + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + namespace: public + group: DEFAULT_GROUP + sentinel: + transport: + dashboard: localhost:8080 + port: 8720 + eager: true + datasource: + url: jdbc:mysql://localhost:3306/video_auth?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + redis: + host: localhost + port: 6379 + password: + database: 0 + +mybatis-plus: + mapper-locations: classpath:mapper/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +jwt: + secret: video-platform-secret-key-2024-nuaa + expiration: 86400 + token-header: Authorization +``` + +7. 创建主启动类`AuthApplication.java`: + +```java +package com.nuaa.video.auth; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class AuthApplication { + public static void main(String[] args) { + SpringApplication.run(AuthApplication.class, args); + } +} +``` + +### 5. 创建用户服务模块 (video-user) + +1. 右键父工程 -> New -> Module +2. 选择"Maven",点击"Next" +3. 填写模块信息: + - Name: `video-user` + - Parent: `com.nuaa.video:video-platform` +4. 点击"Finish" + +5. 修改video-user的pom.xml: + +```xml + + + + video-platform + com.nuaa.video + 1.0.0 + + 4.0.0 + + video-user + + + + com.nuaa.video + video-common + ${project.version} + + + +``` + +6. 创建application.yml: + +```yaml +server: + port: 9002 + +spring: + application: + name: video-user + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + namespace: public + group: DEFAULT_GROUP + sentinel: + transport: + dashboard: localhost:8080 + port: 8721 + eager: true + datasource: + url: jdbc:mysql://localhost:3306/video_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + redis: + host: localhost + port: 6379 + password: + database: 1 + +mybatis-plus: + mapper-locations: classpath:mapper/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +``` + +7. 创建主启动类`UserApplication.java`: + +```java +package com.nuaa.video.user; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class UserApplication { + public static void main(String[] args) { + SpringApplication.run(UserApplication.class, args); + } +} +``` + +### 6. 创建内容服务模块 (video-content) + +1. 右键父工程 -> New -> Module +2. 选择"Maven",点击"Next" +3. 填写模块信息: + - Name: `video-content` + - Parent: `com.nuaa.video:video-platform` +4. 点击"Finish" + +5. 修改video-content的pom.xml: + +```xml + + + + video-platform + com.nuaa.video + 1.0.0 + + 4.0.0 + + video-content + + + + com.nuaa.video + video-common + ${project.version} + + + + + org.apache.rocketmq + rocketmq-spring-boot-starter + 2.2.3 + + + + + net.bramp.ffmpeg + ffmpeg + 0.7.0 + + + +``` + +6. 创建application.yml: + +```yaml +server: + port: 9003 + +spring: + application: + name: video-content + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + namespace: public + group: DEFAULT_GROUP + sentinel: + transport: + dashboard: localhost:8080 + port: 8722 + eager: true + datasource: + url: jdbc:mysql://localhost:3306/video_content?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + redis: + host: localhost + port: 6379 + password: + database: 2 + rocketmq: + name-server: localhost:9876 + producer: + group: video-content-group + +mybatis-plus: + mapper-locations: classpath:mapper/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +minio: + endpoint: http://localhost:9000 + accessKey: minioadmin + secretKey: minioadmin + bucketName: video-platform +``` + +7. 创建主启动类`ContentApplication.java`: + +```java +package com.nuaa.video.content; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class ContentApplication { + public static void main(String[] args) { + SpringApplication.run(ContentApplication.class, args); + } +} +``` + +### 7. 创建评论服务模块 (video-comment) + +1. 右键父工程 -> New -> Module +2. 选择"Maven",点击"Next" +3. 填写模块信息: + - Name: `video-comment` + - Parent: `com.nuaa.video:video-platform` +4. 点击"Finish" + +5. 修改video-comment的pom.xml: + +```xml + + + + video-platform + com.nuaa.video + 1.0.0 + + 4.0.0 + + video-comment + + + + com.nuaa.video + video-common + ${project.version} + + + +``` + +6. 创建application.yml: + +```yaml +server: + port: 9004 + +spring: + application: + name: video-comment + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + namespace: public + group: DEFAULT_GROUP + sentinel: + transport: + dashboard: localhost:8080 + port: 8723 + eager: true + datasource: + url: jdbc:mysql://localhost:3306/video_comment?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + redis: + host: localhost + port: 6379 + password: + database: 3 + +mybatis-plus: + mapper-locations: classpath:mapper/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +``` + +7. 创建主启动类`CommentApplication.java`: + +```java +package com.nuaa.video.comment; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class CommentApplication { + public static void main(String[] args) { + SpringApplication.run(CommentApplication.class, args); + } +} +``` + +### 8. 创建推荐服务模块 (video-recommend) + +1. 右键父工程 -> New -> Module +2. 选择"Maven",点击"Next" +3. 填写模块信息: + - Name: `video-recommend` + - Parent: `com.nuaa.video:video-platform` +4. 点击"Finish" + +5. 修改video-recommend的pom.xml: + +```xml + + + + video-platform + com.nuaa.video + 1.0.0 + + 4.0.0 + + video-recommend + + + + com.nuaa.video + video-common + ${project.version} + + + + + org.apache.spark + spark-mllib_2.12 + 3.4.1 + + + + + org.apache.commons + commons-math3 + 3.6.1 + + + +``` + +6. 创建application.yml: + +```yaml +server: + port: 9005 + +spring: + application: + name: video-recommend + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + namespace: public + group: DEFAULT_GROUP + sentinel: + transport: + dashboard: localhost:8080 + port: 8724 + eager: true + datasource: + url: jdbc:mysql://localhost:3306/video_recommend?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + redis: + host: localhost + port: 6379 + password: + database: 4 + +mybatis-plus: + mapper-locations: classpath:mapper/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +``` + +7. 创建主启动类`RecommendApplication.java`: + +```java +package com.nuaa.video.recommend; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class RecommendApplication { + public static void main(String[] args) { + SpringApplication.run(RecommendApplication.class, args); + } +} +``` + +### 9. 创建管理后台模块 (video-admin) + +1. 右键父工程 -> New -> Module +2. 选择"Maven",点击"Next" +3. 填写模块信息: + - Name: `video-admin` + - Parent: `com.nuaa.video:video-platform` +4. 点击"Finish" + +5. 修改video-admin的pom.xml: + +```xml + + + + video-platform + com.nuaa.video + 1.0.0 + + 4.0.0 + + video-admin + + + + com.nuaa.video + video-common + ${project.version} + + + +``` + +6. 创建application.yml: + +```yaml +server: + port: 9006 + +spring: + application: + name: video-admin + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + namespace: public + group: DEFAULT_GROUP + sentinel: + transport: + dashboard: localhost:8080 + port: 8725 + eager: true + datasource: + url: jdbc:mysql://localhost:3306/video_admin?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + redis: + host: localhost + port: 6379 + password: + database: 5 + +mybatis-plus: + mapper-locations: classpath:mapper/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +``` + +7. 创建主启动类`AdminApplication.java`: + +```java +package com.nuaa.video.admin; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class AdminApplication { + public static void main(String[] args) { + SpringApplication.run(AdminApplication.class, args); + } +} +``` + diff --git a/docs/开发环境搭建.md b/docs/开发环境搭建.md new file mode 100644 index 0000000..2f54427 --- /dev/null +++ b/docs/开发环境搭建.md @@ -0,0 +1,90 @@ +## 开发环境步骤 + +**安装JDK 17** + +```bash +# Ubuntu/Debian +sudo apt install openjdk-17-jdk + +# CentOS/RHEL +sudo yum install java-17-openjdk-devel +``` + +**安装Docker和Docker Compose** + +```bash +# 安装Docker +curl -fsSL https://get.docker.com | sh +sudo systemctl enable --now docker + +# 安装Docker Compose +sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +sudo chmod +x /usr/local/bin/docker-compose +``` + +**安装MySQL 8.0** + +```bash +docker run -d --name mysql8 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=video_auth -v /data/mysql:/var/lib/mysql mysql:8.0 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci +``` + +**安装Redis 7.0** + +```bash +docker run -d --name redis7 -p 6379:6379 redis:7.0-alpine +``` + +**RocketMQ 5.1.4** + +```bash +# 先安装NameServer +docker run -d --name rmqnamesrv -p 9876:9876 apache/rocketmq:5.1.4 sh mqnamesrv + +# 再安装Broker +docker run -d --name rmqbroker --link rmqnamesrv:namesr -p 10909:10909 -p 10911:10911 -e "NAMESRV_ADDR=namesrv:9876" -e "JAVA_OPTS=-Duser.home=/opt" apache/rocketmq:5.1.4 sh mqbroker -c /home/rocketmq/rocketmq-5.1.4/conf/broker.conf +``` + +**minio** + +```bash +docker run -d --name minio -p 9002:9000 -p 9001:9001 -v /data/minio:/data -e "MINIO_ROOT_USER=minioadmin" -e "MINIO_ROOT_PASSWORD=minioadmin" quay.io/minio/minio server /data --console-address ":9001" +``` + +**安装Nacos 2.3.2** + +```bash +docker run -d --name nacos -p 8848:8848 -p 9848:9848 -p 9849:9849 -e MODE=standalone -e JVM_XMS=512m -e JVM_XMX=512m nacos/nacos-server:v2.3.2 +``` + +**Sentinel Dashboard 1.8.6** + +#### **使用官方发布的 JAR 包自行构建镜像** + +1. **创建 `Dockerfile`** + + ```bash + FROM eclipse-temurin:8-jre + + # 下载 Sentinel 1.8.6 官方 JAR + RUN wget -O /sentinel-dashboard.jar \ + https://github.com/alibaba/Sentinel/releases/download/1.8.6/sentinel-dashboard-1.8.6.jar + + # 设置时区(可选) + RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone + + EXPOSE 8080 + CMD ["java", "-Dserver.port=8080", "-Dcsp.sentinel.dashboard.server=localhost:8080", "-jar", "/sentinel-dashboard.jar"] + ``` + +2. **构建镜像** + + ```bash + docker build -t sentinel-dashboard:1.8.6 . + ``` + +3. **运行容器** + + ```bash + docker run -d --name sentinel -p 8080:8080 sentinel-dashboard:1.8.6 + ``` + diff --git a/sql/init.sql b/sql/init.sql index c3fd577..353337f 100644 --- a/sql/init.sql +++ b/sql/init.sql @@ -773,10 +773,10 @@ INSERT IGNORE INTO `admin_user_role` (`admin_id`, `role_id`) VALUES -- 初始化系统配置 INSERT IGNORE INTO `admin_system_config` (`config_key`, `config_value`, `description`) VALUES - ('site_name', '南航在线视频平台', '网站名称'), + ('site_name', '高可用在线视频平台', '网站名称'), ('site_logo', '/static/logo.png', '网站Logo'), ('site_favicon', '/static/favicon.ico', '网站图标'), - ('site_copyright', 'Copyright © 2024 南京航空航天大学', '版权信息'), + ('site_copyright', 'Copyright © 2024 XXXXXX', '版权信息'), ('video_upload_limit', '1024', '视频上传大小限制(MB)'), ('video_review_enabled', '1', '视频审核开关(0:关闭,1:开启)'), ('comment_review_enabled', '0', '评论审核开关(0:关闭,1:开启)'), diff --git a/video-gateway/src/main/resources/application.yml b/video-gateway/src/main/resources/application.yml index 98a4fc8..d89b735 100644 --- a/video-gateway/src/main/resources/application.yml +++ b/video-gateway/src/main/resources/application.yml @@ -7,7 +7,7 @@ spring: cloud: nacos: discovery: - server-addr: 127.0.0.1:8848 + server-addr: 5.180.253.115:8848 namespace: public group: DEFAULT_GROUP gateway: @@ -54,7 +54,7 @@ spring: - StripPrefix=1 sentinel: transport: - dashboard: localhost:8080 + dashboard: 5.180.253.115:8080 port: 8719 eager: true scg: