在群輝的 NAS 上,使用 acme.sh 搭配 DSM 的任務管理器,來自動更新憑證 (終於可以不用再手動了orz)
使用 acme.sh 取得憑證
首先下載 acme (目前使用 dev branch)
$ wget -O /tmp/acme.sh.zip https://github.com/acmesh-official/acme.sh/archive/dev.zip # currently using dev branch $ sudo 7z x -o/usr/local/share /tmp/acme.sh.zip $ sudo mv /usr/local/share/acme.sh-dev/ /usr/local/share/acme.sh # currently using dev release $ sudo chown -R <your admin account> /usr/local/share/acme.sh/
取得憑證
$ cd /usr/local/share/acme.sh $ ./acme.sh --issue -d "*.example.com" --dns dns_cf --home $PWD
此處以 skysky.tk
為例,觸發 ./acme.sh --issue
後,acme 機器人會要求你在 dns 紀錄中新增 txt 紀錄:
我的 DNS server 一樣是架在 Synology NAS 上,在 DNS server 中對應域名新增該紀錄
接著設定 DSM 帳號密碼,並重新觸發 acme.sh ,讓 acme 機器人獲取憑證,並將憑證部署到 Synology 憑證中
$ export SYNO_Username="<your DSM admin username>" $ export SYNO_Password="<your DSM admin password>" $ export SYNO_Certificate="skycer" # 這是稍後在 DSM 中會看到,剛申請好的憑證名稱 $ export SYNO_Create=1 # create certificate if it doesn't exist $ ./acme.sh -d "*.example.com" --deploy --deploy-hook synology_dsm --home $PWD
若 acme 有正確識別到你新增的 TXT DNS紀錄,並成功透過 localhost:5000 將憑證部署到 synology NAS上,到這邊為止,憑證就申請成功了
任務排程表
在 DSM 的任務排程表中新增你要固定執行的 script
$ /usr/local/share/acme.sh/acme.sh --renew -d "*.example.com" --home /usr/local/share/acme.sh # 若當下需要測試的話可以加上 --force 選項