zoukankan      html  css  js  c++  java
  • etcd3.0集群安装

    etcd 是一个分布式一致性键值存储,用于共享配置和服务发现,Go编写,并使用 Raft 一致性算法来管理高可用复制日志。

    特性

    简单:支持curl方式的用户API(http+json)
    安全:可选ssl客户端证书认证
    快速:单实例可达1000/s写操作
    可靠:使用Raft实现分布式

    etcd有三种集群化启动方案:
    静态配置
    自身服务发现
    通过DNS进行服务发现

    主机环境
    192.168.1.3   node1
    192.168.1.4   node2
    192.168.1.5   node3

    OS: CentOS7.0
    etcd: etcd-v3.0.0-linux-amd64.tar.gz

    1、解压etcd(三个节点都需操作)
    tar xf etcd-v3.0.0-linux-amd64.tar.gz -C /usr/local/
    mv /usr/local/etcd-v3.0.0-linux-amd64 /usr/local/etcd
    export ETCDCTL_API=3  ##如果不设置,api还是版本2
    2、启动(这里是以静态方式启动)
    node1
    =========
    nohup ./etcd --name e1 --initial-advertise-peer-urls http://192.168.1.3:2380 --listen-peer-urls http://192.168.1.3:2380 --initial-cluster-token etcd-cluster-1 --data-dir /data/etcd/data --wal-dir /data/etcd/wal --listen-client-urls http://192.168.1.3:2379,http://127.0.0.1:2379,http://127.0.0.1:22379,http://127.0.0.1:32379 --advertise-client-urls http://192.168.1.3:2379 --initial-cluster e1=http://192.168.1.3:2380,e2=http://192.168.1.4:2380,e3=http://192.168.1.5:2380 --initial-cluster-state new >> etcd.log 2>&1 &

    node2
    ======
    nohup ./etcd --name e2 --initial-advertise-peer-urls http://192.168.1.4:2380  --listen-peer-urls http://192.168.1.4:2380 --initial-cluster-token etcd-cluster-1 --data-dir /data/etcd/data --wal-dir /data/etcd/wal --listen-client-urls http://192.168.1.4:2379,http://127.0.0.1:2379,http://127.0.0.1:22379,http://127.0.0.1:32379 --advertise-client-urls http://192.168.1.4:2379 --initial-cluster e1=http://192.168.1.3:2380,e2=http://192.168.1.4:2380,e3=http://192.168.1.5:2380 --initial-cluster-state new >> etcd.log 2>&1 &

    node3
    =======
    nohup ./etcd --name e3 --initial-advertise-peer-urls http://192.168.1.5:2380 --listen-peer-urls http://192.168.1.5:2380 --initial-cluster-token etcd-cluster-1 --data-dir /data/etcd/data --wal-dir /data/etcd/wal --listen-client-urls http://192.168.1.5:2379,http://127.0.0.1:2379,http://127.0.0.1:22379,http://127.0.0.1:32379 --advertise-client-urls http://192.168.1.5:2379 --initial-cluster e1=http://192.168.1.3:2380,e2=http://192.168.1.4:2380,e3=http://192.168.1.5:2380 --initial-cluster-state new >> etcd.log 2>&1 &



    ###参数详解
    –data-dir      #指定节点的数据存储目录,包括节点ID 集群ID 集群初始化配置 Snapshot文件 若未指定—wal-dir 还会存储WAL文件;
    –wal-dir       #指定节点的was文件的存储目录 若指定了该参数 wal文件会和其他数据文件分开存储;
    –name          #节点名称
    –initial-advertise-peer-urls    #参数表示节点监听其他节点同步信号的地址
    –listen-peer-urls               #监听URL 用于与其他节点通讯
    –advertise-client-urls          #告知客户端url 也就是服务的url
    –initial-cluster                #集群中所有节点new or existing
    –initial-cluster-token          #集群的ID 如果所在的网络环境配置了多个etcd集群 为了避免意外发生 最好使用–initial-cluster-token参数为每个集群单独配置一个token认证,这样就可以确保每个集群和集群的成员都拥有独特的ID.
    --force-new-cluster             #加备份的数据重新启动节点
    peer-urls                       #通常监听的端口为2380(老版本的端口为7001)包括所有已经在集群中正常工作的所有节点的地址。
    client-urls                     #通常监听的端口为2379(老版本的端口为4001)为适应复杂的网络环境,新版etcd监听客户端请求的url从原来的1个变为现在可配置的多个 这样etcd可以配合多块网卡同时监听不同网络下的请求。
    --initial-cluster-state new     #用于指示本次是否为新建集群。有两个取值new和existing。如果填为existing,则该member启动时会尝试与其他member交互。
    集群初次建立时,要填为new,经尝试最后一个节点填existing也正常,其他节点不能填为existing。
    集群运行过程中,一个member故障后恢复时填为existing,经尝试填为new也正常。

    3. 查看成员信息
    root@node1:/usr/local/etcd# ./etcdctl member list
    aa8379415edde74c, started, e3, http://192.168.1.3:2380, http://192.168.1.3:2379
    da3cf4bd9e4c6189, started, e2, http://192.168.1.4:2380, http://192.168.1.4:2379
    e6c603bf0f013bfc, started, e1, http://192.168.1.5:2380, http://192.168.1.5:2379

    root@node1:/usr/local/etcd#  curl  http://127.0.0.1:2379/v2/members

    4. 集群健康状态检查
    etcdctl cluster-health

    5. 查看成员角色
    curl http://127.0.0.1:2379/v2/stats/leader

    6. etcd 修改通过Ip访问方式
    ./etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380
    7. 删除一个成员
    curl http://192.168.1.131:2379/v2/members/42c5aa0fece37ff6 -XDELETE

    8. 增加一个成员
    1. curl http://127.0.0.1:2379/v2/members -XPOST -H "Content-Type: application/json" -d '{"peerURLs": ["http://192.168.1.193:2380"]}'

    2. etcdctl member add node3 http://192.168.1.193:2380
    在新节点,启动etcd服务



    测试读写速度
    boom -m PUT -d value="hello world!" -n 1000000 -c 10 -H "Content-Type: application/x-www-form-urlencoded" http://127.0.0.1/v2/keys/foo/car


    ###集群备份
    #!/bin/bash
    date_time=`date +%Y%m%d`
    etcdctl backup --data-dir /data/etcd/ --backup-dir /data/etcd_backup/${date_time}
    find /data/etcd_backup/ -ctime +7 -exec rm -r {} ;

  • 相关阅读:
    PHP之十六个魔术方法详解
    PHP之十六个魔术方法详解
    让Docker容器使用静态独立的外部IP(便于集群组建)
    桥接和nat模式区别
    使用 GitHub / GitLab 的 Webhooks 进行网站自动化部署
    docker gitlab
    docker gitlab安装
    docker ui管理工具
    docker 批量删除容器
    Scrapy设置代理
  • 原文地址:https://www.cnblogs.com/Z-style/p/6873400.html
Copyright © 2011-2022 走看看