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 由于刚开始学习 ...
随机推荐
- Json操作
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- jQuery—一些常见方法(3)【width(),innerWidth(),outerWidth()】
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- spring data mongodb中,如果对象中的属性不想加入到数据库字段中
spring data mongodb中,如果对象中的属性不想加入到数据库字段中,可加@Transient注解,声明为透明属性 spring data mongodb 官网帮助文档 http://ww ...
- margin系列之百分比
本系列摘自 px; height: 600px; } #demo p{ margin: 10% 5%; } HTML: <div id="demo"> <p&g ...
- PHP学习笔记(4) - 实现自己的MVC框架
在PHP中实现一个所谓的MVC框架非常简单.这里说一下思路. 一.首先用spl_autoload_register函数实现自己的类型自动加载机制.这样其他代码都不需要再考虑如何将类所在的文件inclu ...
- 针对目前高校移动App的火热,哥决定点一把火
最近正在做市场调研,还请众位大哥大姐们帮忙投个票,求扩散 http://user.qzone.qq.com/717010686/vote/00000000feb6bc2a3ebd1e53
- json在线校验
弄了一个在线校验,清爽无广告,欢迎大家收藏 http://www.zhhoney.com/
- Binding的源和路径
书上写着:Binding的源也就是数据的源头.Binding对于源的要求很简单-只要他是一个对象!并且通过属性(Property)公开自己的数据,它就可以作为Binding的源了.就像上一篇我写的那个 ...
- SD卡FAT32文件系统格式
一.声明 1.本文来源和主旨 2.本文测试环境 二.SD卡FAT文件系统 1.SD卡FAT32文件系统的整体布局 2.FAT文件系统简介 ① 文件分配表 ② 目录项 三.DBR(DOS BOOT RE ...
- 【重构】m站重构思路
不重构全部模块,只对以下内容做基础重构就可以,第三方方式 1.验证码作为独立的服务,用户写入验证码获得id,服务端获取验证码id对应内容(根据时间和存储空间 清理验证码) 2.支付接口h5环境独立配置 ...