docker_practice/etcd/install.md

98 lines
3.6 KiB
Go
Raw Normal View History

2014-12-31 09:11:09 +00:00
##
2017-12-03 10:53:35 +00:00
`etcd` `Go` [](https://github.com/coreos/etcd) 下载源代码自行编译,也可以下载编译好的二进制文件,甚至直接使用制作好的 `Docker` 镜像文件来体验。
2017-12-03 05:57:02 +00:00
> etcd `3.x`
2014-12-31 09:11:09 +00:00
###
[github.com/coreos/etcd/releases](https://github.com/coreos/etcd/releases/) 页面,用户可以选择需要的版本,或通过下载工具下载。
2017-12-03 05:57:02 +00:00
使 `curl`
2014-12-31 09:11:09 +00:00
2017-11-13 10:54:38 +00:00
```bash
2017-12-03 05:57:02 +00:00
$ curl -L https://github.com/coreos/etcd/releases/download/v3.2.10/etcd-v3.2.10-linux-amd64.tar.gz -o etcd-v3.2.10-linux-amd64.tar.gz
$ tar xzvf etcd-v3.2.10-linux-amd64.tar.gz
$ cd etcd-v3.2.10-linux-amd64
2014-12-31 09:11:09 +00:00
```
2017-12-03 05:57:02 +00:00
2017-11-13 10:54:38 +00:00
```bash
2014-12-31 09:11:09 +00:00
$ ls
2017-12-03 05:57:02 +00:00
Documentation README-etcdctl.md README.md READMEv2-etcdctl.md etcd etcdctl
2014-12-31 09:11:09 +00:00
```
2017-12-03 05:57:02 +00:00
`etcd` `etcdctl`
2014-12-31 09:11:09 +00:00
2017-12-03 05:57:02 +00:00
`etcd` `etcdctl` `/usr/local/bin/`
2014-12-31 09:11:09 +00:00
2017-11-13 10:54:38 +00:00
```bash
2014-12-31 09:11:09 +00:00
$ sudo cp etcd* /usr/local/bin/
```
2017-12-03 10:53:35 +00:00
`2379` `2380` `etcd`
2017-12-03 05:57:02 +00:00
2017-11-13 10:54:38 +00:00
```bash
2017-12-03 05:57:02 +00:00
$ etcd
2017-12-03 11:18:34.406082 I | etcdmain: etcd Version: 3.2.10
2017-12-03 11:18:34.406226 I | etcdmain: Git SHA: GitNotFound
2017-12-03 11:18:34.406235 I | etcdmain: Go Version: go1.9.2
2017-12-03 11:18:34.406242 I | etcdmain: Go OS/Arch: darwin/amd64
2017-12-03 11:18:34.406250 I | etcdmain: setting maximum number of CPUs to 4, total number of available CPUs is 4
2017-12-03 11:18:34.406265 N | etcdmain: failed to detect default host (default host not supported on darwin_amd64)
2017-12-03 11:18:34.406279 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd
2017-12-03 11:18:34.406457 N | etcdmain: the server is already initialized as member before, starting as etcd member...
2017-12-03 11:18:34.411579 I | embed: listening for peers on http://localhost:2380
2017-12-03 11:18:34.411938 I | embed: listening for client requests on localhost:2379
2014-12-31 09:11:09 +00:00
```
2017-12-03 10:53:35 +00:00
使 `etcdctl` `testkey: "hello world"` `etcd`
2017-12-03 05:57:02 +00:00
2017-11-13 10:54:38 +00:00
```bash
$ ETCDCTL_API=3 etcdctl member list
2017-12-03 05:57:02 +00:00
8e9e05c52164694d, started, default, http://localhost:2380, http://localhost:2379
$ ETCDCTL_API=3 etcdctl put testkey "hello world"
2017-12-03 05:57:02 +00:00
OK
$ etcdctl get testkey
testkey
2014-12-31 09:11:09 +00:00
hello world
```
2017-12-03 05:57:02 +00:00
2014-12-31 09:11:09 +00:00
etcd
2017-12-03 05:57:02 +00:00
### Docker
`quay.io/coreos/etcd` `etcd` `2379` `2380`
2017-11-13 10:54:38 +00:00
```bash
2017-12-03 05:57:02 +00:00
$ export NODE1=192.168.1.21
$ docker run --name etcd \
-p 2379:2379 \
-p 2380:2380 \
--volume=etcd-data:/etcd-data \
quay.io/coreos/etcd:latest \
/usr/local/bin/etcd \
--data-dir=/etcd-data --name node1 \
--initial-advertise-peer-urls http://${NODE1}:2380 --listen-peer-urls http://0.0.0.0:2380 \
--advertise-client-urls http://${NODE1}:2379 --listen-client-urls http://0.0.0.0:2379 \
--initial-cluster node1=http://${NODE1}:2380
2014-12-31 09:11:09 +00:00
```
2017-12-03 05:57:02 +00:00
>etcd `quay.io/coreos/etcd` `gcr.io/etcd-development/etcd` 使
2017-12-03 10:53:35 +00:00
`etcd`
2017-12-03 05:57:02 +00:00
### macOS
2014-12-31 09:11:09 +00:00
2017-11-13 10:54:38 +00:00
```bash
2017-12-03 05:57:02 +00:00
$ brew install etcd
$ etcd
$ etcdctl member list
2014-12-31 09:11:09 +00:00
```