Service discovery for Mesos tasks with Registrator and consul

Source: Internet
Author: User
Tags mesosphere docker run

Purpose of implementation:

Because the actual working node in Mesos is slave, the task (container) that the framework marathon initiates is executed on a random slave, so slave is started on each registrator to discover the containers on this machine. It automatically registers the container on the current host to consul. But consul find a salve to start the line, it will be selected as leader, the other slave on the start of Registrator when you specify this leader on the line

Environment:

192.168.0.149 Mesos-master, Zookeeper
192.168.0.161 Mesos-master, Zookeeper, Marathon
192.168.0.174 Mesos-master, Zookeeper
192.168.0.239 Mesos-slave, Consul-server, Registrator
192.168.0.236 Mesos-slave, Registrator

Deployment:

Define IP

host_ip_1=192.168.0.149host_ip_2=192.168.0.161host_ip_3=192.168.0.174

192.168.0.149

Start Zookeeper

[[email protected] ~]# Docker run-d--net= "host"-E server_id=1-e Additional_zookeeper_1=server.1=${host_ip_1} : 2888:3888-e additional_zookeeper_2=server.2=${host_ip_2}:2888:3888-e Additional_zookeeper_3=server.3=${host_ip_ 3}:2888:3888 Garland/zookeeper

Start Mesos-master

[[email protected] ~]# Docker run--net= "host"-P 5050:5050-E "Mesos_hostname=${host_ip_1}"-E "mesos_ip=${host_ip_1}" -E "Mesos_zk=zk://${host_ip_1}:2181,${host_ip_2}:2181,${host_ip_3}:2181/mesos"-E "mesos_port=5050"-E "MESOS_LOG_ Dir=/var/log/mesos "-E" mesos_quorum=2 "-E" mesos_registry=in_memory "-E" Mesos_work_dir=/var/lib/mesos "-D garland/me Sosphere-docker-mesos-master

192.168.0.161

Start Zookeeper

[email protected] ~]# Docker run-d--net= "host"-E server_id=2-e additional_zookeeper_1=server.1=${host_ip_1}:2888: 3888-e additional_zookeeper_2=server.2=${host_ip_2}:2888:3888-e Additional_zookeeper_3=server.3=${host_ip_3} : 2888:3888 Garland/zookeeper

Start Mesos-master

[[email protected] ~]# Docker run--net= "host"-P 5050:5050-E "mesos_hostname=${host_ip_2}"-E "mesos_ip=${host_ip_2} "-E" Mesos_zk=zk://${host_ip_1}:2181,${host_ip_2}:2181,${host_ip_3}:2181/mesos "-E" mesos_port=5050 "-E" MESOS_LOG_ Dir=/var/log/mesos "-E" mesos_quorum=2 "-E" mesos_registry=in_memory "-E" Mesos_work_dir=/var/lib/mesos "-D garland/me Sosphere-docker-mesos-master

Start Marathon

[email protected] ~]# Docker run-d-P 8080:8080 mesosphere/marathonv0.14.0--master zk://${host_ip_1}:2181,${host_ip _2}:2181,${host_ip_3}:2181/mesos--zk Zk://${host_ip_1}:2181,${host_ip_2}:2181,${host_ip_3}:2181/marathon

192.168.0.174

Start Zookeeper

[email protected] ~]# Docker run-d--net= "host"-E server_id=3-e additional_zookeeper_1=server.1=${host_ip_1}:2888: 3888-e additional_zookeeper_2=server.2=${host_ip_2}:2888:3888-e Additional_zookeeper_3=server.3=${host_ip_3} : 2888:3888 Garland/zookeeper

Start Mesos-master

