acmeGoBaidu

command module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 3 Imported by: 0

README

acmeGoBaidu 是一个用Go编写的自动申请SSL证书并同步到百度CDN、阿里云存储桶的工具。

GitHub Repo stars

Why?

1. 为什么会选择百度的CDN?

  • 百度CDN支持单栈IPV6回源,且适合动态DDNS域名。
  • 百度CDN支持自定义端口回源,适合自定义服务端口。

2. 域名不备案可以选择百度CDN吗?

  • 不能,百度CDN需要备案的域名。如果你的域名没有备案,那么请你选择其他CDN服务商。

3. 为什么要做这个工具?

  • 百度CDN免费的证书只能申请20次(包括续签),是的你没听错。
  • 申请证书需要人工操作,且需要等待,这个工具可以自动申请证书并同步到百度CDN。
  • 因为我喜欢折腾,无意间发现家用IPV6有公网地址,但是是动态的,所以就做了DDNS,但是运营商封了80、443端口,找了一圈,发现只有百度CDN支持单栈IPV6回源、自定义端口回源,所以就有了这个工具。

4. 为什么只支持cloudflare?

  • 只是在自动同步CNAME记录,只支持cloudflare,在域名解析的时候,可以使用其他服务商,用的是acme的三方包,所以支持大部分市面上的DNS服务商,详情查看acme.sh
  • 本人使用的是cloudflare,如果有其他服务商的需求可以提issue。

5.推荐什么方式运行?

  • 推荐使用k8s、k3s、docker等容器化方式运行.
  • 当然由于工具自带定时任务,也可以直接运行在服务器上。

6. 如何知道服务商支持的域名解析?

  • 请查看acme.sh, 并且能够在acme.sh中找到对应的服务商的环境变量。

7. 为什么我无法运行?

  • 你没有config.yaml文件,或者没有配置CLOUDFLARE_EMAILCLOUDFLARE_API_KEYBAIDUYUN_ACCESSKEYBAIDUYUN_SECRETKEY这些必须要的环境变量。

安装acmeGoBaidu

acmeGoBaidu需要go1.21才能安装成功。执行一下命令

go install -v github.com/wjlin0/acmeGoBaidu/cmd/acmeGoBaidu@latest

下载准备运行的二进制文件

用法

命令行

在运行的当前目录下创建一下config.yaml 文件

acme:
  email: "wjlgeren@163.com"
  domains:
    - domain: "cdn.wjlin0.com"
      provider: "cloudflare"
      to: 'ali,kodo'
      ali:
        kodo:
          bucket: "wjlin0"
          region: "cn-chengdu"
          cname:
            enabled: true
            value: "wjlin0.oss-cn-chengdu.aliyuncs.com."
    - domain: "www.wjlin0.com"
      provider: "cloudflare"
      to: 'baidu,cdn'
      baidu:
        cdn:
          origin:
            - peer: "https://test.wjlin0.com:10443"
              host: "www.wjlin0.com"
              isp: "cm"
            - peer: "http://test.wjlin0.com:1080"
              host: "www.wjlin0.com"
              isp: "cm"
          form: dynamic
          ipv6: true
          http2: true
          quic: true
          http3: true
          dsa:
            enabled: true
            rules:
              - type: "method"
                value: 'GET;POST;PUT;DELETE;OPTIONS'
              - type: "path"
                value: "/"
          cname:
            enabled: true
            value: "www.wjlin0.com.a.bdydns.com."

配置服务商、百度的认证信息 例如:cloudflare的认证信息

export CLOUDFLARE_EMAIL="xxx@xx.com"
export CLOUDFLARE_API_KEY="xxxxx"
export BAIDUYUN_ACCESSKEY="xxxxx"
export BAIDUYUN_SECRETKEY="xxxxx"
export OSS_ACCESS_KEY_ID="xxxxx"
export OSS_ACCESS_KEY_SECRET="xxxxx"

创建完成后执行以下命令

acmeGoBaidu

docker

