Skip to content

部署文档

版本号修改修改时间备注
v1.0.0王小琱2024.12.20初次修订


1. 项目简介

exchange-notify-service-backend 是一款为交易所及金融业务提供多渠道通知(站内信、邮件、短信等)的微服务,具备高可用、可扩展、易集成等特点。服务通过 gRPC 对外提供接口,支持消息异步推送、RabbitMQ 消息队列、MySQL 持久化等能力。

2. 环境要求

  • Go 版本:1.21 及以上
  • Docker:20.10 及以上
  • RabbitMQ:3.x 及以上
  • 邮件服务:需配置邮件发送URL

3. 部署方式

3.1 本地部署

3.1.1 下载代码

bash
git clone https://gitlab.atom8.io/hkbitex/exchange-notify-service-backend.git
cd exchange-notify-service-backend

3.1.2 安装依赖

bash
# 安装 protoc 工具
make init

# 更新依赖
make tidy

3.1.3 编译代码

bash
make build

3.1.4 配置说明

环境变量类型是否必填说明
APP_LOG_LEVELstring可选,默认info日志级别设置,可设置为:trace、debug、info、warn、error、fatal
SERVER_HOSTstring必填服务监听地址(如 0.0.0.0:8080)
METRICS_SWITCHstring必填metrics 开关,on:启用、off:关闭
METRICS_HOSTstring必填metrics 服务监听地址(如 0.0.0.0:18080)
MYSQL_READstring必填MySQL 读库 DSN,例如:user:password@tcp(host:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local
MYSQL_WRITEstring必填MySQL 写库 DSN(同上)
RABBITMQ_URISstring必填RabbitMQ URI,多个用英文逗号分隔
RABBITMQ_DEFAULT_EXCHNAGEstring必填RabbitMQ 默认交换机名称
RABBITMQ_USER_EXCHNAGEstring必填RabbitMQ 用户交换机名称
RABBITMQ_ADMIN_EXCHNAGEstring必填RabbitMQ 管理员交换机名称
RABBITMQ_PLATFORM_EXCHNAGEstring必填RabbitMQ 平台交换机名称
EMAIL_URLstring必填邮件服务URL
GRPC_SERVER_USERstring必填用户服务gRPC地址
USER_API_KEYstring必填用户API密钥

3.1.5 启动服务

创建 Systemd 文件 /etc/systemd/system/exchange-notify-service-backend.service:

bash
[Unit]
Description=exchange-notify-service-backend
After=network.target

[Service]
WorkingDirectory=/app/exchange-notify-service-backend/exchange-notify-service-backend
Type=simple
User=root
ExecStart=/app/exchange-notify-service-backend/exchange-notify-service-backend
StandardOutput=append:/app/exchange-notify-service-backend/logs/output.log
StandardError=append:/app/exchange-notify-service-backend/logs/error.log
Restart=on-failure
EnvironmentFile=/app/exchange-notify-service-backend/.env

[Install]
WantedBy=multi-user.target

service exchange-notify-service-backend start

重载并启动服务:

bash
# 创建必要的目录
mkdir -p /app/exchange-notify-service-backend/logs

# 复制配置文件
cp .env.default /app/exchange-notify-service-backend/.env
cp exchange-notify-service-backend /app/exchange-notify-service-backend/

# 启动服务
systemctl daemon-reload
systemctl start exchange-notify-service-backend
systemctl enable exchange-notify-service-backend

# 检查服务状态
systemctl status exchange-notify-service-backend

3.2 Docker部署(推荐生产环境)

3.2.1 下载代码

bash
git clone https://gitlab.atom8.io/hkbitex/exchange-notify-service-backend.git
cd exchange-notify-service-backend

3.2.2 编译代码

bash
make docker

3.2.3 环境变量

在项目根目录创建 .env 文件(内容同上),或直接通过 Docker -e 方式传入。

3.2.4 启动服务

bash
docker run -d \
  --name exchange-notify-service-backend \
  --env-file .env \
  -p 8080:8080 \
  registry.example.com/exchange-notify-service-backend:latest

4. 数据库配置

服务初始化需要在sender表中增加一条记录,用于发送站内信。详情见数据库设计文档

5. 日志配置

5.1 日志位置

  • 默认日志输出:/app/exchange-notify-service-backend/logs/
  • 日志文件:
    • output.log:标准输出日志
    • error.log:错误日志

5.2 日志级别

  • 可通过 .env 配置(如 info、debug、error等)
  • 建议生产环境使用 info 级别

6. 监控配置

7. 其他说明

🚀 构建现代化数字资产交易平台