zoukankan      html  css  js  c++  java
  • etcd 集群搭建

    现有三台机器 CentOS7 

    node1 10.2.0.10

    node2 10.2.0.11

    node3 10.2.0.12

     1 源码解压命令行方式

    node1

    ./etcd --name infra0 --data-dir /home/etcddata --initial-advertise-peer-urls http://10.2.0.10:2380 
    --listen-peer-urls http://10.2.0.10:2380 
    --listen-client-urls http://10.2.0.10:2379,http://127.0.0.1:2379 
    --advertise-client-urls http://10.2.0.10:2379 
    --initial-cluster-token etcd-cluster-1 
    --initial-cluster infra0=http://10.2.0.10:2380,infra1=http://10.2.0.11:2380,infra2=http://10.2.0.12:2380 
    --initial-cluster-state new

    node2 

    ./etcd --name infra1 --data-dir /home/etcddata --initial-advertise-peer-urls http://10.2.0.11:2380 
    --listen-peer-urls http://10.2.0.11:2380 
    --listen-client-urls http://10.2.0.11:2379,http://127.0.0.1:2379 
    --advertise-client-urls http://10.2.0.11:2379 
    --initial-cluster-token etcd-cluster-1 
    --initial-cluster infra0=http://10.2.0.10:2380,infra1=http://10.2.0.11:2380,infra2=http://10.2.0.12:2380 
    --initial-cluster-state new

    node3

    ./etcd --name infra2 --data-dir /home/etcddata --initial-advertise-peer-urls http://10.2.0.12:2380 
    
    --listen-peer-urls http://10.2.0.12:2380 
    --listen-client-urls http://10.2.0.12:2379,http://127.0.0.1:2379 
    --advertise-client-urls http://10.2.0.12:2379 
    --initial-cluster-token etcd-cluster-1 
    --initial-cluster infra0=http://10.2.0.10:2380,infra1=http://10.2.0.11:2380,infra2=http://10.2.0.12:2380 
    --initial-cluster-state new

    变化的部分 --name 、host地址

    2服务器启动方式

    $cat /usr/lib/systemd/system/etcd.service

    # cat /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=/var/lib/etcd/ EnvironmentFile=-/etc/etcd/etcd.conf #环境变量配置文件 User=etcd #用户 # set GOMAXPROCS to number of processors #ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name="${ETCD_NAME}" --data-dir="${ETCD_DATA_DIR}" --listen-client-urls="${ETCD_LISTEN_CLIENT_URLS}"" ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /home/install/etcd/etcd --name="${ETCD_NAME}" --data-dir="${ETCD_DATA_DIR}" --listen-client-urls="${ETCD_LISTEN_CLIENT_URLS}" --initial-advertise-peer-urls="${ETCD_INITIAL_ADVERTISE_PEER_URLS}" --listen-peer-urls="${ETCD_LISTEN_PEER_URLS}" --advertise-client-urls="${ETCD_ADVERTISE_CLIENT_URLS}" --initial-cluster-token="${ETCD_INITIAL_CLUSTER_TOKEN}" --initial-cluster="${ETCD_INITIAL_CLUSTER}" --initial-cluster-state="${ETCD_INITIAL_CLUSTER_STATE}"" #启动脚本 Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target [root@node1 etcddata]#

    $ cat /etc/etcd/etcd.conf

    
    # cat /etc/etcd/etcd.conf
    # [member]
    ETCD_NAME=etcd1
    ETCD_DATA_DIR="/home/etcddata"
    #ETCD_WAL_DIR=""
    #ETCD_SNAPSHOT_COUNT="10000"
    #ETCD_HEARTBEAT_INTERVAL="100"
    #ETCD_ELECTION_TIMEOUT="1000"
    ETCD_LISTEN_PEER_URLS="http://node1:2380"
    ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
    #ETCD_MAX_SNAPSHOTS="5"
    #ETCD_MAX_WALS="5"
    #ETCD_CORS=""
    #
    #[cluster]
    ETCD_INITIAL_ADVERTISE_PEER_URLS="http://node1:2380"
    # if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
    ETCD_INITIAL_CLUSTER="etcd1=http://node1:2380,etcd2=http://node2:2380,etcd3=http://node3:2380"
    ETCD_INITIAL_CLUSTER_STATE="new"
    ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
    ETCD_ADVERTISE_CLIENT_URLS="http://node1:2379"
    #ETCD_DISCOVERY=""
    #ETCD_DISCOVERY_SRV=""
    #ETCD_DISCOVERY_FALLBACK="proxy"
    #ETCD_DISCOVERY_PROXY="

    node2 node3 根据以上相应修改

    备注 log查看 为系统日志 tail -500f /var/log/message

    集群方式启动后不能清除数据文件,数据文件在第一次启动后生成,修改配置文件后重新系统如果不清除数据文件新配置不生效。

    注意:etcd有要求,如果--listen-client-urls被设置了,那么就必须同时设置--advertise-client-urls,所以即使设置和默认相同,也必须显式设置 

    原理说明参考

    http://www.infoq.com/cn/articles/coreos-analyse-etcd/

  • 相关阅读:
    2019.01.06-dtoj-2437: [Noi2011]兔兔与蛋蛋
    2019.01.03-bzoj-1443-[JSOI2009]游戏Game
    2019.01.03-dtoj-4104-yjqaa
    2019.01.03-sg函数模板
    2019.01.02-bzoj-4550: 小奇的博弈
    2019.01.02-dtoj2293-幻想乡开店(shop)
    OCP 071中文考试题库(cuug内部资料)第5题
    OCP 063中文考试题库(cuug内部资料)第4题
    OCP 063中文考试题库(cuug内部资料)第3题
    OCP 062中文考试题库(cuug内部资料)第4题
  • 原文地址:https://www.cnblogs.com/zhangeamon/p/5395187.html
Copyright © 2011-2022 走看看