首页 技术 正文
技术 2022年11月10日
0 收藏 475 点赞 3,373 浏览 1532 个字

Service discovery and configuration made easy. Distributed, highly available, and datacenter-aware.

服务发现和配置,分布式,高可用性,数据中心。

  • 服务注册 – 服务端注册相应的的主机、端口号及其它身份验证信息,协议,版本号,以及运行环境等详细资料。

  • 服务发现 – 客户端应用通过向注册中心查询,获取可用服务列表,相应服务详细信息。

  • 基本服务格式:

     {
    "service":{
    "id": "myservice",
    "name": "myservice",
    "address": "servicehost",
    "port": serviceport,
    "tags": ["tag"],
    "checks": [
    {
    "http": "http://host.port/health",
    "interval": "5s"
    }
    ]
    }
    }
  • 健康检查(checks):
    script check:consul主动去检查服务的健康状况

     {
    "check": {
    "id": "scheck",
    "name": "scheck",
    "script": "/*.py", //必须
    "interval": "10s", //必须
    "timeout": "1s"
    }
    }

    ttl check:服务主动向consul报告自己的健康状况

     {
    "check": {
    "id": "scheck",
    "name": "scheck",
    "notes": "scheck",
    "ttl": "30s"
    }
    }

    http check:

     {
    "check": {
    "id": "scheck",
    "name": "scheck",
    "http": "http://host:port/health",
    "interval": "10s",
    "timeout": "1s"
    }
    }

    tcp check:

     {
    "check": {
    "id": "scheck",
    "name": "scheck",
    "tcp": "host:22",
    "interval": "10s",
    "timeout": "1s"
    }
    }
  • 服务注册:

    • 配置文件静态注册:/etc/consul.d/myserver.json,

      添加如上服务配置,重启consul,并将配置文件的路径给consul(指定参数:-config-dir /etc/consul.d)

    • HTTP API接口来动态注册:/v1/agent/service/register http put方法注册。

      curl -X PUT -d ‘{“id”: “myserver”,”name”: “myserver”,”address”: “serverhost”,”port”: serverport,”tags”: [“tag”],”checks”: [{“http”: “http://healthhost:port/health”,”interval”: “5s”}]}’ http://host:8500/v1/agent/service/register

  • maven dependency:

     <dependency>
    <groupId>com.orbitz.consul</groupId>
    <artifactId>consul-client</artifactId>
    <version>xxx</version>
    </dependency>
     <dependency>
    <groupId>com.ecwid.consul</groupId>
    <artifactId>consul-api</artifactId>
    <version>xxx</version>
    </dependency>

项目地址:https://github.com/windwant/windwant-service/tree/master/consul-service

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850