• consul


    • python-consul

    import consul

    c = consul.Consul(host="192.168.111.111")

    c.kv.put("key","value")

    a = c.kv.get("key")

    print a

    ('107', {u'LockIndex': 0, u'ModifyIndex': 107, u'Value': 'value', u'Flags': 0, u'Key': u'key', u'CreateIndex': 107})

    a = c.session.create(name="mhc",behavior='release',ttl=25)
    c.kv.put("key111", "v2222", acquire=a)
    b = c.kv.get("key111")[1]
    print b

    {u'LockIndex': 1, u'ModifyIndex': 332, u'Value': 'v2222', u'Session': u'63d76352-f2ee-8cf0-8c01-b91581d22c1a', u'Flags': 0, u'Key': u'key111', u'CreateIndex': 332}

    a = c.session.create(name="mhc",behavior='release',ttl=25)
    c.kv.put("key111", "v2222", acquire=a)
    time.sleep(2)
    print c.kv.put("key111", "done", release=a)
    b = c.kv.get("key111")[1]
    print b

    True

    {u'LockIndex': 3, u'ModifyIndex': 368, u'Value': 'done', u'Flags': 0, u'Key': u'key111', u'CreateIndex': 332}

    ------------------------------------------------------------------------------------------------------

    watch

    w.py

    #!/bin/python
    import sys
    import json

    if __name__ == "__main__":
    print "1111"
    a = sys.stdin.readline().strip()
    a = json.loads(a)

    print a
    print a["Value"]

    -------------------------------------

    [root@localmesos ~]# consul watch -type=key -key=key /root/PycharmProjects/test/w.py
    1111
    {"Key":"key","CreateIndex":11,"ModifyIndex":80,"LockIndex":0,"Flags":0,"Value":"MzMz","Session":""}
    1111
    {"Key":"key","CreateIndex":11,"ModifyIndex":98,"LockIndex":0,"Flags":0,"Value":"MjIy","Session":""}

    consul watch -type=service -service=consul /root/PycharmProjects/test/w.py
    1111
    [{u'Node': {u'Node': u'localmesos', u'Datacenter': u'dc1', u'TaggedAddresses': {u'wan': u'192.168.111.111', u'lan': u'192.168.111.111'}, u'ModifyIndex': 6, u'Meta': {}, u'Address': u'192.168.111.111', u'CreateIndex': 5, u'ID': u'cbefa43c-4343-8ee7-dee1-4944e230a1b1'}, u'Checks': [{u'Node': u'localmesos', u'CheckID': u'serfHealth', u'Name': u'Serf Health Status', u'ServiceName': u'', u'Notes': u'', u'Status': u'passing', u'ServiceID': u'', u'ServiceTags': [], u'Output': u'Agent alive and reachable'}], u'Service': {u'Service': u'consul', u'Tags': [], u'ModifyIndex': 6, u'EnableTagOverride': False, u'ID': u'consul', u'Address': u'', u'CreateIndex': 5, u'Port': 8300}}]

    ------------------------------------------------------------------------------

     consul agent -data-dir=/consul/data -config-dir=/consul/config -server -client=0.0.0.0 -bootstrap -ui

    consul agent -data-dir=/consul/data2 -config-dir=/consul/config2 -rejoin -retry-join 109.105.4.65 -retry-max 10 -retry-interval 10s
    consul agent -data-dir=/consul/data2 -config-dir=/consul/config2 -rejoin -retry-join 109.105.4.65:8301 -retry-max 10 -retry-interval 10s -config-file=/consul/config2/default.json -node-id=f4dc3632-51eb-c95b-af68-0aff63567ebf

    Node1:
     
    start-script: consul agent -config-dir /tmp/config-n1/consul.d -config-file /tmp/config-n1/consul.d/default.json
    config:
     
    {
      "data_dir": "/tmp/Consul/data-n1",
      "server": true,
      "node_name": "node1",
      "bootstrap_expect": 3,
      "client_addr": "0.0.0.0",
      "ports": {
        "dns": 8600,
        "http": 8500,
        "rpc": 8400,
        "serf_lan": 8301,
        "serf_wan": 8302,
        "server": 8300
      }
    }
     
    Node2:
     
    start-script: consul agent -config-dir /tmp/config-n2/consul.d -config-file /tmp/config-n2/consul.d/default.json
    config:
     
    {
      "data_dir": "/tmp/Consul/data-n2",
      "server": true,
      "node_name": "node2",
      "bootstrap_expect": 3,
      "client_addr": "0.0.0.0",
      "ports": {
        "dns": 8601,
        "http": 8501,
        "rpc": 8401,
        "serf_lan": 8311,
        "serf_wan": 8312,
        "server": 8301
      }
    }
     
    Node3:
     
    start-script: consul agent -config-dir /tmp/config-n3/consul.d -config-file /tmp/config-n3/consul.d/default.json
    config:
     
    {
      "data_dir": "/tmp/Consul/data-n3",
      "server": true,
      "node_name": "node3",
      "bootstrap_expect": 3,
      "client_addr": "0.0.0.0",
      "ports": {
        "dns": 8603,
        "http": 8503,
        "rpc": 8403,
        "serf_lan": 8331,
        "serf_wan": 8332,
        "server": 8303
      }
    }
    ----------------------------------------------------------------

    docker 启动consul

     docker run -d -h master -v /mnt:/data -p $ip:8300:8300 -p $ip:8301:8301 -p $ip:8301:8301/udp -p $ip:8302:8302 -p $ip:8302:8302/udp -p $ip:8400:8400 -p 8500:8500 consul:0.7.1  agent -server -client=0.0.0.0 -bootstrap -ui

    本地 consul

    consul  agent -server -client=0.0.0.0 -bootstrap -ui -data-dir=/tmp/consul -advertise=192.168.111.111



  • 相关阅读:
    Django其五
    数据库操作
    小程序navigateBack,子页面传值给父页面
    深拷贝
    sql语句case when 以及left()
    IE高级配置中,存在SSL支持协议,例如SSL TLS。
    linux服务器后台运行服务
    各种浏览器文件下载
    localStorage sessionStorage 用法
    url编码乱码问题解决
  • 原文地址:https://www.cnblogs.com/mhc-fly/p/6918005.html
Copyright © 2020-2023  润新知