[[email protected] ~]# Docker run--net= "host"-P 5050:5050-E "Mesos_hostname=${host_ip_3}"-E "mesos_ip=${host_ip_3} "-E" Mesos_zk=zk://${host_ip_1}:2181,${host_ip_2}:2181,${host_ip_3}:2181/mesos "-E" mesos_port=5050 "-E" MESOS_LOG_ Dir=/var/log/mesos "-E" mesos_quorum=2 "-E" mesos_registry=in_memory "-E" Mesos_work_dir=/var/lib/mesos "-D garland/me Sosphere-docker-mesos-master

192.168.0.239

Installing Mesos-slave

Install mesosphere source [[email protected] ~]# rpm-ivh/mesosphere-el-repo-7-1.noarch.rpm install mesos[[email protected] ~]# yum-y Install Mesos configuration Mesos[[email protected] ~]# echo Zk://192.168.0.149:2181,192.168.0.161:2181,192.168.0.174:2181/mesos >/etc/mesos/zk[[email protected] ~]# echo 192.168.0.239 | sudo tee/etc/mesos-slave/hostname[[email protected] ~]# echo ' Docker,mesos ' >/etc/mesos-slave/containerizers Start Mesos-slave[[email protected] ~]# systemctl start mesos-slave && systemctl enable Mesos-slave[[email Protect ED] ~]# systemctl Disable Mesos-master

Start Consul-server

[email protected] ~]# Docker run-d--name=consul--net=host gliderlabs/consul-server-bootstrap-bind=192.168.0.239

Note: A node starts on the line, it will choose itself as leader

Test Consul-server

[[email protected] ~]# Curl 192.168.0.239:8500/v1/catalog/services{"Consul": []}

Note: can also be accessed by the browser: http://192.168.0.239:8500/ui/

Start Registrator

[[email protected] ~]# docker run-d--name=registrator \--net=host \--volume=/var/run/docker.sock:/tmp/docker . sock \ Gliderlabs/registrator:latest consul://192.168.0.239:8500

Test whether the Registrator is in conjunction with Consul to automatically register the service inside and start a Redis container test

[[email protected] ~]# Docker run-d-P--name=redis redis[[email protected] ~]# Curl 192.168.0.239:8500/v1/catalog/servic Es{"Consul": [], "Redis": []}

Consul now has a service called Redis, we can see more about this service, such as Port, IP

[[email protected] ~]# Curl $ (boot2docker IP): 8500/v1/catalog/service/redis[{"Node": "Boot2docker", "Address": " 10.0.2.15 "," ServiceID ":" boot2docker:redis:6379 "," ServiceName ":" Redis "," servicetags ": null," serviceaddress ":" "," Serviceport ": 32768}]

All slave container registration information can be seen in the consul

650) this.width=650, "src=" Http://s2.51cto.com/wyfs02/M02/7E/44/wKioL1b7WefRHu-yAACDvhkeDvI099.png "title=" ~] @I4 ~~1xc4hjj@ (4hzxtq.png "alt=" Wkiol1b7wefrhu-yaacdvhkedvi099.png "/>

You can also use the DNS API to test

[[email protected] ~]# dig @127.0.0.1 -p 8600 redis.service.consul;  <<>> DiG 9.9.4-RedHat-9.9.4-18.el7 <<>> @127.0.0.1 -p  8600 redis.service.consul;  (1 server found);  global options: +cmd;;  Got answer:;;  ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 937;;  flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0,  additional: 0;;  WARNING: recursion requested but not available;;  QUESTION SECTION:;redis.service.consul.INA;;  ANSWER SECTION:redis.service.consul.0INA192.168.0.239;;  Query time: 1 msec;;  server: 127.0.0.1#8600 (127.0.0.1);  WHEN: Wed Mar 30 12:43:34 CST 2016;;  msg size  rcvd: 74


Reference article:

Https://github.com/sekka1/mesosphere-docker

http://gliderlabs.com/registrator/latest/user/quickstart/


This article is from the "Ming Linux blog" blog, be sure to keep this source http://zhaijunming5.blog.51cto.com/10668883/1758353

Service discovery for Mesos tasks with Registrator and consul

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.