Purpose

  • Run a cluster on localhost while investigating etcd
  • Use a static cluster (So we have no external dependecies for bootstrapping)

Background information

Bootstrap

  • Will use static bootstrapping
  • Client connection port default is 2379 (Just supporting a single port per node), we will decerement the port for subsequent nodes so we do not get a port conflict
  • Peer connection (Raft consensus) port default is 2380 (Just supporting a single port per node), we will increment the port for subsequent nodes so we do not get a port conflict
  • Will use /tmp/etcdinv directory for the cluster - If you want the cluster to stick around use a different directory
    • If all nodes are stopped and then restarted the cluster will try to restart with this state, if the OS has not already purged this content
  • Will write node logs to a file and run process in the background
# etcd bin directory
etcd_bin_dir=/home/pmcgrath/go/src/github.com/coreos/etcd/bin/ # Ensure we have a root directory for the cluster - Note we are using /tmp here, if you want the cluster to stick arounf use a different directory
mkdir -p /tmp/etcdinv # Run node 1
$etcd_bin_dir./etcd \
-name node1 \
-data-dir /tmp/ectdinv/node1 \
  -advertise-client-urls http://localhost:2379 \
-listen-peer-urls http://localhost:2380 \
-listen-client-urls http://localhost:2379 \
-initial-advertise-peer-urls http://localhost:2380 \
-initial-cluster-token MyEtcdCluster \
-initial-cluster node1=http://localhost:2380,node2=http://localhost:2381,node3=http://localhost:2382 \
-initial-cluster-state new &> /tmp/etcdinv/node1.log & # Run node 2
$etcd_bin_dir./etcd \
-name node2 \
-data-dir /tmp/ectdinv/node2 \
  -advertise-client-urls http://localhost:2378 \
-listen-peer-urls http://localhost:2381 \
-listen-client-urls http://localhost:2378 \
-initial-advertise-peer-urls http://localhost:2381 \
-initial-cluster-token MyEtcdCluster \
-initial-cluster node1=http://localhost:2380,node2=http://localhost:2381,node3=http://localhost:2382 \
-initial-cluster-state new &> /tmp/etcdinv/node2.log & # Run node 3
$etcd_bin_dir./etcd \
-name node3 \
-data-dir /tmp/ectdinv/node3 \
-advertise-client-urls http://localhost:2377 \
-listen-peer-urls http://localhost:2382 \
-listen-client-urls http://localhost:2377 \
-initial-advertise-peer-urls http://localhost:2382 \
-initial-cluster-token MyEtcdCluster \
-initial-cluster node1=http://localhost:2380,node2=http://localhost:2381,node3=http://localhost:2382 \
-initial-cluster-state new &> /tmp/etcdinv/node3.log & # List nodes
ETCDCTL_PEERS=http://127.0.0.1:2379 $etcd_bin_dir/etcdctl member list
  • You can see the cluster node pids using

    • pidof etcd
    • ps aux | grep etcd

Interacting with the cluster using etcdctl

  • Will use the client port 2379 based on this
  • etcdctl defaults to 4001 at this time
  • I could have added an extra client url for 4001 when bring up the nodes, but I'm guessing 4001 will be removed at some stage
# etcd bin directory
etcd_bin_dir=/home/pmcgrath/go/src/github.com/coreos/etcd/bin/ # Using node1
# Write a key
ETCDCTL_PEERS=http://127.0.0.1:2379 $etcd_bin_dir/etcdctl set /dir1/key1 value1
# Should echo value1 # Read key
ETCDCTL_PEERS=http://127.0.0.1:2379 $etcd_bin_dir/etcdctl get /dir1/key1
# Should echo value1 # Using node3
# Read key
ETCDCTL_PEERS=http://127.0.0.1:2377 $etcd_bin_dir/etcdctl get /dir1/key1
# Should echo value1

Kill one of the nodes

# etcd bin directory
etcd_bin_dir=/home/pmcgrath/go/src/github.com/coreos/etcd/bin/ # Kill node2
pidof etcd
# Should only have 3 pids
kill $(ps aux | grep 'etcd \-name node2' | cut -d ' ' -f 2)
pidof etcd
# Should only have 2 pids # Read key using node1
ETCDCTL_PEERS=http://127.0.0.1:2379 $etcd_bin_dir/etcdctl get /dir1/key1
# Should echo value1 # Read key using node2
ETCDCTL_PEERS=http://127.0.0.1:2378 $etcd_bin_dir/etcdctl get /dir1/key1
# Should fail indicating cluster node could not available # Read key using node3
ETCDCTL_PEERS=http://127.0.0.1:2377 $etcd_bin_dir/etcdctl get /dir1/key1
# Should echo value1

Using a proxy

