我尝试将etcd作为在podman容器中运行的 systemd 服务启动。
启动后,我从 systemd 收到此错误日志:
systemd[1]: etcd.service: Got notification message from PID 4696, but reception only permitted for main PID 4868
但是 etcd 似乎可以开始尝试通知容器守护进程:
21T15:31:08.817Z","caller":"etcdserver/server.go:2500","msg":"cluster version>
Aug 21 15:31:08 ip-10-0-0-71 podman[4696]: {"level":"info","ts":"2021-08-21T15:31:08.817Z","caller":"etcdmain/main.go:47","msg":"notifying init daemon>
Aug 21 15:31:08 ip-10-0-0-71 podman[4696]: {"level":"info","ts":"2021-08-21T15:31:08.818Z","caller":"etcdmain/main.go:53","msg":"successfully notified>
但 systemd 似乎没有意识到这一点并终止了 etcd 服务:
Aug 21 15:32:34 ip-10-0-0-71 systemd[1]: etcd.service: start operation timed out. Terminating.
Aug 21 15:32:35 ip-10-0-0-71 podman[4696]: {"level":"info","ts":"2021-08-21T15:32:35.000Z","caller":"osutil/interrupt_unix.go:64","msg":"received sign>
Aug 21 15:32:35 ip-10-0-0-71 podman[4696]: {"level":"info","ts":"2021-08-21T15:32:35.000Z","caller":"embed/etcd.go:367","msg":"closing etcd server","n>
这是 systemd 服务状态:
$ sudo systemctl status etcd.service
● etcd.service - etcd
Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: enabled)
Active: failed (Result: timeout) since Sat 2021-08-21 15:32:35 UTC; 8min ago
Process: 4868 ExecStart=/usr/bin/podman run -p 2380:2380 -p 2379:2379 --volume=/var/lib/etcd:/etcd-data:z --name etcd 842445240665.dkr.ecr.eu-nort>
Main PID: 4868 (code=exited, status=0/SUCCESS)
CPU: 3.729s
这是我从 podman 开始的 etcd 的 systemd 单元服务文件:
cat <<EOF | sudo tee /etc/systemd/system/etcd.service
[Unit]
Description=etcd
After=podman_ecr_login.service mk_etcd_data_dir.service
[Service]
Type=notify
ExecStart=/usr/bin/podman run -p 2380:2380 -p 2379:2379 --volume=/var/lib/etcd:/etcd-data:z \
--name etcd <my-aws-account>.dkr.ecr.eu-north-1.amazonaws.com/etcd:v3.5.0 \
/usr/local/bin/etcd --data-dir=/etcd-data \
--name etcd0 \
--advertise-client-urls http://127.0.0.1:2379 \
--listen-client-urls http://0.0.0.0:2379 \
--initial-advertise-peer-urls http://127.0.0.1:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster etcd0=http://127.0.0.1:2380
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable etcd
sudo systemctl start etcd
我怀疑这可能与Type=notify
我使用 podman 或 etcd 的方式有关。我以与 etcd 文档中所述类似的方式启动 etcd:在容器内运行 etcd 集群 - 运行单个节点 etcd。我在 Debian 11 上使用 Podman 3.0.1 运行它。
关于如何使用 podman 作为 systemd 服务启动 etcd 的任何建议?
根据此问题评论,这些服务应该运行,
Type=simple
因为它们不会向 systemd 发出信号。这个podman 的PR设置它Type=exec
似乎也很好用。Type=exec
在我的服务单元文件中更改后,它现在可以工作: