Running an etcd cluster on localhost
Purpose
- Run a cluster on localhost while investigating etcd
- Use a static cluster (So we have no external dependecies for bootstrapping)
Background information
- etcd source
- How to use etcdctl and etcd coreos's distributed key value store
- etcd clustering
- etcd documentation
- Consul which is a very popular alternative
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的更多相关文章
- webserver Etcd Cluster / CoreOS etcd / macOS etcd
s https://coreos.com/etcd/ https://coreos.com/etcd/docs/latest/ macOS mojave etcd 003deMac-mini:~ ma ...
- 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; ...
- 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 ...
- <Spark><Running on a Cluster>
Introduction 之前学习的时候都是通过使用spark-shell或者是在local模式运行spark 这边我们首先介绍Spark分布式应用的架构,然后讨论在分布式clusters中运行Spa ...
- 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 ...
- Etcd全套安装教程
一.安装 1.1 二进制安装 从这里下载: etcd-v3.2.11-linux-amd64.tar.gz 下载包后解压即可运行: # 解压 tar zxvf etcd-v3.2.11-linux-a ...
- etcd安装和所遇到的坑
首先参照 https://www.cnblogs.com/lyzw/p/6016789.html来安装 虚拟机:VMware® Workstation 12 Pro 系统:CentOS Linux r ...
- 附001.etcd配置文件详解
一 示例yml配置文件 # This is the configuration file for the etcd server. # Human-readable name for this m ...
- 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 由于刚开始学习 ...
随机推荐
- 16_会话技术_Session案例
[购物车中的信息保存] [Book.java] package com.Higgin.shopping; public class Book { private String id; private ...
- mysql innodb 数据打捞(三)innodb 簇不连接页的扫描提取(计划)
操作系统簇大小一般是4K,而innoDB的页大小一般是16K,那么就有可能16K的页没有存储在连续的簇中,这样扫描软件就不会扫描出来这样的页面.为了解决这个问题,决定给软件增加半页扫描功能. 在第一次 ...
- ubuntu获取硬盘的uuid。
1.用UUID来标识硬盘有很多好处,它是一个硬盘的唯一代号,所以当硬盘插口位置变化时,虽然sda可能会变成sdc,但这个码是不会变的.所以在 fstab中用/dev/sda1这样的硬盘标识可能会有混乱 ...
- php 中 isset()函数 和 empty()函数的区别
首先这两个函数都是用来测试变量的状态: isset()函数判断一个变量是否在 如果存在返回true 否则返回false empty()函数判断一个变量是否为空,如果为空返回true 否则返回fals ...
- JQuery中的动画
一.show()方法和hide()方法 这两种方法是jQuery动画的最基本方法.当为元素调用show方法时相当于将该元素的display样式改为block或者inline,同理,如果当元素调用hid ...
- 常用PHP缓存技术
1.全页面静态化缓存 也就是将页面全部生成html静态页面,用户访问时直接访问的静态页面,而不会去走php服务器解析的流程. 一种比较常用的实现方式是用输出缓存: Ob_start() ******要 ...
- C#实现登录窗口(不用隐藏)
C#登录窗口的实现,特点就是不用隐藏,感兴趣的朋友不要错过 (1).在程序入口处,打开登录窗口 复制代码代码如下: static void Main() { Application.EnableV ...
- PHP学习心得(十)——控制结构
if 结构是很多语言包括 PHP 在内最重要的特性之一,它允许按照条件执行代码片段. if 语句可以无限层地嵌套在其它 if 语句中,这给程序的不同部分的条件执行提供了充分的弹性. else 延伸了 ...
- 【方言】Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 几种 方言配置差异 <?xml v ...
- 统计 iOS 设备锁定、解锁次数-b
今天下了个软件,可以记录手机解锁的次数和使用时间,当然啦,App 必须在后台运行着.当时比较纳闷的是有什么 API 可以接收设备解锁事件或通知的,Google 了下,还真有哎——我是链接:http:/ ...