微服務實踐——Docker與服務發現

MireyaKirkw 8年前發布 | 37K 次閱讀 Docker Web服務器 MongoDB

Docker Java App Load Balanced By Nginx Or Apache HTTP, Mongo Replica Set And Hazelcast Cluster

背景

為了發揮Docker在跨多個服務器的分布式應用程序的部署(甚至是跨區域)的能力,人們不應該限制哪些服務進到哪個服務器。動態可擴展性(或自動縮放)的關鍵環境的要求(如生產環境)不只是適用于新的微服務架構設計。也適用于典型的單片應用程序的部署。如果這些服務綁定在特定的服務器上,那么這些程序的未來的可擴展性是很困難的。

為了能夠實現服務發現,我們需要滿足以下條件:

  • Service registration  在服務器上保存這些正在運行服務的端口。
  • Service discovery  實現發現我們在服務器保存在注冊過程中的信息

我們還要實現強的服務,以滿足企業級對服務發現的要求。包括以下這些問題:

  • 我們如何注銷停止工作的服務?
  • 我們如何對這些”發現了的”服務實施負載均衡?
  • 如果服務在橫向擴展或者縮放的過程中被刪除了怎么辦?

大多數典型的服務發現工具擁有某種高度可用的分布式(key/value)存儲,大家可以參考閱讀這篇博客 http://technologyconversations.com/2015/09/08/service-discovery-zookeeper-vs-etcd-vs-consul/

這些工具的主要缺點是他們自己在容器中運行對第三方工具的依賴。為了使用Consul,打個比方。一個用戶需要在程序中使用Consul 和Registrator 容器-這一定會使容器的數量增加。那么用戶就需要管理這些容器。

DCHQ,從另一方面說。如果使用代理來協調服務注冊和服務發現。把信息存儲在底層DCHQ數據庫。這意味著我們不需要附加的容器。另外,服務發現框架,允許用戶自定義某些事件需要被執行的同時,利用的不只是IP和應用程序中的其他容器的主機名的信息提供了更大的靈活性。在部署的時候使用的也是環境變量的值。

這并不等于說服務發現框架使用DHCQ就能完全替代其它工具,最好的工具還是能夠滿足業務的需求。

在這篇blog中,我們將介紹使用Docker部署3個服務發現的程序,包括: Nginx & Apache HTTP Server load balancing , Mongo Replica Set and Hazelcast Cluster .

包括以下內容:

  • 構建能夠在任意Linux 主機上面運行的YAML-based 程序模板
  • 在任何云基礎架構上的配置和自動擴展(本文我們以Microsoft Azure為例)
  • 在Microsoft Azure集群部署分布式,高可用性應用程序
  • 監控運行容器的 CPU, Memory & I/O
  • Tomacat 應用服務集群擴展
  • MongoDB的分片服務擴展
  • Hazelcast 集群擴展

構建能夠在任意Linux 主機上面運行的YAML-based 程序模板

用戶一旦登錄到DCHQ (either the hosted DCHQ.io or on-premise version),用戶可以導航到 Manage > App/Machine,然后可以點擊 +創建新的 Docker Compose模板

我們使用 Docker Hub官方鏡像創建了5  個程序的模板

這些模板包括了一下程序棧:

  • Multi-Tier Java Application with Nginx, Tomcat, Solr and Mongo — using Consul and Registrator for service discovery
  • Multi-Tier Java Application with Nginx, Tomcat, Solr and Mongo — using DCHQ’s service discovery framework
  • Multi-Tier Java Application with Apache HTTP Server, Tomcat, Solr, and Cassandra) — using DCHQ’s service discovery framework
  • Mongo Replica Set — using DCHQ’s service discovery framework
  • Hazelcast Cluster — using DCHQ’s service discovery framework

更多關于Docker application modeling in DCHQ的資料可以訪問: http://dchq.co/docker-compose.html

更多關于Docker service discovery in DCHQ的資料可以訪問: http://dchq.co/docker-service-discovery.html

Request Time & Post-Provision 的Web Servers 和 Application Servers配置插件

通過這些程序的模板,你會發現一些容器為了配置容器會調用Bash腳本插件。這些腳本對post-provision操作執行的非常好。

這些插件可以在 Manage > Plug-ins導航中創建,一旦這些腳本啟動是,DHCQ代理服務會執行這些容器里面的腳本。用戶可以指定一個能被在請求之后被覆蓋的參數。在$符號之前的都可以被成為參數,比如: $file_url 可以是一個參數,它允許開發者指定的網址下載一個WAR文件,還可以在當用戶希望更新運行在容器上例如Java WAR文件請求時間和后規定被覆蓋:

