ETCD集群部署,启用SSL模式,自建证书

ETCD是基于Raft算法实现的强一致性分布式键值存储系统

启动命令

docker启动注意限制日志大小,时间同步,数据挂载。内存大小和自动压缩建议设置合适的范围并且开启否则可能会宕机第一次创建集群时,cluste-state=new,其他时间加入的节点均为existing设置好初始化集群注册信息(name、urls)等,可以依次启动。

/usr/local/bin/etcd
# 节点名称
--name 
# 数据存放地址
--data-dir=/etcd-data
# 心跳间隔
--heartbeat-interval
# 选举超时时间
--election-timeout
# 存储空间配额(内存),官方建议不超过8G,到达阈值会拒绝写
--quota-backend-bytes
# 自动压缩模式 revision 基于版本号压缩|periodic 基于时间周期压缩
--auto-compaction-mode
# 压缩间隔 (保留近N个版本 / 保留近N小时数据)
--auto-compaction-retention
# 向集群广播的该节点接收客户端监听url,支持多协议多端口:http://ip:port,https://ip:port
--advertiese-client-urls
# 该节点监听请求地址:http://0.0.0.0:port,https://0.0.0.0:port
--listen-client-urls
# 单个事务允许最大操作条数
--max-txn-ops
# 默认false,是否开启peer对等连接请求ssl认证
--peer-client-cert-auth=true
# peer-ca证书地址
--peer-trusted-ca-file=cafilepath
# peer认证证书
--peer-cert-file=filepath
# peer证书私钥
--peer-key-file=filepath
# 节点间监听peer对等连接,可以不设置证书使用http协议:https://ip:port
--listen-peer-urls
# 通知到集群上的该节点peer监听地址,和listen一样就好:https://ip:port
--initial-advertise-peer-urls
# 加入集群时初始化的节点node-name=peerurl信息:ename1=url1,ename2=url2,ename3=url3
--initial-cluster
# 当前节点加入时集群状态:existing|new
--initial-cluster-state
# 初始化该节点的token,各个节点相同即可
--initial-cluster-token

证书准备

cfssl安装&授权

curl -s -L -o ~/bin/cfssljson https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64curl -s -L -o ~/bin/cfssl https://pkg.cfssl.org/R1.2/cfssl_linux-amd64chmod +x ~/bin/{cfssl,cfssljson}

证书生成

客户端证书流程一样(hosts=[]),这里只保证节点间安全验证,只举例server端证书。

CA

cfssl gencert -initca ca-csr.json | cfssljson -bare ca -生成:ca.pem \ ca-key.pem这些文件注意保存,当拓展节点时有可能需要

ca-csr.json

{
  "CN": "Etcd",
  "key":{
    "algo":"rsa",
    "size":4096
  },
  "names":[
    {
      "C":"CN",
      "L":"Beijing",
      "O":"ETCD",
      "OU":"Base",
      "ST":"Beijing"
    }
  ]
}

Peer证书

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=peer peer-csr.json | cfssljson -bare peer生成文件:peer.pem \ peer-key.pem

ca-config.json

{
  "signing":{
    "default":{
      "expiry":"100000h"
    },
    "profiles":{
      "peer":{
        "usages":["signing", "key encipherment", "server auth", "client auth"],
        "expiry": "100000h"
      },
      "client":{
        "usages":["signing", "key encipherment", "server auth", "client auth"],
        "expiry": "100000h"
      }
    }
  }
}

peer-csr.json

{
  "CN":"etcd-peer",
  "hosts":[
    "ip1","ip2","ip3"
  ],
  "key":{
    "algo":"rsa",
    "size":4096
  },
  "names":[
    {
      "C":"CN",
      "L":"Beijing",
      "O":"ETCD",
      "OU":"Base",
      "ST":"Beijing"
    }
  ]
}

Doker启动Demo

version: '3'
services:
	etcd-1:
  	container_name: "etcd-1"
  	image: "quay.io/coreos/etcd:v3.4.18"
  	restart: always
  	ulimits:
    	nofile:
      	soft: "65535"
      	hard: "65535"
    network_mode: "host"
    volumes:
    - /etc/localtime:/etc/localtime:ro
    - ./data/etcd-1:/data
    - ./pki:/etc/cert
    logging:
      driver:"json-file"
      options:
        max-size:"5g"
    command: >
              /usr/local/bin/etcd
              --name="etcd-1"
              --logger=zap
              --data-dir=/data
              --election-timeout=3000
              --quota-backend-bytes=2g
              --auto-compation-mode=revision
              --auto-compation-retention=50
              --peer-cert-file=/etc/cert/peer.pem
              --peer-key-file=/etc/cert/peer-key.pem
              --peer-trusted-ca-file=/etc/cert/ca.pem
              --peer-client-cert-auth=true
              --advertise-client-urls=http://ip:2379
              --listen-client-urls=http://0.0.0.0:2379
              --listen-peer-urls=https://0.0.0.0:2380
              --initial-advertise-peer-urls=https://ip:2380
              --initial-cluster etcd1=peerurl1,etcd2=peerurl2,etcd3=peerurl3
              --initial-cluster-token=自定义
              --initial-cluster-state=new|existing
              --max-txn-ops=4096
              

全部评论

相关推荐

头像
10-22 20:13
中南大学 Java
序言大家好呀。我是希晨er,一个初入职场的程序猿小登最近上班摸鱼刷到了一篇文章:10年深漂,放弃高薪,回长沙一年有感,还有聊聊30岁大龄程序员过往的心路历程,突然就有点感慨。我如今也做出了和大明哥一样的抉择,只是更早。此外我22年的人生,好像从来没好好记录过。正好现在工作不太忙,就想把这些经历写下来,也希望能得到社区里各位前辈的指点个人背景我是03年出生的西安娃,父母都是普通打工人。刚从中南大学软件工程专业毕业半年,现在在老家的央企过着躺平摆烂的日子成长轨迹从农村到城市的童年我家并不是西安的,只是爸妈在西安上班,从小学之后就把我接到了西安。后来老家房子拆了,爷爷奶奶也搬了过来。农村的生活,我觉...
Yki_:看哭了,恋爱那一段你女朋友说你不够关心她,可你毕竟也愿意遇到矛盾写几千字来和她慢慢分析;说不愿意给她花钱,我感觉可能只是消费观不一样;如果她想留在长沙,也应该提前跟你说开。不过她也许会心疼你放弃大厂offer转向数字马力?我也因为同样的原因有过一段幸福而充满遗憾的感情,不过跟爱情相比确实前途更重要一点。至于offer的选择,换我我也会这么选。把这些旧事记录下来以后,接下来就好好向前看吧,加油兄弟
🍊晨光随笔
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务