start etcd failed by "bind: cannot assign requested address"

8.9k views Asked by At

i run etcd as docker container ,and 10.132.41.234 is my host ip which i run docker container on ,and i get error info like this ,i do not know if it is right and i do now familiar with etcd,some one can help? thx!

2017-09-13 08:55:03.339612 I | etcdmain: etcd Version: 3.0.17
2017-09-13 08:55:03.339891 I | etcdmain: Git SHA: cc198e2
2017-09-13 08:55:03.339902 I | etcdmain: Go Version: go1.6.4
2017-09-13 08:55:03.339912 I | etcdmain: Go OS/Arch: linux/amd64
2017-09-13 08:55:03.339921 I | etcdmain: setting maximum number of CPUs to 2, total number of available CPUs is 2
2017-09-13 08:55:03.340059 I | etcdmain: peerTLS: cert = /etc/ssl/certs/server.pem, key = /etc/ssl/certs/server-key.pem, ca = , trusted-ca = /etc/ssl/certs/ca.pem, client-cert-auth = true
2017-09-13 08:55:03.342794 I | etcdmain: listening for peers on https://127.0.0.1:2380
2017-09-13 08:55:03.342844 I | etcdmain: clientTLS: cert = /etc/ssl/certs/server.pem, key = /etc/ssl/certs/server-key.pem, ca = , trusted-ca = /etc/ssl/certs/ca.pem, client-cert-auth = true
2017-09-13 08:55:03.345340 I | etcdmain: stopping listening for peers on https://127.0.0.1:2380
2017-09-13 08:55:03.345386 C | etcdmain: listen tcp 10.132.41.234:2379: bind: cannot assign requested address


 docker run -d -v /opt/certs:/etc/ssl/certs -v /opt/etcd-data:/etcd-data -p 2380:2380 -p 2379:2379 \
 --name etcd gcr.io/google_containers/etcd-amd64:3.0.17 \
  /usr/local/bin/etcd \
 --name etcd0 \
 --data-dir=/etcd-data \
 --advertise-client-urls https://10.132.41.234:2379,https://127.0.0.1:2379 \
 --listen-client-urls https://10.132.41.234:2379,https://127.0.0.1:2379 \
 --initial-advertise-peer-urls https://127.0.0.1:2380 \
 --listen-peer-urls https://127.0.0.1:2380 \
 --initial-cluster-token etcd-cluster-1 \
 --initial-cluster etcd0=https://127.0.0.1:2380,etcd1=https://127.0.0.1:2380,etcd2=https://127.0.0.1:2380 \
 --initial-cluster-state new \
 --cert-file=/etc/ssl/certs/server.pem \
 --key-file=/etc/ssl/certs/server-key.pem \
 --peer-cert-file=/etc/ssl/certs/server.pem \
 --peer-key-file=/etc/ssl/certs/server-key.pem \
 --trusted-ca-file=/etc/ssl/certs/ca.pem \
 --peer-trusted-ca-file=/etc/ssl/certs/ca.pem \
 --peer-client-cert-auth=true \
 --client-cert-auth=true
2

There are 2 answers

0
Punnerud On

If you follow the etcd guide, check if this point to the machine you are running the command on:

THIS_NAME=${NAME_4}
THIS_IP=${HOST_4}

Replace 4 with the correct number.

0
valenbb On

I got the same error when trying to bind to the server's IP. I fixed this (though, not sure what the consequence will be) by adding 0.0.0.0 in both --listen-peer-urls and --listen-client-urls:

docker run --net=host -d -p 2379:2379 \
  -p 2380:2380 \
  --restart=always \
  --volume=${DATA_DIR}:/etcd-data \
  --name etcd0 quay.io/coreos/etcd:${ETCD_VERSION} \
  /usr/local/bin/etcd \
  --data-dir=/etcd-data --name ${THIS_NAME} \
  --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://0.0.0.0:2380 \
  --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://0.0.0.0:2379** \
  --initial-cluster ${CLUSTER} \
  --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}

Used curl to verify working cluster:

curl http://IP:2379/v2/members
{"members":[{"id":"d587abebd4bc78d","name":"etcd1","peerURLs":["http://IP:2380"],"clientURLs":["http://IP:2379"]},{"id":"17efb04cb71d981c","name":"etcd0","peerURLs":["http://IP:2380"],"clientURLs":["http://IP:2379"]},{"id":"3d50a0b6f7f6bda6","name":"etcd3","peerURLs":["http://IP:2380"],"clientURLs":["http://IP:2379"]}]}

Docker command comes directly from coreos etcd website: https://coreos.com/etcd/docs/3.2.9/op-guide/container.html#docker