1. 程式人生 > >CentOS 部署Etcd集群

CentOS 部署Etcd集群

etcd etc flannel k8s kubernets docker

一、環境介紹

操作系統信息:CentOS 7 64位

服務器信息:

192.168.80.130 Etcd-master

192.168.80.131 Etcd-node1

192.168.80.132 Etcd-node2



二、部署前準備


1、設置免密登錄

[Master]

[[email protected] ~]# ssh-keygen

[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub Etcd-node1

[[email protected]

/* */ ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub Etcd-node2


2、所有機器上操作

a、添加hosts

[[email protected] ~]# 192.168.80.130 Etcd-master

[[email protected] ~]# 192.168.80.131 Etcd-node1

[[email protected] ~]# 192.168.80.132 Etcd-node2

b、同步時間

[[email protected]

~]# yum -y lrzsz git wget python-devel ntp net-tools curl cmake epel-release rpmdevtools openssl-devel kernel-devel gcc redhat-rpm-config bridge-utils

[[email protected] ~]# yum groupinstall "Development Tools" -y

[[email protected] ~]# cp -Rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

[[email protected] ~]# ntpdate 133.100.11.8

[[email protected] ~]# sed -i ‘s#ZONE="America/New_York"#ZONE="Asia/Shanghai"#g‘ /etc/sysconfig/clock

[[email protected] ~]# hwclock -w

[[email protected] ~]# date -R


三、部署Etcd


[Master]

1、安裝及配置Master節點

[[email protected] ~]# yum -y install etcd

[[email protected] ~]# cat /etc/etcd/etcd.conf

# [member]

ETCD_NAME="etcd-master"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

#ETCD_WAL_DIR=""

#ETCD_SNAPSHOT_COUNT="10000"

#ETCD_HEARTBEAT_INTERVAL="100"

#ETCD_ELECTION_TIMEOUT="1000"

ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:4001,http://0.0.0.0:2379"

#ETCD_MAX_SNAPSHOTS="5"

#ETCD_MAX_WALS="5"

#ETCD_CORS=""

#

#[cluster]

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://etcd-master:2380"

# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."

ETCD_INITIAL_CLUSTER="etcd-node1=http://etcd-node1:2380,etcd-node2=http://etcd-node2:2380,etcd-master=http://etcd-master:2380"

ETCD_INITIAL_CLUSTER_STATE="new"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_ADVERTISE_CLIENT_URLS="http://Etcd-master:2379,http://Etcd-master:4001"


[Node]

2、安裝及配置Node1節點

[[email protected] ~]# yum -y install etcd

[[email protected] ~]# cat /etc/etcd/etcd.conf

# [member]

ETCD_NAME="etcd-node1"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

#ETCD_WAL_DIR=""

#ETCD_SNAPSHOT_COUNT="10000"

#ETCD_HEARTBEAT_INTERVAL="100"

#ETCD_ELECTION_TIMEOUT="1000"

ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:4001,http://0.0.0.0:2379"

#ETCD_MAX_SNAPSHOTS="5"

#ETCD_MAX_WALS="5"

#ETCD_CORS=""

#

#[cluster]

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://etcd-node1:2380"

# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."

ETCD_INITIAL_CLUSTER="etcd-node1=http://etcd-node1:2380,etcd-node2=http://etcd-node2:2380,etcd-master=http://etcd-master:2380"

ETCD_INITIAL_CLUSTER_STATE="new"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_ADVERTISE_CLIENT_URLS="http://etcd-node1:2379,http://etcd-node1:4001"


3、安裝及配置Node2節點:

[[email protected] ~]# yum -y install etcd

[[email protected] ~]# cat /etc/etcd/etcd.conf

# [member]

ETCD_NAME="etcd-node2"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

#ETCD_WAL_DIR=""

#ETCD_SNAPSHOT_COUNT="10000"

#ETCD_HEARTBEAT_INTERVAL="100"

#ETCD_ELECTION_TIMEOUT="1000"

ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:4001,http://0.0.0.0:2379"

#ETCD_MAX_SNAPSHOTS="5"

#ETCD_MAX_WALS="5"

#ETCD_CORS=""

#

#[cluster]

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://etcd-node2:2380"

# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."

ETCD_INITIAL_CLUSTER="etcd-node1=http://etcd-node1:2380,etcd-node2=http://etcd-node2:2380,etcd-master=http://etcd-master:2380"

ETCD_INITIAL_CLUSTER_STATE="new"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_ADVERTISE_CLIENT_URLS="http://etcd-node2:2379,http://etcd-node2:4001"


4、啟動Etcd服務

[master]

[[email protected] ~]# systemctl restart etcd

[node1]

[[email protected] ~]# systemctl restart etcd

[node2]

[[email protected] ~]# systemctl restart etcd

5、查看服務狀態

[master]

[[email protected] ~]# etcdctl member list

6c74f3fd7534bb5: name=etcd-node1 peerURLs=http://etcd-node1:2380 clientURLs=http://etcd-node1:2379,http://etcd-node1:4001 isLeader=false

a57a17f287dbe7bb: name=etcd-node2 peerURLs=http://etcd-node2:2380 clientURLs=http://etcd-node2:2379,http://etcd-node2:4001 isLeader=true

ffe21a7812eb7c5f: name=etcd-master peerURLs=http://etcd-master:2380 clientURLs= isLeader=false


[node1]

[[email protected] ~]# etcdctl member list

6c74f3fd7534bb5: name=etcd-node1 peerURLs=http://etcd-node1:2380 clientURLs=http://etcd-node1:2379,http://etcd-node1:4001 isLeader=false

a57a17f287dbe7bb: name=etcd-node2 peerURLs=http://etcd-node2:2380 clientURLs=http://etcd-node2:2379,http://etcd-node2:4001 isLeader=true

ffe21a7812eb7c5f: name=etcd-master peerURLs=http://etcd-master:2380 clientURLs= isLeader=false


[node2]

[[email protected] ~]# etcdctl member list

6c74f3fd7534bb5: name=etcd-node1 peerURLs=http://etcd-node1:2380 clientURLs=http://etcd-node1:2379,http://etcd-node1:4001 isLeader=false

a57a17f287dbe7bb: name=etcd-node2 peerURLs=http://etcd-node2:2380 clientURLs=http://etcd-node2:2379,http://etcd-node2:4001 isLeader=true

ffe21a7812eb7c5f: name=etcd-master peerURLs=http://etcd-master:2380 clientURLs= isLeader=false


四、測試集群同步情況


[master]

[[email protected] ~]# etcdctl set zlyangdir/zlyangkeys0 0

0

[[email protected] ~]# etcdctl ls zlyangdir

zlyangdir/zlyangkeys0

[[email protected] ~]# etcdctl get zlyangdir/zlyangkeys0

0


[node1]

[[email protected] ~]# etcdctl ls zlyangdir

zlyangdir/zlyangkeys0

[[email protected] ~]# etcdctl get zlyangdir/zlyangkeys0

0


[node2]

[[email protected] ~]# etcdctl ls zlyangdir

zlyangdir/zlyangkeys0

[[email protected] ~]# etcdctl get zlyangdir/zlyangkeys0

0



官方部署方案:https://coreos.com/etcd/docs/latest/op-guide/clustering.html


至此Etcd集群搭建已經完成,如有問題請聯系:[email protected]


本文出自 “Elephant” 博客,請務必保留此出處http://zlyang.blog.51cto.com/1196234/1951164

CentOS 部署Etcd集群