該插件ID需要在定義YAML應用程序模板時候提供,例如:調用Nginxbash腳本插件。我們可以參照下面的plug-in ID:

Nginx:
  image: nginx:latest
  publish_all: true
  mem_min: 50m
  host: host1
  plugins:
    - !plugin
      id: 0H1Nk
      restart: true
      lifecycle: on_create, post_scale_out:AppServer, post_scale_in:AppServer, post_stop:AppServer, post_start:AppServer
      arguments:
        # Use container_private_ip if you're using Docker networking
        - servers=server {{AppServer | container_private_ip}}:8080;
        # Use container_hostname if you're using Weave networking
        #- servers=server {{AppServer | container_hostname}}:8080;
Nginx:
  image: nginx:latest
  publish_all: true
  mem_min: 50m
  host: host1
  plugins:
    - !plugin
      id: 0H1Nk
      restart: true
      lifecycle: on_create, post_scale_out:AppServer, post_scale_in:AppServer, post_stop:AppServer, post_start:AppServer
      arguments:
        # Use container_private_ip if you're using Docker networking
        - servers=server {{AppServer | container_private_ip}}:8080;
        # Use container_hostname if you're using Weave networking
        #- servers=server {{AppServer | container_hostname}}:8080;

你會發現,同樣的Nginx插件,在不同的階段得到了執行。

  • 當 Nginx 容器 創建的時候  — 在這種情況下, 應用程序的容器IP會被注入到默認配置文件下面。以便實現服務的負載均衡。
  • 當應用程序服務集群需要縮放或者擴展的時候 — 在這種情況下, 更新后應用程序容器的IP地址會被注入到默認的配置文件中,以便更好的實現負載均衡。
  • 當應用程序停止或者啟動時— 在這種情況下,更新后應用程序容器的IP地址會被注入到默認的配置文件中,以便更好的實現負載均衡。

然而這里的服務發現框架同時做著服務發現和服務注冊的事情。

服務發現插件的生命周期

  • on_create — executes the plug-in when creating the container
  • on_start — executes the plug-in after a container starts
  • on_stop — executes the plug-in before a container stops
  • on_destroy — executes the plug-in before destroying a container
  • post_create — executes the plug-in after the container is created and running
  • post_start[:Node] — executes the plug-in after another container starts
  • post_stop[:Node] — executes the plug-in after another container stops
  • post_destroy[:Node] — executes the plug-in after another container is destroyed
  • post_scale_out[:Node] — executes the plug-in after another cluster of containers is scaled out
  • post_scale_in[:Node] — executes the plug-in after another cluster of containers is scaled in

要訪問Nginx, Apache HTTP Server (httpd), Mongo Replica Set, and Hazelcast Cluster需要遵循EULA許可。

配置部署在多臺主機HA的cluster_size與host 參數

  • host1, host2, host3 , etc. – selects a host randomly within a data-center (or cluster) for container deployments
  • IP Address 1, IP Address 2, etc. — allows a user to specify the actual IP addresses to use for container deployments
  • Hostname 1, Hostname 2, etc. — allows a user to specify the actual hostnames to use for container deployments
  • Wildcards (e.g. “db- ”, or “app-srv- ”) – to specify the wildcards to use within a hostname

通過鏡像綁定環境變量

  • {{alphanumeric | 8}} – creates a random 8-character alphanumeric string. This is most useful for creating random passwords.
  • {{Image Name | ip}} – allows you to enter the host IP address of a container as a value for an environment variable. This is most useful for allowing the middleware tier to establish a connection with the database.
  • {{Image Name | container_ip}} – allows you to enter the name of a container as a value for an environment variable. This is most useful for allowing the middleware tier to establish a secure connection with the database (without exposing the database port).
  • {{Image Name | container_private_ip}} – allows you to enter the internal IP of a container as a value for an environment variable. This is most useful for allowing the middleware tier to establish a secure connection with the database (without exposing the database port).
  • {{Image Name | port_Port Number}} – allows you to enter the Port number of a container as a value for an environment variable. This is most useful for allowing the middleware tier to establish a connection with the database. In this case, the port number specified needs to be the internal port number – i.e. not the external port that is allocated to the container. For example, {{PostgreSQL | port_5432}} will be translated to the actual external port that will allow the middleware tier to establish a connection with the database.
  • {{Image Name | Environment Variable Name}} – allows you to enter the value an image’s environment variable into another image’s environment variable. The use cases here are endless – as most multi-tier applications will have cross-image dependencies.

