etcd

2021/03/20

etcd

参考资料

介绍

etcd是一款高性能的开源的分布式key-value分布式存储系统,可以用于配置共享和服务的注册与发现等功能。类似于zookeeper和consul。

etcd应用场景:

  • 1.服务发现(Service Discovery)
  • 2.配置中心
  • 3.消息发布与订阅
  • 4.负载均衡
  • 5.分布式通知与协调
  • 6.分布式锁、分布式队列
  • 7.集群监控与Leader竞选

使用etcd的项目

  • 1.CoreOS
  • 2.Kubernetes
  • 3.CloudFoundry
  • 4.docker swarm kit

一、单机部署

# 1.下载etcd二进制文件
wget https://github.com/etcd-io/etcd/releases/download/v3.5.5/etcd-v3.5.5-linux-amd64.tar.gz
 
# 2.解压
tar -xzvf etcd-v3.5.5-linux-amd64.tar.gz
cd etcd-v3.5.5-linux-amd64.tar
mv etcd etcdctl /usr/local/bin
 
# 3。创建目录
mkdir -p /data/etcd/2379/
cd /data/etcd/2379
mkdir conf wal data
 
# 4.创建配置文件(修改ip为实际ip)
vi /data/etcd/2379/conf/etcd.conf
name: 'etcd0'
data-dir: /data/etcd/2379/data
wal-dir: /data/etcd/2379/wal
snapshot-count: 10000
heartbeat-interval: 1000
election-timeout: 5000
quota-backend-bytes: 0
listen-peer-urls: http://1.1.1.1:2380
# 对外提供服务的地址,客户端会连接到这里和 etcd 交互
listen-client-urls: 'http://1.1.1.1:2379,http://127.0.0.1:2379'
max-snapshots: 5
max-wals: 5
cors:
initial-advertise-peer-urls: http://1.1.1.1:2380
advertise-client-urls: http://1.1.1.1:2379
initial-cluster: etcd0=http://1.1.1.1:2380
initial-cluster-token: 'etcd_cluster_0'
initial-cluster-state: 'new' 
strict-reconfig-check: false
enable-v2: true
client-transport-security:            
peer-transport-security:            
debug: False
log-package-levels:
force-new-cluster: False

# 5.创建systemd文件
vi /usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
 
[Service]
Type=notify
WorkingDirectory=/data/etcd/2379/data
User=root
TimeoutStartSec=10
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=2 /usr/local/bin/etcd --config-file=\"/data/etcd/2379/conf/etcd.conf\""
Restart=on-failure
RestartSec=10s
LimitNOFILE=65536
 
[Install]
WantedBy=multi-user.target
 
# 6.重载配置文件
systemctl daemon-reload
 
# 7.启动服务(3个节点同时执行)
systemctl start etcd

二、集群部署

注意修改ip、节点name

# 1.下载etcd二进制文件
wget https://github.com/etcd-io/etcd/releases/download/v3.5.5/etcd-v3.5.5-linux-amd64.tar.gz
 
# 2.解压
tar -xzvf etcd-v3.5.5-linux-amd64.tar.gz
cd etcd-v3.5.5-linux-amd64.tar
mv etcd etcdctl /usr/local/bin
 
# 3.创建目录
mkdir -p /data/etcd/2379/
cd /data/etcd/2379
mkdir conf wal data
 
# 4.创建配置文件(修改ip为实际ip)
vi /data/etcd/2379/conf/etcd.conf
name: 'etcd24'
# Path to the data directory.
data-dir: /data/etcd/2379/data
# Path to the dedicated wal directory.
wal-dir: /data/etcd/2379/wal
snapshot-count: 10000
heartbeat-interval: 100
election-timeout: 1000
quota-backend-bytes: 0
listen-peer-urls: http://1.1.1.1:2380
listen-client-urls: http://0.0.0.0:2379
max-snapshots: 5
max-wals: 5
cors:
initial-advertise-peer-urls: http://1.1.1.1:2380
advertise-client-urls: http://1.1.1.1:2379
initial-cluster: etcd24=http://1.1.1.1:2380,etcd25=http://1.1.1.2:2380,etcd26=http://1.1.1.3:2380
initial-cluster-token: 'etcd_cluster_1'
initial-cluster-state: 'new'
strict-reconfig-check: false
enable-v2: true
client-transport-security:            
peer-transport-security:            
debug: False
log-package-levels:
force-new-cluster: False
 
# 5.创建systemd文件
vi /usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
 
[Service]
Type=notify
WorkingDirectory=/data/etcd/2379/data
User=root
TimeoutStartSec=10
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=2 /usr/local/bin/etcd --config-file=\"/data/etcd/2379/conf/etcd.conf\""
Restart=on-failure
RestartSec=10s
LimitNOFILE=65536
 
[Install]
WantedBy=multi-user.target
 
# 6.重载配置文件
systemctl daemon-reload
 
# 7.启动服务(3个节点同时执行)
systemctl start etcd

问题记录

Post Directory

扫码关注公众号:暂无公众号
发送 290992
即可立即永久解锁本站全部文章