## 安装
etcd 基于 Go 语言实现,因此,用户可以从 [项目主页](https://github.com/coreos/etcd) 下载源代码自行编译,也可以下载编译好的二进制文件,甚至直接使用制作好的 Docker 镜像文件来体验。
### 二进制文件方式下载
编译好的二进制文件都在 [github.com/coreos/etcd/releases](https://github.com/coreos/etcd/releases/) 页面,用户可以选择需要的版本,或通过下载工具下载。
例如,下面的命令使用 curl 工具下载压缩包,并解压。
```
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
```
解压后,可以看到文件包括
```
$ ls
etcd etcdctl etcd-migrate README-etcdctl.md README.md
```
其中 etcd 是服务主文件,etcdctl 是提供给用户的命令客户端,etcd-migrate 负责进行迁移。
推荐通过下面的命令将三个文件都放到系统可执行目录 `/usr/local/bin/` 或 `/usr/bin/`。
```
$ sudo cp etcd* /usr/local/bin/
```
运行 etcd,将默认组建一个两个节点的集群。数据库服务端默认监听在 2379 和 4001 端口,etcd 实例监听在 2380 和 7001 端口。显示类似如下的信息:
```
$ ./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
```
此时,可以使用 etcdctl 命令进行测试,设置和获取键值 `testkey: "hello world"`,检查 etcd 服务是否启动成功:
```
$ ./etcdctl set testkey "hello world"
hello world
$ ./etcdctl get testkey
hello world
```
说明 etcd 服务已经成功启动了。
当然,也可以通过 HTTP 访问本地 2379 或 4001 端口的方式来进行操作,例如查看 `testkey` 的值:
```
$ curl -L http://localhost:4001/v2/keys/testkey
{"action":"get","node":{"key":"/testkey","value":"hello world","modifiedIndex":3,"createdIndex":3}}
```
### Docker 镜像方式下载
镜像名称为 quay.io/coreos/etcd:v2.0.0_rc.1,可以通过下面的命令启动 etcd 服务监听到 4001 端口。
```
$ sudo docker run -p 4001:4001 -v /etc/ssl/certs/:/etc/ssl/certs/ quay.io/coreos/etcd:v2.0.0_rc.1
```
- 前言
- Docker 简介
- 什么是 Docker
- 为什么要用 Docker
- 基本概念
- 镜像
- 容器
- 仓库
- 安装
- Ubuntu
- CentOS
- 镜像
- 获取镜像
- 列出
- 创建
- 存出和载入
- 移除
- 实现原理
- 容器
- 启动
- 守护态运行
- 终止
- 进入容器
- 导出和导入
- 删除
- 仓库
- Docker Hub
- 私有仓库
- 配置文件
- 数据管理
- 数据卷
- 数据卷容器
- 备份、恢复、迁移数据卷
- 使用网络
- 外部访问容器
- 容器互联
- 高级网络配置
- 快速配置指南
- 配置 DNS
- 容器访问控制
- 端口映射实现
- 配置 docker0 网桥
- 自定义网桥
- 工具和示例
- 编辑网络配置文件
- 实例:创建一个点到点连接
- 实战案例
- 使用 Supervisor 来管理进程
- 创建 tomcat/weblogic 集群
- 多台物理主机之间的容器互联
- 标准化开发测试和生产环境
- 安全
- 内核名字空间
- 控制组
- 服务端防护
- 内核能力机制
- 其它安全特性
- 总结
- Dockerfile
- 基本结构
- 指令
- 创建镜像
- 底层实现
- 基本架构
- 名字空间
- 控制组
- 联合文件系统
- 容器格式
- 网络
- Docker Compose 项目
- 简介
- 安装
- 使用
- 命令说明
- YAML 模板文件
- Docker Machine 项目
- 简介
- 安装
- 使用
- Docker Swarm 项目
- 简介
- 安装
- 使用
- 调度器
- 过滤器
- Etcd 项目
- 简介
- 安装
- 使用 etcdctl
- Fig 项目
- 简介
- 安装
- 命令参考
- fig.yml参考
- 环境变量参考
- 实战 Django
- 实战 Rails
- 实战 wordpress
- CoreOS 项目
- 简介
- 工具
- 快速搭建CoreOS集群
- Kubernetes 项目
- 简介
- 快速上手
- 基本概念
- kubectl 使用
- 架构设计
- Mesos 项目
- 简介
- 安装与使用
- 原理与架构
- 配置项解析
- 常见框架
- 附录一:命令查询
- 附录二:常见仓库介绍
- Ubuntu
- CentOS
- MySQL
- MongoDB
- Redis
- Nginx
- WordPress
- Node.js
- 附录三:有用的资源