構建 Nginx Docker 鏡像的 Consul

  • Git URLhttps://github.com/dchqinc/nginx-consul.git
  • Git Branch – this field is optional — but a user can specify a branch from a GitHub project. The default branch is master.
  • Git Credentials – a user can store the credentials to a private GitHub repository securely in DCHQ. This can be done by navigating to Manage > Cloud Providers and Repos and clicking on the + to select Credentials
  • Cluster – the building of Docker images is orchestrated through the DCHQ agent. As a result, a user needs to select a cluster on which an agent will be used to execute the building of Docker images. If a cluster has not been created yet, please refer to this section to either register already running hosts or automate the provisioning of new virtual infrastructure.
  • Push to Registry – a user can push the newly created image on either a public or private repository on Docker Hub or Quay. To register a Docker Hub or Quay account, a user should navigate to Manage > Cloud Providers and clicking on the + to select Docker Registries
  • Repository – this is the name of the repository on which the image will be pushed. For example, our image was pushed to dchq/nginx-consul:latest
  • Tag – this is the tag name that you would like to give for the new image. The supported tag names in DCHQ include:
    • {{date}} — formatted date
    • {{timestamp}} — the full time-stamp
  • Cron Expression – a user can schedule the building of Docker images using out-of-box cron expressions. This facilitates daily and nightly builds for users.

Multi-Tier Java (Consul-Nginx-Tomcat-Solr-Mongo)

Nginx:
  image: dchq/nginx-consul:latest
  publish_all: true
  mem_min: 50m
  host: host1
  plugins:
    - !plugin
      id: GINmu
      restart: true
      lifecycle: on_create
      arguments:
        - APPSERVER_IP={{AppServer | container_private_ip}}
        - SERVICE_NAME={{AppServer | SERVICE_NAME}}
        - SERVICE_TAGS={{AppServer | SERVICE_TAGS}}
        - CONSUL_IP={{Consul | container_private_ip}}

AppServer:
  image: tomcat:8.0.21-jre8
  mem_min: 600m
  host: host1
  cluster_size: 1
  environment:
    - mongo_url={{Mongo|container_private_ip}}:27017/dchq
    - solr_host={{Solr|container_private_ip}}
    - solr_port=8983
    - SERVICE_NAME=app
    - SERVICE_TAGS=production
  plugins:
    - !plugin
      id: oncXN
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/dbconnect.war
        - dir=/usr/local/tomcat/webapps/ROOT.war
        - delete_dir=/usr/local/tomcat/webapps/ROOT
Consul:
  image: progrium/consul:latest
  host: host1
  ports:
    - "8300:8300"
    - "8400:8400"
    - "8500:8500"
    - "8600:53/udp"  
  command: -server -bootstrap -advertise 10.0.2.15

Registrator:
  image: gliderlabs/registrator:latest
  host: host1
  command: consul://<HOST_IP>:8500
  volumes:
    - "/var/run/docker.sock:/tmp/docker.sock"

Solr:
  image: solr:latest
  mem_min: 300m
  host: host1
  publish_all: false
  plugins:
    - !plugin
      id: doX8s
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/names.zip
Mongo:
  image: mongo:latest
  host: host1
  mem_min: 400m
Nginx:
  image: dchq/nginx-consul:latest
  publish_all: true
  mem_min: 50m
  host: host1
  plugins:
    - !plugin
      id: GINmu
      restart: true
      lifecycle: on_create
      arguments:
        - APPSERVER_IP={{AppServer | container_private_ip}}
        - SERVICE_NAME={{AppServer | SERVICE_NAME}}
        - SERVICE_TAGS={{AppServer | SERVICE_TAGS}}
        - CONSUL_IP={{Consul | container_private_ip}}
 
AppServer:
  image: tomcat:8.0.21-jre8
  mem_min: 600m
  host: host1
  cluster_size: 1
  environment:
    - mongo_url={{Mongo|container_private_ip}}:27017/dchq
    - solr_host={{Solr|container_private_ip}}
    - solr_port=8983
    - SERVICE_NAME=app
    - SERVICE_TAGS=production
  plugins:
    - !plugin
      id: oncXN
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/dbconnect.war
        - dir=/usr/local/tomcat/webapps/ROOT.war
        - delete_dir=/usr/local/tomcat/webapps/ROOT
