consul(第一篇)consul 入门
2016-06-01 21:31
696 查看
consul 入门
consul是什么
consul包含多个组件,从整体上看可以理解为一个服务发现、配置的工具,包含一下几个特点:服务发现(Service Discovery):客户端通过consul提供服务,其他客户端可以通过consul利用dns或者http发现依赖服务
健康检查(Health Checking): consul提供任务的健康检查,可以用来操作或者监控集群的健康,也可以在服务发现时去除失效的服务
键值对存储(Key/Value Store): 存储层级键值对
多数据中心(Multi Datacenter): consul支持开箱即用的多数据中心
consul 安装
1.下载consul安装包并解压wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip unzip consul_0.6.4_linux_amd64.zip
解压后得到可执行的二进制文件,执行
./consul得到
usage: consul [--version] [--help] <command> [<args>] Available commands are: agent Runs a Consul agent configtest Validate config file event Fire a new event exec Executes a command on Consul nodes force-leave Forces a member of the cluster to enter the "left" state info Provides debugging information for operators join Tell Consul agent to join cluster keygen Generates a new encryption key keyring Manages gossip layer encryption keys leave Gracefully leaves the Consul cluster and shuts down lock Execute a command holding a lock maint Controls node or service maintenance mode members Lists the members of a Consul cluster monitor Stream logs from a Consul agent reload Triggers the agent to reload configuration files rtt Estimates network round trip time between nodes version Prints the Consul version watch Watch for changes in Consul
表示consul成功安装,同时将
consul所在目录配置到
path,例如这里
consul在
software努力下,进行如下配置
vim ~/.bash_profile export GOROOT=/software/go export GOPATH=/root/work PATH=$PATH:$HOME/bin:$GOROOT/bin:/software export PATH source ~/.bash_profile
启动
首先下载web-uiwget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_web_ui.zip[/code]
通过下面命令启动consulconsul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -advertise 120.76.145.187 -client 120.76.145.187 -ui-dir /software/consul-uiserver表示启动的为consul server ,构建一个consul cluster 一般建议使用3或者5个consul serverbootstrap-expect 1表示期望的服务节点数目为1-data-dir数据目录,如果该文件夹不存在则手工创建,如果在consul发生错误后,建议先清理该目录文件advertise设置广播地址,ip可以设置为公网ipclient设置client访问的地址ui-dirweb控制台目录位置
注意 通过advertiseclient才能在WAN上访问consul,否则只能在LAN内访问.
官方给出的快捷启动为consul agent -dev如果想简单体验一下可以使用该命令
启动后访问http://ip:8500/ui得到如下界面获取基本信息
获取consul server集群中的成员列表使用命令方式
如果以局域网中,直接使用consul members
如果是广域网中,使用consul members --rpc-addr=ip:8400
得到结果:Node Address Status Type Build Protocol DC iZ94235juoyZ 120.76.145.187:8301 alive server 0.6.4 2 dc1使用http接口方式
curl 120.76.145.187:8500/v1/catalog/nodes
返回结果:[{"Node":"iZ94235juoyZ","Address":"120.76.145.187","TaggedAddresses":{"wan":"120.76.145.187"},"CreateIndex":3,"ModifyIndex":4}]通过dns方式
dig @120.76.145.187 -p 8600 iZ94235juoyZ.node.consul
返回结果:; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @120.76.145.187 -p 8600 iZ94235juoyZ.node.consul ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 625 ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; WARNING: recursion requested but not available ;; QUESTION SECTION: ;iZ94235juoyZ.node.consul. IN A ;; ANSWER SECTION: iZ94235juoyZ.node.consul. 0 IN A 120.76.145.187 ;; Query time: 0 msec ;; SERVER: 120.76.145.187#8600(120.76.145.187) ;; WHEN: Wed Jun 1 21:24:31 2016 ;; MSG SIZE rcvd: 82
ok ~ it’s work ! more about is here
转载请注明
http://blog.csdn.net/liaokailin/article/details/51559228
欢迎关注,您的肯定是对我最大的支持![]()
相关文章推荐
- etcd的使用
- Cloudfoundry Diego 中consul的应用
- Swarm创建docker集群:服务发现-etcd
- Swarm创建docker集群:服务发现-配置文件法
- 使用Consul快速搭建简易分布式服务监控系统
- [转载]微服务实战(四):服务发现的可行方案以及实践案例
- [Consul]Error starting agent: Failed to get advertise address: Multiple private IPs found.
- Consul & Registrator & Rails Service all together in separate Docker container
- confd+etcd完成后端服务器的自动检测
- docker深入2-使用registrator和consul-template自动注册和变更服务
- 监控之美--prometheus配置文件动态管理
- 服务发现之美:Consul集群搭建
- 干货分享微服务spring-cloud(2.概览)
- Docker可视化界面(Consul+Shipyard+Swarm+Service Discover
- consul安装
- zookeeper+mesos+docker+swarm
- Consul文档简要整理
- 【NoSQL】抛弃VIP构建MongoDB RepSet +Consul高可用切换系统
- 【NoSQL】抛弃VIP,使用consul和sentinel构建redis的高可用系统
- 顺序表(动态开辟内存)