etcd 是什么?
etcd is a distributed reliable key-value store for the most critical data of a distributed system, with a focus on being:
- Simple*: well-defined, user-facing API (gRPC)*
 
- Secure: automatic TLS with optional client cert authentication
 
- Fast*: benchmarked 10,000 writes/sec*
 
- Reliable: properly distributed using Raft
 
搭建
搭建一个测试环境测试一下,当然最方便的就是用docker.
1 2 3 4 5 6 7 8 9 10
   | docker pull busybox
  docker run -it --rm busybox
 
 
 
  mkdir -p /root/data
  nohup ./etcd --config-file /root/config.yml &
   | 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
   | 
  data-dir: /root/data listen-client-urls: http://172.17.0.2:2379,http://localhost:2379 advertise-client-urls: http://172.17.0.2:2379,http://localhost:2379 name: 'etcd1'
  listen-peer-urls: http://172.17.0.2:2380 initial-advertise-peer-urls: http://172.17.0.2:2380 initial-cluster: 'etcd1=http://172.17.0.2:2380,etcd2=http://172.17.0.3:2380' initial-cluster-token: 'etcd-cluster' initial-cluster-state: 'new'
 
 
  data-dir: /root/data listen-client-urls: http://172.17.0.3:2379,http://localhost:2379 advertise-client-urls: http://172.17.0.3:2379,http://localhost:2379 name: 'etcd2'
  listen-peer-urls: http://172.17.0.3:2380 initial-advertise-peer-urls: http://172.17.0.3:2380 initial-cluster: 'etcd1=http://172.17.0.2:2380,etcd2=http://172.17.0.3:2380' initial-cluster-token: 'etcd-cluster' initial-cluster-state: 'new'
 
  | 
 
测试
1 2 3 4 5 6 7 8 9
   | 
  ./etcdctl mkdir testdir
  ./etcdctl set testdir/testkey testvalue
  ./etcdctl ls testdir/
  ./etcdctl get testdir/testkey
 
  |