Consul的安装与试用

Consul的安装与试用


2016-5-23




一)安装在RedHat7.2


1. VM@aws info


[root@ip-172-30-0-43home]# uname -a

Linuxip-172-30-0-43.ec2.internal 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 2917:29:29 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux

[root@ip-172-30-0-43home]# cat /etc/redhat-release

RedHat Enterprise Linux Server release 7.2 (Maipo)




2. 安装

主页https://www.consul.io/


当然 版本

https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip


下载, 然后unzip 解压, 得到唯一个可执行文件

wgethttps://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip

unzipconsul_0.6.4_linux_amd64.zip


检查一下版本

[root@ip-172-30-0-43consul]# ./consul version

Consulv0.6.4

ConsulProtocol: 3 (Understands back to: 1)

[root@ip-172-30-0-43consul]#



3. Bootstrap Server 模式 启动

./consulagent -server -bootstrap-expect=1 -data-dir /tmp/consul

./consulagent -server -bootstrap -data-dir /tmp/consul


输出如下:

[root@ip-172-30-0-43consul]# ./consul agent -server -bootstrap-expect=1 -data-dir/tmp/consul

==>WARNING: BootstrapExpect Mode is specified as 1; this is the same asBootstrap mode.

==>WARNING: Bootstrap mode enabled! Do not enable unless necessary

==>Starting Consul agent...

==>Starting Consul agent RPC...

==>Consul agent running!

Nodename: 'ip-172-30-0-43.ec2.internal'

Datacenter:'dc1'

Server:true (bootstrap: true)

ClientAddr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)

ClusterAddr: 172.30.0.43 (LAN: 8301, WAN: 8302)

Gossipencrypt: false, RPC-TLS: false, TLS-Incoming: false

Atlas:<disabled>

......(省略)......



4. 查看,成员info


[root@ip-172-30-0-43consul]# ./consul members

Node Address Status Type Build Protocol DC

ip-172-30-0-43.ec2.internal 172.30.0.43:8301 alive server 0.6.4 2 dc1

[root@ip-172-30-0-43consul]# ./consul members -detailed

Node Address Status Tags

ip-172-30-0-43.ec2.internal 172.30.0.43:8301 alive bootstrap=1,build=0.6.4:26a0ef8c,dc=dc1,port=8300,role=consul,vsn=2,vsn_max=3,vsn_min=1


[root@ip-172-30-0-43consul]# ./consul info

agent:

check_monitors= 0

check_ttls= 0

checks= 0

services= 1

build:

......(省略)......




二)服务的注册与发现


1. 节点的基本情况

两台Node


ip-172-30-0-43 RedHat7.2 172.30.0.43Server

ip-172-30-0-89 Amazon(4.1.10)172.30.0.89 Server



2. 运行的主要命令

参数-bootstrap-expect=2指明 是两台server

/home/consul/consulagent -server -bootstrap-expect=2 -data-dir /tmp/consul-node=ip-172-30-0-43 -bind=172.30.0.43 -dc=dc1



/home/consul/consulagent -server -bootstrap-expect=2 -data-dir /tmp/consul-node=ip-172-30-0-89 -bind=172.30.0.89 -dc=dc1



/home/consul/consuljoin 172.30.0.89




3. 控制台输出

[root@ip-172-30-0-43tmp]# /home/consul/consul agent -server -bootstrap-expect=2 -data-dir/tmp/consul -node=ip-172-30-0-43 -bind=172.30.0.43 -dc=dc1

==>WARNING: Expect Mode enabled, expecting 2 servers

==>Starting Consul agent...

==>Starting Consul agent RPC...

==>Consul agent running!

Nodename: 'ip-172-30-0-43'

Datacenter:'dc1'

Server:true (bootstrap: false)

ClientAddr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)

ClusterAddr: 172.30.0.43 (LAN: 8301, WAN: 8302)

Gossipencrypt: false, RPC-TLS: false, TLS-Incoming: false

Atlas:<disabled>


==>Log data will now stream in as it occurs:


2016/05/1601:48:46 [INFO] serf: EventMemberJoin: ip-172-30-0-43 172.30.0.43

