溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

CentOS 部署Etcd集群

發(fā)布時(shí)間:2020-05-27 01:05:28 來(lái)源:網(wǎng)絡(luò) 閱讀:4072 作者:yangxuncai110 欄目:建站服務(wù)器


一、環(huán)境介紹

操作系統(tǒng)信息:CentOS 7 64位

服務(wù)器信息:

    192.168.80.130  Etcd-master

    192.168.80.131  Etcd-node1

    192.168.80.132  Etcd-node2



二、部署前準(zhǔn)備


  1、設(shè)置免密登錄

  [Master]

        [root@Etcd-master ~]# ssh-keygen

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

        [root@Etcd-master ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub Etcd-node2


  2、所有機(jī)器上操作

    a、添加hosts

        [root@Etcd-master ~]# 192.168.80.130  Etcd-master

        [root@Etcd-master ~]# 192.168.80.131  Etcd-node1

        [root@Etcd-master ~]# 192.168.80.132  Etcd-node2

    

    b、同步時(shí)間

        [root@Etcd-master ~]# 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

        [root@Etcd-master ~]# yum groupinstall "Development Tools" -y

        [root@Etcd-master ~]# cp -Rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

        [root@Etcd-master ~]# ntpdate 133.100.11.8

        [root@Etcd-master ~]# sed -i 's#ZONE="America/New_York"#ZONE="Asia/Shanghai"#g' /etc/sysconfig/clock

        [root@Etcd-master ~]# hwclock -w

        [root@Etcd-master ~]# date -R


三、部署Etcd


    [Master]

    1、安裝及配置Master節(jié)點(diǎn)

    [root@Etcd-master ~]# yum -y install etcd

    [root@Etcd-master ~]# 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節(jié)點(diǎn)

        [root@Etcd-node1 ~]# yum -y install etcd

        [root@Etcd-node1 ~]# 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節(jié)點(diǎn):

        [root@Etcd-node2 ~]# yum -y install etcd

        [root@Etcd-node2 ~]# 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、啟動(dòng)Etcd服務(wù)

        [master]

        [root@Etcd-master ~]# systemctl restart etcd

        [node1]

        [root@Etcd-node1 ~]# systemctl restart etcd

        [node2]

        [root@Etcd-node2 ~]# systemctl restart etcd

    5、查看服務(wù)狀態(tài)

        [master]

    [root@Etcd-master ~]# 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]

        [root@Etcd-node1 ~]# 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]

        [root@Etcd-node2 ~]# 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


四、測(cè)試集群同步情況


     [master]

        [root@Etcd-master ~]# etcdctl set zlyangdir/zlyangkeys0 0

0

        [root@Etcd-master ~]# etcdctl ls zlyangdir

zlyangdir/zlyangkeys0

        [root@Etcd-master ~]# etcdctl get zlyangdir/zlyangkeys0

0


    [node1]

        [root@Etcd-node1 ~]# etcdctl ls zlyangdir

zlyangdir/zlyangkeys0

        [root@Etcd-node1 ~]# etcdctl get zlyangdir/zlyangkeys0

0


    [node2]

        [root@Etcd-node2 ~]# etcdctl ls zlyangdir

zlyangdir/zlyangkeys0

        [root@Etcd-node2 ~]# etcdctl get zlyangdir/zlyangkeys0

0



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


至此Etcd集群搭建已經(jīng)完成,如有問(wèn)題請(qǐng)聯(lián)系:DBA_Master@163.com


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI