zoukankan      html  css  js  c++  java
  • kong结合consul

    • 早期版本

    ./etcdctl ls / --recursive

    /name
    /name1
    /name1/wyc
    /name1/wu
    /name1/chao
    /name1/chao/age

    ./etcdctl -o extended get /name1/wyc

    Key: /name1/wyc
    Created-Index: 8
    Modified-Index: 8
    TTL: 0
    Index: 9

    11

    ./etcdctl watch /name1/wyc

    当修改这个键的时候,watch就会输出最新的值并退出
    --forever 一直监测直到用户按CTRL+C退出



    curl -L http://localhost:2379/v2/keys/name

    =========

    kong

    负载均衡

    1.基于dns的负载均衡,后端服务的注册在kong之外完成,kong只接收来自dns服务器的更新。dns的ttl(time to live)决定了信息被刷新的频率,


    kong with consul:

    use consul as a dns server, then you'll have to live with TTL expiry times. Alternatively run a script on changes (services added/removed) to add a target entity through the Kong management api。

    consul角色
    1.agent是在consul集群中每个机器成员中运行的一个常驻进程。可以当做server或者server的身份运行。所有agent都可以运行dns或者http接口,并且执行健康检查和保持服务信息的同步。
    2.client是一个agent,将rpc调用转向对应的服务。client是无状态的。唯一的在后台执行的逻辑就是加入Gossip同步池。
    3.server同样是一个agent,职责包括实现集群的一致性,维护集群状态,响应rpc请求,与其他数据中心交换数据。

    consul发现服务
    consul提供了dns和http两种查询服务的方式。DNS 服务的默认端口设置为8600。Consul 服务被放置在 .consul 的命名空间下,DNS 查询的基础规则为 SERVICENAME.service.consul。其中 service 子域表示查询服务,SERVICENAME正是查询服务的名称。除了通过 DNS API,HTTP 服务也可用于服务查询。

    consul使用

    1. 启动consul服务 consul agent -server -bootstrap -data-dir /tmp/consul -node=consul1 -bind 172.0.0.10
    2. 启动consul服务 consul agent -server -data-dir /tmp/consul -node=consul2 -bind 172.0.0.11 -join 172.0.0.10
    3. 启动业务服务(监听8045) consul agent -data-dir /tmp/consul -node=service1 -config-dir /etc/consul.d -bind 172.0.0.13 -join 172.0.0.10
      在节点启动脚本中,我们已经将业务服务的定义信息写入/etc/consul.d/mysvc.json文件。这样在 Consul 客户端服务启动之后,就能将服务的信息同步到集群中的所有节点。
      mysvc.json:
    {
        "service": {
            "name": "my-svc",
            "tags": [
                "microservice"
            ],
            "port": 8045,
            "check": {
                "script": "curl localhost:8045/status | grep OK || exit 2",
                "interval": "5s"
            }
        }
    }
    

    {
      "service": {
        "name": "web3",
        "tags": ["master"],
        "address": "127.0.0.1",
        "port": 10000,
        "checks": [
          {
            "http": "http://localhost:10000/health",
            "interval": "10s"
          }
        ]
      }
    }
    

    4.机器节点,用于查看集群状态 consul agent -client=172.0.0.12 -ui-dir /vagrant/web/ -data-dir /tmp/consul -node=status -bind 172.0.0.12 -join 172.0.0.10

    ui

    http://localhost:8500/ui/#/dc1/nodes


  • 相关阅读:
    面向对象
    ArrayList 集合
    JAVA 方法
    JAVA数组
    JAVA基础2
    JAVA基础1(语法)
    JAVA基础(jdk安装和环境变量的配置)
    数据结构练习题
    多表查询
    数据约束
  • 原文地址:https://www.cnblogs.com/mentalidade/p/10394301.html
Copyright © 2011-2022 走看看