2016/05/1601:48:46 [INFO] serf: EventMemberJoin: ip-172-30-0-43.dc1 172.30.0.43

2016/05/1601:48:46 [INFO] raft: Node at 172.30.0.43:8300 [Follower] enteringFollower state

2016/05/1601:48:46 [INFO] consul: adding LAN server ip-172-30-0-43 (Addr:172.30.0.43:8300) (DC: dc1)

2016/05/1601:48:46 [INFO] consul: adding WAN server ip-172-30-0-43.dc1 (Addr:172.30.0.43:8300) (DC: dc1)

2016/05/1601:48:46 [ERR] agent: failed to sync remote state: No cluster leader

2016/05/1601:48:47 [WARN] raft: EnableSingleNode disabled, and no known peers.Aborting election.

2016/05/1601:48:56 [INFO] agent.rpc: Accepted client: 127.0.0.1:41616

2016/05/1601:48:56 [INFO] agent: (LAN) joining: [172.30.0.89]

2016/05/1601:48:56 [INFO] serf: EventMemberJoin: ip-172-30-0-89 172.30.0.89

2016/05/1601:48:56 [INFO] agent: (LAN) joined: 1 Err: <nil>

2016/05/1601:48:56 [INFO] consul: adding LAN server ip-172-30-0-89 (Addr:172.30.0.89:8300) (DC: dc1)

2016/05/1601:48:56 [INFO] consul: Attempting bootstrap with nodes:[172.30.0.43:8300 172.30.0.89:8300]

2016/05/1601:48:57 [INFO] consul: New leader elected: ip-172-30-0-89

2016/05/1601:49:00 [INFO] agent: Synced service 'consul'



[root@ip-172-30-0-89tmp]# /home/consul/consul agent -server -bootstrap-expect=2 -data-dir/tmp/consul -node=ip-172-30-0-89 -bind=172.30.0.89 -dc=dc1

==>WARNING: Expect Mode enabled, expecting 2 servers

==>Starting Consul agent...

==>Starting Consul agent RPC...

==>Consul agent running!

Nodename: 'ip-172-30-0-89'

Datacenter:'dc1'

Server:true (bootstrap: false)

ClientAddr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)

ClusterAddr: 172.30.0.89 (LAN: 8301, WAN: 8302)

Gossipencrypt: false, RPC-TLS: false, TLS-Incoming: false

Atlas:<disabled>


==>Log data will now stream in as it occurs:


2016/05/1605:48:50 [INFO] serf: EventMemberJoin: ip-172-30-0-89 172.30.0.89

2016/05/1605:48:50 [INFO] serf: EventMemberJoin: ip-172-30-0-89.dc1 172.30.0.89

2016/05/1605:48:50 [INFO] raft: Node at 172.30.0.89:8300 [Follower] enteringFollower state

2016/05/1605:48:50 [INFO] consul: adding LAN server ip-172-30-0-89 (Addr:172.30.0.89:8300) (DC: dc1)

2016/05/1605:48:50 [INFO] consul: adding WAN server ip-172-30-0-89.dc1 (Addr:172.30.0.89:8300) (DC: dc1)

2016/05/1605:48:50 [ERR] agent: failed to sync remote state: No cluster leader

2016/05/1605:48:51 [WARN] raft: EnableSingleNode disabled, and no known peers.Aborting election.

2016/05/1605:48:56 [INFO] serf: EventMemberJoin: ip-172-30-0-43 172.30.0.43

2016/05/1605:48:56 [INFO] consul: adding LAN server ip-172-30-0-43 (Addr:172.30.0.43:8300) (DC: dc1)

2016/05/1605:48:56 [INFO] consul: Attempting bootstrap with nodes:[172.30.0.89:8300 172.30.0.43:8300]

2016/05/1605:48:57 [WARN] raft: Heartbeat timeout reached, starting election

2016/05/1605:48:57 [INFO] raft: Node at 172.30.0.89:8300 [Candidate] enteringCandidate state

2016/05/1605:48:57 [INFO] raft: Election won. Tally: 2

2016/05/1605:48:57 [INFO] raft: Node at 172.30.0.89:8300 [Leader] enteringLeader state

2016/05/1605:48:57 [INFO] consul: cluster leadership acquired

