zoukankan      html  css  js  c++  java
  • ETCD服务

    ETCD

    简介

    ETCD是一个开源的、分布式的键值对数据存储系统,由Go语言实现,用于存储key-value键值对,同时不仅仅是存储,主要用途是提供共享配置及服务发现,使用Raft一致性算法来管理高度可用的复制日志。有下面特点

    • 简单:定义明确,面向用户的API(gRPC)
    • 安全:具有可选客户端证书身份验证的自动TLS
    • 快速:基准测试10,000次/秒
    • 可靠:使用Raft正确分布

    NOTE:

      ETCD适用于较小的原数据键值对的处理,对于大的键值对数据的处理回导致其他请求时间的增加。数据目前最大支持1M数据的RPC请求,目前来说没有办法实现更大数据的配置

    使用场景:服务发现、消息定义发布、负载均衡、分布式通知与协调、分布式锁、分布式队列、集群监控与Leader竞选

    安装 

    环境Linux,下载安装包https://github.com/etcd-io/etcd/releases/download/v3.4.0/etcd-v3.4.0-linux-amd64.tar.gz到本地,从git中筛选版本https://github.com/etcd-io/etcd/releases

    [root@centos7 ~]# wget https://github.com/etcd-io/etcd/releases/download/v3.4.0/etcd-v3.4.0-linux-amd64.tar.gz
    

    解压

    [root@centos7 ~]# tar zxvf etcd-v3.4.0-linux-amd64.tar.gz 

    进入目录,启动,默认监听本地2379端口

    [root@centos7 ~]# cd etcd-v3.4.0-linux-amd64
    [root@centos7 etcd-v3.4.0-linux-amd64]# ./etcd

    验证

    [root@centos7 etcd-v3.4.0-linux-amd64]# ./etcdctl put foo bar
    OK
    [root@centos7 etcd-v3.4.0-linux-amd64]# ./etcdctl get foo
    foo
    bar
    

     查看接口版本

    [root@centos7 etcd-v3.4.0-linux-amd64]# ./etcdctl version
    etcdctl version: 3.4.0
    API version: 3.4

    查看集群成员信息

    [root@centos7 ~]# etcdctl member list
    8e9e05c52164694d, started, default, http://localhost:2380, http://localhost:2379, false
    

    简单使用

    写入

    [root@centos7 ~]# etcdctl put foo bar
    OK
    [root@centos7 ~]# etcdctl put foo1 bar1
    OK

     读取

    [root@centos7 ~]# etcdctl get foo
    foo
    bar
    [root@centos7 ~]# etcdctl get foo --print-value-only
    bar
    [root@centos7 ~]# etcdctl get  --prefix foo
    foo
    bar
    foo1
    bar1

    删除

    [root@centos7 ~]# etcdctl del foo
    1
    [root@centos7 ~]# etcdctl get foo
    

      

    租期

    授权租期

    [root@centos7 ~]# etcdctl lease grant 20
    lease 694d6d2a9dbd8d0d granted with TTL(20s)
    [root@centos7 ~]# etcdctl put --lease=694d6d2a9dbd8d0d foo bar
    OK
    [root@centos7 ~]# etcdctl get foo
    foo
    bar
    [root@centos7 ~]# etcdctl get foo

    撤销租期

    [root@centos7 ~]# etcdctl lease grant 60
    lease 694d6d2a9dbd8d1c granted with TTL(60s)
    [root@centos7 ~]# etcdctl put --lease=694d6d2a9dbd8d1c foo bar
    OK
    [root@centos7 ~]# etcdctl lease revoke 694d6d2a9dbd8d1c
    lease 694d6d2a9dbd8d1c revoked
    [root@centos7 ~]# etcdctl get foo
    

    租期保持存活

    [root@centos7 ~]# etcdctl lease grant 10
    lease 694d6d2a9dbd8d24 granted with TTL(10s)
    [root@centos7 ~]# etcdctl lease keep-alive 694d6d2a9dbd8d24
    lease 694d6d2a9dbd8d24 keepalived with TTL(10)
    lease 694d6d2a9dbd8d24 keepalived with TTL(10)
    lease 694d6d2a9dbd8d24 keepalived with TTL(10)
    lease 694d6d2a9dbd8d24 keepalived with TTL(10)
    

      

     观察者

    [root@centos7 ~]# etcdctl watch foo
    PUT
    foo
    bar1
    DELETE
    foo
    

      

      

  • 相关阅读:
    Java 9 揭秘(14. HTTP/2 Client API)
    Java 9 揭秘(13. Collection API 更新)
    Java 9 揭秘(12. Process API 更新)
    JAVA数组与List相互转换
    linux下开启oracle服务和开启监听
    Centos7安装Redis
    Hibernate乐观锁无法Catch到org.hibernate.StaleObjectStateException
    Eclipse远程调试Tomcat
    Centos7 使用Docker搭建Oracle测试环境
    Maven安装Oracle驱动包到本地仓库
  • 原文地址:https://www.cnblogs.com/lianzhilei/p/11517364.html
Copyright © 2011-2022 走看看