# etcd bin directory
etcd_bin_dir=/home/pmcgrath/go/src/github.com/coreos/etcd/bin/ # Run a read write proxy - on 8080
$etcd_bin_dir/etcd \
-proxy on \
-name proxy \
-listen-client-urls http://localhost:8080 \
-initial-cluster node1=http://localhost:2380,node2=http://localhost:2381,node3=http://localhost:2382 &> /tmp/etcdinv/proxy.log & # Read existing key
ETCDCTL_PEERS=http://127.0.0.1:8080 $etcd_bin_dir/etcdctl get /dir1/key1
# Should echo value1 # Write a key
ETCDCTL_PEERS=http://127.0.0.1:8080 $etcd_bin_dir/etcdctl set /dir1/key2 value2
# Should echo value2 # Read existing key
ETCDCTL_PEERS=http://127.0.0.1:8080 $etcd_bin_dir/etcdctl get /dir1/key1
# Should echo value2  ./etcdctl -peers 127.0.0.1:2379 member list

Running an etcd cluster on localhost的更多相关文章

  1. webserver Etcd Cluster / CoreOS etcd / macOS etcd

    s https://coreos.com/etcd/ https://coreos.com/etcd/docs/latest/ macOS mojave etcd 003deMac-mini:~ ma ...

  2. Error: client: etcd cluster is unavailable or misconfigured; error #0: dial tcp 127.0.0.1:4001: getsockopt: connection refused

    配置docker网络flannel时,配置etcd的key的时候出现以下错误 Error:  client: etcd cluster is unavailable or misconfigured; ...

  3. rancher v2.2.4创建kubernetes集群出现[etcd] Failed to bring up Etcd Plane: [etcd] Etcd Cluster is not healthy

    主机:rancher(172.16.2.17),master(172.16.2.95),node01(172.16.2.234),node02(172.16.2.67) 问题:开始是用的rancher ...

  4. <Spark><Running on a Cluster>

    Introduction 之前学习的时候都是通过使用spark-shell或者是在local模式运行spark 这边我们首先介绍Spark分布式应用的架构,然后讨论在分布式clusters中运行Spa ...

  5. etcd命令说明 etcd Version: 3.0.15

    etcd Version: 3.0.15Git SHA: fc00305Go Version: go1.6.3Go OS/Arch: linux/amd64 https://github.com/co ...

  6. Etcd全套安装教程

    一.安装 1.1 二进制安装 从这里下载: etcd-v3.2.11-linux-amd64.tar.gz 下载包后解压即可运行: # 解压 tar zxvf etcd-v3.2.11-linux-a ...

  7. etcd安装和所遇到的坑

    首先参照 https://www.cnblogs.com/lyzw/p/6016789.html来安装 虚拟机:VMware® Workstation 12 Pro 系统:CentOS Linux r ...

  8. 附001.etcd配置文件详解

    一 示例yml配置文件 # This is the configuration file for the etcd server.   # Human-readable name for this m ...

  9. k8s1.4.3安装实践记录(1)-etcd、docker、flannel安装配置

    虚拟机:VMware® Workstation 12 Pro 系统:CentOS Linux release 7.2.1511 (Core) 3.10.0-327.el7.x86_64 由于刚开始学习 ...

随机推荐

  1. 在centos7中限制kvm虚拟机可访问的资源

    最近通过艰苦卓绝的度娘(我很想用谷歌,可是,你懂的),终于搞明白如何在centos7中限制kvm虚拟机可访问的资源了.度娘给出的结果中,大部分都说的很对,然而,却很难照着做,主要原因有两点:1.网上的 ...

  2. Windows下lex 与 yacc的使用

     Windows下lex 与 yacc的使用 首先 下载下载flex和bison.网址是http://pan.baidu.com/s/1dDlfiW5 选择下载就好了,下载后解压到你电脑中的任一盘中. ...

  3. (CodeForces 558C) CodeForces 558C

    题目链接:http://codeforces.com/problemset/problem/558/C 题意:给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = a ...

  4. 第43条:返回零长度的数组或者集合,而不是null

    private final List<Cheese> cheesesInStock = ...; public Cheese[] getCheese() { if(cheesesInSto ...

  5. Windows Phone中用到的类名及对应的命名控件及引用

    //INotifyPropertyChanged using System.ComponentModel; //ICommand using System.Windows.Input; //Actio ...

  6. CheckedListBox与下拉框联动代码

    private void yewubind(string id) { //给业务类型下拉框绑定业务类型数据 DataTable dtyewu = sb.SelectLast(id, 0); bool ...

  7. React Native在虚拟运行app时,报错RCTRootView not found,怎么解决?

    报错: 解决方案:

  8. sae-服务器php运行环境配置

    config.yaml 语法- OPTION: ARG1 ARG2 ... - OPTION: if (CONDICTIONs) ACTION CONDITION可以是以下任意一种: 使用 == 和 ...

  9. poj 1904 King's Quest

    King's Quest 题意:有N个王子和N个妹子;(1 <= N <= 2000)第i个王子喜欢Ki个妹子:(详见sample)题给一个完美匹配,即每一个王子和喜欢的一个妹子结婚:问每 ...

  10. C99标准中的部分新特性

    我有点怀疑我会不会C语言了. 1.变长数组(VLA) ; scanf("%d", &n); int arr[n]; 2.数组初始化 ] = {[] = , [] = , [ ...