安装 Etcd

说明

Zebra 使用 Etcd 作为注册中心,版本为 3.1.7。

本指导只提供安装单机版的 Etcd 的相关指导,实际生产环境需使用Etcd Cluster 模式,具体安装步骤请参考 Etcd 官方网站。

下载

点击 https://github.com/etcd-io/etcd/releases/download/v3.1.7/etcd-v3.1.7-linux-amd64.tar.gz 下载 Etcd。

上传

上传下载的 Etcd 到 /tmp 目录,然后执行如下命令。

  1. mkdir -p /opt/zebra/etcd
  2. tar xzvf /tmp/etcd-v3.1.7-linux-amd64.tar.gz -C /opt/zebra/etcd --strip-components=1
  3. rm -rf /tmp/etcd-v3.1.7-linux-amd64.tar.gz

添加配置

执行如下命令

  1. mkdir -p /opt/zebra/etcd/conf
  2. touch /opt/zebra/etcd/conf/etcd.conf.yml

把下面配置添加到 etcd.conf.yml 里面。 // TODO 要替换为github的链接,不直接贴配置。

  1. # This is the configuration file for the etcd server.
  2. # Human-readable name for this member.
  3. name: 'default'
  4. # Path to the data directory.
  5. data-dir:
  6. # Path to the dedicated wal directory.
  7. wal-dir:
  8. # Number of committed transactions to trigger a snapshot to disk.
  9. snapshot-count: 10000
  10. # Time (in milliseconds) of a heartbeat interval.
  11. heartbeat-interval: 100
  12. # Time (in milliseconds) for an election to timeout.
  13. election-timeout: 1000
  14. # Raise alarms when backend size exceeds the given quota. 0 means use the
  15. # default quota.
  16. quota-backend-bytes: 0
  17. # List of comma separated URLs to listen on for peer traffic.
  18. listen-peer-urls: http://0.0.0.0:2380
  19. # List of comma separated URLs to listen on for client traffic.
  20. listen-client-urls: http://0.0.0.0:2379
  21. # Maximum number of snapshot files to retain (0 is unlimited).
  22. max-snapshots: 5
  23. # Maximum number of wal files to retain (0 is unlimited).
  24. max-wals: 5
  25. # Comma-separated white list of origins for CORS (cross-origin resource sharing).
  26. cors:
  27. # List of this member's peer URLs to advertise to the rest of the cluster.
  28. # The URLs needed to be a comma-separated list.
  29. initial-advertise-peer-urls: http://0.0.0.0:2380
  30. # List of this member's client URLs to advertise to the public.
  31. # The URLs needed to be a comma-separated list.
  32. advertise-client-urls: http://0.0.0.0:2379
  33. # Discovery URL used to bootstrap the cluster.
  34. discovery:
  35. # Valid values include 'exit', 'proxy'
  36. discovery-fallback: 'proxy'
  37. # HTTP proxy to use for traffic to discovery service.
  38. discovery-proxy:
  39. # DNS domain used to bootstrap initial cluster.
  40. discovery-srv:
  41. # Initial cluster configuration for bootstrapping.
  42. initial-cluster:
  43. # Initial cluster token for the etcd cluster during bootstrap.
  44. initial-cluster-token: 'etcd-cluster'
  45. # Initial cluster state ('new' or 'existing').
  46. initial-cluster-state: 'new'
  47. # Reject reconfiguration requests that would cause quorum loss.
  48. strict-reconfig-check: false
  49. # Accept etcd V2 client requests
  50. enable-v2: true
  51. # Enable runtime profiling data via HTTP server
  52. enable-pprof: true
  53. # Valid values include 'on', 'readonly', 'off'
  54. proxy: 'off'
  55. # Time (in milliseconds) an endpoint will be held in a failed state.
  56. proxy-failure-wait: 5000
  57. # Time (in milliseconds) of the endpoints refresh interval.
  58. proxy-refresh-interval: 30000
  59. # Time (in milliseconds) for a dial to timeout.
  60. proxy-dial-timeout: 1000
  61. # Time (in milliseconds) for a write to timeout.
  62. proxy-write-timeout: 5000
  63. # Time (in milliseconds) for a read to timeout.
  64. proxy-read-timeout: 0
  65. client-transport-security:
  66. # Path to the client server TLS cert file.
  67. cert-file:
  68. # Path to the client server TLS key file.
  69. key-file:
  70. # Enable client cert authentication.
  71. client-cert-auth: false
  72. # Path to the client server TLS trusted CA cert file.
  73. trusted-ca-file:
  74. # Client TLS using generated certificates
  75. auto-tls: false
  76. peer-transport-security:
  77. # Path to the peer server TLS cert file.
  78. cert-file:
  79. # Path to the peer server TLS key file.
  80. key-file:
  81. # Enable peer client cert authentication.
  82. client-cert-auth: false
  83. # Path to the peer server TLS trusted CA cert file.
  84. trusted-ca-file:
  85. # Peer TLS using generated certificates.
  86. auto-tls: false
  87. # Enable debug-level logging for etcd.
  88. debug: false
  89. logger: zap
  90. # Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
  91. log-outputs: [stderr]
  92. # Force to create a new one member cluster.
  93. force-new-cluster: false
  94. auto-compaction-mode: periodic
  95. auto-compaction-retention: 1

启动

  1. cd /opt/zebra/etcd
  2. nohup ./etcd --config-file ./conf/etcd.conf.yml &