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 由于刚开始学习 ...
随机推荐
- [MAXscript Tool]FFX_PalyBack v1.1 ShowReel
自己的写的一个简单的脚本方便实现大面积的烟,火,爆炸,云的效果.能实现静态动态的切换,还有快速的偏移FumeFX的缓存,支持随机缓存 具体看这个插件的ShowReel,结算的三套基础的火焰然后用此脚本 ...
- ios专题 - objc runtime 动态增加属性
objective-c中,有类别可以在不修改源码的基础上增加方法:近排在看别人的开源代码时,发现还可以动态增加属性.而且是在运行时,太牛B了. 使用运行时库,必须要先引入 objc/runtime.h ...
- myeclipse 右键 Add Struts... 页面报404 错误
网上试了很多种方法都不对,结果老师两下点出来了 我的改正方法是: 将WebRoot/WEB-INF/web.xml中的 <url-pattern>/*</url-pattern> ...
- Apache Shiro入门实例
Shiro是一个强大灵活的开源安全框架,提供身份验证.授权.会话管理.密码体系. 1.先创建一个Maven项目 2.配置pom <project xmlns="http://maven ...
- python 自动化之路 day 04
内容目录: 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 4.嵌套函数 5.递归 6.匿名函数 7.函数式编程介绍 8.高阶函数 9.内置函数 1.函数基本语法及特性 背景提要 现在老 ...
- Apache服务
Apache服务的安装: Apache服务程序的软件包名称是:httpd 安装方法: rpm软件包安装.源码编译安装.yum安装 yum install httpd 安装完成后启动: revice h ...
- Oracle 关于事物的描述
事物在Oracle中的4种状态: commit--提交 rollback--全部回滚 savepoint name;--定义一个回滚到这里的点:例如:savepoint a; rollback to ...
- 读书计划——javascript dom 编程艺术(一)
用脑图把基础体系再捋清楚一边.
- MVC+EF 随笔小计————Html Helpers
理论基础 -- Html Helpers 主要分成输入类和显示类. 输入类: TextArea, TextBox Password Hidden DropDownList ListBox (与Drop ...
- 调用windows api 获取系统分辨率
c++中: int cxScreen,cyScreen; cxScreen=GetSystemMetrics(SM_CXSCREEN); cyScreen=GetSystemMetrics(SM_CY ...