Consul:
  image: progrium/consul:latest
  host: host1
  ports:
    - "8300:8300"
    - "8400:8400"
    - "8500:8500"
    - "8600:53/udp"  
  command: -server -bootstrap -advertise 10.0.2.15
 
Registrator:
  image: gliderlabs/registrator:latest
  host: host1
  command: consul://<HOST_IP>:8500
  volumes:
    - "/var/run/docker.sock:/tmp/docker.sock"
 
Solr:
  image: solr:latest
  mem_min: 300m
  host: host1
  publish_all: false
  plugins:
    - !plugin
      id: doX8s
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/names.zip
Mongo:
  image: mongo:latest
  host: host1
  mem_min: 400m

Multi-Tier Java (ApacheLB-Tomcat-Solr-Mongo)

HTTP-LB:
  image: httpd:latest
  publish_all: true
  mem_min: 50m
  host: host1
  plugins:
    - !plugin
      id: uazUi
      restart: true
      lifecycle: on_create, post_scale_out:AppServer, post_scale_in:AppServer
      arguments:
        # Use container_private_ip if you're using Docker networking
        - BalancerMembers=BalancerMember http://{{AppServer | container_private_ip}}:8080
        # Use container_hostname if you're using Weave networking
        #- BalancerMembers=BalancerMember http://{{AppServer | container_hostname}}:8080
AppServer:
  image: tomcat:8.0.21-jre8
  mem_min: 600m
  host: host1
  cluster_size: 1
  environment:
    - mongo_url={{Mongo|container_private_ip}}:27017/dchq
    - solr_host={{Solr|container_private_ip}}
    - solr_port=8983
  plugins:
    - !plugin
      id: oncXN
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/dbconnect.war
        - dir=/usr/local/tomcat/webapps/ROOT.war
        - delete_dir=/usr/local/tomcat/webapps/ROOT
Solr:
  image: solr:latest
  mem_min: 300m
  host: host1
  publish_all: false
  plugins:
    - !plugin
      id: doX8s
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/names.zip
Mongo:
  image: mongo:latest
  host: host1
  mem_min: 400m
HTTP-LB:
  image: httpd:latest
  publish_all: true
  mem_min: 50m
  host: host1
  plugins:
    - !plugin
      id: uazUi
      restart: true
      lifecycle: on_create, post_scale_out:AppServer, post_scale_in:AppServer
      arguments:
        # Use container_private_ip if you're using Docker networking
        - BalancerMembers=BalancerMemberhttp://{{AppServer | container_private_ip}}:8080
        # Use container_hostname if you're using Weave networking
        #- BalancerMembers=BalancerMember http://{{AppServer | container_hostname}}:8080
AppServer:
  image: tomcat:8.0.21-jre8
  mem_min: 600m
  host: host1
  cluster_size: 1
  environment:
    - mongo_url={{Mongo|container_private_ip}}:27017/dchq
    - solr_host={{Solr|container_private_ip}}
    - solr_port=8983
  plugins:
    - !plugin
      id: oncXN
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/dbconnect.war
        - dir=/usr/local/tomcat/webapps/ROOT.war
        - delete_dir=/usr/local/tomcat/webapps/ROOT
Solr:
  image: solr:latest
  mem_min: 300m
  host: host1
  publish_all: false
  plugins:
    - !plugin
      id: doX8s
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/names.zip
Mongo:
  image: mongo:latest
  host: host1
  mem_min: 400m

Multi-Tier Java (Nginx-Tomcat-Solr-MySQL)

Nginx:
  image: nginx:latest
  publish_all: true
  mem_min: 50m
  host: host1
  plugins:
    - !plugin
      id: 0H1Nk
      restart: true
      lifecycle: on_create, post_scale_out:AppServer, post_scale_in:AppServer
      arguments:
        # Use container_private_ip if you're using Docker networking
        - servers=server {{AppServer | container_private_ip}}:8080;
        # Use container_hostname if you're using Weave networking
        #- servers=server {{AppServer | container_hostname}}:8080;
