GoWindGoWind
首页
框架
GoWind Toolkit
  • 开源项目

    • GoWind Admin(后台管理)
    • GoWind CMS(内容管理)
    • GoWind UBA(行为分析)
    • GoWind Shop(电商)
    • GoWind Kanban(协作看板)
    • GoWind Ledger(家庭记账)
    • GoWind ShortPlay(短剧社区)
    • GoWind Ops(运维平台)
    • RushWind(Rust 生态)
  • Open Core(社区开源 · 企业版增强)

    • GoWind OA(协同办公)
    • GoWind ERP(业财一体)
    • GoWind WMS(多货主仓储)
  • 商业产品

    • GoWind IM(即时通讯)
    • GoWind CRM(B2B 销售管理)
    • GoWind Trade(外贸全流程管理)
    • GoWind IoT(物联网)
    • GoWind Edu(AI 教育)
    • GoWind MES(制造执行)
    • GoWind CDC(数据管道)
    • GoWind SDP(零信任网关)
    • GoWind Quant(量化研究)
    • GoWind Trade Radar(外贸选品雷达)
    • GoWind Game Radar(游戏立项雷达)
  • 简体中文
  • English
GitHub
首页
框架
GoWind Toolkit
  • 开源项目

    • GoWind Admin(后台管理)
    • GoWind CMS(内容管理)
    • GoWind UBA(行为分析)
    • GoWind Shop(电商)
    • GoWind Kanban(协作看板)
    • GoWind Ledger(家庭记账)
    • GoWind ShortPlay(短剧社区)
    • GoWind Ops(运维平台)
    • RushWind(Rust 生态)
  • Open Core(社区开源 · 企业版增强)

    • GoWind OA(协同办公)
    • GoWind ERP(业财一体)
    • GoWind WMS(多货主仓储)
  • 商业产品

    • GoWind IM(即时通讯)
    • GoWind CRM(B2B 销售管理)
    • GoWind Trade(外贸全流程管理)
    • GoWind IoT(物联网)
    • GoWind Edu(AI 教育)
    • GoWind MES(制造执行)
    • GoWind CDC(数据管道)
    • GoWind SDP(零信任网关)
    • GoWind Quant(量化研究)
    • GoWind Trade Radar(外贸选品雷达)
    • GoWind Game Radar(游戏立项雷达)
  • 简体中文
  • English
GitHub
  • 介绍

    • GoWind CMS 产品介绍
    • GoWind CMS 安装指南
  • 后端文档

    • CMS 后端架构总览
    • CMS 后端模块总览
    • CMS Protobuf API 定义
    • CMS 配置与部署指南
    • 后端扩展机制指南
  • 前端文档

    • CMS 前端架构
    • CMS 前端模块总览
  • 入门教程

    • 新增内容类型全栈实战教程
    • 多端 API 客户端代码生成教程
  • 核心教程

    • 内容多语言翻译实战教程
    • 内容发布工作流实战教程
    • 区块编辑器实战教程
    • Headless API 对接多端实战教程
    • 前台应用开发实战教程
  • 进阶教程

    • 多站点管理实战教程
    • 媒体资源管理实战教程
    • 评论系统实战教程
    • 事件总线架构实战教程
    • Lua 脚本扩展实战教程
  • 高阶教程

    • 权限系统实战教程
    • 双端登录安全实战教程
    • 加密与安全工具实战教程
    • 全文搜索实战教程
    • 任务调度实战教程
    • 实时消息推送实战教程
    • 性能监控实战教程
    • 字典管理系统实战教程
  • 综合教程

    • 全栈集成实战教程
    • 三服务部署实战教程

CMS 配置与部署指南

GoWind CMS 采用三服务架构(Admin / App / Core),配置管理比单服务系统更复杂。本文档详细介绍各服务的配置文件、环境变量、代码生成和服务管理。

一、配置文件组织

1.1 目录结构

app/
├── core/service/configs/
│   ├── server.yaml          # Core Service 配置(gRPC + Asynq + 数据层)
│   └── registry.yaml        # 服务注册(Etcd)
├── admin/service/configs/
│   ├── server.yaml          # Admin Service 配置(HTTP + gRPC 客户端)
│   └── registry.yaml
└── app/service/configs/
    ├── server.yaml           # App Service 配置(HTTP + gRPC 客户端)
    └── registry.yaml

1.2 三服务配置关系

二、Core Service 配置

2.1 server.yaml

# app/core/service/configs/server.yaml
server:
  # gRPC 服务器(内部通信)
  grpc:
    addr: "0.0.0.0:0"              # 端口由 Etcd 动态分配
    timeout: 60s

  # Asynq 异步任务
  asynq:
    uri: "redis://:*Abcd123456@redis:6379/1"
    enable_gracefully_shutdown: true
    shutdown_timeout: 3s
    codec: "json"
    concurrency: 10
    queues:
      critical: 10
      default: 5
      low: 1

# 数据层配置
data:
  database:
    driver: postgres
    source: "host=postgres port=5432 user=postgres password=*Abcd123456 dbname=cms sslmode=disable"

  redis:
    addr: "redis:6379"
    password: "*Abcd123456"
    db: 0
    read_timeout: 0.2s
    write_timeout: 0.2s

  # 对象存储
  oss:
    type: "minio"                    # minio / local / s3
    endpoint: "minio:9000"
    access_key: "minioadmin"
    secret_key: "minioadmin"
    bucket: "cms"
    use_ssl: false

  # 搜索引擎
  search:
    type: "opensearch"
    endpoint: "http://opensearch:9200"
    username: "admin"
    password: "admin"

