zoukankan      html  css  js  c++  java
  • Go环境下,编译运行etcd与goreman集群管理(1)

    Go环境下编译运行etcd与goreman管理

    近几年了Go在比特币、区块链、云服务等相关重要领域贡献突出,作为IT行业的传承“活到老、学到光头”,保持学习心态。

    周末放假,补充一二

    主题:在Go环境下首试传闻已久的etcd与goreman, 开源高性能KV集群服务,并提供共享配置、服务的注册和发现,在当前微服务流行的年代,充当着中间存储与代理服务的重要角色,除了与redis相对比功能相似外,etcd更贴近于微服务集成,得益于它的共享配置、服务的注册和发现。

    SO,试行一把并作记录~~

    1.安装Golang

    下载地址: https://studygolang.com/dl 各平台版本按需自助,

    此处for MAC: https://studygolang.com/dl/golang/go1.12.1.darwin-amd64.pkg

    2.获取etcd与goreman源码

    go get github.com/etcd-io/etcd   
    go get github.com/mattn/goreman

    3.编译,并生成exe到$GOPATH/bin目录,( go build编译输出到main文件同目录,go install编译输出到$GOPATH/bin )

    go install github.com/etcd-io/etcd          #KV服务
    go install github.com/etcd-io/etcd/etcdctl     #读写控件
    go install github.com/mattn/goreman        #KV集群管理

    4.启动执行,启动goreman需要一个集群配置来启动和管理集群的etcd,并选中其中一个作为Master其余作为Slave

    创建 $GOPATH/bin/Procfile文件

    # Use goreman to run `go get github.com/mattn/goreman`
    etcd1: etcd --name infra1 --listen-client-urls http://127.0.0.1:2379 --advertise-client-urls http://127.0.0.1:2379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
    etcd2: etcd --name infra2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
    etcd3: etcd --name infra3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
    #proxy: etcd grpc-proxy start --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379 --listen-addr=127.0.0.1:23790 --advertise-client-url=127.0.0.1:23790 --enable-pprof

    执行命令

    PS:~/go/bin goreman start 

    附:更多转阅 https://frank6866.gitbooks.io/linux/content/chapters/db/db-etcd-etcdctl.html

    5.验证结果

    当前启动集群:

    http://127.0.0.1:2379
    http://127.0.0.1:22379
    http://127.0.0.1:32379

    往其中一个服务添加一个key,然后在另外两个服务读取

    # 添加一个Key,默认缺省endpoints服务为端口2379,可以不用写
    etcdctl put mykey "this is a hello world"
    
    
    # 在2379上读取
    etcdctl get mykey
    
    # 在22379上读取
    etcdctl --endpoints=http://localhost:22379 get mykey
    
    # 在33379上读
    etcdctl --endpoints=http://localhost:32379 get mykey

    Bingo~

  • 相关阅读:
    flash中网页跳转总结
    as3自定义事件
    mouseChildren启示
    flash拖动条移出flash无法拖动
    需要一个策略文件,但在加载此媒体时未设置checkPolicyFile标志
    Teach Yourself SQL in 10 Minutes
    电子书本地转换软件 Calibre
    Teach Yourself SQL in 10 Minutes
    Teach Yourself SQL in 10 Minutes
    Teach Yourself SQL in 10 Minutes – Page 31 练习
  • 原文地址:https://www.cnblogs.com/dzone/p/10658316.html
Copyright © 2011-2022 走看看