consul

阳光岛主 2017-04-21

root@ubuntu:/home/nescafe/temp# cp consul /usr/bin

root@ubuntu:/home/nescafe/temp# consul -v

Consul v0.8.1

Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

root@ubuntu:/home/nescafe/temp# consul agent -dev

root@ubuntu:/home/nescafe# consul members

Node    Address         Status  Type    Build  Protocol  DC

ubuntu  127.0.0.1:8301  alive   server  0.8.1  2         dc1

root@ubuntu:/home/nescafe# sudo apt-get update

root@ubuntu:/home/nescafe/temp# sudo apt-get install virtualbox-5.1

root@ubuntu:/home/nescafe/temp# apt-get -f install

root@ubuntu:/home/nescafe/temp# apt install curl

root@ubuntu:/home/nescafe# curl localhost:8500/v1/catalog/nodes

root@ubuntu:/home/nescafe/temp# curl localhost:8500/v1/catalog/nodes

[

    {

        "ID": "fcde1a12-724a-b4b4-44b7-05fbb684bbac",

        "Node": "ubuntu",

        "Address": "127.0.0.1",

        "TaggedAddresses": {

            "lan": "127.0.0.1",

            "wan": "127.0.0.1"

        },

        "Meta": {},

        "CreateIndex": 5,

        "ModifyIndex": 6

    }

]

root@ubuntu:/home/nescafe/temp# dig @127.0.0.1 -p 8600 Armons-MacBook-Air.node.consul

; <<>> DiG 9.10.3-P4-Ubuntu <<>> @127.0.0.1 -p 8600 Armons-MacBook-Air.node.consul

; (1 server found)

#停止服务

ctrl+z

root@ubuntu:/home/nescafe/temp# mkdir /etc/consul.d

root@ubuntu:/home/nescafe/temp# echo '{"service": {"name": "web", "tags": ["rails"], "port": 80}}' \

>     | sudo tee /etc/consul.d/web.json

{"service": {"name": "web", "tags": ["rails"], "port": 80}}

root@ubuntu:/home/nescafe/temp# consul agent -dev -config-dir=/etc/consul.d

#curl 7.53.1 for Windows

https://winampplugins.co.uk/curl/

nescafe@ubuntu:~$ curl http://localhost:8500/v1/catalog/service/web

[

    {

        "ID": "fcde1a12-724a-b4b4-44b7-05fbb684bbac",

        "Node": "ubuntu",

        "Address": "127.0.0.1",

        "TaggedAddresses": {

            "lan": "127.0.0.1",

            "wan": "127.0.0.1"

        },

        "NodeMeta": {},

        "ServiceID": "web",

        "ServiceName": "web",

        "ServiceTags": [

            "rails"

        ],

        "ServiceAddress": "",

        "ServicePort": 80,

        "ServiceEnableTagOverride": false,

        "CreateIndex": 7,

        "ModifyIndex": 7

    }

]

nescafe@ubuntu:~$ curl 'http://localhost:8500/v1/health/service/web?passing'

[

    {

        "Node": {

            "ID": "fcde1a12-724a-b4b4-44b7-05fbb684bbac",

            "Node": "ubuntu",

            "Address": "127.0.0.1",

            "TaggedAddresses": {

                "lan": "127.0.0.1",

                "wan": "127.0.0.1"

            },

            "Meta": {},

            "CreateIndex": 5,

            "ModifyIndex": 6

        },

        "Service": {

            "ID": "web",

            "Service": "web",

            "Tags": [

                "rails"

            ],

            "Address": "",

            "Port": 80,

            "EnableTagOverride": false,

            "CreateIndex": 7,

            "ModifyIndex": 7

        },

        "Checks": [

            {

                "Node": "ubuntu",

                "CheckID": "serfHealth",

                "Name": "Serf Health Status",

                "Status": "passing",

                "Notes": "",

                "Output": "Agent alive and reachable",

                "ServiceID": "",

                "ServiceName": "",

                "CreateIndex": 5,

                "ModifyIndex": 5

            }

        ]

    }

]

root@ubuntu:/home/nescafe# consul agent -ui

https://demo.consul.io/ui/

相关推荐