Introduction to principle and use of consul

Source: Internet
Author: User
Tags curl zookeeper etcd brew cask macbook
Description

This paper introduces a service discovery and configuration sharing software, briefly introduces the principle and use of consul, a small text, hoping to attract interested children's shoes together to explore research. What's consul?

Consul is a service software that supports distributed and highly available service discovery and configuration sharing in multiple data centers, developed by Hashicorp company in Go language, and is open source based on Mozilla Public License 2.0 protocol. Consul supports health checks and allows the HTTP and DNS protocol invoke APIs to store key-value pairs.
Command line super-handy virtual machine management software Vgrant is also a product developed by Hashicorp Company.
The consistency protocol uses the RAFT algorithm to guarantee the high availability of the service. Use the gossip protocol to manage members and broadcast messages, and to support ACL access control. Consul Usage Scenario Docker instance registration and configuration sharing CoreOS instance registration and configuration sharing vitess cluster SaaS application configuration sharing and CONFD service integration, dynamically generating nginx and Haproxy profiles consul is that the Raft algorithm is used to ensure consistency, which is more direct than the complex Paxos algorithm. In contrast, Zookeeper uses Paxos, and ETCD uses Raft. Support for multiple data centers, internal and external network services using different ports for monitoring. Multi-data center cluster can avoid single point of failure of single data center, and its deployment needs to consider network delay, fragmentation and so on. Both zookeeper and ETCD do not provide support for multiple data center features. Support for health checks. ETCD does not provide this functionality. Supports HTTP and DNS protocol interfaces. Zookeeper integration is more complex, ETCD only supports HTTP protocol. The Web admin interface is provided by the authorities, Etcd without this function.

Comprehensive comparison, consul as a new star of service registration and configuration management, is worthy of concern and research. the role of consul

Client: Clients, stateless, forwarding HTTP and DNS interface requests to server-side clusters within the LAN.
Server: Servers, save configuration information, highly available clusters, communicate with local clients over a LAN, and communicate with other data centers over a wide area network. The number of servers per data center is recommended as 3 or 5.

Install Consul

Mac OS X:

Brew Cask Install consul

Linux 64bit:

wget https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip
unzip 0.4.1_linux_amd64.zip
sudo mv Consul/bin

For additional system installation procedures, please refer to the official website documentation. Initial Experience

Start:
Consul Agent-server-bootstrap-expect 1-data-dir/tmp/consul-node LITAO-MACBOOK-PRO-DC sz-1

View Members:

Consul members

To view nodes:

Curl 127.0.0.1:8500/v1/catalog/nodes

To view node information using the DNS protocol:

Dig @127.0.0.1-p 8600 Litao-macbook-pro.node.consul Registration Service

Register two instances of Mysql service, data center in Sz-1, Port is 3306. The following commands are specified:

Curl-x put-d ' {"Datacenter": "Sz-1", "Node": "Mysql-1", "address": \
"Mysql-1.node.consul", "service": {"Service": " MySQL "," tags ": [" Master "," v1 "], \
" Port ": 3306}} ' http://127.0.0.1:8500/v1/catalog/register
curl-x put-d ' Datacenter ":" Sz-1 "," Node ":" Mysql-2 "," address ": \
" Mysql-2.node.consul "," service ": {" service ":" MySQL "," tags ": ["Slave", "v1"],\
"Port": 3306}} ' Http://127.0.0.1:8500/v1/catalog/register

Curl Http://127.0.0.1:8500/v1/catalog/service/mysql

["Address
        ": "Mysql-1.node.consul",
        "node": "Mysql-1",
        "Serviceid": "MySQL",
        "ServiceName": "MySQL",
        "Serviceport": 3306,
        "servicetags": [
            "Master",
            "v1"
        ]
    },
    {
        "address ":" Mysql-2.node.consul ","
        Node ":" Mysql-2 ",
        " Serviceid ":" MySQL ",
        " ServiceName ":" MySQL ",
        " Serviceport ": 3306,
        " servicetags ": [
            " Slave ",
            " v1 "
        ]
    }
]

Dig @127.0.0.1-p 8600 Mysql.service.consul SRV

; <<>> DiG 9.10.0-p2 <<>> @127.0.0.1-p 8600 Mysql.service.consul SRV
; (1 server found)
;; Global options: +cmd
; Got answer:;
;->>header<<-opcode:query, Status:noerror, id:12821
;; flags:qr AA Rd; Query:1, Answer:2, authority:0, Additional:2
; Warning:recursion requested but not available

;; Question section:
; mysql.service.consul.    In  SRV

;; ANSWER:
mysql.service.consul. 0 in  SRV 1 1 3306 mysql-2.node.sz-1.consul.
Mysql.service.consul. 0 in  SRV 1 1 3306 mysql-1.node.sz-1.consul.;;

ADDITIONAL:
mysql-2.node.sz-1.consul. 0 in  CNAME mysql-2.node.consul.
Mysql-1.node.sz-1.consul. 0 in  CNAME mysql-1.node.consul.;;

Query time:0 msec
;; server:127.0.0.1#8600 (127.0.0.1)
; When:tue Dec 16:42:38 CST 2014
;; MSG SIZE  rcvd:280
Reference Links

Https://www.consul.io
http://txt.fliglio.com/2014/05/encapsulated-services-with-consul-and-confd/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.