deploy

command module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

证书自动部署 CLI 工具

一个自动化的 SSL 证书部署工具,用于从 anssl.cn 下载并部署证书到服务器。

特性

  • 🚀 自动化部署证书到 Nginx、Apache、RustFS 并自动重载服务
  • ✅ 内置 HTTP-01 验证服务,自动响应 ACME challenge
  • ☁️ 支持自动上传证书到云服务(阿里云、七牛云)
  • 🔧 守护进程模式,支持后台运行
  • 🖥️ 多平台支持:macOS、Linux、Windows(amd64/arm64)

快速开始

1. 安装

GitHub Releases 下载适合你系统的版本:

# Linux
wget https://github.com/https-cert/deploy/releases/latest/download/anssl-linux-amd64.tar.gz
tar -xzf anssl-linux-amd64.tar.gz
chmod +x anssl
sudo mv anssl /usr/local/bin/
2. 配置

创建 config.yaml 文件:

server:
  # 从 anssl.cn 设置 -> 个人资料 中获取
  accessKey: "your_access_key_here"
  # HTTP-01 验证服务端口
  port: 19000

ssl:
  # Nginx 证书目录(可选)
  nginxPath: "/etc/nginx/ssl"
  # Apache 证书目录(可选)
  apachePath: "/etc/apache2/ssl"
  # RustFS TLS 证书目录(可选)
  rustFSPath: "/etc/rustfs/tls"

# 云服务配置(可选)
provider:
  - name: "aliyun"
    remark: "阿里云"
    auth:
      accessKeyId: "your-aliyun-access-key-id"
      accessKeySecret: "your-aliyun-access-key-secret"

  - name: "qiniu"
    remark: "七牛云"
    auth:
      accessKey: "your-qiniu-access-key"
      accessSecret: "your-qiniu-access-secret"

  - name: "cloudTencent"
    remark: "腾讯云"
    auth:
      secretId: "your-tencent-secret-id"
      secretKey: "your-tencent-secret-key"
已支持的云服务商
服务商 name 值 认证字段
阿里云 aliyun accessKeyId, accessKeySecret
七牛云 qiniu accessKey, accessSecret
腾讯云 cloudTencent secretId, secretKey
3. 配置 Nginx

添加 HTTP-01 验证反向代理(用于证书申请):

# 在 server 块中添加
location ~ ^/.well-known/acme-challenge/(.+)$ {
    proxy_pass http://localhost:19000/acme-challenge/$1;
    proxy_set_header Host $host;
}

重载 Nginx:

sudo nginx -t && sudo nginx -s reload
4. 运行
# 启动守护进程
sudo ./anssl daemon -c config.yaml

# 查看状态
./anssl status

# 查看日志
./anssl log -f

HTTP-01 验证工作流程

  1. 在网站申请免费证书
  2. 后端推送 ACME challenge token 到 CLI
  3. CLI 自动缓存并响应 Let's Encrypt 验证请求
  4. 验证成功,证书签发
  5. 自动下载并部署证书到配置的服务(Nginx/Apache/RustFS)
  6. 自动重载 Nginx 和 Apache 服务

全程自动化,无需手动操作。

常用命令

# 守护进程管理
./anssl daemon -c config.yaml  # 启动守护进程
./anssl status                 # 查看状态
./anssl stop                   # 停止
./anssl restart -c config.yaml # 重启

# 日志查看
./anssl log                    # 查看日志
./anssl log -f                 # 实时跟踪

# 更新
./anssl check-update           # 检查更新
./anssl update                 # 执行更新

配置说明

配置项 必填 说明
server.accessKey 从 anssl.cn 获取的访问密钥
server.port HTTP-01 验证端口,默认 19000
ssl.nginxPath Nginx 证书目录,配置后自动部署并重载 Nginx
ssl.apachePath Apache 证书目录,配置后自动部署并重载 Apache
ssl.rustFSPath RustFS TLS 证书目录,配置后自动部署证书
provider 云服务配置(阿里云/七牛云)

故障排除

HTTP-01 验证失败
# 1. 检查 Nginx 配置
sudo nginx -t
cat /etc/nginx/sites-enabled/default | grep acme-challenge

# 2. 检查端口占用
lsof -i :19000

# 3. 测试验证服务
curl http://localhost:19000/acme-challenge/test-token

# 4. 查看日志
./anssl log -f
权限错误
# 方式 1:使用 sudo
sudo ./anssl daemon -c config.yaml

# 方式 2:配置用户目录
# 修改 config.yaml: ssl.path: "$HOME/nginx/ssl"
./anssl daemon -c config.yaml
开机自启动(systemd)
sudo tee /etc/systemd/system/anssl.service > /dev/null <<EOF
[Unit]
Description=Certificate Deploy Service
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/anssl start -c /etc/anssl/config.yaml
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable anssl
sudo systemctl start anssl

常见问题

Q: AccessKey 在哪里获取? A: 登录 anssl.cn → 设置 → 个人资料

Q: 支持哪些 Web 服务器? A: 支持 Nginx、Apache 和 RustFS TLS 自动部署。只需在 config.yaml 中配置对应的证书目录,即可实现自动部署和服务重载(Nginx 和 Apache)

Q: 可以同时部署到多个服务吗? A: 可以。在 config.yaml 中同时配置 nginxPathapachePathrustFSPath,证书更新时会自动部署到所有配置的服务

Q: 证书会同时部署到本地和云服务吗? A: 在 anssl.cn 控制台配置部署目标时,可以选择部署到本地 CLI(Nginx/Apache/RustFS)或云服务(阿里云/七牛云)。每个证书可以配置多个部署目标,实现同时部署

Q: HTTP-01 验证需要手动操作吗? A: 不需要。配置好 Nginx 反向代理后,验证全程自动完成

开发

# 安装依赖
go mod download

# 运行测试
go test -v ./...

# 构建
go build -o anssl main.go

相关链接

许可证

MIT License

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL