欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

etcd集群搭建步骤

程序员文章站 2022-07-13 22:19:34
...

etcd集群搭建步骤(三台虚拟机集群)

  • 1.环境准备:cenOS(linux)系统的电脑,最好使用虚拟机;已安装了git,go等

  • 2.安装etcd :yum install etcd (默认放在/etc目录下)(我的版本是3.1.3,可以使用etcd –version命令查看版本号)

  • 3.启动etcd服务:etcd

  • 4.测试是否安装成功 : 执行 etcdctl set key 6 命令,etcdctl get key 是否得到6.

    以上是单点etcd的搭建,接下来集群搭建


    执行命令 vim /etc/etcd/etcd.conf ,修改etecd.conf

提示: etcd-3.x版本支持yaml和json两种配置文件格式,配置模板见https://github.com/coreos/etcd/blob/master/etcd.conf.yml.sample

#Human-readable name for this member.
name: 'etcd1'    // 建议起名字

# Path to the data directory.
data-dir: "/var/lib/etcd/etcd0.etcd"   //一般是这个,可也以使用默认 "/var/lib/etcd/default.etcd"

# Path to the dedicated wal directory.
wal-dir:

# Number of committed transactions to trigger a snapshot to disk.
snapshot-count: 10000

# Time (in milliseconds) of a heartbeat interval.
heartbeat-interval: 100

# Time (in milliseconds) for an election to timeout.
election-timeout: 1000

# Raise alarms when backend size exceeds the given quota. 0 means use the
# default quota.
quota-backend-bytes: 0

# List of comma separated URLs to listen on for peer traffic.
listen-peer-urls: http://192.168.0.117:2380  //操作电脑ip

# List of comma separated URLs to listen on for client traffic.
listen-client-urls: http://192.168.0.117:2379   //操作电脑ip

# Maximum number of snapshot files to retain (0 is unlimited).
max-snapshots: 5

# Maximum number of wal files to retain (0 is unlimited).
max-wals: 5

# Comma-separated white list of origins for CORS (cross-origin resource sharing).
cors:

# List of this member's peer URLs to advertise to the rest of the cluster.
# The URLs needed to be a comma-separated list.
initial-advertise-peer-urls: http://192.168.0.117:2380

# List of this member's client URLs to advertise to the public.//操作电脑ip
# The URLs needed to be a comma-separated list.
advertise-client-urls: http://192.168.0.117:2379  //操作电脑ip

# Discovery URL used to bootstrap the cluster.
discovery:

# Valid values include 'exit', 'proxy'
discovery-fallback: 'proxy'

# HTTP proxy to use for traffic to discovery service.
discovery-proxy:

# DNS domain used to bootstrap initial cluster.
discovery-srv:

# Initial cluster configuration for bootstrapping.
initial-cluster: "etcd1=http://192.168.0.117:2380,etcd2=http://192.168.0.119:2380,etcd3=http://192.168.0.120:2380"                  //要集群的机子的IP,与前面起的名字一致

# Initial cluster token for the etcd cluster during bootstrap.
initial-cluster-token: 'etcd-cluster'     //集群token ,三台机子一样

# Initial cluster state ('new' or 'existing').
initial-cluster-state: 'new'    //集群状态为  new/existing  第一次new

# Reject reconfiguration requests that would cause quorum loss.
strict-reconfig-check: false

# Accept etcd V2 client requests
enable-v2: true

# Valid values include 'on', 'readonly', 'off'
proxy: 'off'

# Time (in milliseconds) an endpoint will be held in a failed state.
proxy-failure-wait: 5000

# Time (in milliseconds) of the endpoints refresh interval.
proxy-refresh-interval: 30000

# Time (in milliseconds) for a dial to timeout.
proxy-dial-timeout: 1000

# Time (in milliseconds) for a write to timeout.
proxy-write-timeout: 5000

# Time (in milliseconds) for a read to timeout.
proxy-read-timeout: 0

client-transport-security:
  # DEPRECATED: Path to the client server TLS CA file.
  ca-file:

  # Path to the client server TLS cert file.
  cert-file:

  # Path to the client server TLS key file.
  key-file:

  # Enable client cert authentication.
  client-cert-auth: false

  # Path to the client server TLS trusted CA key file.
  trusted-ca-file:

  # Client TLS using generated certificates
  auto-tls: false

peer-transport-security:
  # DEPRECATED: Path to the peer server TLS CA file.
  ca-file:

  # Path to the peer server TLS cert file.
  cert-file:

  # Path to the peer server TLS key file.
  key-file:

  # Enable peer client cert authentication.
  client-cert-auth: false

  # Path to the peer server TLS trusted CA key file.
   trusted-ca-file:

  # Peer TLS using generated certificates.
  auto-tls: false

# Enable debug-level logging for etcd.
debug: false

# Specify a particular log level for each etcd package (eg: 'etcdmain=CRITICAL,etcdserver=DEBUG'.
log-package-levels:

# Force to create a new one member cluster.
force-new-cluster: false

使用修改得配置文件启动服务(根据 etcd –h来查找命令)0etcd - -config-file /etc/etcd/etcd.conf 三台机子一样
查看member list是否集群成功
etcdctl -peers 192.168.0.117:2379 member list 查询机子的ip

etcd集群搭建步骤
表示集群成功,进行数据测试。
在leader机上,设值 ,看follow是否能得到值
leader设值命令 :etcdctl –endpoints http://192.168.0.117:2379 set j 2
follow得值: etcdctl –endpoints http://192.168.0.119:2379 get j


备注:
查看日志journalctl -xe
查看etcd启动的状态 ps -ef|grep etcd
显示隐藏文件ls -la
etcd命令:etcd –help(仔细看)

相关标签: 集群