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. Java_log4j

      Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件,甚至是套接口服务器.事件记录器等:我们也可以控制每一条日志的输出格式: ...

  2. linux shell编程学习笔记(二) --- grep命令

    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全局正则表达 ...

  3. 每天一个linux命令(1):more命令

    more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...

  4. Nginx+keepalived实现负载均衡

    Nginx的优点是: 1.工作在网络的7层之上,可以针对http应用做一些分流的策略,比如针对域名.目录结构,它的正则规则比HAProxy更为强大和灵活,这也是它目前广泛流行的主要原因之一,Nginx ...

  5. Entity Framework多对多关联映射的实现

    Entity Framework是微软官方提供的一个ORM解决方案,它有纯正的血统,比NHibernate更容易使用并且与现有其它官方框架配合更加密切. 时代不断的在发展变化,记得10年前还是ADO( ...

  6. 网络设备作用和工作ISO层

    物理层——中继器和集线器 二者都起数字信号放大和中转的作用. 中继器 Repeater 用来延长网络距离的互连设备.REPEATER可以增强线路上衰减的信号,它两端即可以连接相同的传输媒体,也可以连接 ...

  7. post请求json内容丢失问题

    今天在项目组用json传输数据 post方法提交 发现传输过去的数据json内的+ 号被直接干掉了. 后来传输之前直接先编码. 接收端: public void ProcessRequest(Http ...

  8. 解决关于IIS10.0下无法安装 URL 重写模块 2的问题

    win10 系统自带的IIS是IIS10.0,官网提示URL Rewrite 2.0是只要IIS7.0以上的版本就可以安装,但是在IIS10.0下安装却一直失败.错误提示如下: 那么如何才能正确安装呢 ...

  9. CODEVS 3286 火柴排队

    [题目描述 Description] 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度.现在将每盒中的火柴各自排成一列,同一列火柴的高度互不相同,两列火柴之间的距离定义为: ,其中 ai表示 ...

  10. 防止横竖屏时,iphone自动缩放的一段js代码

    function orientation_change() {     var viewport = document.querySelector('meta[name="viewport& ...