• etcd 裸机部署【简单易懂】


    一、下载安装包

    1. ETCD_VER=v3.4.16 GOOGLE_URL=https://storage.googleapis.com/etcd
    2. GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
    3. DOWNLOAD_URL=${GOOGLE_URL}
    4. curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /opt/etcd-${ETCD_VER}-linux-amd64.tar.gz

    二、创建安装目录及数据目录

    1. mkdir -p /opt/etcd/conf/ /etcd-data/logs/
    2. tar xf /opt/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /opt/etcd/
    3. cp /opt/etcd/etcd-v3.4.16-linux-amd64/etcd /usr/bin/. && cp /opt/etcd/etcd-v3.4.16-linux-amd64/etcdctl /usr/bin/.

    三、创建启动脚本及配置文件

    etcd配置文件

    1. vim /opt/etcd/conf/etcd.yml
    2. #写入如下内容
    3. name: etcd-0 #一般etcd集群为三个节点,修改后面的序号即可
    4. # 数 据 存 储 目 录
    5. data-dir: /etcd-data
    6. # 日 志 文 件 配 置
    7. # logger: zap
    8. --log-outputs: stderr
    9. # log-level: info
    10. #开 启 grpc gateway
    11. enable-grpc-gateway: true
    12. # 客 户 端 连 接 相 关 配 置
    13. # 服 务 监 听 端 点
    14. listen-client-urls: http://0.0.0.0:2379
    15. # 向 客 户 端 发 布 的 服 务 端 点
    16. advertise-client-urls: http://10.183.90.10:2379 #修改为本机的ip
    17. # 集 群 相 关 配 置
    18. # 监 听 集 群 其 他 节 点 连 接 的 端 点
    19. listen-peer-urls: http://0.0.0.0:2380
    20. # 向 集 群 其 他 节 点 发 布 的 服 务 端 点
    21. initial-advertise-peer-urls: http://10.183.90.10:2380 #修改为本机的ip
    22. # 集 群 成 员 的 名 字 以 及 服 务 端 点 列 表 , 名 字 与 每 个 节 点 配 置 的 name字 段 值 对 应
    23. initial-cluster: etcd-0=http://10.183.90.10:2380,etcd-1=http://10.183.88.52:2380,etcd-2=http://10.183.89.143:2380
    24. # 集 群 标 识 token, 可 以 认 为 是 集 群 名 字
    25. initial-cluster-token: etcd-devops-prod #集群名称
    26. # 创 建 一 个 新 的 集 群 。 如 果 data-dir目 录 下 的 数 据 属 于 另 外 一 个 集 群 , 则 无 法 启 动
    27. inital-cluster-state: new
    28. # etcd使用内存limit 如果机器为8G,就填6G
    29. quota-backend-bytes: 6442450944
    30. # 最大快照数量
    31. max-snapshots: 5
    32. # 保留的wal文件的最大数量
    33. max-wals: 5
    34. # 触发磁盘快照的已提交事务数。
    35. snapshot-count: 5000
    36. # 服务器将接受的最大客户端请求大小(以字节为单位)。
    37. max-request-bytes: 10485760
    38. # 开启自动压缩。0表示禁用自动压缩。
    39. auto-compaction-retention: "1"

    启动脚本

    1. vim etcd0_start.sh #依次类推,例如etcd第二个节点etcd1_start.sh,第三个节点etcd2_start.sh
    2. nohup /usr/bin/etcd --config-file=/opt/etcd/conf/etcd.yml > /etcd-data/logs/etcd.log 2>&1 &
    3. chmod +x etcd0_start.sh

    四、启动etcd服务

    1. etcd0
    2. bash etcd0_start.sh
    3. etcd1
    4. bash etcd1_start.sh
    5. etcd2
    6. bash etcd2_start.sh

    五、验证服务

    命令行验证

    1. [root@ip-10-152-0-37 etcd]# etcdctl endpoint status --cluster -w table
    2. +---------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
    3. | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
    4. +---------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
    5. | http://10.152.0.37:2379 | 4139c8599b429a90 | 3.4.16 | 20 kB | true | false | 21 | 13 | 13 | |
    6. | http://10.152.18.84:2379 | f1114884241bd302 | 3.4.16 | 16 kB | false | false | 21 | 13 | 13 | |
    7. | http://10.152.15.161:2379 | f65346c2ae141289 | 3.4.16 | 20 kB | false | false | 21 | 13 | 13 | |
    8. +---------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
    9. [root@ip-10-152-0-37 etcd]# etcdctl endpoint health --cluster -w table
    10. +---------------------------+--------+------------+-------+
    11. | ENDPOINT | HEALTH | TOOK | ERROR |
    12. +---------------------------+--------+------------+-------+
    13. | http://10.152.0.37:2379 | true | 1.032243ms | |
    14. | http://10.152.18.84:2379 | true | 2.094489ms | |
    15. | http://10.152.15.161:2379 | true | 3.483197ms | |
    16. +---------------------------+--------+------------+-------+
    17. [root@ip-10-152-0-37 etcd]# etcdctl member list -w table
    18. +------------------+---------+--------+---------------------------+---------------------------+------------+
    19. | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER |
    20. +------------------+---------+--------+---------------------------+---------------------------+------------+
    21. | 4139c8599b429a90 | started | etcd-0 | http://10.152.0.37:2380 | http://10.152.0.37:2379 | false |
    22. | f1114884241bd302 | started | etcd-2 | http://10.152.18.84:2380 | http://10.152.18.84:2379 | false |
    23. | f65346c2ae141289 | started | etcd-1 | http://10.152.15.161:2380 | http://10.152.15.161:2379 | false |
    24. +------------------+---------+--------+---------------------------+---------------------------+------------+
    25. #写入key进行测试
    26. [root@ip-10-152-0-37 etcd]# etcdctl put "sunwenbo is good man" yes
    27. OK
    28. [root@ip-10-152-0-37 etcd]# etcdctl get "sunwenbo is good man"
    29. sunwenbo is good man
    30. yes
    31. [root@ip-10-152-0-37 etcd]#

    python代码进行简单的测试

    1. import etcd3
    2. client = etcd3.client(host='10.152.0.37',port=2379) #连接etcd
    3. r = client.put('test', 'sunwenbo') #往etcd中存键值
    4. b = client.get('test') #获取etcd中的键值
    5. print(b)

  • 相关阅读:
    科技云报道:推进工业新质生产力机器人有望成为AI下一个新引擎?
    百数助力山西读印:印章定制行业的信息化转型深度解析
    微信小程序之生成二维码
    (附源码)node.js物资管理系统 毕业设计 071130
    PCL1.12.1 with QT6.3.2 编译部署
    C# LINQ常用操作方法——提升你的编程效率
    智安网络|面临日益增长的安全威胁:云安全和零信任架构的重要性
    OpenHarmony专用术语了解学习
    CentOS 7中安装ZooKeeper
    问题求解:总计600人,每次刀一个奇数位的人,最后剩下谁的概率最高 暴力求解法
  • 原文地址:https://blog.csdn.net/weixin_43798031/article/details/127104801