consul介绍与安装

简介: Consul是一个微服务管理软件。支持多数据中心下,分布式高可用的,服务发现和配置共享。采用 `Raft 算法`,用来保证服务的高可用。

consul介绍

Consul是一个微服务管理软件。支持多数据中心下,分布式高可用的,服务发现和配置共享。采用 Raft 算法,用来保证服务的高可用。

参考文献

软件下载:https://www.consul.io/downloads

软件安装

下载软件

wget https://releases.hashicorp.com/consul/1.10.1/consul_1.10.1_linux_amd64.zip

解压软件

unzip consul_1.10.1_linux_amd64.zip

将软件置于系统启动目录

mv consul /usr/local/bin/consul

软件启动

consul agent -server -bootstrap-expect 1 -data-dir /data/consul -node=sn1 -bind=192.168.1.100 -ui -client=0.0.0.0

image-20210806172111277

访问ui界面

访问地址:ip:8500

image-20210806171949244

软件启动说明

consul必须启动agent才能使用,有两种启动模式server和client。

server用与持久化服务信息,集群官方建议3或5个节点。client只用与于server交互。ui界面可以查看集群情况的。

参数解释

-bootstrap-expect:集群期望的节点数,只有节点数量达到这个值才会选举leader。

-server: 运行在server模式

-data-dir:指定数据目录,其他的节点对于这个目录必须有读的权限

-node:指定节点的名称

-bind:为该节点绑定一个地址

-config-dir:指定配置文件,定义服务的,默认所有一.json结尾的文件都会读

-enable-script-checks=true:设置检查服务为可用

-datacenter: 数据中心没名称,

-join:加入到已有的集群中

基本使用

常用命令介绍

如果不想用命令操作,当然你也可以通过 ui 界面进行服务管理。

服务管理

注册一个服务

[root@204 ~]# curl -X PUT -d '{"ID":"order_1","Name":"order","Tags":["xdp-\/core.order"],"Address":"192.168.232.201","Port":18307,"Check":{"name":"order_1.check","tcp":"192.168.232.201:18307","interval":"10s","timeout":"2s"}}' http://192.168.169.99:8500/v1/agent/service/register

查询指定服务

[root@204 ~]# curl http://192.168.169.99:8500/v1/health/service/order

