博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Running an etcd cluster on localhost
阅读量:5160 次
发布时间:2019-06-13

本文共 4807 字,大约阅读时间需要 16 分钟。

Purpose

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

Background information

  • etcd 
  • etcd 
  • etcd 
  •  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 directoryetcd_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 directorymkdir -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 
  • 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 directoryetcd_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 directoryetcd_bin_dir=/home/pmcgrath/go/src/github.com/coreos/etcd/bin/# Kill node2pidof 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 directoryetcd_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

转载于:https://www.cnblogs.com/toSeeMyDream/p/5465834.html

你可能感兴趣的文章
对于数组排序类算法的终极解决方案
查看>>
Android 学习 豆瓣学习 sd卡缓存 内存缓存 下拉刷新 日志编辑等
查看>>
如何配置git send-email相关的邮箱信息?
查看>>
bzoj 4774: 修路
查看>>
转载--php 7.2 安装 mcrypt 扩展
查看>>
使用JUnit测试预期异常
查看>>
HDU5523 Game
查看>>
如何安装pip
查看>>
WCF完美搭建android平台服务之一
查看>>
ResNet笔记
查看>>
数据结构化与保存
查看>>
Facebook Error Code 901
查看>>
C#设计模式之11:命令模式
查看>>
使按钮失效的方法
查看>>
【娱乐】检查你的电脑是“男人”还是“女人”
查看>>
MySQL的system命令在渗透测试中的使用以及UDF提权
查看>>
node,js开发环境的搭建
查看>>
第25月第11天 deeplearning.ai
查看>>
hdu 2117
查看>>
Hibernate查询
查看>>