ETCD集群部署文檔

ETCD部署及解釋

一、部署環(huán)境

主機(jī)賬號(hào) 主機(jī)密碼
root XXXXXXXXX

二、資源配置

|主機(jī)名|IP地址|CPU(核心)|內(nèi)存(GB)|系統(tǒng)硬盤(GB)|掛載硬盤(GB)|
|-|-|-|-|-|-|-|
|etcd-k8s-master-1|192.168.40.140|2|4|20|100|
|etcd-k8s-master-2|192.168.40.141|2|4|20|100|
|etcd-k8s-master-3|192.168.40.142|2|4|20|100|

三、安裝、啟動(dòng)etcd

3.1 安裝ansible

# 安裝ansible
yum install ansible -y

# 配置ansible hosts文件
vim /etc/ansible/hosts
[etcd]
192.168.40.140
192.168.40.141
192.168.40.142
[all:vars]
ansible_ssh_user="root"
ansible_ssh_pass="XXXXXXXXX"

# 編寫分發(fā)文件
vim ssh-key.yml 
- hosts: all
  become: yes
  tasks: 
   - name: Auth
     authorized_key: 
      user: root
      key: "{{lookup('file','~/.ssh/id_rsa.pub')}}"

#生成ssh-key文件
ssh-keygen

3.2 編輯分發(fā)hosts文件

# 編輯hosts文件
vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.40.140 etcd-1 etcd-k8s-master-1
192.168.40.141 etcd-2 etcd-k8s-master-2
192.168.40.142 etcd-3 etcd-k8s-master-3

# 分發(fā)hosts文件
ansible all -m copy -a "src=/etc/hosts dest=/etc/hosts"

3.2 安裝golang

# 下載golang并創(chuàng)建對(duì)應(yīng)目錄
cd /opt
wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
tar xvf go1.13.4.linux-amd64.tar.gz go1.13.4.linux-amd64.tar.gz
mkdir -P /opt/gopath/{src,bin,pkg}

# 配置golang環(huán)境變量
vim /etc/profile.d/go.sh
    export GOROOT=/opt/go
    export GOPATH=/opt/gopath
    export PATH=$PATH:$GOROOT/bin

# 刷新環(huán)境變量
. /etc/profile.d/go.sh

3.2 編譯etcd與etcdctl代碼生成二進(jìn)制文件與分發(fā)

3.2.1 編譯生成與分發(fā)etcd

go get github.com/etcd-io/etcd
cd /opt/gopath/src/go.etcd.io/etcd
go build
ansible all -m copy -a "src=./etcd dest=/bin/etcd mode=u+rwx,g+rx,o+rx"

3.2.2 編譯生成與分發(fā)etcd

cd /opt/gopath/src/go.etcd.io/etcd/etcdctl
go build
ansible all -m copy -a "src=./etcdctl dest=/bin/etcdctl mode=u+rwx,g+rx,o+rx"

此處如果發(fā)生報(bào)錯(cuò):<font color=red>build go.etcd.io/etcd/etcdctl: cannot load github.com/bgentry/speakeasy: github.com/bgentry/speakeasy@v0.1.0: Get https://proxy.golang.org/github.com/bgentry/speakeasy/@v/v0.1.0.zip: dial tcp 216.58.200.49:443: i/o timeout</font>

執(zhí)行:

git clone https://github.com/bgentry/speakeasy.git /opt/gopath/src/github.com/

3.3 etcd啟動(dòng)項(xiàng)

etcd節(jié)點(diǎn)1

nohup etcd --name etcd-1 \
  --initial-advertise-peer-urls 'http://192.168.40.140:2380' \
  --listen-peer-urls 'http://192.168.40.140:2380' \
  --advertise-client-urls 'http://192.168.40.140:2379' \
  --listen-client-urls 'http://192.168.40.140:2379' \
  --initial-cluster-token 'etcd-1' \
  --initial-cluster etcd-1=http://192.168.40.140:2380,etcd-2=http://192.168.40.141:2380,etcd-3=http://192.168.40.142:2380 \
  --data-dir /opt/${HOSTNAME}.etcd \
  --initial-cluster-state 'new'&

etcd節(jié)點(diǎn)2