[{"Node":{"ID":"0d05756b-e7d3-6fbb-38e4-334de3220fea","Node":"consul1.4.4_client_public_5","Address":"172.17.0.5","Datacenter":"xdp_dc","TaggedAddresses":{"lan":"172.17.0.5","wan":"172.17.0.5"},"Meta":{"consul-network-segment":""},"CreateIndex":229415,"ModifyIndex":229415},"Service":{"ID":"order_1","Service":"order","Tags":["xdp-/core.order"],"Address":"192.168.232.201","Meta":null,"Port":18307,"Weights":{"Passing":1,"Warning":1},"EnableTagOverride":false,"ProxyDestination":"","Proxy":{},"Connect":{},"CreateIndex":229415,"ModifyIndex":229415},"Checks":[{"Node":"consul1.4.4_client_public_5","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"Agent alive and reachable","ServiceID":"","ServiceName":"","ServiceTags":[],"Definition":{},"CreateIndex":229415,"ModifyIndex":229415},{"Node":"consul1.4.4_client_public_5","CheckID":"service:order_1","Name":"order_1.check","Status":"passing","Notes":"","Output":"TCP connect 192.168.232.201:18307: Success","ServiceID":"order_1","ServiceName":"order","ServiceTags":["xdp-/core.order"],"Definition":{},"CreateIndex":229415,"ModifyIndex":303563}]}][root@204 ~]#

查询所有服务

[root@204 ~]# curl http://192.168.169.99:8500/v1/agent/services

{"core.product-/192.168.16.170:8001":{"ID":"core.product-/192.168.16.170:8001","Service":"core.product","Tags":["xdp-/core.product"],"Meta":{},"Port":18306,"Address":"192.168.232.100","Weights":{"Passing":1,"Warning":1},"EnableTagOverride":false},"goods_1":{"ID":"goods_1","Service":"goods","Tags":["xdp-/core.product"],"Meta":{},"Port":18307,"Address":"192.168.232.200","Weights":{"Passing":1,"Warning":1},"EnableTagOverride":false},"test1":{"ID":"test1","Service":"test1name","Tags":["xdp-/core.product"],"Meta":{},"Port":18306,"Address":"192.168.232.100","Weights":{"Passing":1,"Warning":1},"EnableTagOverride":false}}[root@204 ~]#

注销服务

[root@204 ~]# curl -X PUT http://192.168.169.99:8500/v1/agent/service/deregister/order_1

key/value配置中心命令行

查看所有key/value

[root@204 ~]# curl http://192.168.169.99:8500/v1/kv/?recurse
[{"LockIndex":0,"Key":"dd","Flags":0,"Value":"ewoiYiI6ImEiCn0=","CreateIndex":103396,"ModifyIndex":104797},{"LockIndex":0,"Key":"dd/dd/ff/uu","Flags":0,"Value":"NTU1NQ==","CreateIndex":104870,"ModifyIndex":104927},{"LockIndex":0,"Key":"dd/dd/gg","Flags":0,"Value":null,"CreateIndex":104868,"ModifyIndex":104868},{"LockIndex":0,"Key":"dd/ff","Flags":0,"Value":"MTIz","CreateIndex":104864,"ModifyIndex":104864}][root@204 ~]#

查询所有的key/value

[root@204 ~]# curl http://192.168.169.99:8500/v1/kv/?recurse
[{"LockIndex":0,"Key":"dd","Flags":0,"Value":"ewoiYiI6ImEiCn0=","CreateIndex":103396,"ModifyIndex":104797},{"LockIndex":0,"Key":"dd/dd/ff/uu","Flags":0,"Value":"NTU1NQ==","CreateIndex":104870,"ModifyIndex":104927},{"LockIndex":0,"Key":"dd/dd/gg","Flags":0,"Value":null,"CreateIndex":104868,"ModifyIndex":104868},{"LockIndex":0,"Key":"dd/ff","Flags":0,"Value":"MTIz","CreateIndex":104864,"ModifyIndex":104864}]

添加key/value

[root@204 ~]# curl -X PUT -d 'test' http://192.168.169.99:8500/v1/kv/abc/key1
true

说明

key: abc/key1

value:test

查看单个key/value

[root@204 ~]# curl http://192.168.169.99:8500/v1/kv/abc/key1
[{"LockIndex":0,"Key":"abc/key1","Flags":0,"Value":"dGVzdA==","CreateIndex":304012,"ModifyIndex":304012}]

说明

value是test的base64编码(使用base64编码是为了允许非UTF-8的字符)

修改key/value

[root@204 ~]# curl -X PUT -d 'test666' http://192.168.169.99:8500/v1/kv/abc/key1
true

删除key/value

[root@204 ~]# curl -X DELETE  http://192.168.169.99:8500/v1/kv/abc/key1
true
相关文章
|
7月前
|
存储 Ubuntu 网络协议
|
7月前
|
运维 网络协议 Linux
2024年最全CentOS8 Consul微服务架构安装(1)_agent(1),Linux运维开发面试
2024年最全CentOS8 Consul微服务架构安装(1)_agent(1),Linux运维开发面试
|
7月前
Consul安装教程和注册
Consul安装教程和注册
86 0
|
Java Shell 网络安全
consul安装启动流程
consul安装启动流程
352 0
|
存储 监控 网络协议
Consul简介和安装
Consul 是一套开源的分布式服务发现和配置管理系统,由 HashiCorp 公司用 Go 语言开发。
Consul简介和安装
|
iOS开发 MacOS
macOS下载、安装和启动consul
macOS下载、安装和启动consul
304 0
macOS下载、安装和启动consul
|
数据中心 开发工具 网络协议
|
网络协议 前端开发 atlas
Consul 简介、安装、常用命令的使用
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010046908/article/details/61916389 1 Consul简介 Consul 是 HashiCorp 公司推出的开源工具,用于实现分布式系统的服务发现与配置。
2014 0