# 资金服务平台单机部署文档 > 版本: v1.0 > 更新日期: 2026-02-20 > 作者: zhangjf --- ## 一、部署概述 ### 1.1 部署架构 ``` ┌─────────────────────────────────────────────────────────────────┐ │ 单机部署架构 │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────────────────────────────┐ │ │ │ 前端服务 │ │ │ │ fund-admin (Nginx:80) fund-mobile (Nginx:81) │ │ │ └─────────────────────────┬───────────────────────────────┘ │ │ │ │ │ ┌─────────────────────────▼───────────────────────────────┐ │ │ │ Gateway (8000) │ │ │ │ API网关 + Token验证 │ │ │ └─────────────────────────┬───────────────────────────────┘ │ │ │ │ │ ┌─────────────────────────┼───────────────────────────────┐ │ │ │ │ │ │ │ │ ┌────────┬────────┬───┴───┬────────┬────────┐ │ │ │ │ ▼ ▼ ▼ ▼ ▼ ▼ │ │ │ │ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │ │ │ │ │ sys │ │ cust │ │ proj │ │ req │ │ exp │ │rcpt │ │ │ │ │ │:8100 │ │:8200 │ │:8300 │ │:8400 │ │:8500 │ │:8600 │ │ │ │ │ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ │ │ │ │ │ │ │ │ ┌──────┐ ┌──────┐ │ │ │ │ │report│ │ file │ │ │ │ │ │:8700 │ │:8800 │ │ │ │ │ └──────┘ └──────┘ │ │ │ │ │ │ │ │ 业务微服务集群 │ │ │ └──────────────────────────────────────────────────────────┘ │ │ │ │ ┌──────────────────────────────────────────────────────────┐ │ │ │ 基础设施服务 │ │ │ │ MySQL(3306) Redis(6379) Nacos(8848/8048) │ │ │ └──────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────┘ ``` ### 1.2 服务清单 | 服务名称 | 端口 | 说明 | |----------|------|------| | fund-gateway | 8000 | API网关 | | fund-sys | 8100 | 系统管理服务 | | fund-cust | 8200 | 客户管理服务 | | fund-proj | 8300 | 项目管理服务 | | fund-req | 8400 | 需求工单服务 | | fund-exp | 8500 | 支出管理服务 | | fund-receipt | 8600 | 收款管理服务 | | fund-report | 8700 | 报表服务 | | fund-file | 8800 | 文件服务 | ### 1.3 目录结构 ``` /opt/fundplatform/ # 应用根目录 ├── deploy/ # 部署目录 │ ├── fund-gateway/ # Gateway服务 │ │ ├── fund-gateway.jar # 服务JAR包 │ │ ├── application.yml # 服务配置文件 │ │ ├── start.sh # 启动脚本 │ │ ├── stop.sh # 停止脚本 │ │ └── restart.sh # 重启脚本 │ ├── fund-sys/ # 系统服务 │ │ ├── fund-sys.jar │ │ ├── application.yml │ │ ├── start.sh │ │ ├── stop.sh │ │ └── restart.sh │ ├── fund-cust/ # 客户服务 │ ├── fund-proj/ # 项目服务 │ ├── fund-req/ # 需求服务 │ ├── fund-exp/ # 支出服务 │ ├── fund-receipt/ # 收款服务 │ ├── fund-report/ # 报表服务 │ ├── fund-file/ # 文件服务 │ ├── start-all.sh # 一键启动所有服务 │ ├── stop-all.sh # 一键停止所有服务 │ ├── restart-all.sh # 一键重启所有服务 │ └── status.sh # 查看所有服务状态 ├── sql/ # 数据库脚本 │ ├── fund_platform_schema.sql # 表结构 │ └── fund_platform_init.sql # 初始化数据 └── config/ # 公共配置 └── env.properties # 环境变量配置 /datacfs/applogs/ # 日志根目录 ├── fund-gateway/ # Gateway日志 │ ├── info.log │ ├── error.log │ └── aop.log ├── fund-sys/ # 系统服务日志 ├── fund-cust/ # 客户服务日志 ├── fund-proj/ # 项目服务日志 ├── fund-req/ # 需求服务日志 ├── fund-exp/ # 支出服务日志 ├── fund-receipt/ # 收款服务日志 ├── fund-report/ # 报表服务日志 └── fund-file/ # 文件服务日志 ``` --- ## 二、环境安装与配置 ### 2.1 环境要求 | 组件 | 版本要求 | 说明 | |------|----------|------| | 操作系统 | CentOS 7+ / Ubuntu 18+ | Linux服务器 | | JDK | 21+ | Java运行环境 | | MySQL | 8.0+ | 数据库 | | Redis | 7.0+ | 缓存服务 | | Nacos | 3.0+ | 服务注册中心 | ### 2.2 安装 JDK 21 ```bash # 方式一:使用包管理器安装 (Ubuntu) sudo apt update sudo apt install openjdk-21-jdk # 方式二:使用包管理器安装 (CentOS) sudo yum install java-21-openjdk java-21-openjdk-devel # 方式三:手动安装 cd /opt wget https://download.java.net/openjdk/jdk21/ri/openjdk-21+35_linux-x64_bin.tar.gz tar -xzf openjdk-21+35_linux-x64_bin.tar.gz ln -s /opt/jdk-21 /opt/java # 配置环境变量 cat >> /etc/profile << 'EOF' export JAVA_HOME=/opt/java export PATH=$JAVA_HOME/bin:$PATH EOF source /etc/profile # 验证安装 java -version ``` ### 2.3 安装 MySQL 8.0 ```bash # Ubuntu 安装 sudo apt update sudo apt install mysql-server-8.0 # CentOS 安装 sudo yum install mysql-server # 启动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';" # 创建数据库用户(可选,用于应用连接) sudo mysql -u root -p'zjf@123456' << 'EOF' CREATE USER 'fund_user'@'%' IDENTIFIED BY 'Fund@123456'; GRANT ALL PRIVILEGES ON *.* TO 'fund_user'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES; EOF ``` ### 2.4 安装 Redis 7.0 ```bash # Ubuntu 安装 sudo apt update sudo apt install redis-server # CentOS 安装 (需要EPEL源) sudo yum install epel-release sudo yum install redis # 配置密码 sudo sed -i 's/# requirepass foobared/requirepass zjf@123456/' /etc/redis/redis.conf # 配置持久化 sudo sed -i 's/appendonly no/appendonly yes/' /etc/redis/redis.conf # 启动Redis sudo systemctl restart redis sudo systemctl enable redis # 验证安装 redis-cli -a 'zjf@123456' ping ``` ### 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 mv nacos nacos-server # 配置端口(可选,默认8848) cd /opt/nacos-server/conf sed -i 's/server.port=8848/server.port=8848/' application.properties # 配置MySQL持久化(推荐生产环境使用) cat >> application.properties << 'EOF' spring.datasource.platform=mysql db.num=1 db.url.0=jdbc:mysql://localhost:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai db.user.0=root db.password.0=zjf@123456 EOF # 创建Nacos数据库 mysql -u root -p'zjf@123456' << 'EOF' CREATE DATABASE IF NOT EXISTS nacos_config CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; EOF # 导入Nacos表结构 mysql -u root -p'zjf@123456' nacos_config < /opt/nacos-server/conf/mysql-schema.sql # 启动Nacos(单机模式) cd /opt/nacos-server/bin sh startup.sh -m standalone # 查看启动日志 tail -f /opt/nacos-server/logs/start.out # 访问控制台 # http://服务器IP:8848/nacos # 默认账号密码:nacos / nacos ``` ### 2.6 创建Nacos命名空间 ```bash # 登录Nacos控制台或使用API创建命名空间 curl -X POST 'http://localhost:8848/nacos/v1/console/namespaces' \ -d 'customNamespaceId=fund-platform' \ -d 'namespaceName=资金服务平台' \ -d 'namespaceDesc=资金服务平台命名空间' ``` --- ## 三、数据库创建和初始化 ### 3.1 创建数据库 ```bash # 登录MySQL mysql -u root -p'zjf@123456' # 执行创建数据库脚本 ``` ```sql -- 创建各服务数据库 CREATE DATABASE IF NOT EXISTS fund_sys CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE DATABASE IF NOT EXISTS fund_cust CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE DATABASE IF NOT EXISTS fund_proj CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE DATABASE IF NOT EXISTS fund_req CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE DATABASE IF NOT EXISTS fund_exp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE DATABASE IF NOT EXISTS fund_receipt CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE DATABASE IF NOT EXISTS fund_report CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE DATABASE IF NOT EXISTS fund_file CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- 查看数据库 SHOW DATABASES; ``` ### 3.2 初始化表结构 ```bash # 上传SQL脚本到服务器 cd /opt/fundplatform mkdir -p sql # 执行表结构脚本 mysql -u root -p'zjf@123456' fund_sys < sql/fund_sys_schema.sql mysql -u root -p'zjf@123456' fund_cust < sql/fund_cust_schema.sql mysql -u root -p'zjf@123456' fund_proj < sql/fund_proj_schema.sql mysql -u root -p'zjf@123456' fund_req < sql/fund_req_schema.sql mysql -u root -p'zjf@123456' fund_exp < sql/fund_exp_schema.sql mysql -u root -p'zjf@123456' fund_receipt < sql/fund_receipt_schema.sql mysql -u root -p'zjf@123456' fund_report < sql/fund_report_schema.sql mysql -u root -p'zjf@123456' fund_file < sql/fund_file_schema.sql # 执行初始化数据脚本 mysql -u root -p'zjf@123456' fund_sys < sql/fund_sys_init.sql ``` --- ## 四、服务部署 ### 4.1 创建部署目录 ```bash # 创建应用目录 mkdir -p /opt/fundplatform/deploy mkdir -p /opt/fundplatform/sql mkdir -p /opt/fundplatform/config # 创建日志目录 mkdir -p /datacfs/applogs/fund-gateway mkdir -p /datacfs/applogs/fund-sys mkdir -p /datacfs/applogs/fund-cust mkdir -p /datacfs/applogs/fund-proj mkdir -p /datacfs/applogs/fund-req mkdir -p /datacfs/applogs/fund-exp mkdir -p /datacfs/applogs/fund-receipt mkdir -p /datacfs/applogs/fund-report mkdir -p /datacfs/applogs/fund-file ``` ### 4.2 编译打包 ```bash # 在开发机上编译打包 cd /path/to/fundplatform mvn clean package -DskipTests # 打包结果 # fund-gateway/target/fund-gateway-0.0.1-SNAPSHOT.jar # fund-sys/target/fund-sys-0.0.1-SNAPSHOT.jar # ... ``` ### 4.3 上传部署文件 ```bash # 上传JAR包和配置文件到服务器 scp fund-gateway/target/fund-gateway-0.0.1-SNAPSHOT.jar user@server:/opt/fundplatform/deploy/fund-gateway/fund-gateway.jar scp fund-gateway/src/main/resources/application.yml user@server:/opt/fundplatform/deploy/fund-gateway/ scp fund-sys/target/fund-sys-0.0.1-SNAPSHOT.jar user@server:/opt/fundplatform/deploy/fund-sys/fund-sys.jar scp fund-sys/src/main/resources/application.yml user@server:/opt/fundplatform/deploy/fund-sys/ # ... 其他服务类似 ``` ### 4.4 配置文件修改 各服务配置文件需要根据实际环境修改以下配置: ```yaml # MySQL配置 spring: datasource: url: jdbc:mysql://数据库IP:3306/fund_sys?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai username: fund_user password: Fund@123456 # Redis配置 data: redis: host: Redis服务器IP port: 6379 password: zjf@123456 # Nacos配置 cloud: nacos: discovery: server-addr: Nacos服务器IP:8848 namespace: fund-platform ``` ### 4.5 部署脚本 每个服务目录下包含以下脚本: #### start.sh - 启动脚本 ```bash #!/bin/bash # 服务启动脚本 APP_NAME="fund-gateway" APP_HOME="/opt/fundplatform/deploy/${APP_NAME}" LOG_HOME="/datacfs/applogs/${APP_NAME}" JAR_FILE="${APP_HOME}/${APP_NAME}.jar" PID_FILE="${APP_HOME}/${APP_NAME}.pid" # JVM参数 JAVA_OPTS="-Xms256m -Xmx512m -XX:+UseG1GC" # 日志参数 LOG_OPTS="-Dlogging.file.path=${LOG_HOME} -DAPP_NAME=${APP_NAME}" # 检查是否已运行 if [ -f "$PID_FILE" ]; then PID=$(cat $PID_FILE) if ps -p $PID > /dev/null 2>&1; then echo "${APP_NAME} is already running (PID: $PID)" exit 1 fi fi # 启动服务 echo "Starting ${APP_NAME}..." nohup java $JAVA_OPTS $LOG_OPTS -jar $JAR_FILE \ --spring.config.location=${APP_HOME}/application.yml \ > /dev/null 2>&1 & # 保存PID echo $! > $PID_FILE echo "${APP_NAME} started (PID: $(cat $PID_FILE))" ``` #### stop.sh - 停止脚本 ```bash #!/bin/bash # 服务停止脚本 APP_NAME="fund-gateway" APP_HOME="/opt/fundplatform/deploy/${APP_NAME}" PID_FILE="${APP_HOME}/${APP_NAME}.pid" # 检查是否运行 if [ ! -f "$PID_FILE" ]; then echo "${APP_NAME} is not running" exit 0 fi PID=$(cat $PID_FILE) if ! ps -p $PID > /dev/null 2>&1; then echo "${APP_NAME} is not running" rm -f $PID_FILE exit 0 fi # 停止服务 echo "Stopping ${APP_NAME} (PID: $PID)..." kill $PID # 等待停止 for i in {1..30}; do if ! ps -p $PID > /dev/null 2>&1; then break fi sleep 1 done # 强制停止 if ps -p $PID > /dev/null 2>&1; then echo "Force killing ${APP_NAME}..." kill -9 $PID fi rm -f $PID_FILE echo "${APP_NAME} stopped" ``` #### restart.sh - 重启脚本 ```bash #!/bin/bash # 服务重启脚本 APP_NAME="fund-gateway" SCRIPT_DIR=$(dirname "$0") ${SCRIPT_DIR}/stop.sh sleep 3 ${SCRIPT_DIR}/start.sh ``` ### 4.6 一键管理脚本 #### start-all.sh - 一键启动所有服务 ```bash #!/bin/bash # 一键启动所有服务 DEPLOY_HOME="/opt/fundplatform/deploy" # 服务启动顺序(先启动基础服务) SERVICES=( "fund-gateway" "fund-sys" "fund-cust" "fund-proj" "fund-req" "fund-exp" "fund-receipt" "fund-report" "fund-file" ) echo "==========================================" echo " Starting all services..." echo "==========================================" for service in "${SERVICES[@]}"; do if [ -f "${DEPLOY_HOME}/${service}/start.sh" ]; then echo "" echo "Starting ${service}..." ${DEPLOY_HOME}/${service}/start.sh sleep 5 fi done echo "" echo "==========================================" echo " All services started" echo "==========================================" ${DEPLOY_HOME}/status.sh ``` #### stop-all.sh - 一键停止所有服务 ```bash #!/bin/bash # 一键停止所有服务 DEPLOY_HOME="/opt/fundplatform/deploy" # 服务停止顺序(反向停止) SERVICES=( "fund-file" "fund-report" "fund-receipt" "fund-exp" "fund-req" "fund-proj" "fund-cust" "fund-sys" "fund-gateway" ) echo "==========================================" echo " Stopping all services..." echo "==========================================" for service in "${SERVICES[@]}"; do if [ -f "${DEPLOY_HOME}/${service}/stop.sh" ]; then echo "" echo "Stopping ${service}..." ${DEPLOY_HOME}/${service}/stop.sh sleep 2 fi done echo "" echo "==========================================" echo " All services stopped" echo "==========================================" ``` #### restart-all.sh - 一键重启所有服务 ```bash #!/bin/bash # 一键重启所有服务 DEPLOY_HOME="/opt/fundplatform/deploy" ${DEPLOY_HOME}/stop-all.sh echo "" echo "Waiting 10 seconds..." sleep 10 ${DEPLOY_HOME}/start-all.sh ``` #### status.sh - 查看所有服务状态 ```bash #!/bin/bash # 查看所有服务状态 DEPLOY_HOME="/opt/fundplatform/deploy" SERVICES=( "fund-gateway:8000" "fund-sys:8100" "fund-cust:8200" "fund-proj:8300" "fund-req:8400" "fund-exp:8500" "fund-receipt:8600" "fund-report:8700" "fund-file:8800" ) echo "==========================================" echo " Service Status" echo "==========================================" printf "%-20s %-10s %-10s %s\n" "Service" "Port" "Status" "PID" echo "------------------------------------------" for item in "${SERVICES[@]}"; do service="${item%%:*}" port="${item##*:}" pid_file="${DEPLOY_HOME}/${service}/${service}.pid" if [ -f "$pid_file" ]; then PID=$(cat $pid_file) if ps -p $PID > /dev/null 2>&1; then printf "%-20s %-10s \033[32m%-10s\033[0m %s\n" "$service" "$port" "RUNNING" "$PID" else printf "%-20s %-10s \033[31m%-10s\033[0m %s\n" "$service" "$port" "STOPPED" "-" fi else printf "%-20s %-10s \033[31m%-10s\033[0m %s\n" "$service" "$port" "STOPPED" "-" fi done echo "==========================================" ``` --- ## 五、部署操作指南 ### 5.1 首次部署 ```bash # 1. 创建目录 mkdir -p /opt/fundplatform/deploy mkdir -p /datacfs/applogs # 2. 上传部署包 # 将deploy目录上传到/opt/fundplatform/ # 3. 赋予执行权限 chmod +x /opt/fundplatform/deploy/*/start.sh chmod +x /opt/fundplatform/deploy/*/stop.sh chmod +x /opt/fundplatform/deploy/*/restart.sh chmod +x /opt/fundplatform/deploy/*.sh # 4. 修改配置文件 # 编辑各服务的application.yml,配置数据库、Redis、Nacos地址 # 5. 启动所有服务 /opt/fundplatform/deploy/start-all.sh # 6. 检查服务状态 /opt/fundplatform/deploy/status.sh ``` ### 5.2 服务管理 ```bash # 启动单个服务 /opt/fundplatform/deploy/fund-sys/start.sh # 停止单个服务 /opt/fundplatform/deploy/fund-sys/stop.sh # 重启单个服务 /opt/fundplatform/deploy/fund-sys/restart.sh # 一键启动所有服务 /opt/fundplatform/deploy/start-all.sh # 一键停止所有服务 /opt/fundplatform/deploy/stop-all.sh # 一键重启所有服务 /opt/fundplatform/deploy/restart-all.sh # 查看服务状态 /opt/fundplatform/deploy/status.sh ``` ### 5.3 日志查看 ```bash # 查看实时日志 tail -f /datacfs/applogs/fund-sys/info.log # 查看错误日志 tail -f /datacfs/applogs/fund-sys/error.log # 查看API请求日志 tail -f /datacfs/applogs/fund-sys/aop.log # 查看所有服务日志 tail -f /datacfs/applogs/*/info.log ``` ### 5.4 服务更新 ```bash # 1. 备份旧版本 cp /opt/fundplatform/deploy/fund-sys/fund-sys.jar /opt/fundplatform/deploy/fund-sys/fund-sys.jar.bak # 2. 上传新版本JAR包 scp fund-sys.jar user@server:/opt/fundplatform/deploy/fund-sys/ # 3. 重启服务 /opt/fundplatform/deploy/fund-sys/restart.sh # 4. 检查服务状态 /opt/fundplatform/deploy/status.sh tail -f /datacfs/applogs/fund-sys/info.log ``` --- ## 六、常见问题处理 ### 6.1 服务无法启动 ```bash # 检查端口占用 netstat -tlnp | grep 8100 # 检查Java进程 ps -ef | grep fund-sys # 查看启动日志 tail -100 /datacfs/applogs/fund-sys/info.log # 检查配置文件 cat /opt/fundplatform/deploy/fund-sys/application.yml ``` ### 6.2 服务注册失败 ```bash # 检查Nacos是否运行 curl http://localhost:8848/nacos/v1/console/health/readiness # 检查服务注册状态 curl http://localhost:8848/nacos/v1/ns/instance/list?serviceName=fund-sys&namespaceId=fund-platform # 检查Nacos命名空间 curl http://localhost:8848/nacos/v1/console/namespaces ``` ### 6.3 数据库连接失败 ```bash # 检查MySQL是否运行 systemctl status mysql # 测试数据库连接 mysql -h localhost -u fund_user -p'Fund@123456' -e "SELECT 1" # 检查数据库是否存在 mysql -u root -p'zjf@123456' -e "SHOW DATABASES LIKE 'fund_%'" ``` ### 6.4 Redis连接失败 ```bash # 检查Redis是否运行 systemctl status redis # 测试Redis连接 redis-cli -a 'zjf@123456' ping ``` --- ## 七、附录 ### 7.1 环境变量配置 ```bash # /opt/fundplatform/config/env.properties # MySQL配置 MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USERNAME=fund_user MYSQL_PASSWORD=Fund@123456 # Redis配置 REDIS_HOST=localhost REDIS_PORT=6379 REDIS_PASSWORD=zjf@123456 # Nacos配置 NACOS_HOST=localhost NACOS_PORT=8848 NACOS_NAMESPACE=fund-platform NACOS_USERNAME=nacos NACOS_PASSWORD=nacos ``` ### 7.2 端口清单 | 服务 | 端口 | 协议 | |------|------|------| | MySQL | 3306 | TCP | | Redis | 6379 | TCP | | Nacos API | 8848 | HTTP | | Nacos 控制台 | 8048 | HTTP | | fund-gateway | 8000 | HTTP | | fund-sys | 8100 | HTTP | | fund-cust | 8200 | HTTP | | fund-proj | 8300 | HTTP | | fund-req | 8400 | HTTP | | fund-exp | 8500 | HTTP | | fund-receipt | 8600 | HTTP | | fund-report | 8700 | HTTP | | fund-file | 8800 | HTTP | ### 7.3 访问地址 | 服务 | 地址 | |------|------| | API网关 | http://服务器IP:8000 | | Nacos控制台 | http://服务器IP:8848/nacos | | 管理后台 | http://服务器IP:80 | ### 7.4 默认账号 | 系统 | 用户名 | 密码 | |------|--------|------| | Nacos | nacos | nacos | | 管理后台 | admin | 123456 | --- **文档结束**