nohup etcd --name etcd-2 \
  --initial-advertise-peer-urls 'http://192.168.40.141:2380' \
  --listen-peer-urls 'http://192.168.40.141:2380' \
  --advertise-client-urls 'http://192.168.40.141:2379' \
  --listen-client-urls 'http://192.168.40.141:2379' \
  --initial-cluster-token 'etcd-1' \
  --initial-cluster etcd-1=http://192.168.40.140:2380,etcd-2=http://192.168.40.141:2380,etcd-3=http://192.168.40.142:2380 \
  --data-dir /opt/${HOSTNAME}.etcd \
  --initial-cluster-state 'new'&

etcd節(jié)點(diǎn)3

nohup etcd --name etcd-3 \
  --initial-advertise-peer-urls 'http://192.168.40.142:2380' \
  --listen-peer-urls 'http://192.168.40.142:2380' \
  --advertise-client-urls 'http://192.168.40.142:2379' \
  --listen-client-urls 'http://192.168.40.142:2379' \
  --initial-cluster-token 'etcd-1' \
  --initial-cluster etcd-1=http://192.168.40.140:2380,etcd-2=http://192.168.40.141:2380,etcd-3=http://192.168.40.142:2380 \
  --data-dir /opt/${HOSTNAME}.etcd \
  --initial-cluster-state 'new'&

3.4 etcd啟動(dòng)項(xiàng)信息

  • --name:etcd在集群中的節(jié)點(diǎn)名稱,在同一個(gè)集群中必須是唯一的
  • --initial-advertise-peer-urls:建議用于集群內(nèi)部幾點(diǎn)之間的交互的URL地址,幾點(diǎn)見講義該值進(jìn)行通信
  • --listen-peer-urls:用于集群內(nèi)各個(gè)節(jié)點(diǎn)之間通信的URL地址,每個(gè)節(jié)點(diǎn)可以監(jiān)聽多個(gè)url地址,集群內(nèi)部將通過這些URL地址進(jìn)行數(shù)據(jù)交互,例如,leader幾點(diǎn)的選舉、Message消息的傳輸或者快照的傳輸?shù)取?/li>
  • --advertise-client-urls:建議客戶端使用的RUL地址,該值用于etcd代理或etcd成員與etcd幾點(diǎn)通信
  • --listen-client-urls:用于當(dāng)前地址與客戶端交互的URL地址,每個(gè)幾點(diǎn)可以向客戶端提供多個(gè)URL地址
  • --initial-cluster-token:集群的唯一標(biāo)識(shí)
  • --initial-cluster:集群中所有的initial-advertise-peer-urls
  • --data-dic:數(shù)據(jù)的存放位置,${name}該節(jié)點(diǎn)的名字
  • --initial-cluster-state new:新集群的標(biāo)識(shí)

測(cè)試集群否正常

[root@etcd-k8s-master-1 ~]# etcdctl --endpoints=192.168.40.140:2379,192.168.40.141:2379,192.168.40.142:2379 endpoint health
192.168.40.140:2379 is healthy: successfully committed proposal: took = 2.268118ms
192.168.40.141:2379 is healthy: successfully committed proposal: took = 2.396264ms
192.168.40.142:2379 is healthy: successfully committed proposal: took = 3.042977ms
[root@etcd-k8s-master-1 ~]# etcdctl --write-out=table --endpoints=192.168.40.140:2379,192.168.40.141:2379,192.168.40.142:2379 endpoint status
+---------------------+------------------+-----------+---------+-----------+------------+-----------+------------+--------------------+--------+
|     ENDPOINT        |        ID        |  VERSION  | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+---------------------+------------------+-----------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 192.168.40.140:2379 | 1f5cb9a09297a825 | 3.5.0-pre |   20 kB |     false |      false |         9 |          9 |                  9 |        |
| 192.168.40.141:2379 | 8a5428646f2d78bf | 3.5.0-pre |   20 kB |      true |      false |         9 |          9 |                  9 |        |
| 192.168.40.142:2379 | f16ab1eb94b31b0d | 3.5.0-pre |   16 kB |     false |      false |         9 |          9 |                  9 |        |
+---------------------+------------------+-----------+---------+-----------+------------+-----------+------------+--------------------+--------+
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容