189 8069 5689

CentOS部署Etcd集群-创新互联

一、环境介绍

创新互联是一家成都网站建设、做网站,提供网页设计,网站设计,网站制作,建网站,按需定制,网站开发公司,从2013年创立是互联行业建设者,服务者。以提升客户品牌价值为核心业务,全程参与项目的网站策划设计制作,前端开发,后台程序制作以及后期项目运营并提出专业建议和思路。

操作系统信息:CentOS 7 64位

服务器信息:

  192.168.80.130  Etcd-master

  192.168.80.131  Etcd-node1

  192.168.80.132  Etcd-node2

二、部署前准备

 1、设置免密登录

 [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、所有机器上操作

  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、同步时间

      [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节点

    [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节点

        [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节点:

        [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、启动Etcd服务

        [master]

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

        [node1]

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

        [node2]

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

    5、查看服务状态

        [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

四、测试集群同步情况

     [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集群搭建已经完成,如有问题请联系:DBA_Master@163.com

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站题目:CentOS部署Etcd集群-创新互联
文章出自:http://cdxtjz.cn/article/djcgid.html

其他资讯