2016/05/1605:48:57 [INFO] consul: New leader elected: ip-172-30-0-89

2016/05/1605:48:57 [INFO] raft: pipelining replication to peer 172.30.0.43:8300

2016/05/1605:48:57 [INFO] consul: member 'ip-172-30-0-89' joined, markinghealth alive

2016/05/1605:48:57 [INFO] consul: member 'ip-172-30-0-43' joined, markinghealth alive

2016/05/1605:48:59 [INFO] agent: Synced service 'consul'



[root@ip-172-30-0-43~]# /home/consul/consul join 172.30.0.89

Successfullyjoined cluster by contacting 1 nodes.

[root@ip-172-30-0-43~]# /home/consul/consul members

Node Address Status Type Build Protocol DC

ip-172-30-0-43 172.30.0.43:8301 alive server 0.6.4 2 dc1

ip-172-30-0-89 172.30.0.89:8301 alive server 0.6.4 2 dc1


[root@ip-172-30-0-43~]# tree /tmp/consul/

/tmp/consul/

├── checkpoint-signature

├── raft

│   ├── peers.json

│   ├── raft.db

│   └── snapshots

└── serf

├── local.snapshot

└── remote.snapshot


3 directories, 5 files



输入Ctrl+ C 后,停止服务, 输出如下:

^C==>Caught signal: interrupt

==>Gracefully shutting down agent...

2016/05/1603:03:30 [INFO] consul: server starting leave

2016/05/1603:03:30 [INFO] serf: EventMemberLeave: ip-172-30-0-43.dc1172.30.0.43

2016/05/1603:03:30 [INFO] consul: removing WAN server ip-172-30-0-43.dc1 (Addr:172.30.0.43:8300) (DC: dc1)

2016/05/1603:03:31 [INFO] serf: EventMemberLeave: ip-172-30-0-43 172.30.0.43

2016/05/1603:03:31 [INFO] consul: removing LAN server ip-172-30-0-43 (Addr:172.30.0.43:8300) (DC: dc1)

2016/05/1603:03:31 [INFO] raft: Removed ourself, transitioning to follower

2016/05/1603:03:32 [INFO] agent: requesting shutdown

2016/05/1603:03:32 [INFO] consul: shutting down server

2016/05/1603:03:32 [ERR] dns: error starting tcp server: accept tcp127.0.0.1:8600: use of closed network connection

2016/05/1603:03:32 [INFO] agent: shutdown complete





4. 存储值

利用打开的8500http服务,存储某些值。


[root@ip-172-30-0-43tmp]# curl -X PUT -d 'bar'http://localhost:8500/v1/kv/foo

true[root@ip-172-30-0-43tmp]#

[root@ip-172-30-0-43tmp]# curlhttp://localhost:8500/v1/kv/foo

[{"LockIndex":0,"Key":"foo","Flags":0,"Value":"YmFy","CreateIndex":144,"ModifyIndex":144}][root@ip-172-30-0-43tmp]#

[root@ip-172-30-0-43tmp]# echo "YmFy" | base64 --decode

bar[root@ip-172-30-0-43tmp]#




5. 其他


重启,但加上-rejoin命令:

如:

/home/consul/consulagent -server -bootstrap-expect=2 -data-dir /tmp/consul-node=ip-172-30-0-43 -bind=172.30.0.43 -dc=dc1 -rejoin



退出, 使用consul leave 命令







三)进一步的思考与问题

1. 几种一致性算法或者相关概念

GOSSIPCONSENSUS, SERF


2. 相关的产品

ZooKeeper, doozerd, etcd

Chef, Puppet, etc.

Nagios, Sensu

SkyDNS

SmartStack

Serf


3. 多数据中心,

延迟? 配置?

如何写入数据?脚本 (curl http请求?)

分裂?一个数据中心, 分裂成两个或多个



4. 某一个server退出(leave命令)重新加入, 有问题,

不能正确选举leader


5. 发现IBM的一些资料如:


借助ConsulDocker支持即插即用的服务发现(servicediscovery)

http://www.ibm.com/developerworks/cn/cloud/library/cl-plug-and-play-service-discovery-with-consul-and-docker-bluemix/


准备进一步学习....

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值