## 安裝
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
- 附錄三:有用的資源