定义服务文件时缺少“=”etcd

定义服务文件时缺少“=”etcd

我在遵循 Kelsey Hightower 的“Kubernetes 艰难之路”教程时遇到了困难。我已经偏离了脚本,因为我正在尝试在本地服务器上引导 k8s。

我已经到了引导 etcd 的地步,但是,当我创建服务时出现错误:

Failed to start etcd.service: Unit is not loaded properly: Bad message.
See system logs and 'systemctl status etcd.service' for details.

检查日志并得到:

Jun 21 20:16:49 controller-0 systemd[1]: [/etc/systemd/system/etcd.service:9] Missing '='.
Jun 21 20:16:49 controller-0 systemd[1]: [/etc/systemd/system/etcd.service:9] Missing '='.
Jun 21 20:17:25 controller-0 systemd[1]: [/etc/systemd/system/etcd.service:9] Missing '='.

这是 etcd.service 文件:

[Unit]
Description=etcd service
Documentation=https://github.com/coreos/etcd

[Service]
User=etcd
Type=notify
ExecStart=/usr/local/bin/etcd \\
 --name ${ETCD_NAME} \\
 --data-dir /var/lib/etcd \\
 --initial-advertise-peer-urls http://${ETCD_HOST_IP}:2380 \\
 --listen-peer-urls http://${ETCD_HOST_IP}:2380 \\
 --listen-client-urls http://${ETCD_HOST_IP}:2379,http://127.0.0.1:2379 \\
 --advertise-client-urls http://${ETCD_HOST_IP}:2379 \\
 --initial-cluster-token etcd-cluster-1 \\
 --initial-cluster etcd-1=http://192.168.0.7:2380 \\
 --initial-cluster-state new \\
 --heartbeat-interval 1000 \\
 --election-timeout 5000
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

答案1

@Michael Hampton 指出了答案。之所以使用两个反斜杠,是因为代码应该从终端编写(在指南中)。在 etcd.service 文件中,应该用单个 来换行。

[Unit]
Description=etcd service
Documentation=https://github.com/coreos/etcd

[Service]
User=etcd
Type=notify
ExecStart=/usr/local/bin/etcd \
 --name ${ETCD_NAME} \
 --data-dir /var/lib/etcd \
 --initial-advertise-peer-urls http://${ETCD_HOST_IP}:2380 \
 --listen-peer-urls http://${ETCD_HOST_IP}:2380 \
 --listen-client-urls http://${ETCD_HOST_IP}:2379,http://127.0.0.1:2379 \
 --advertise-client-urls http://${ETCD_HOST_IP}:2379 \
 --initial-cluster-token etcd-cluster-1 \
 --initial-cluster etcd-1=http://192.168.0.7:2380 \
 --initial-cluster-state new \
 --heartbeat-interval 1000 \
 --election-timeout 5000
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

相关内容