• ETCD实战


    一、建立集群

    1、在每台机器上建立环境变量

    TOKEN=token-01
    CLUSTER_STATE=new
    NAME_1=machine-1
    NAME_2=machine-2
    NAME_3=machine-3
    HOST_1=10.240.0.17
    HOST_2=10.240.0.18
    HOST_3=10.240.0.19
    CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

    2、在每台机器上运行如下命令
    # For machine 1
    THIS_NAME=${NAME_1}
    THIS_IP=${HOST_1}
    etcd --data-dir=data.etcd --name ${THIS_NAME} 
    	--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 
    	--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 
    	--initial-cluster ${CLUSTER} 
    	--initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}

    # For machine 2
    THIS_NAME=${NAME_2}
    THIS_IP=${HOST_2}
    etcd --data-dir=data.etcd --name ${THIS_NAME} 
    	--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 
    	--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 
    	--initial-cluster ${CLUSTER} 
    	--initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}

    # For machine 3
    THIS_NAME=${NAME_3}
    THIS_IP=${HOST_3}
    etcd --data-dir=data.etcd --name ${THIS_NAME} 
    	--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 
    	--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 
    	--initial-cluster ${CLUSTER} 
    	--initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}

    3、连接测试
    export ETCDCTL_API=3
    HOST_1=10.240.0.17
    HOST_2=10.240.0.18
    HOST_3=10.240.0.19
    ENDPOINTS=$HOST_1:2379,$HOST_2:2379,$HOST_3:2379
    
    etcdctl --endpoints=$ENDPOINTS member list
    etcdctl --endpoints=$ENDPOINTS put foo "Hello World!"
    etcdctl --endpoints=$ENDPOINTS get foo
    etcdctl --endpoints=$ENDPOINTS --write-out="json" get foo


    ===选举
    etcdctl --endpoints=$ENDPOINTS elect one p1
    
    # another client with the same name blocks
    etcdctl --endpoints=$ENDPOINTS elect one p2


    ==分布式锁
    etcdctl --endpoints=$ENDPOINTS lock mutex1
    
    # another client with the same name blocks
    etcdctl --endpoints=$ENDPOINTS lock mutex1


    ==查看集群状态

    etcdctl --write-out=table --endpoints=$ENDPOINTS endpoint status

    etcdctl --endpoints=$ENDPOINTS endpoint health
    ==快照
    ENDPOINTS=$HOST_1:2379
    etcdctl --endpoints=$ENDPOINTS snapshot save my.db


    ==升级
    # write key in etcd version 2 store
    export ETCDCTL_API=2
    etcdctl --endpoints=http://$ENDPOINT set foo bar
    
    # read key in etcd v2
    etcdctl --endpoints=$ENDPOINTS --output="json" get foo
    
    # stop etcd node to migrate, one by one
    
    # migrate v2 data
    export ETCDCTL_API=3
    etcdctl --endpoints=$ENDPOINT migrate --data-dir="default.etcd" --wal-dir="default.etcd/member/wal"
    
    # restart etcd node after migrate, one by one
    
    # confirm that the key got migrated
    etcdctl --endpoints=$ENDPOINTS get /foo

     
     
     
     



     
  • 相关阅读:
    C++入门经典-例3.4-根据成绩划分等级
    C++入门经典-例3.3-if-else语句的奇偶性判别
    C++入门经典-例3.2-根据分数判断是否优秀
    C++入门经典-例3.1-判断输入的数字是否为奇数
    C++入门经典-例2.17强制类型转换
    C++入门经典-例2.16-隐式类型转换
    C++入门经典-例2.15-逗号表达式的应用
    C++入门经典-例2.14-使用移位运算
    C++入门经典-例2.13-左移运算
    Spring之Bean管理------注解方式
  • 原文地址:https://www.cnblogs.com/justart/p/11670845.html
Copyright © 2020-2023  润新知