⚠️ MVP 阶段说明
本项目为全新项目,尚未上线,当前处于 MVP(最小可行产品)阶段。
本文档描述的是 MVP 版本的部署方案,生产环境部署前需完成性能优化和安全加固。版本:v1.0-MVP | 更新日期:2026-06-16 | 状态:开发中
| 组件 | 最低版本 | 推荐版本 | 说明 |
|---|---|---|---|
| JDK | 17 | 17.0.x LTS | 必须,Spring Boot 3.x 要求 |
| Maven | 3.8 | 3.9+ | 构建工具 |
| MySQL | 8.0 | 8.0.33+ | 主数据库 |
| Redis | 6.0 | 7.0+ | 缓存、限流、验证码 |
| 环境 | CPU | 内存 | 磁盘 |
|---|---|---|---|
| 开发环境 | 2核 | 4GB | 20GB |
| 测试环境 | 4核 | 8GB | 50GB |
| 生产环境 | 8核 | 16GB | 100GB SSD |
# 安装 MySQL 8.0
# Windows: 下载 MySQL Installer
# Linux:
sudo apt install mysql-server-8.0
# 创建数据库
mysql -u root -p
CREATE DATABASE zhijiayun_pharmacy
DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_unicode_ci;
# 创建应用用户(生产环境建议不使用root)
CREATE USER 'zhijiayun'@'%' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON zhijiayun_pharmacy.* TO 'zhijiayun'@'%';
FLUSH PRIVILEGES;
# Windows: 使用 Memurai 或 WSL 安装
# Linux:
sudo apt install redis-server
# 配置密码(生产环境必须)
# 编辑 /etc/redis/redis.conf
requirepass your_redis_password
# 启动
sudo systemctl start redis
sudo systemctl enable redis
主配置文件:zhijiayun-gateway/src/main/resources/application.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/zhijiayun_pharmacy?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true
username: zhijiayun
password: your_secure_password
hikari:
minimum-idle: 5
maximum-pool-size: 20
idle-timeout: 300000
max-lifetime: 1800000
connection-timeout: 30000
spring:
data:
redis:
host: localhost
port: 6379
password: your_redis_password
database: 0
timeout: 5000ms
lettuce:
pool:
max-active: 16
max-idle: 8
min-idle: 2
max-wait: 3000ms
jwt:
secret: YourSuperSecretKeyForJWTTokenGenerationMustBeAtLeast256BitsLong!! # 生产环境必须更换
expiration: 86400000 # 24小时
refresh-expiration: 604800000 # 7天
重要:生产环境必须替换
jwt.secret,建议使用 256 位以上随机字符串。
sms:
access-key-id: ${ALIBABA_CLOUD_ACCESS_KEY_ID}
access-key-secret: ${ALIBABA_CLOUD_ACCESS_KEY_SECRET}
sign-name: 知家云药房
template-code: SMS_000000
通过环境变量注入 AK/SK,不要硬编码在配置文件中。
wechat:
open:
app-id: your_wechat_app_id
app-secret: your_wechat_app_secret
qr-connect:
redirect-uri: https://your-domain.com/api/auth/wechat/callback
scope: snsapi_login
# 在项目根目录执行
mvn clean package -DskipTests
# 产物位置
# zhijiayun-gateway/target/zhijiayun-gateway-1.0.0.jar
# 方式一:Maven 直接运行
mvn spring-boot:run -pl zhijiayun-gateway
# 方式二:运行 JAR
java -jar zhijiayun-gateway/target/zhijiayun-gateway-1.0.0.jar
# 方式三:指定配置文件
java -jar zhijiayun-gateway/target/zhijiayun-gateway-1.0.0.jar \
--spring.datasource.url=jdbc:mysql://prod-db:3306/zhijiayun_pharmacy \
--spring.data.redis.host=prod-redis
# 使用环境变量
export ALIBABA_CLOUD_ACCESS_KEY_ID=your_key_id
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=your_key_secret
# JVM 参数启动
java -Xms2g -Xmx4g \
-Dspring.profiles.active=prod \
-jar zhijiayun-gateway-1.0.0.jar \
> /var/log/zhijiayun/app.log 2>&1 &
# /etc/systemd/system/zhijiayun.service
[Unit]
Description=Zhijiayun Pharmacy Application
After=network.target mysql.service redis.service
[Service]
Type=simple
User=zhijiayun
WorkingDirectory=/opt/zhijiayun
ExecStart=/usr/bin/java -Xms2g -Xmx4g -jar zhijiayun-gateway-1.0.0.jar
Restart=always
RestartSec=10
Environment=ALIBABA_CLOUD_ACCESS_KEY_ID=your_key_id
Environment=ALIBABA_CLOUD_ACCESS_KEY_SECRET=your_key_secret
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable zhijiayun
sudo systemctl start zhijiayun
sudo systemctl status zhijiayun
应用启动时自动执行 schema.sql 建表脚本(通过 spring.sql.init 配置)。
默认等级数据随 schema.sql 自动插入:
| 等级 | 每日配额 | 每月配额 |
|---|---|---|
| 普通用户 (NORMAL) | 5 | 100 |
| VIP会员 (VIP) | 20 | 500 |
| SVIP会员 (SVIP) | 100 | 3000 |
默认端口:8080
curl http://localhost:8080/actuator/health
| 环境 | 日志路径 |
|---|---|
| 开发 | 控制台输出 |
| 生产 | /var/log/zhijiayun/app.log |
upstream zhijiayun {
server 127.0.0.1:8080;
}
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
location / {
proxy_pass http://zhijiayun;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 80;
server_name your-domain.com;
return 301 https://$host$request_uri;
}
| 检查项 | 状态 |
|---|---|
| MySQL 连接池配置合理 | ☐ |
| Redis 密码已设置 | ☐ |
| JWT Secret 已更换为随机字符串 | ☐ |
| AK/SK 通过环境变量注入 | ☐ |
| 微信回调地址已更新为生产域名 | ☐ |
| HTTPS 证书已配置 | ☐ |
| 日志输出到文件并配置轮转 | ☐ |
| 数据库备份策略已制定 | ☐ |
| 限流参数已根据实际流量调整 | ☐ |
| JVM 内存参数已设置 | ☐ |