# 链路追踪
tracer:
  enabled: true
  provider: jaeger
  endpoint: "http://jaeger:14268/api/traces"

2.2 registry.yaml

# app/core/service/configs/registry.yaml
registry:
  type: "etcd"
  etcd:
    endpoints:
      - "etcd:2379"
    timeout: 5s
    ttl: 10                           # 注册 TTL

三、Admin Service 配置

3.1 server.yaml

# app/admin/service/configs/server.yaml
server:
  # REST HTTP 服务器
  rest:
    addr: "0.0.0.0:6600"
    timeout: 5s

  # SSE 服务器
  sse:
    addr: "0.0.0.0:6601"

# gRPC 客户端(连接 Core Service)
client:
  grpc:
    core:
      target: "discovery:///cms-core-service"   # 通过 Etcd 发现
      timeout: 5s

# 服务发现
registry:
  type: "etcd"
  etcd:
    endpoints:
      - "etcd:2379"

# JWT 配置
auth:
  jwt:
    secret: "your-jwt-secret-key"
    issuer: "cms-admin"
    expire: 86400                        # Token 有效期(秒)

# 权限引擎
authorizer:
  type: "casbin"
  model: "configs/rbac_model.conf"

# CORS
cors:
  enabled: true
  allow_origins:
    - "http://localhost:5666"
    - "https://admin.cms.gowind.cloud"

3.2 认证白名单

// app/admin/service/internal/server/rest_server.go
// Admin 白名单:仅登录接口免认证
rpc.AddWhiteList(
    adminV1.OperationAuthenticationServiceLogin,
)

四、App Service 配置

4.1 server.yaml

# app/app/service/configs/server.yaml
server:
  rest:
    addr: "0.0.0.0:6700"
    timeout: 5s

  sse:
    addr: "0.0.0.0:6701"

client:
  grpc:
    core:
      target: "discovery:///cms-core-service"
      timeout: 5s

registry:
  type: "etcd"
  etcd:
    endpoints:
      - "etcd:2379"

auth:
  jwt:
    secret: "your-jwt-secret-key"
    issuer: "cms-app"
    expire: 604800                      # 前台 Token 7 天有效

# CORS(前台需要更宽松的跨域)
cors:
  enabled: true
  allow_origins:
    - "*"
  allow_methods: [GET, POST, PUT, DELETE, OPTIONS]
  allow_headers: [Authorization, Content-Type, Accept-Language]

4.2 前台白名单

// app/app/service/internal/server/rest_server.go
// App 白名单:内容浏览类接口免认证
rpc.AddWhiteList(
    appV1.OperationAuthenticationServiceLogin,

    // 内容浏览(免登录)
    appV1.OperationPostServiceList,
    appV1.OperationPostServiceGet,
    appV1.OperationCategoryServiceList,
    appV1.OperationCategoryServiceGet,
    appV1.OperationTagServiceList,
    appV1.OperationTagServiceGet,
    appV1.OperationPageServiceList,
    appV1.OperationPageServiceGet,
    appV1.OperationCommentServiceList,
    appV1.OperationCommentServiceGet,
    appV1.OperationNavigationServiceList,
)

五、代码生成

5.1 Make 命令

# Makefile
.PHONY: gen api ent wire ts openapi

# 一键生成所有代码
gen: api ent wire ts openapi

# 生成 Protobuf Go 代码
api:
	buf generate

# 生成 Ent ORM 代码
ent:
	go generate ./app/core/service/internal/data/ent

# 生成 Wire 依赖注入代码
wire:
	cd app/core/service/cmd/server && wire
	cd app/admin/service/cmd/server && wire
	cd app/app/service/cmd/server && wire

# 生成 TypeScript 客户端代码
ts:
	buf generate --path api/protos/admin
	buf generate --path api/protos/app

# 生成 OpenAPI 文档
openapi:
	buf generate --template buf.openapi.gen.yaml

5.2 开发工作流

六、服务管理

6.1 gow CLI

# 启动单个服务
gow run core
gow run admin
gow run app

# 指定配置文件
gow run admin -conf ./configs

# 带环境变量
DB_HOST=localhost gow run core

6.2 启动顺序

Core Service 必须先启动并注册到 Etcd,Admin 和 App 通过 Etcd 发现 Core。

七、环境变量

环境变量默认值说明
DB_HOSTpostgres数据库地址
DB_PASSWORD-数据库密码
REDIS_HOSTredisRedis 地址
REDIS_PASSWORD-Redis 密码
OSS_ENDPOINTminio:9000对象存储地址
OS_HOSTopensearch搜索引擎地址
ETCD_ENDPOINTSetcd:2379Etcd 地址
JWT_SECRET-JWT 密钥

八、相关文档

  • CMS 安装指南
  • CMS 后端架构总览
  • 三服务部署实战
  • GoWind Admin 配置部署指南
Edit this page
最近更新:: 2026/6/21 20:19
Contributors: Bobo
Prev
CMS Protobuf API 定义
Next
后端扩展机制指南