May 22, 2021 Docker From entry to practice
Etcd is implemented in the Go language, so users can download the source code from the project home page to compile it themselves, download the compiled binary files, or even experience it directly with a created Docker image file.
Compiled binary files are available on github.com/coreos/etcd/releases page, and users can choose which version they want or download them through the download tool.
For example, the following command uses the curl tool to download the package and unzip it.
curl -L https://github.com/coreos/etcd/releases/download/v2.0.0-rc.1/etcd-v2.0.0-rc.1-linux-amd64.tar.gz -o etcd-v2.0.0-rc.1-linux-amd64.tar.gz
tar xzvf etcd-v2.0.0-rc.1-linux-amd64.tar.gz
cd etcd-v2.0.0-rc.1-linux-amd64
After decompression, you can see that the files are included
$ ls
etcd etcdctl etcd-migrate README-etcdctl.md README.md
Where etcd is the service master file, etcdctl is the command client provided to the user, and etcd-migrate is responsible for migration.
It is recommended that all three files be placed in the system executable
/usr/local/bin/
/usr/bin/
$ sudo cp etcd* /usr/local/bin/
Run etcd and a two-node cluster will be formed by default. T he database service side listens by default on ports 2379 and 4001, and the etcd instance listens on ports 2380 and 7001. Displays information like this:
$ ./etcd
2014/12/31 14:52:09 no data-dir provided, using default data-dir ./default.etcd
2014/12/31 14:52:09 etcd: listening for peers on http://localhost:2380
2014/12/31 14:52:09 etcd: listening for peers on http://localhost:7001
2014/12/31 14:52:09 etcd: listening for client requests on http://localhost:2379
2014/12/31 14:52:09 etcd: listening for client requests on http://localhost:4001
2014/12/31 14:52:09 etcdserver: name = default
2014/12/31 14:52:09 etcdserver: data dir = default.etcd
2014/12/31 14:52:09 etcdserver: snapshot count = 10000
2014/12/31 14:52:09 etcdserver: advertise client URLs = http://localhost:2379,http://localhost:4001
2014/12/31 14:52:09 etcdserver: initial advertise peer URLs = http://localhost:2380,http://localhost:7001
2014/12/31 14:52:09 etcdserver: initial cluster = default=http://localhost:2380,default=http://localhost:7001
2014/12/31 14:52:10 etcdserver: start member ce2a822cea30bfca in cluster 7e27652122e8b2ae
2014/12/31 14:52:10 raft: ce2a822cea30bfca became follower at term 0
2014/12/31 14:52:10 raft: newRaft ce2a822cea30bfca [peers: [], term: 0, commit: 0, lastindex: 0, lastterm: 0]
2014/12/31 14:52:10 raft: ce2a822cea30bfca became follower at term 1
2014/12/31 14:52:10 etcdserver: added local member ce2a822cea30bfca [http://localhost:2380 http://localhost:7001] to cluster 7e27652122e8b2ae
2014/12/31 14:52:11 raft: ce2a822cea30bfca is starting a new election at term 1
2014/12/31 14:52:11 raft: ce2a822cea30bfca became candidate at term 2
2014/12/31 14:52:11 raft: ce2a822cea30bfca received vote from ce2a822cea30bfca at term 2
2014/12/31 14:52:11 raft: ce2a822cea30bfca became leader at term 2
2014/12/31 14:52:11 raft.node: ce2a822cea30bfca elected leader ce2a822cea30bfca at term 2
2014/12/31 14:52:11 etcdserver: published {Name:default ClientURLs:[http://localhost:2379 http://localhost:4001]} to cluster 7e27652122e8b2ae
At this point, you can use the etcdctl command to test, set and get the
testkey: "hello world"
to check that the etcd service started successfully:
$ ./etcdctl set testkey "hello world"
hello world
$ ./etcdctl get testkey
hello world
Explain that the etcd service has been successfully started.
Of course, you can also do this by accessing local 2379 or 4001 ports over HTTP, such as viewing
testkey
$ curl -L http://localhost:4001/v2/keys/testkey
{"action":"get","node":{"key":"/testkey","value":"hello world","modifiedIndex":3,"createdIndex":3}}
The mirror name is quay.io/coreos/etcd:v2.0.0_rc.1 and the etcd service can be started by the following command to listen for the 4001 port.
$ sudo docker run -p 4001:4001 -v /etc/ssl/certs/:/etc/ssl/certs/ quay.io/coreos/etcd:v2.0.0_rc.1