systemd

本教學說明如何在 Linux 系統上為 KES 建立 systemd 服務。

安裝

下載適用於您的架構和作業系統的最新 KES 二進位檔。

例如,在 linux/amd64 上執行

curl -X GET 'https://github.com/minio/kes/releases/latest/download/kes-linux-amd64' --output kes-linux-amd64
sudo install kes-linux-amd64  /usr/local/bin/kes

建立使用者/群組

為 KES 建立新的 Unix 使用者和群組

useradd kes -s /sbin/nologin
如果您選擇的使用者和群組名稱與 kes 不同,請更新 kes.service 檔案。
kes 使用者需要具有 /etc/kes/ 目錄的讀取權限。

設定

更新位於 /etc/kes/config.yml 下的 KES 伺服器設定。

若要建立新的 KES 伺服器設定檔,請參閱

以下範例是來自我們的 檔案系統指南 的設定檔

address: 0.0.0.0:7373
admin:
   identity: disabled  # We disable the admin identity since we don't need it in this guide 

tls:
  key:  private.key
  cert: public.crt

policy:
  my-app: 
    allow:
    - /v1/key/create/app-key*
    - /v1/key/generate/app-key*
    - /v1/key/decrypt/app-key*
    identities:
    - ${APP_IDENTITY}

keystore:
  fs:
    path: ./keys # Choose a directory for the secret keys

systemd 服務

透過在 /etc/systemd/system 下建立 kes.service 檔案來建立 systemd 服務

[Unit]
Description=KES
Documentation=https://github.com/minio/kes/wiki
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/kes

[Service]
WorkingDirectory=/etc/kes/

User=kes
Group=kes
ProtectProc=invisible

ExecStart=/usr/local/bin/kes server --config=/etc/kes/config.yaml

# Let systemd restart this service always
Restart=always

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536

# Specifies the maximum number of threads this process can create
TasksMax=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no

# Enable memory locking features used to prevent paging.
AmbientCapabilities=CAP_IPC_LOCK

[Install]
WantedBy=multi-user.target

特權連接埠

如果您打算在特權連接埠號碼(小於 1024 的號碼)上執行 KES,並以一般非 root 使用者的身分執行服務,請透過 kes.service 檔案中的 AmbientCapabilities 指令新增綁定功能

[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE

重新啟動時啟動

若要在重新啟動後自動啟動 KES,請執行

systemctl enable kes.service
在啟動時停用 `kes.service`

若要防止 KES 在重新啟動後啟動,請執行

systemctl disable kes.service

啟動或停止 KES

若要啟動 KES,請執行

systemctl start kes.service

若要停止 KES,請執行

systemctl stop kes.service