AppServer:
  image: tomcat:8.0.21-jre8
  mem_min: 600m
  host: host1
  cluster_size: 1
  environment:
    - database_driverClassName=com.mysql.jdbc.Driver
    - database_url=jdbc:mysql://{{MySQL|container_hostname}}:3306/{{MySQL|MYSQL_DATABASE}}
    - database_username={{MySQL|MYSQL_USER}}
    - database_password={{MySQL|MYSQL_ROOT_PASSWORD}}
    - solr_host={{Solr|container_private_ip}}
    - solr_port=8983
  plugins:
    - !plugin
      id: oncXN
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/dbconnect.war
        - dir=/usr/local/tomcat/webapps/ROOT.war
        - delete_dir=/usr/local/tomcat/webapps/ROOT
Solr:
  image: solr:latest
  mem_min: 300m
  host: host1
  publish_all: false
  plugins:
    - !plugin
      id: doX8s
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/names.zip
MySQL:
  image: mysql:latest
  host: host1
  mem_min: 400m
  environment:
    - MYSQL_USER=root
    - MYSQL_DATABASE=names
    - MYSQL_ROOT_PASSWORD={{alphanumeric|8}}
Nginx:
  image: nginx:latest
  publish_all: true
  mem_min: 50m
  host: host1
  plugins:
    - !plugin
      id: 0H1Nk
      restart: true
      lifecycle: on_create, post_scale_out:AppServer, post_scale_in:AppServer
      arguments:
        # Use container_private_ip if you're using Docker networking
        - servers=server {{AppServer | container_private_ip}}:8080;
        # Use container_hostname if you're using Weave networking
        #- servers=server {{AppServer | container_hostname}}:8080;
AppServer:
  image: tomcat:8.0.21-jre8
  mem_min: 600m
  host: host1
  cluster_size: 1
  environment:
    - database_driverClassName=com.mysql.jdbc.Driver
    - database_url=jdbc:mysql://{{MySQL|container_hostname}}:3306/{{MySQL|MYSQL_DATABASE}}
    - database_username={{MySQL|MYSQL_USER}}
    - database_password={{MySQL|MYSQL_ROOT_PASSWORD}}
    - solr_host={{Solr|container_private_ip}}
    - solr_port=8983
  plugins:
    - !plugin
      id: oncXN
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/dbconnect.war
        - dir=/usr/local/tomcat/webapps/ROOT.war
        - delete_dir=/usr/local/tomcat/webapps/ROOT
Solr:
  image: solr:latest
  mem_min: 300m
  host: host1
  publish_all: false
  plugins:
    - !plugin
      id: doX8s
      restart: true
      arguments:
        - file_url=https://github.com/dchqinc/dchq-docker-java-solr-mongo-cassandra-example/raw/master/names.zip
MySQL:
  image: mysql:latest
  host: host1
  mem_min: 400m
  environment:
    - MYSQL_USER=root
    - MYSQL_DATABASE=names
    - MYSQL_ROOT_PASSWORD={{alphanumeric|8}}

Mongo Replica Set Cluster

mongo_rs1_srv1:
  image: mongo:latest
  mem_min: 400m
  publish_all: true
  command: --replSet rs1
  environment:
    # inject clustered node ips
    - MONGO_RS1_SRV2_IP={{mongo_rs1_srv2|container_private_ip}}
    # The above mapping will insert comma separated ip list e.g. 10.1.1.1,10.1.12
  plugins:
    - !plugin
      # This plugin initializes the Replica Set
      lifecycle: on_create
      id: QX25F
    - !plugin
      # This plug-in re-balances the Replica Set post scale out
      lifecycle: post_scale_out:mongo_rs1_srv2
      id: sxKM9
    - !plugin
      # This plug-in re-balances the Replica Set post scale in
      lifecycle: post_scale_in:mongo_rs1_srv2
      id: YIALH
# Define this node as clustered
mongo_rs1_srv2:
  image: mongo:latest
  mem_min: 400m
  cpu_shares: 1
  cluster_size: 2
  command: --replSet rs1
mongo_rs1_srv1:
  image: mongo:latest
  mem_min: 400m
  publish_all: true
  command: --replSetrs1
  environment:
    # inject clustered node ips
    - MONGO_RS1_SRV2_IP={{mongo_rs1_srv2|container_private_ip}}
    # The above mapping will insert comma separated ip list e.g. 10.1.1.1,10.1.12
  plugins:
    - !plugin
      # This plugin initializes the Replica Set
      lifecycle: on_create
      id: QX25F
    - !plugin
      # This plug-in re-balances the Replica Set post scale out
      lifecycle: post_scale_out:mongo_rs1_srv2
      id: sxKM9
    - !plugin
      # This plug-in re-balances the Replica Set post scale in
      lifecycle: post_scale_in:mongo_rs1_srv2
      id: YIALH
