在主機(jī) 192.168.1.236 上,通過如下安裝 etcd 服務(wù),然后修改配置文件:
yum -y install etcd
其中 etcd 的數(shù)據(jù)目錄為:/data/k8s/etcd/纵顾,通過如下指令設(shè)置的訪問權(quán)限:
chown etcd.etcd /appdata/k8s/etcd
chmod 754 /appdata/k8s/
結(jié)果啟動(dòng)失敗伍茄。通過命令 ‘ journalctl -xe ' 查看日志,發(fā)現(xiàn)如下報(bào)錯(cuò)信息:
Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: Starting Etcd Server...
-- Subject: Unit etcd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit etcd.service has begun starting up.
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: recognized and used environment variable ETCD_ADVERTISE_CLIENT_URLS=http://localhost:2379
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: recognized environment variable ETCD_NAME, but unused: shadowed by corresponding flag
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: recognized environment variable ETCD_DATA_DIR, but unused: shadowed by corresponding flag
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: recognized environment variable ETCD_LISTEN_CLIENT_URLS, but unused: shadowed by corresponding flag
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: etcd Version: 3.3.11
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: Git SHA: 2cf9e51
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: Go Version: go1.10.3
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: Go OS/Arch: linux/amd64
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: setting maximum number of CPUs to 8, total number of available CPUs is 8
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: listening for peers on http://localhost:2380
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: listening for client requests on localhost:2379
Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: cannot access data directory: mkdir /data/k8s/etcd: permission denied
Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: etcd.service: main process exited, code=exited, status=1/FAILURE
Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: Failed to start Etcd Server.
-- Subject: Unit etcd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit etcd.service has failed.
--
-- The result is failed.
Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: Unit etcd.service entered failed state.
Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: etcd.service failed.
Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: etcd.service holdoff time over, scheduling restart.
Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: Stopped Etcd Server.
-- Subject: Unit etcd.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit etcd.service has finished shutting down.
通過如下命令:
vi /usr/lib/systemd/system/etcd.service
查看 etcd.service 的內(nèi)容:
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\""
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
可以發(fā)現(xiàn)其運(yùn)行用戶是 etcd施逾,那么修改為 root:
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=root
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\""
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
再將數(shù)據(jù)目錄的權(quán)限修改為 root:
chown -R root.root /data/k8s/etcd
chmod -R 754 /data/k8s/etcd
在通過如下命令重新加載配置:
systemctl daemon-reload
再重新啟動(dòng)etcd.service:
service etcd start
發(fā)現(xiàn)這次啟動(dòng)成功了敷矫。查看其狀態(tài):
service etcd status
內(nèi)容為:
[root@test system]# systemctl status etcd
● etcd.service - Etcd Server
Loaded: loaded (/usr/lib/systemd/system/etcd.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2020-03-28 14:37:11 CST; 8s ago
Main PID: 21851 (etcd)
Tasks: 19
Memory: 16.2M
CGroup: /system.slice/etcd.service
└─21851 /usr/bin/etcd --name=etcd1 --data-dir=/data/k8s/etcd/ --listen-client-urls=http://localhost:2379
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 2
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: 8e9e05c52164694d became leader at term 2
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 2
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: setting up the initial cluster version to 3.3
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: set the initial cluster version to 3.3
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: enabled capabilities for version 3.3
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: published {Name:etcd1 ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: ready to serve client requests
Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!
Mar 28 14:37:11 test.saas.microreal.cn systemd[1]: Started Etcd Server.
嘗試往 etcd 中插入一條數(shù)據(jù)例获,然后再取出來:
etcdctl set /test/data 123455
etcdctl get /test/data