• Etcd-v3.4.27集群部署


    下载etcd

    1. # wget https://storage.googleapis.com/etcd/v3.4.27/etcd-v3.4.27-linux-amd64.tar.gz
    2. --2024-07-16 09:46:54-- https://storage.googleapis.com/etcd/v3.4.27/etcd-v3.4.27-linux-amd64.tar.gz
    3. Resolving storage.googleapis.com (storage.googleapis.com)... 142.251.43.27, 172.217.163.59, 172.217.160.123, ...
    4. Connecting to storage.googleapis.com (storage.googleapis.com)|142.251.43.27|:443... connected.
    5. HTTP request sent, awaiting response... 200 OK
    6. Length: 16171146 (15M) [application/x-tar]
    7. Saving to: ‘etcd-v3.4.27-linux-amd64.tar.gz’
    8. 100%[===========================================================================================================================>] 16,171,146 8.40MB/s in 1.8s
    9. 2024-07-16 09:46:56 (8.40 MB/s) - ‘etcd-v3.4.27-linux-amd64.tar.gz’ saved [16171146/16171146]

    如果是下载其他版本。则可以用如下脚本,修改版本号

    1. ETCD_VER=v3.4.27
    2. # choose either URL
    3. GOOGLE_URL=https://storage.googleapis.com/etcd
    4. GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
    5. DOWNLOAD_URL=${GOOGLE_URL}
    6. rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
    7. rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test
    8. curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
    9. tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download-test --strip-components=1
    10. rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
    11. /tmp/etcd-download-test/etcd --version
    12. /tmp/etcd-download-test/etcdctl version

    新增配置文件etcd.conf.yml

    1. # cat etcd.conf.yml
    2. # 节点名称,不能重复,需要和initial-cluster配置项中每个服务器ip对应的节点名对齐
    3. name: etcd02
    4. # etcd data和wal存储路径,按实际部署目录修改
    5. data-dir: /data/dataos/modo/etcd-v3.4.27/data
    6. wal-dir: /data/dataos/modo/etcd-v3.4.27/wal
    7. # # 客户端监听端口 IP和占用端口按实际部署情况修改
    8. listen-client-urls: http://10.200.207.2:2379,http://127.0.0.1:2379
    9. advertise-client-urls: http://10.200.207.2:2379,http://127.0.0.1:2379
    10. # etcd集群通信端口配置,IP和占用端口按实际部署情况修改
    11. listen-peer-urls: http://10.200.207.2:2380
    12. initial-advertise-peer-urls: http://10.200.207.2:2380
    13. # 集群配置,三个节点的 节点名=ip:端口 按实际部署情况修改
    14. initial-cluster: etcd01=http://10.200.207.1:2380,etcd02=http://10.200.207.2:2380,etcd03=http://10.200.207.3:2380
    15. initial-cluster-token: etcd-cluster-token
    16. initial-cluster-state: new

    启动etcd

    1. # cat start_etcd.sh
    2. #!/bin/bash
    3. nohup ./etcd --config-file=etcd.conf.yml > ./logs/etcd.log 2>&1 &

    查看etcd

    1. # etcdctl
    2. -bash: etcdctl: command not found

    命令未找到,添加配置

    1. # ll /usr/local/bin/
    2. total 0
    3. # cp /data/dataos/modo/etcd-v3.4.27/etcd /usr/local/bin/
    4. # cp /data/dataos/modo/etcd-v3.4.27/etcdctl /usr/local/bin/
    5. # vi /etc/profile
    6. # source /etc/profile
    7. # etcdctl version
    8. etcdctl version: 3.4.27
    9. API version: 3.4

    /etc/profile文件中新增etcdctl的api版本,默认使用2

    # 在文件最后加入变量,因为etcd默认使用V2版本,我们需要V3版本的API。 export ETCDCTL_API=3

    etcd开机自启动

    1. # vi /etc/systemd/system/etcd.service
    2. # systemctl daemon-reload
    3. # systemctl enable etcd
    4. # systemctl start etcd
    5. # systemctl status etcd
    6. ● etcd.service - Etcd Server
    7. Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: disabled)
    8. Active: active (running) since Tue 2024-07-16 10:28:48 CST; 7s ago
    9. Docs: https://github.com/coreos/etcd
    10. Main PID: 26450 (etcd)
    11. CGroup: /system.slice/etcd.service
    12. └─26450 /usr/local/bin/etcd
    13. Jul 16 10:28:47 10.200.207.2 etcd[26450]: raft2024/07/16 10:28:47 INFO: 8e9e05c52164694d became leader at term 2
    14. Jul 16 10:28:47 10.200.207.2 etcd[26450]: raft2024/07/16 10:28:47 INFO: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 2
    15. Jul 16 10:28:48 10.200.207.2 etcd[26450]: sync duration of 1.384904543s, expected less than 1s
    16. Jul 16 10:28:48 10.200.207.2 etcd[26450]: published {Name:default ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32
    17. Jul 16 10:28:48 10.200.207.2 etcd[26450]: ready to serve client requests
    18. Jul 16 10:28:48 10.200.207.2 etcd[26450]: setting up the initial cluster version to 3.4
    19. Jul 16 10:28:48 10.200.207.2 systemd[1]: Started Etcd Server.
    20. Jul 16 10:28:48 10.200.207.2 etcd[26450]: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!
    21. Jul 16 10:28:48 10.200.207.2 etcd[26450]: set the initial cluster version to 3.4
    22. Jul 16 10:28:48 10.200.207.2 etcd[26450]: enabled capabilities for version 3.4
    23. # netstat -antp | grep 2379
    24. tcp 0 0 127.0.0.1:2379 0.0.0.0:* LISTEN 26450/etcd
    25. tcp 0 0 127.0.0.1:35094 127.0.0.1:2379 ESTABLISHED 26450/etcd
    26. tcp 0 0 127.0.0.1:2379 127.0.0.1:35094 ESTABLISHED 26450/etcd
    1. # 创建用户,设置密码
    2. etcdctl --endpoints http://10.1.27.23:2379,http://10.1.27.24:2379,http://10.1.27.25:2379 --new-user-password=auyd871477sha user add root
    3. # 添加角色
    4. etcdctl --endpoints http://10.1.27.23:2379,http://10.1.27.24:2379,http://10.1.27.25:2379 --user=root:auyd871477sha role add root
    5. # 授权角色
    6. etcdctl --endpoints http://10.1.27.23:2379,http://10.1.27.24:2379,http://10.1.27.25:2379 --user=root:auyd871477sha user grant-role root root
    7. # 配置允许登录
    8. etcdctl --endpoints http://10.1.27.23:2379,http://10.1.27.24:2379,http://10.1.27.25:2379 --user=root:auyd871477sha auth enable
    9. # 查询账号列表,验证root账号是否创建成功
    10. etcdctl --endpoints http://10.1.27.23:2379,http://10.1.27.24:2379,http://10.1.27.25:2379 --user='root' --password='auyd871477sha' user list
    11. # 说明
    12. # http://10.1.27.23:2379,http://10.1.27.24:2379,http://10.1.27.25:2379 为3个节点的连接信息,具体可以看每个节点的配置
    13. # auyd871477sha root的密码
    14. # 其余命令按照样例执行

    etcd新增用户

    前提是,主机上防火墙,iptabls关闭,要么就设置端口可以访问。

    1. 创建用户,设置密码
    2. # etcdctl --endpoints http://10.200.207.1:2379,http://10.200.207.2:2379,http://10.200.207.3:2379 --new-user-password=auyd871477sha user add root
    3. User root created
    4. 添加角色
    5. # etcdctl --endpoints http://10.200.207.1:2379,http://10.200.207.2:2379,http://10.200.207.3:2379 --user=root:auyd871477sha role add root
    6. {"level":"warn","ts":"2024-07-16T10:43:55.774319+0800","caller":"clientv3/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"endpoint://client-b99c1334-e97a-4db8-a518-7daa4232f486/10.200.207.1:2379","attempt":0,"error":"rpc error: code = FailedPrecondition desc = etcdserver: authentication is not enabled"}
    7. Role root created
    8. 授权角色
    9. # etcdctl --endpoints http://10.200.207.1:2379,http://10.200.207.2:2379,http://10.200.207.3:2379 --user=root:auyd871477sha user grant-role root root
    10. {"level":"warn","ts":"2024-07-16T10:45:01.539572+0800","caller":"clientv3/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"endpoint://client-96b7c611-46c1-4744-a997-f6c0f55dee0c/10.200.207.1:2379","attempt":0,"error":"rpc error: code = FailedPrecondition desc = etcdserver: authentication is not enabled"}
    11. Role root is granted to user root
    12. 设置允许登陆
    13. # etcdctl --endpoints http://10.200.207.1:2379,http://10.200.207.2:2379,http://10.200.207.3:2379 --user=root:auyd871477sha auth enable
    14. {"level":"warn","ts":"2024-07-16T10:45:24.638387+0800","caller":"clientv3/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"endpoint://client-7f3bb6ef-11f0-44f1-875f-e17108e25fc8/10.200.207.1:2379","attempt":0,"error":"rpc error: code = FailedPrecondition desc = etcdserver: authentication is not enabled"}
    15. Authentication Enabled
    16. 查询账号列表,验证root账号是否创建成功
    17. # etcdctl --endpoints http://10.200.207.1:2379,http://10.200.207.2:2379,http://10.200.207.3:2379 --user='root' --password='auyd871477sha' user list
    18. root

  • 相关阅读:
    主流MQ对比和选型
    在线协作工具都有哪些?推荐这10款
    一文学会鉴别“套壳”ChatGPT模型
    第二期书生浦语大模型训练营第四次笔记
    1.8 打好shell基础
    Zabbix技术分享——如何配置SNMPTrap监控
    WebSocket 心跳机制如何实现
    【问题总结】为什么路由器可以互联下三层不同的协议?【从隔离冲突域和广播域的角度分析】【数据传输过程】
    Datawhale团队第八期录取名单!
    详解欧拉计划第622题:完美洗牌
  • 原文地址:https://blog.csdn.net/red_sky_blue/article/details/140457478