# Define this node as clustered
mongo_rs1_srv2:
  image: mongo:latest
  mem_min: 400m
  cpu_shares: 1
  cluster_size: 2
  command: --replSetrs1

Hazelcast Cluster

Hazelcast-Management-Center:
  image: hazelcast/management-center:latest
  # Use this configuration if deploying to a shared VM
  publish_all: true
  # (Recommended) Use this configuration if deploying to a dedicated VM
  #ports:
  #  - 8080:8080
  host: host1
  environment:
    - HAZELCAST_IP={{Hazelcast | container_private_ip}}
Hazelcast:
  image: hazelcast/hazelcast:latest
  # Use this configuration if deploying to a shared VM
  publish_all: true
  # (Recommended) Use this configuration if deploying to a dedicated VM
  #ports:
  #  - 5701:5701
  cluster_size: 1
  host: host1
  plugins:
    - !plugin
      id: Qgp4H
      lifecycle: post_create, post_scale_out:Hazelcast, post_scale_in:Hazelcast
      restart: true
      arguments:
        # Use this configuration if deploying to a shared VM
        - Hazelcast_IP=<member>{{Hazelcast | container_private_ip}}</member>
        # (Recommended) Use this configuration if deplying to a dedicated VM
        #- Hazelcast_IP=<member>{{Hazelcast | ip}}</member>
        - Management_Center_URL=http://{{Hazelcast-Management-Center | ip}}:{{Hazelcast-Management-Center | port_8080}}/mancenter
  environment:
    # Uncomment the line below to specify the heap size
    #- MIN_HEAP_SIZE="1g" 
    # Uncomment the line below to provide your own hazelcast.xml file
    - JAVA_OPTS=-Dhazelcast.config=/opt/hazelcast/hazelcast.xml
  volumes:
    # Uncomment the line below if you plan to use your own hazelcast.xml file
    #- ./configFolder:./configFolder
Hazelcast-Management-Center:
  image: hazelcast/management-center:latest
  # Use this configuration if deploying to a shared VM
  publish_all: true
  # (Recommended) Use this configuration if deploying to a dedicated VM
  #ports:
  #  - 8080:8080
  host: host1
  environment:
    - HAZELCAST_IP={{Hazelcast | container_private_ip}}
Hazelcast:
  image: hazelcast/hazelcast:latest
  # Use this configuration if deploying to a shared VM
  publish_all: true
  # (Recommended) Use this configuration if deploying to a dedicated VM
  #ports:
  #  - 5701:5701
  cluster_size: 1
  host: host1
  plugins:
    - !plugin
      id: Qgp4H
      lifecycle: post_create, post_scale_out:Hazelcast, post_scale_in:Hazelcast
      restart: true
      arguments:
        # Use this configuration if deploying to a shared VM
        - Hazelcast_IP=<member>{{Hazelcast | container_private_ip}}</member>
        # (Recommended) Use this configuration if deplying to a dedicated VM
        #- Hazelcast_IP=<member>{{Hazelcast | ip}}</member>
        - Management_Center_URL=http://{{Hazelcast-Management-Center | ip}}:{{Hazelcast-Management-Center | port_8080}}/mancenter
  environment:
    # Uncomment the line below to specify the heap size
    #- MIN_HEAP_SIZE="1g"
    # Uncomment the line below to provide your own hazelcast.xml file
    - JAVA_OPTS=-Dhazelcast.config=/opt/hazelcast/hazelcast.xml
  volumes:
    # Uncomment the line below if you plan to use your own hazelcast.xml file
    #- ./configFolder:./configFolder

實現Docker配置和自動擴展的基礎設施

一旦應用程序被保存,用戶可以注冊一個云服務提供商自動Docker集群的配置和自動縮放的功能。在不止18種云服務上,包括VMware vSphere, OpenStack, CloudStack, Amazon Web Services, Rackspace, Microsoft Azure, DigitalOcean, IBM SoftLayer, Google Compute Engine等

這里有一些主流云平臺的資料:

英文原文: https://www.voxxed.com/blog/2016/01/docker-service-discovery-microsoft-azure/?ref=dzone

微服務實踐——Docker與服務發現

來自: https://xiequan.info/在docker上運行微服務實踐/

 本文由用戶 MireyaKirkw 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!