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