docker run -d --name acmeGoBaidu -e CLOUDFLARE_EMAIL="xxx@xx.com" -e CLOUDFLARE_API_KEY="xxxxx" -e BAIDUYUN_ACCESSKEY="xxxx" -e OSS_ACCESS_KEY_ID="xxxx" -e OSS_ACCESS_KEY_SECRET="xxxx" -e BAIDUYUN_ACCESSKEY="xxxx" -e CRON="0 0 * * 1" -v ./data/config.yaml:/app/config/config.yaml -v ./data/certs:/app/certs wjlin0/acmegobaidu:latest

K8s

编写一下yaml文件


apiVersion: v1
kind: ConfigMap
metadata:
  name: acme-go-baidu-config
data:
  config.yaml: |
    acme:
      email: "wjlgeren@163.com"
      domains:
        - domain: "cdn.wjlin0.com"
          provider: "cloudflare"
          to: 'ali,kodo'
          ali:
            kodo:
              bucket: "wjlin0"
              region: "cn-chengdu"
              cname:
                enabled: true
                value: "wjlin0.oss-cn-chengdu.aliyuncs.com."
        - domain: "www.wjlin0.com"
          provider: "cloudflare"
          to: 'baidu,cdn'
          baidu:
            cdn:
              origin:
                - peer: "https://test.wjlin0.com:10443"
                  host: "www.wjlin0.com"
                  isp: "cm"
                - peer: "http://test.wjlin0.com:1080"
                  host: "www.wjlin0.com"
                  isp: "cm"
              form: dynamic
              ipv6: true
              http2: true
              quic: true
              http3: true
              dsa:
                enabled: true
                rules:
                  - type: "method"
                    value: 'GET;POST;PUT;DELETE;OPTIONS'
                  - type: "path"
                    value: "/"
              cname:
                enabled: true
                value: "www.wjlin0.com.a.bdydns.com."
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: acme-go-baidu-deployment
spec:
  selector:
    matchLabels:
      app: acme-go-baidu
  template:
    metadata:
      labels:
        app: acme-go-baidu
    spec:
      restartPolicy: Always
      containers:
        - name: acme-go-baidu-container
          image: wjlin0/acmegobaidu:latest
          resources:
            limits:
              memory: '32Mi'
              cpu: '50m'
          env:
            - name: CONFIG_PATH
              value: '/app/config/config.yaml'
            - name: JSON_PATH
              value: '/app/certs/certificate.json'
            - name: CRON
              value: '0 0 * * 1' # 每周一凌晨执行
            - name: CLOUDFLARE_EMAIL
              value: 'xxx@xxx.com'
            - name: CLOUDFLARE_API_KEY
              value: 'xxxxx'
            - name: BAIDUYUN_ACCESSKEY
              value: 'xxxxx'
            - name: BAIDUYUN_SECRETKEY
              value: 'xxxxx'
            - name: OSS_ACCESS_KEY_ID
              value: 'xxxxx'
            - name: OSS_ACCESS_KEY_SECRET
              value: 'xxxxx'
          command:
            - "acmeGoBaidu"
          volumeMounts:
            - mountPath: '/app'
              subPath: 'acmeGoBaidu.yaml'
              name: config
              readOnly: true
            - mountPath: '/app/certs'
              name: certs 
      volumes:
        - name: config
          configMap:
            name: acme-go-baidu-config
        - name: certs
          persistentVolumeClaim:
            claimName: acme-go-baidu-pvc

创建pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: acme-go-baidu-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Mi
# 创建 pvc
kubectl create -f pvc.yaml
# 运行
kubectl apply -f acmeGoBaidu.yaml

注意

根域名可能无法配置CNAME 记录,配置后,不生效

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
pkg
baidu/cloudflare
Package cloudflare implements a DNS provider for solving the DNS-01 challenge using cloudflare DNS.
Package cloudflare implements a DNS provider for solving the DNS-01 challenge using cloudflare DNS.

Jump to

Keyboard shortcuts

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