ETCD单机部署与ETCD集群部署

搭建单机etcd

安装epel源

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm

安装etcd

yum install etcd

配置hosts

vim /etc/hosts
    etcd-25-23 10.39.25.23

配置etcd文件

[root@etcd-25-23 etcd]# cat etcd.conf 
# [member]
ETCD_NAME=default                            #etcd服务名字
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"   #etcd数据目录
#ETCD_WAL_DIR=""
#ETCD_SNAPSHOT_COUNT="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="ttp://10.39.25.23:2379,http://localhost:2380"
ETCD_LISTEN_CLIENT_URLS="http://10.39.25.23:2379,http://127.0.0.1:2379" #客户端访问的地址和端口
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""

启动/查看etcd

systemctl restart etcd
systemctl status etcd 

查看etcd数据目录

tree /var/lib/etcd/default.etcd/
    /var/lib/etcd/default.etcd/
    └── member
        ├── snap
        │   └── db
        └── wal
            ├── 0000000000000000-0000000000000000.wal
            └── 0.tmp

etcd单机搭建完成


搭建etcd集群

安装epel源

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm

安装etcd

yum install etcd

配置hosts

vim /etc/hosts
    etcd-25-23 10.39.25.23
    etcd-25-24 10.39.25.24
    etcd-25-25 10.39.25.25

修改配置

10.39.25.23的配置

vim /etc/etcd/etcd.conf
    ETCD_NAME=etcd-25-23
    ETCD_DATA_DIR="/var/lib/etcd/etcd-cluster"
    ETCD_LISTEN_PEER_URLS="http://10.39.25.23:2380"
    ETCD_LISTEN_CLIENT_URLS="http://10.39.25.23:2379,http://127.0.0.1:2379"
    ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.39.25.23:2380"
    ETCD_INITIAL_CLUSTER="etcd-25-23=http://10.39.25.23:2380,etcd-25-24=http://10.39.25.24:2380,etcd-25-25=http://10.39.25.25:2380"
    ETCD_INITIAL_CLUSTER_STATE="new"
    ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
    ETCD_ADVERTISE_CLIENT_URLS="http://10.39.25.23:2379"
systemctl start etcd
systemctl satus etcd

10.39.25.25的配置

vim /etc/etcd/etcd.conf
    ETCD_NAME=etcd-25-25
    ETCD_DATA_DIR="/var/lib/etcd/etcd-cluster"
    ETCD_LISTEN_PEER_URLS="http://10.39.25.25:2380"
    ETCD_LISTEN_CLIENT_URLS="http://10.39.25.25:2379,http://127.0.0.1:2379"
    ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.39.25.25:2380"
    ETCD_INITIAL_CLUSTER="etcd-25-23=http://10.39.25.23:2380,etcd-25-24=http://10.39.25.24:2380,etcd-25-25=http://10.39.25.25:2380"
    ETCD_INITIAL_CLUSTER_STATE="new"
    ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
    ETCD_ADVERTISE_CLIENT_URLS="http://10.39.25.25:2379"
systemctl start etcd
systemctl satus etcd
10.39.25.24的配置
vim /etc/etcd/etcd.conf
    ETCD_NAME=etcd-25-24
    ETCD_DATA_DIR="/var/lib/etcd/etcd-cluster"
    ETCD_LISTEN_PEER_URLS="http://10.39.25.24:2380"
    ETCD_LISTEN_CLIENT_URLS="http://10.39.25.24:2379,http://127.0.0.1:2379"
    ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.39.25.24:2380"
    ETCD_INITIAL_CLUSTER="etcd-25-23=http://10.39.25.23:2380,etcd-25-24=http://10.39.25.24:2380,etcd-25-25=http://10.39.25.25:2380"
    ETCD_INITIAL_CLUSTER_STATE="new"
    ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
    ETCD_ADVERTISE_CLIENT_URLS="http://10.39.25.24:2379"
systemctl start etcd
systemctl satus etcd

查看etcd集群节点

etcdctl member list
    7e5e9b85b854c4f6: name=etcd-25-23 peerURLs=http://10.39.25.23:2380 clientURLs=http://10.39.25.23:2379 isLeader=true
    c25ca32dd7fbc99f: name=etcd-25-24 peerURLs=http://10.39.25.24:2380 clientURLs=http://10.39.25.24:2379 isLeader=false
    de67b2618c148f0d: name=etcd-25-25 peerURLs=http://10.39.25.25:2380 clientURLs=http://10.39.25.25:2379 isLeader=false

查看集群状态

etcdctl  cluster-health
    member 7e5e9b85b854c4f6 is healthy: got healthy result from http://10.39.25.23:2379
    member c20ca32dd7fbc99f is healthy: got healthy result from http://10.39.25.24:2379
    member de67b2618c148f0d is healthy: got healthy result from http://10.39.25.25:2379
    cluster is healthy

测试:
在23上创建一个TianRandai的目录

[root@etcd-25-23 ~]# etcdctl  mkdir TianRandai

在24与25上查看是是否存在

[root@etcd-25-24 ~]# etcdctl ls
/TianRandai
[root@etcd-25-25 ~]# etcdctl ls
/TianRandai


ETCD单机部署与ETCD集群部署_第1张图片

集群搭建完毕

转载于:https://blog.51cto.com/tianrandai01/2065452

你可能感兴趣的:(ETCD单机部署与ETCD集群部署)