etcd-io / etcd

Distributed reliable key-value store for the most critical data of a distributed system
https://etcd.io
Apache License 2.0
47.83k stars 9.77k forks source link

How to run etcd in daemon? #10958

Closed newman0089 closed 5 years ago

newman0089 commented 5 years ago

Hello! Tell me, please, how can the etcd cluster be started as a daemon?

I tried running etcd like systemctl start etcd. Before launching, I edited the /etc/default/etcd file to set my variables. But the cluster is not going to. When executing the etcdctl member list command on various nodes of the cluster, I only get information about this node. What am I doing wrong?

My /etc/default/etcd:

#[member]
ETCD_LISTEN_PEER_URLS="http://10.10.0.1:2380,http://127.0.0.1:7001"
ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379, http://10.10.0.1:2379"

#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.10.0.1:2380"
ETCD_INITIAL_CLUSTER="etcd1=http://10.10.0.1:2380,etcd2=http://10.10.0.2:2380,etcd3=http://10.10.0.3:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://10.10.0.1:2379"
ETCD_INITIAL_CLUSTER_TOKEN="cluster_new"
ETCD_INITIAL_CLUSTER_STATE="new"
spzala commented 5 years ago

@newman0089 not sure if you looked this one but good instructions provided here https://github.com/etcd-io/etcd/tree/master/contrib/systemd/etcd3-multinode Also wondering what's the output of member list? Thanks!

newman0089 commented 5 years ago

@spzala Thanks for the help! I used https://github.com/etcd-io/etcd/blob/master/contrib/systemd/etcd.service. It is acceptable? One file was created for each node in the cluster.

spzala commented 5 years ago

@newman0089 yrw! Yes that's what the https://github.com/etcd-io/etcd/tree/master/contrib/systemd/etcd3-multinode use but it also gives more details on setting up the cluster. I haven't tried it myself though but trying to help. When you run etcd on the every node do you see any error in the log?

newman0089 commented 5 years ago

@spzala I see no errors. Thank you for help

spzala commented 5 years ago

@newman0089 interesting. So all nodes run fine as a cluster and you could only see one member. Would you please post the logs just to see if there is anything not so obvious there. Thanks!

hexfusion commented 5 years ago

If you want etcd to consume your ENV file you need to define it in the systemd unit explicitly like so.

EnvironmentFile=-/etc/default/etcd

If you used this https://github.com/etcd-io/etcd/blob/master/contrib/systemd/etcd.service

All of the nodes would start as single-node etcd clusters because no runtime config is passed other than below, which you could confirm in the startup logs.

Environment=ETCD_DATA_DIR=/var/lib/etcd
Environment=ETCD_NAME=%m

This is the reason that member list only returns a single node. Please revise remove the old data-dir and let us know if you still have problems.

newman0089 commented 5 years ago

@hexfusion

One of my etcd.service files looks like this:

[Unit]
Description=etcd key-value store
Documentation=https://github.com/etcd-io/etcd
After=network.target

[Service]
User=etcd
Type=notify
Environment=ETCD_DATA_DIR=/etc/project/etcd/data
Environment=ETCD_NAME=etcd1
Environment=ETCD_LISTEN_PEER_URLS="http://10.10.0.1:2380,http://127.0.0.1:7001"
Environment=ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379, http://10.10.0.1:2379"
Environment=ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.10.0.1:2380"
Environment=ETCD_INITIAL_CLUSTER="etcd1=http://10.10.0.1:2380,etcd2=http://10.10.0.2:2380,etcd3=http://10.10.0.3:2380"
Environment=ETCD_ADVERTISE_CLIENT_URLS="http://10.10.0.1:2379"
Environment=ETCD_INITIAL_CLUSTER_TOKEN="prod"
Environment=ETCD_INITIAL_CLUSTER_STATE="new"
ExecStart=/usr/bin/etcd
Restart=always
RestartSec=10s
LimitNOFILE=40000

[Install]
WantedBy=multi-user.target

I think this is working correctly. Because the etcdctl member list command gives me a list of cluster nodes. And also, when one cluster node is turned off, the remaining nodes report that they cannot connect to the switched off node.

I ran into a problem that when two nodes fall, the third does not return the key. But then I realized that this is the correct behavior, since etcd uses the raft protocol and is based on quorum. I'm right?

Tell me, please, is there a way to check the health of etcd nodes using the command? Since the etcdctl member list command is not informative. When a node falls, it is still listed.

spzala commented 5 years ago

@newman0089 to check health, you can use etcdctl endpoint health or etcdctl endpoint --cluster health e.g.

etcdctl --endpoints=$ENDPOINTS endpoint --cluster health
http://x.x.x.x.:2379 is healthy: successfully committed proposal: took = 2.896694ms
http://x.x.x.x:2379 is healthy: successfully committed proposal: took = 2.239161ms
newman0089 commented 5 years ago

@spzala These commands did not work: No help topic for 'endpoint' My version is 3.2.17. I used etcdctl cluster-health Is that acceptable?

spzala commented 5 years ago

@newman0089 ahh.. yes that's fine for 3.2 You can read more here https://github.com/etcd-io/etcd/blob/master/Documentation/v2/admin_guide.md#health-monitoring