# 资金服务平台部署运维文档 > 版本: v2.0 > 更新日期: 2026-02-20 > 作者: zhangjf --- ## 一、本地开发环境搭建 ### 1.1 环境要求 | 组件 | 版本要求 | 说明 | |------|----------|------| | JDK | 21+ | Java开发工具包 | | Maven | 3.9+ | 项目构建工具 | | MySQL | 8.0+ | 数据库 | | Redis | 7.0+ | 缓存服务 | | Nacos | 3.0+ | 服务注册与配置中心 | | Node.js | 18+ | 前端开发环境 | ### 1.2 安装步骤 #### 1.2.1 安装 JDK 21 ```bash # Ubuntu/Debian sudo apt update sudo apt install openjdk-21-jdk # 配置环境变量 echo 'export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64' >> ~/.bashrc echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc source ~/.bashrc # 验证安装 java -version ``` #### 1.2.2 安装 Maven 3.9 ```bash # 下载并解压 Maven wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz tar -xzf apache-maven-3.9.9-bin.tar.gz -C /opt/ # 配置环境变量 echo 'export MAVEN_HOME=/opt/apache-maven-3.9.9' >> ~/.bashrc echo 'export PATH=$MAVEN_HOME/bin:$PATH' >> ~/.bashrc source ~/.bashrc # 验证安装 mvn -version ``` #### 1.2.3 安装 MySQL 8.0 ```bash # Ubuntu/Debian sudo apt update sudo apt install mysql-server-8.0 # 启动 MySQL sudo systemctl start mysql sudo systemctl enable mysql # 配置 root 密码 sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'zjf@123456';" # 创建数据库 mysql -u root -p'zjf@123456' -e "CREATE DATABASE fund_platform CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" ``` #### 1.2.4 安装 Redis ```bash # Ubuntu/Debian sudo apt update sudo apt install redis-server # 配置密码 sudo sed -i 's/# requirepass foobared/requirepass zjf@123456/' /etc/redis/redis.conf # 启动 Redis sudo systemctl restart redis sudo systemctl enable redis # 验证安装 redis-cli -a zjf@123456 ping ``` #### 1.2.5 安装 Nacos 3.0 ```bash # 下载 Nacos cd /opt wget https://github.com/alibaba/nacos/releases/download/3.0.0/nacos-server-3.0.0.tar.gz tar -xzf nacos-server-3.0.0.tar.gz # 配置端口 cd nacos/conf sed -i 's/server.port=8848/server.port=8048/' application.properties # 启动 Nacos(单机模式) cd /opt/nacos/bin sh startup.sh -m standalone # 访问控制台:http://localhost:8048/nacos # 默认账号密码:nacos / nacos ``` #### 1.2.6 安装 Node.js 18 ```bash # 使用 nvm 安装 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash source ~/.bashrc nvm install 18 nvm use 18 # 验证安装 node -v npm -v ``` ### 1.3 项目初始化 ```bash # 克隆项目 git clone cd fundplatform # 初始化数据库 mysql -u root -p'zjf@123456' < sql/fund_platform_schema.sql mysql -u root -p'zjf@123456' < sql/fund_platform_init.sql # 配置环境变量 cp .env.example .env # 编辑 .env 文件,配置数据库、Redis、Nacos 连接信息 ``` ### 1.4 启动服务 ```bash # 1. 确保 MySQL、Redis、Nacos 已启动 # 2. 启动后端服务(在各自服务目录执行) cd fund-gateway mvn spring-boot:run cd fund-sys mvn spring-boot:run # 3. 启动前端(Vue 3) cd fund-admin npm install npm run dev # 4. 访问系统 # 管理后台:http://localhost:3000 # 网关地址:http://localhost:8000 # Nacos 控制台:http://localhost:8048/nacos # Grafana 监控:http://localhost:3000 (Docker环境) 或 http://localhost:3001 (本地开发) # Prometheus:http://localhost:9090 ``` --- ## 二、Docker Compose 部署 ### 2.1 部署架构 项目支持 **Docker Compose 一键部署**,包含以下服务组件: ``` ┌─────────────────────────────────────────────────────────────────────────────┐ │ Docker Compose 部署架构 │ ├─────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────┐ │ │ │ 前端服务 │ │ │ │ fund-admin │ ← 管理后台 (http://localhost:80) │ │ │ fund-mobile │ ← 移动端H5 (http://localhost:81) │ │ └──────┬───────┘ │ │ │ │ │ ┌──────┴───────┐ │ │ │ Gateway │ ← API网关 (http://localhost:8000) │ │ │ :8000 │ │ │ └──────┬───────┘ │ │ │ │ │ ┌──────┴──────────────────────────────────────────┐ │ │ │ │ │ │ ▼ ▼ ▼ ▼ │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ │fund-sys │ │fund-cust│ │fund-proj│ │fund-req │ │ ← 业务微服务集群 │ │ │ :8100 │ │ :8200 │ │ :8300 │ │ :8400 │ │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ │ │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ │fund-exp │ │fund-rcpt│ │fund-rpt │ │ │ │ │ :8500 │ │ :8600 │ │ :8700 │ │ │ │ └─────────┘ └─────────┘ └─────────┘ │ │ │ │ │ │ ┌──────────────────────┬─────────────────────┐ │ │ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ MySQL │ │ Redis │ │ Nacos │ ← 基础设施 │ │ │ :3306 │ │ :6379 │ │ :8848 │ │ │ └─────────┘ └─────────┘ └─────────┘ │ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ 监控体系 │ │ │ │ ┌─────────────┐ ┌─────────────┐ │ │ │ │ │ Prometheus │ │ Grafana │ │ │ │ │ │ :9090 │──────────────│ :3000 │ │ │ │ │ └─────────────┘ └─────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` ### 2.2 服务清单 | 服务 | 端口 | 说明 | |------|------|------| | fund-admin | 80 | 管理后台前端 | | fund-mobile | 81 | 移动端H5 | | gateway | 8000 | API网关 | | fund-sys | 8100 | 系统管理服务 | | fund-sys-vip001 | 8101 | 系统服务VIP专属实例 | | fund-cust | 8200 | 客户管理服务 | | fund-proj | 8300 | 项目管理服务 | | fund-req | 8400 | 需求工单服务 | | fund-exp | 8500 | 支出管理服务 | | fund-receipt | 8600 | 收款管理服务 | | fund-report | 8700 | 报表服务 | | fund-file | 8800 | 文件服务 | | mysql | 3306 | MySQL数据库 | | redis | 6379 | Redis缓存 | | nacos | 8848 | Nacos服务注册中心 | | prometheus | 9090 | Prometheus监控 | | grafana | 3000 | Grafana可视化 | ### 2.3 快速部署 ```bash # 1. 克隆项目 git clone cd fundplatform # 2. 初始化环境 ./deploy.sh init # 3. 构建镜像 ./deploy.sh build # 4. 启动所有服务 ./deploy.sh start # 5. 查看服务状态 ./deploy.sh status # 6. 查看日志 ./deploy.sh logs --service fund-sys ``` ### 2.4 部署脚本命令 | 命令 | 说明 | |------|------| | `./deploy.sh start` | 启动所有服务 | | `./deploy.sh stop` | 停止所有服务 | | `./deploy.sh restart` | 重启所有服务 | | `./deploy.sh build` | 构建所有镜像 | | `./deploy.sh rebuild` | 重新构建(不使用缓存) | | `./deploy.sh logs` | 查看服务日志 | | `./deploy.sh status` | 查看服务状态 | | `./deploy.sh clean` | 清理未使用的镜像和容器 | | `./deploy.sh init` | 初始化环境(首次部署) | ### 2.5 多租户混合负载模式 项目支持 **多租户混合负载模式**,可实现VIP专属实例与普通租户共享实例并存: ``` ┌─────────────────────────────────────────────────────────────────┐ │ 多租户混合负载模式 │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ 请求 ──► Gateway ──► TenantGatewayFilter (提取租户ID) │ │ │ │ │ ┌───────────────┼───────────────┐ │ │ ▼ ▼ ▼ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ 共享实例 │ │ VIP_004专属 │ │ VIP_005专属 │ │ │ │ (多租户共享) │ │ (单租户独占) │ │ (单租户独占) │ │ │ │ fund-sys │ │ fund-sys- │ │ fund-sys- │ │ │ │ :8100 │ │ vip001:8101 │ │ vip002:8102 │ │ │ │ │ │ │ │ │ │ │ │ TENANT_ID: │ │ TENANT_ID: │ │ TENANT_ID: │ │ │ │ VIP_001, │ │ VIP_004 │ │ VIP_005 │ │ │ │ VIP_002, │ │ │ │ │ │ │ │ VIP_003 │ │ │ │ │ │ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────┘ ``` **配置方式**: 在 `docker-compose.yml` 中通过环境变量 `TENANT_ID` 指定实例服务的租户: ```yaml # 共享实例 - 服务多个租户 fund-sys: environment: TENANT_ID: "VIP_001,VIP_002,VIP_003" # 逗号分隔,服务多个租户 # VIP专属实例 - 单租户独占 fund-sys-vip001: environment: TENANT_ID: "VIP_004" # 单租户专属实例 ``` --- ## 三、测试环境部署 ### 3.1 服务器配置 | 组件 | 配置 | 数量 | |------|------|------| | 应用服务器 | 4核8G | 2台 | | 数据库服务器 | 4核8G | 1台 | | 缓存服务器 | 2核4G | 1台 | ### 3.2 部署架构 ``` ┌─────────────────────────────────────────────────────────────┐ │ 测试环境部署架构 │ ├─────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────┐ │ │ │ Nginx │ ← 负载均衡 + 静态资源 │ │ │ (80/443) │ │ │ └──────┬───────┘ │ │ │ │ │ ┌──────┴──────┐ │ │ │ │ │ │ ▼ ▼ │ │ ┌─────────┐ ┌─────────┐ │ │ │AppSrv-1 │ │AppSrv-2 │ ← 应用服务器(Gateway + Services)│ │ │:8080-8090│ │:8080-8090│ │ │ └────┬────┘ └────┬────┘ │ │ │ │ │ │ └─────┬──────┘ │ │ │ │ │ ┌────────┴────────┐ │ │ │ │ │ │ ▼ ▼ │ │ ┌─────────┐ ┌─────────┐ │ │ │ MySQL │ │ Redis │ │ │ │ :3306 │ │ :6379 │ │ │ └─────────┘ └─────────┘ │ │ │ │ ┌─────────┐ │ │ │ Nacos │ ← 服务注册与配置中心 │ │ │ :8848 │ │ │ └─────────┘ │ │ │ └─────────────────────────────────────────────────────────────┘ ``` ### 3.3 部署步骤 #### 3.3.1 部署 Nacos ```bash # 在服务器上安装 Nacos cd /opt wget https://github.com/alibaba/nacos/releases/download/3.0.0/nacos-server-3.0.0.tar.gz tar -xzf nacos-server-3.0.0.tar.gz cd nacos/conf # 配置 MySQL 持久化 cat >> application.properties << EOF spring.datasource.platform=mysql db.num=1 db.url.0=jdbc:mysql://mysql-server:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai db.user.0=nacos db.password.0=nacos_password EOF # 启动 Nacos(集群模式) cd /opt/nacos/bin sh startup.sh ``` #### 3.3.2 部署 MySQL ```bash # 创建数据库和用户 mysql -u root -p << EOF CREATE DATABASE IF NOT EXISTS fund_platform CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'fund_user'@'%' IDENTIFIED BY 'Fund@123456'; GRANT ALL PRIVILEGES ON fund_platform.* TO 'fund_user'@'%'; FLUSH PRIVILEGES; EOF # 导入表结构和数据 mysql -u fund_user -p'Fund@123456' fund_platform < fund_platform_schema.sql mysql -u fund_user -p'Fund@123456' fund_platform < fund_platform_init.sql ``` #### 3.3.3 部署 Redis ```bash # 配置 Redis sudo tee /etc/redis/redis.conf > /dev/null << EOF bind 0.0.0.0 port 6379 requirepass Redis@123456 maxmemory 2gb maxmemory-policy allkeys-lru appendonly yes EOF # 启动 Redis sudo systemctl restart redis ``` #### 3.3.4 部署应用服务 ```bash # 1. 打包应用 cd fundplatform mvn clean package -DskipTests # 2. 上传 jar 包到服务器 scp fund-gateway/target/fund-gateway-1.0.0.jar user@app-server-1:/opt/fundplatform/ scp fund-sys/target/fund-sys-1.0.0.jar user@app-server-1:/opt/fundplatform/ # 3. 创建启动脚本 cat > /opt/fundplatform/start.sh << 'EOF' #!/bin/bash APP_NAME=$1 JAR_FILE=$2 nohup java -Xms512m -Xmx1024m \ -Dspring.profiles.active=test \ -Dfile.encoding=UTF-8 \ -jar $JAR_FILE > logs/$APP_NAME.log 2>&1 & echo "$APP_NAME started, PID: $!" EOF chmod +x /opt/fundplatform/start.sh # 4. 启动服务 ./start.sh gateway fund-gateway-1.0.0.jar ./start.sh sys fund-sys-1.0.0.jar ``` #### 3.3.5 部署 Nginx ```bash # 安装 Nginx sudo apt install nginx # 配置反向代理 sudo tee /etc/nginx/sites-available/fundplatform << 'EOF' upstream gateway { server app-server-1:8080 weight=5; server app-server-2:8080 weight=5; } server { listen 80; server_name test.fundplatform.com; # 前端静态资源 location / { root /opt/fundplatform/admin; try_files $uri $uri/ /index.html; } # API 代理 location /api/ { proxy_pass http://gateway/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } EOF sudo ln -s /etc/nginx/sites-available/fundplatform /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx ``` --- ## 四、生产环境部署 ### 4.1 服务器配置 | 组件 | 配置 | 数量 | 说明 | |------|------|------|------| | 应用服务器 | 8核16G | 3台 | 运行 Gateway 和微服务 | | 数据库服务器 | 8核16G | 2台 | MySQL 主从 | | 缓存服务器 | 4核8G | 3台 | Redis 集群 | | Nacos 服务器 | 4核8G | 3台 | Nacos 集群 | | Nginx 服务器 | 4核8G | 2台 | 负载均衡 | ### 4.2 部署架构 ``` ┌─────────────────────────────────────────────────────────────────────────────┐ │ 生产环境部署架构 │ ├─────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────┐ ┌──────────────┐ │ │ │ Nginx-1 │◄────────────►│ Nginx-2 │ ← 负载均衡(Keepalived) │ │ │ (VIP:80/443)│ │ │ │ │ └──────┬───────┘ └──────┬───────┘ │ │ │ │ │ │ └──────────────┬───────────────┘ │ │ │ │ │ ┌─────────────────────┼─────────────────────┐ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │AppSrv-1 │ │AppSrv-2 │ │AppSrv-3 │ ← 应用服务集群 │ │ │:8080-8090│ │:8080-8090│ │:8080-8090│ │ │ └────┬────┘ └────┬────┘ └────┬────┘ │ │ │ │ │ │ │ └───────────────────┼───────────────────┘ │ │ │ │ │ ┌──────────────────────┼──────────────────────┐ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ MySQL │◄────────►│ MySQL │ │ Redis │ ← 数据层 │ │ │ Master │ 主从 │ Slave │ │ Cluster │ │ │ │ :3306 │ 复制 │ :3306 │ │ :6379 │ │ │ └─────────┘ └─────────┘ └────┬────┘ │ │ │ │ │ ┌─────────────────────────────────────────────┘ │ │ │ │ │ ▼ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ Nacos-1 │◄►│ Nacos-2 │◄►│ Nacos-3 │ ← Nacos 集群(外置 MySQL) │ │ │ :8848 │ │ :8848 │ │ :8848 │ │ │ └─────────┘ └─────────┘ └─────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` ### 4.3 高可用配置 #### 4.3.1 MySQL 主从配置 ```bash # 主库配置 [mysqld] server-id=1 log-bin=mysql-bin binlog-do-db=fund_platform # 从库配置 [mysqld] server-id=2 relay-log=mysql-relay-bin replicate-do-db=fund_platform # 创建复制用户 CREATE USER 'repl'@'%' IDENTIFIED BY 'Repl@123456'; GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%'; # 从库执行 CHANGE MASTER TO MASTER_HOST='master-host', MASTER_USER='repl', MASTER_PASSWORD='Repl@123456', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=154; START SLAVE; ``` #### 4.3.2 Redis 集群配置 ```bash # 创建 6 个节点(3主3从) redis-server --port 7001 --cluster-enabled yes --cluster-config-file nodes-7001.conf redis-server --port 7002 --cluster-enabled yes --cluster-config-file nodes-7002.conf redis-server --port 7003 --cluster-enabled yes --cluster-config-file nodes-7003.conf redis-server --port 7004 --cluster-enabled yes --cluster-config-file nodes-7004.conf redis-server --port 7005 --cluster-enabled yes --cluster-config-file nodes-7005.conf redis-server --port 7006 --cluster-enabled yes --cluster-config-file nodes-7006.conf # 创建集群 redis-cli --cluster create \ node1:7001 node1:7002 node2:7003 node2:7004 node3:7005 node3:7006 \ --cluster-replicas 1 ``` #### 4.3.3 Nacos 集群配置 ```bash # 配置 cluster.conf cat > /opt/nacos/conf/cluster.conf << EOF nacos-1:8848 nacos-2:8848 nacos-3:8848 EOF # 配置 MySQL 持久化 spring.datasource.platform=mysql db.num=1 db.url.0=jdbc:mysql://mysql-cluster:3306/nacos?... db.user.0=nacos db.password.0=nacos_password # 启动 Nacos sh startup.sh ``` #### 4.3.4 Nginx + Keepalived ```bash # 安装 Keepalived sudo apt install keepalived # 配置 Keepalived(主节点) cat > /etc/keepalived/keepalived.conf << EOF global_defs { router_id NGINX_MASTER } vrrp_script check_nginx { script "/etc/keepalived/check_nginx.sh" interval 2 weight -20 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.100/24 } track_script { check_nginx } } EOF # 健康检查脚本 cat > /etc/keepalived/check_nginx.sh << 'EOF' #!/bin/bash if ! pgrep nginx > /dev/null; then systemctl start nginx sleep 2 if ! pgrep nginx > /dev/null; then systemctl stop keepalived fi fi EOF chmod +x /etc/keepalived/check_nginx.sh ``` --- ## 五、运维手册 ### 5.1 监控体系 #### 5.1.1 应用监控(Prometheus + Grafana) 项目已集成 Prometheus + Grafana 监控体系,通过 Docker Compose 自动部署。 **Prometheus 配置** (`docker/prometheus/prometheus.yml`): ```yaml global: scrape_interval: 15s scrape_configs: - job_name: 'fund-gateway' metrics_path: '/actuator/prometheus' static_configs: - targets: ['gateway:8000'] - job_name: 'fund-sys' metrics_path: '/actuator/prometheus' static_configs: - targets: ['fund-sys:8100', 'fund-sys-vip001:8101'] - job_name: 'fund-cust' metrics_path: '/actuator/prometheus' static_configs: - targets: ['fund-cust:8200'] ``` **访问地址**: - Prometheus: http://localhost:9090 - Grafana: http://localhost:3000 (默认账号: admin / admin123) #### 5.1.2 关键监控指标 | 指标 | 告警阈值 | 说明 | |------|----------|------| | JVM 内存使用率 | > 80% | JVM 堆内存使用百分比 | | CPU 使用率 | > 80% | 服务器 CPU 使用率 | | 磁盘使用率 | > 85% | 磁盘空间使用百分比 | | 接口响应时间 | > 2s | API 平均响应时间 | | 错误率 | > 5% | HTTP 5xx 错误率 | | MySQL 连接数 | > 80% | 数据库连接数使用率 | | Redis 内存使用率 | > 80% | Redis 内存使用百分比 | ### 5.2 日志管理 #### 5.2.1 日志配置 项目采用 Logback 作为日志框架,支持 **TraceId + SpanId 链路追踪**: ```xml %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId:-}][%X{spanId:-}] %-5level %logger{50} - %msg%n ./logs/${APP_NAME}/info.log ./logs/${APP_NAME}/info-%d{yyyy-MM-dd}.%i.log 30 100MB %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId:-}][%X{spanId:-}] %-5level %logger{50} - %msg%n ./logs/${APP_NAME}/aop.log ./logs/${APP_NAME}/aop-%d{yyyy-MM-dd}.%i.log 30 %msg%n ``` **日志文件结构**: ``` logs/ ├── fund-gateway/ │ ├── info.log # 主日志 │ ├── error.log # 错误日志 │ └── aop.log # API请求日志 ├── fund-sys/ │ ├── info.log │ ├── error.log │ └── aop.log └── ... ``` #### 5.2.2 ELK 日志收集 ```yaml # filebeat.yml filebeat.inputs: - type: log enabled: true paths: - /var/log/fundplatform/*.log fields: service: fundplatform multiline.pattern: '^\d{4}-\d{2}-\d{2}' multiline.negate: true multiline.match: after output.elasticsearch: hosts: ["elasticsearch:9200"] index: "fundplatform-%{+yyyy.MM.dd}" ``` ### 5.3 备份策略 #### 5.3.1 数据库备份 ```bash #!/bin/bash # 数据库备份脚本 BACKUP_DIR="/backup/mysql" DATE=$(date +%Y%m%d_%H%M%S) DB_NAME="fund_platform" DB_USER="backup_user" DB_PASS="Backup@123456" # 全量备份 mysqldump -u$DB_USER -p$DB_PASS --single-transaction --routines --triggers $DB_NAME > $BACKUP_DIR/${DB_NAME}_${DATE}.sql # 压缩 gzip $BACKUP_DIR/${DB_NAME}_${DATE}.sql # 删除 7 天前的备份 find $BACKUP_DIR -name "${DB_NAME}_*.sql.gz" -mtime +7 -delete # 上传到对象存储 aws s3 cp $BACKUP_DIR/${DB_NAME}_${DATE}.sql.gz s3://fundplatform-backup/mysql/ ``` #### 5.3.2 备份计划 | 备份类型 | 频率 | 保留时间 | |----------|------|----------| | 全量备份 | 每天 02:00 | 30 天 | | 增量备份 | 每小时 | 7 天 | | 二进制日志 | 实时 | 7 天 | ### 5.4 故障处理 #### 5.4.1 常见故障及处理 | 故障现象 | 可能原因 | 处理方案 | |----------|----------|----------| | 服务无法启动 | 端口冲突 | 检查端口占用,修改配置 | | 数据库连接失败 | 连接池耗尽 | 增加连接池大小,检查慢查询 | | 内存溢出 | 内存泄漏 | 分析堆转储,重启服务 | | 接口超时 | 下游服务慢 | 检查依赖服务,增加熔断 | | Redis 连接失败 | 连接数超限 | 增加连接池,检查连接泄露 | #### 5.4.2 应急处理流程 ``` 1. 故障发现 ↓ 2. 故障确认(查看监控、日志) ↓ 3. 故障定级(P0-核心功能不可用,P1-部分功能受影响,P2-轻微影响) ↓ 4. 启动应急预案 - P0:立即回滚或重启 - P1:限流降级,保留核心功能 - P2:记录问题,计划修复 ↓ 5. 故障恢复验证 ↓ 6. 故障复盘 ``` ### 5.5 性能优化 #### 5.5.1 JVM 调优 ```bash # 生产环境 JVM 参数 java -server \ -Xms4g -Xmx4g \ -XX:MetaspaceSize=256m \ -XX:MaxMetaspaceSize=512m \ -XX:+UseG1GC \ -XX:MaxGCPauseMillis=200 \ -XX:+HeapDumpOnOutOfMemoryError \ -XX:HeapDumpPath=/var/log/fundplatform/heapdump.hprof \ -jar app.jar ``` #### 5.5.2 MySQL 调优 ```ini # my.cnf [mysqld] # 连接配置 max_connections = 500 max_connect_errors = 1000 wait_timeout = 600 interactive_timeout = 600 # InnoDB 配置 innodb_buffer_pool_size = 4G innodb_log_file_size = 512M innodb_flush_log_at_trx_commit = 2 innodb_flush_method = O_DIRECT # 查询缓存 query_cache_type = 1 query_cache_size = 256M # 慢查询日志 slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 2 ``` #### 5.5.3 Redis 调优 ```bash # redis.conf maxmemory 4gb maxmemory-policy allkeys-lru tcp-keepalive 300 timeout 0 ``` --- ## 六、附录 ### 6.1 常用命令 ```bash # 查看服务状态 systemctl status mysql systemctl status redis systemctl status nginx # 查看日志 tail -f logs/fund-gateway/info.log tail -f logs/fund-sys/aop.log # 查看进程 ps -ef | grep java netstat -tlnp | grep 8000 # 数据库操作 mysql -u root -p'zjf@123456' redis-cli -a 'zjf@123456' # Nacos 管理 curl http://localhost:8848/nacos/v1/ns/instance/list?serviceName=fund-sys # Docker 操作 docker ps docker logs fund-gateway docker-compose restart fund-sys ``` ### 6.2 端口清单 | 服务 | 本地开发端口 | Docker端口 | 说明 | |------|-------------|------------|------| | fund-admin | 3000 | 80 | 管理后台前端 | | fund-mobile | 5174 | 81 | 移动端H5 | | Gateway | 8000 | 8000 | API网关 | | fund-sys | 8100 | 8100 | 系统管理服务 | | fund-sys-vip001 | - | 8101 | 系统服务VIP实例 | | fund-cust | 8200 | 8200 | 客户管理服务 | | fund-proj | 8300 | 8300 | 项目管理服务 | | fund-req | 8400 | 8400 | 需求工单服务 | | fund-exp | 8500 | 8500 | 支出管理服务 | | fund-receipt | 8600 | 8600 | 收款管理服务 | | fund-report | 8700 | 8700 | 报表服务 | | fund-file | 8800 | 8800 | 文件服务 | | MySQL | 3306 | 3306 | 数据库 | | Redis | 6379 | 6379 | 缓存 | | Nacos API | 8848 | 8848 | 服务注册 | | Nacos 控制台 | 8048 | - | 配置中心 | | Prometheus | 9090 | 9090 | 监控 | | Grafana | 3001 | 3000 | 可视化 | ### 6.3 环境变量配置 项目使用 `.env` 文件管理环境变量: ```bash # ============================================ # 资金服务平台环境配置 # ============================================ # MySQL 配置 MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USERNAME=root MYSQL_PASSWORD=zjf@123456 MYSQL_AUTH_PLUGIN=caching_sha2_password # Redis 配置 REDIS_HOST=localhost REDIS_PORT=6379 REDIS_PASSWORD=zjf@123456 # Nacos 配置 NACOS_HOST=localhost NACOS_PORT=8848 NACOS_USERNAME=nacos NACOS_PASSWORD=nacos NACOS_CONSOLE_PORT=8048 # Grafana 配置 GRAFANA_PASSWORD=admin123 ``` ### 6.4 访问地址汇总 | 服务 | 本地开发 | Docker部署 | |------|----------|------------| | 管理后台 | http://localhost:3000 | http://localhost:80 | | 移动端H5 | http://localhost:5174 | http://localhost:81 | | API网关 | http://localhost:8000 | http://localhost:8000 | | Nacos控制台 | http://localhost:8048/nacos | http://localhost:8848/nacos | | Prometheus | http://localhost:9090 | http://localhost:9090 | | Grafana | http://localhost:3001 | http://localhost:3000 | ### 6.5 默认账号 | 系统 | 用户名 | 密码 | |------|--------|------| | Nacos | nacos | nacos | | Grafana | admin | admin123 | | 管理后台 | admin | 123456 | --- **文档结束**