跳转到主要内容

部署指南

juhe-sync 数据同步服务部署与配置

什么是 juhe-sync

juhe-sync 是数据同步服务,提供以下核心功能:

  • 接收 SAAS 回调:实时接收企微/个微的消息和事件通知
  • 增量同步联系人:自动同步新增和更新的联系人信息
  • 消息存储:将消息存储到 SQLite 数据库
  • HTTP API:提供 RESTful API 查询联系人、消息、群聊等数据

下载安装

二进制分发

juhe-sync 为独立的二进制文件,下载后直接运行即可。

Linux

bash
# 下载最新版
curl -L -o juhe-sync https://github.com/Hanson/juhe-cli/releases/download/v1.0.0/juhe-sync-linux-amd64
chmod +x juhe-sync
sudo mv juhe-sync /usr/local/bin/

macOS

bash
# Apple Silicon
curl -L -o juhe-sync https://github.com/Hanson/juhe-cli/releases/download/v1.0.0/juhe-sync-darwin-arm64

# Intel
curl -L -o juhe-sync https://github.com/Hanson/juhe-cli/releases/download/v1.0.0/juhe-sync-darwin-amd64

chmod +x juhe-sync
sudo mv juhe-sync /usr/local/bin/

Windows

GitHub Releases 获取 juhe-sync-windows-amd64.exe

启动服务

基础启动

使用配置文件启动服务:

bash
./juhe-sync run --config juhe-sync.json

指定端口

bash
./juhe-sync run --config juhe-sync.json --port 8080

后台运行

bash
# 使用 nohup
nohup ./juhe-sync run --config juhe-sync.json &> juhe-sync.log &

# 使用 systemd(推荐)
sudo systemctl start juhe-sync
sudo systemctl enable juhe-sync

配置回调 URL

注意:设置回调地址会覆盖原有配置

每次调用 set_notify_url 设置回调地址时,会覆盖该设备之前配置的回调地址。如果原有回调地址正在被其他服务使用,请先确认新地址不会影响已有服务,再进行设置。

启动 juhe-sync 后,需要在 juhe-cli 中配置回调 URL:

企微回调

bash
juhe-cli client set_notify_url '{
  "guid": "your_enterprise_guid",
  "notify_url": "https://your-server:8070/callback"
}'

个微回调

bash
juhe-cli wx client set_notify_url '{
  "guid": "your_wx_guid",
  "notify_url": "https://your-server:8070/callback"
}'

验证部署

检查服务状态

bash
# 检查进程
ps aux | grep juhe-sync

# 检查端口
netstat -tlnp | grep 8070

# 检查日志
tail -f juhe-sync.log

测试 API

bash
# 查询同步状态
curl http://localhost:8070/api/sync-status?guid=your_guid

# 查询联系人
curl http://localhost:8070/api/contacts?guid=your_guid&page=1&limit=10

反向代理配置

Nginx 配置示例

nginx
server {
    listen 443 ssl;
    server_name your-domain.com;

    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;

    location /callback {
        proxy_pass http://localhost:8070/callback;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /api/ {
        proxy_pass http://localhost:8070/api/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

下一步