日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

适用于具有Couchbase和WildFly的多容器和多主机应用程序的Docker Machine,Swarm和Compose...

發布時間:2023/12/3 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 适用于具有Couchbase和WildFly的多容器和多主机应用程序的Docker Machine,Swarm和Compose... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

該博客將說明如何使用Docker創建部署在多個主機上的多容器應用程序。 這將使用Docker Machine,Swarm和Compose實現。

是的,所有這三個工具一起使此博客更加有趣!

該圖說明了關鍵組件:

  • Docker Machine用于配置多個Docker主機
  • Docker Swarm將用于創建多主機集群
  • 使用Consul注冊/發現Docker Swarm集群中的每個節點
  • 多容器應用程序將使用Docker Compose進行部署
  • WildFly和Couchbase在不同的主機上配置
  • Docker多主機網絡用于WildFly和Couchbase進行通信

此外,Maven用于配置Couchbase并將應用程序部署到WildFly。

  • Docker上針對Java開發人員的最新說明。

沒有故事,只有純代碼,就去做吧!

使用Docker Machine創建發現服務

  • 創建將托管發現服務的計算機: docker-machine create -d=virtualbox consul-machine Running pre-create checks... Creating machine... Waiting for machine to be running, this may take a few minutes... Machine is running, waiting for SSH to be available... Detecting operating system of created instance... Provisioning created instance... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... To see how to connect Docker to this machine, run: docker-machine env consul-machine
  • 連接到此機器: eval $(docker-machine env consul-machine)
  • 使用以下Compose文件運行Consul服務: myconsul:image: progrium/consulrestart: alwayshostname: consulports:- 8500:8500command: "-server -bootstrap"

    可在https://github.com/arun-gupta/docker-images/blob/master/consul/docker-compose.yml上找到此Compose文件。

    docker-compose up -d Pulling myconsul (progrium/consul:latest)... latest: Pulling from progrium/consul 3b4d28ce80e4: Pull complete e5ab901dcf2d: Pull complete 30ad296c0ea0: Pull complete 3dba40dec256: Pull complete f2ef4387b95e: Pull complete 53bc8dcc4791: Pull complete 75ed0b50ba1d: Pull complete 17c3a7ed5521: Pull complete 8aca9e0ecf68: Pull complete 4d1828359d36: Pull complete 46ed7df7f742: Pull complete b5e8ce623ef8: Pull complete 049dca6ef253: Pull complete bdb608bc4555: Pull complete 8b3d489cfb73: Pull complete c74500bbce24: Pull complete 9f3e605442f6: Pull complete d9125e9e799b: Pull complete Digest: sha256:8cc8023462905929df9a79ff67ee435a36848ce7a10f18d6d0faba9306b97274 Status: Downloaded newer image for progrium/consul:latest Creating consul_myconsul_1

    啟動的容器可以驗證為:

    docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f05d8dd11e7f progrium/consul "/bin/start -server -" 30 seconds ago Up 29 seconds 53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 0.0.0.0:8500->8500/tcp, 8301-8302/udp consul_myconsul_1
  • 使用Docker Machine創建Docker Swarm集群

    Swarm與Machine完全集成在一起,因此是最簡單的入門方法。

  • 創建一個Swarm Master并指向Consul發現服務: docker-machine create -d virtualbox --virtualbox-disk-size "5000" --swarm --swarm-master --swarm-discovery="consul://$(docker-machine ip consul-machine):8500" --engine-opt="cluster-store=consul://$(docker-machine ip consul-machine):8500" --engine-opt="cluster-advertise=eth1:2376" swarm-master Running pre-create checks... Creating machine... Waiting for machine to be running, this may take a few minutes... Machine is running, waiting for SSH to be available... Detecting operating system of created instance... Provisioning created instance... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... Configuring swarm... To see how to connect Docker to this machine, run: docker-machine env swarm-master

    很少有選擇看這里:

  • --swarm使用Swarm配置機器
  • --swarm-master將創建的Machine配置為Swarm master
  • --swarm-discovery定義發現服務的地址
  • --cluster-advertise在網絡上播發計算機
  • --cluster-store指定集群的分布式k / v存儲后端
  • --virtualbox-disk-size將創建的計算機的磁盤--virtualbox-disk-size設置為5GB。 這是必需的,以便可以在任何節點上下載WildFly和Couchbase映像。
  • 查找有關此機器的一些信息: docker-machine inspect --format='{{json .Driver}}' swarm-master {"Boot2DockerImportVM":"","Boot2DockerURL":"","CPU":1,"DiskSize":5000,"HostOnlyCIDR":"192.168.99.1/24","HostOnlyNicType":"82540EM","HostOnlyPromiscMode":"deny","IPAddress":"192.168.99.102","MachineName":"swarm-master","Memory":1024,"NoShare":false,"SSHPort":51972,"SSHUser":"docker","StorePath":"/Users/arungupta/.docker/machine","SwarmDiscovery":"consul://192.168.99.100:8500","SwarmHost":"tcp://0.0.0.0:3376","SwarmMaster":true,"VBoxManager":{}}

    請注意,磁盤大小為5GB。

  • 使用以下命令連接到主服務器: eval "$(docker-machine env --swarm swarm-master)"
  • 查找有關集群的一些信息: docker info Containers: 2 Images: 1 Role: primary Strategy: spread Filters: health, port, dependency, affinity, constraint Nodes: 1swarm-master: 192.168.99.102:2376└ Containers: 2└ Reserved CPUs: 0 / 1└ Reserved Memory: 0 B / 1.021 GiB└ Labels: executiondriver=native-0.2, kernelversion=4.1.13-boot2docker, operatingsystem=Boot2Docker 1.9.1 (TCL 6.4.1); master : cef800b - Fri Nov 20 19:33:59 UTC 2015, provider=virtualbox, storagedriver=aufs CPUs: 1 Total Memory: 1.021 GiB Name: d074fd97682e
  • 創建一個新計算機以加入該集群: docker-machine create -d virtualbox --virtualbox-disk-size "5000" --swarm --swarm-discovery="consul://$(docker-machine ip consul-machine):8500" --engine-opt="cluster-store=consul://$(docker-machine ip consul-machine):8500" --engine-opt="cluster-advertise=eth1:2376" swarm-node-01 Running pre-create checks... Creating machine... Waiting for machine to be running, this may take a few minutes... Machine is running, waiting for SSH to be available... Detecting operating system of created instance... Provisioning created instance... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... Configuring swarm... To see how to connect Docker to this machine, run: docker-machine env swarm-node-01

    請注意,此命令中未指定--swarm-master 。 這樣可以確保創建的計算機是工作程序節點。

  • 創建第二個Swarm節點以加入該集群: docker-machine create -d virtualbox --virtualbox-disk-size "5000" --swarm --swarm-discovery="consul://$(docker-machine ip consul-machine):8500" --engine-opt="cluster-store=consul://$(docker-machine ip consul-machine):8500" --engine-opt="cluster-advertise=eth1:2376" swarm-node-02 Running pre-create checks... Creating machine... Waiting for machine to be running, this may take a few minutes... Machine is running, waiting for SSH to be available... Detecting operating system of created instance... Provisioning created instance... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... Configuring swarm... To see how to connect Docker to this machine, run: docker-machine env swarm-node-02
  • 列出所有創建的計算機: docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM consul-machine - virtualbox Running tcp://192.168.99.100:2376 swarm-master * virtualbox Running tcp://192.168.99.101:2376 swarm-master (master) swarm-node-01 - virtualbox Running tcp://192.168.99.102:2376 swarm-master swarm-node-02 - virtualbox Running tcp://192.168.99.103:2376 swarm-master

    屬于群集的計算機在“群集”列中具有群集的名稱,否則為空白。 例如, consul-machine是一臺獨立的機器,其他所有機器都是swarm-master集群的一部分。 Swarm主機也由SWARM列中的(主機)標識。

  • 連接到Swarm集群并找到有關它的一些信息: eval "$(docker-machine env --swarm swarm-master)" docker info

    注意,指定--swarm連接到Swarm集群。 否則,該命令將僅連接到swarm-master計算機。

    輸出顯示為:

    docker info Containers: 4 Images: 3 Role: primary Strategy: spread Filters: health, port, dependency, affinity, constraint Nodes: 3swarm-master: 192.168.99.102:2376└ Containers: 2└ Reserved CPUs: 0 / 1└ Reserved Memory: 0 B / 1.021 GiB└ Labels: executiondriver=native-0.2, kernelversion=4.1.13-boot2docker, operatingsystem=Boot2Docker 1.9.1 (TCL 6.4.1); master : cef800b - Fri Nov 20 19:33:59 UTC 2015, provider=virtualbox, storagedriver=aufsswarm-node-01: 192.168.99.103:2376└ Containers: 1└ Reserved CPUs: 0 / 1└ Reserved Memory: 0 B / 1.021 GiB└ Labels: executiondriver=native-0.2, kernelversion=4.1.13-boot2docker, operatingsystem=Boot2Docker 1.9.1 (TCL 6.4.1); master : cef800b - Fri Nov 20 19:33:59 UTC 2015, provider=virtualbox, storagedriver=aufsswarm-node-02: 192.168.99.104:2376└ Containers: 1└ Reserved CPUs: 0 / 1└ Reserved Memory: 0 B / 1.021 GiB└ Labels: executiondriver=native-0.2, kernelversion=4.1.13-boot2docker, operatingsystem=Boot2Docker 1.9.1 (TCL 6.4.1); master : cef800b - Fri Nov 20 19:33:59 UTC 2015, provider=virtualbox, storagedriver=aufs CPUs: 3 Total Memory: 3.064 GiB Name: d074fd97682e

    有3個節點-一個Swarm主節點和2個Swarm 工作節點。 此群集中總共有4個容器在運行–主節點和每個節點上有一個Swarm代理,主節點上還有一個額外的swarm-agent-master。 可以通過連接到主數據庫并列出所有容器來驗證這一點。

  • 使用以下命令列出集群中的節點: docker run swarm list consul://$(docker-machine ip consul-machine):8500 192.168.99.102:2376 192.168.99.103:2376 192.168.99.104:2376
  • 使用Docker Compose啟動應用程序環境

    通過提供命令eval "$(docker-machine env --swarm swarm-master)"確保連接到集群。

  • 列出到目前為止Docker創建的所有網絡: docker network ls NETWORK ID NAME DRIVER 33a619ddc5d2 swarm-node-02/bridge bridge e0b73c96ffec swarm-node-02/none null b315e67f0363 swarm-node-02/host host 879d6167be47 swarm-master/bridge bridge f771ddc7d957 swarm-node-01/none null e042754df336 swarm-node-01/host host d2f3b512f9dc swarm-node-01/bridge bridge 5b5bcf135d7b swarm-master/none null fffc34eae907 swarm-master/host host

    Docker為每個主機自動創建三個網絡:

    網絡名字目的
    bridge 容器連接的默認網絡。 在所有Docker安裝中,這是docker0網絡。
    none 特定于容器的網絡堆棧
    host 在主機網絡堆棧上添加一個容器。 網絡配置與主機相同。


    這說明了九個網絡,每個節點三個,如該Swarm集群所示。

  • 使用Compose文件啟動WildFly和Couchbase: mycouchbase:container_name: "db"image: couchbase/serverports:- 8091:8091- 8092:8092- 8093:8093- 11210:11210 mywildfly:image: arungupta/wildfly-adminenvironment:- COUCHBASE_URI=dbports:- 8080:8080- 9990:9990

    在此撰寫文件中:

  • Couchbase服務具有由container_name定義的自定義容器名稱。 在WildFly啟動期間創建新的環境變量COUCHBASE_URI時使用此名稱。
  • arungupta/wildfly-admin映像是因為它將WildFly的管理綁定到所有網絡接口,此外還公開了端口9990。這使WildFly Maven插件可用于部署應用程序。此文件的源位于https://github.com/github .com / arun-gupta / docker-images / blob / master / wildfly-couchbase-javaee7 / docker-compose.yml 。
  • 此應用程序環境可以通過以下方式啟動:

    docker-compose --x-networking up -d Creating network "wildflycouchbasejavaee7" with driver "None" Pulling mywildfly (arungupta/wildfly-admin:latest)... swarm-node-02: Pulling arungupta/wildfly-admin:latest... : downloaded swarm-master: Pulling arungupta/wildfly-admin:latest... : downloaded swarm-node-01: Pulling arungupta/wildfly-admin:latest... : downloaded Creating wildflycouchbasejavaee7_mywildfly_1 Pulling mycouchbase (couchbase/server:latest)... swarm-node-02: Pulling couchbase/server:latest... : downloaded swarm-master: Pulling couchbase/server:latest... : downloaded swarm-node-01: Pulling couchbase/server:latest... : downloaded Creating db

    --x-networking為Swarm集群創建一個覆蓋網絡。 可以通過再次列出網絡來驗證:

    docker network ls NETWORK ID NAME DRIVER 5e93fc34b4d9 swarm-node-01/docker_gwbridge bridge 1c041242f51d wildflycouchbasejavaee7 overlay cc8697c6ce13 swarm-master/docker_gwbridge bridge f771ddc7d957 swarm-node-01/none null 879d6167be47 swarm-master/bridge bridge 5b5bcf135d7b swarm-master/none null fffc34eae907 swarm-master/host host e042754df336 swarm-node-01/host host d2f3b512f9dc swarm-node-01/bridge bridge 33a619ddc5d2 swarm-node-02/bridge bridge e0b73c96ffec swarm-node-02/none null b315e67f0363 swarm-node-02/host host

    創建了三個新的網絡:

  • 連接到多主機網絡的容器會自動連接到docker_gwbridge網絡。 該網絡允許容器在其群集之外具有外部連接,并在每個工作節點上創建。
  • 創建了一個新的覆蓋網絡wildflycouchbasejavaee7 。 連接到不同的Swarm節點并檢查其上是否存在覆蓋網絡。讓我們以master開頭: eval "$(docker-machine env swarm-master)" docker network ls NETWORK ID NAME DRIVER 1c041242f51d wildflycouchbasejavaee7 overlay 879d6167be47 bridge bridge 5b5bcf135d7b none null fffc34eae907 host host cc8697c6ce13 docker_gwbridge bridge

    接下來,使用swarm-node-01 :

    eval "$(docker-machine env swarm-node-01)" docker network ls NETWORK ID NAME DRIVER 1c041242f51d wildflycouchbasejavaee7 overlay d2f3b512f9dc bridge bridge f771ddc7d957 none null e042754df336 host host 5e93fc34b4d9 docker_gwbridge bridge

    最后,使用swarm-node-02 :

    eval "$(docker-machine env swarm-node-02)" docker network ls NETWORK ID NAME DRIVER 1c041242f51d wildflycouchbasejavaee7 overlay e0b73c96ffec none null b315e67f0363 host host 33a619ddc5d2 bridge bridge

    如圖所示, wildflycouchbasejavaee7覆蓋網絡存在于所有計算機上。 這確認為Swarm群集創建的覆蓋網絡已添加到群集中的每個主機。 docker_gwbridge僅在運行應用程序容器的機器上存在。

    閱讀有關Docker Networks的更多信息。

  • 驗證WildFly和Couchbase是否正在運行: docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 23a581295a2b couchbase/server "/entrypoint.sh couch" 9 seconds ago Up 8 seconds 192.168.99.102:8091-8093->8091-8093/tcp, 11207/tcp, 11211/tcp, 192.168.99.102:11210->11210/tcp, 18091-18092/tcp swarm-master/db 7a8a885b23f3 arungupta/wildfly-admin "/opt/jboss/wildfly/b" 9 seconds ago Up 8 seconds 192.168.99.103:8080->8080/tcp, 192.168.99.103:9990->9990/tcp swarm-node-01/wildflycouchbasejavaee7_mywildfly_1
  • 配置應用程序和數據庫

  • 克隆https://github.com/arun-gupta/couchbase-javaee.git 該工作空間包含一個簡單的Java EE應用程序,該應用程序部署在WildFly上,并通過Couchbase中的travel-sample存儲桶提供REST API。
  • 可以使用REST API配置Couchbase服務器。 該應用程序包含一個Maven配置文件,該配置文件允許使用travel-sample存儲桶配置Couchbase服務器。 可以通過以下方式調用: mvn install -Pcouchbase -Ddocker.host=$(docker-machine ip swarm-master). . .* Server auth using Basic with user 'Administrator' > POST /sampleBuckets/install HTTP/1.1 > Authorization: Basic QWRtaW5pc3RyYXRvcjpwYXNzd29yZA==. . .} [data not shown] * upload completely sent off: 17 out of 17 bytes < HTTP/1.1 202 Accepted * Server Couchbase Server is not blacklisted < Server: Couchbase Server. . .
  • 通過指定三個參數將應用程序部署到WildFly:
  • 運行WildFly的主機IP地址
  • WildFly管理領域中用戶的用戶名
  • WildFly管理領域中指定的用戶密碼
  • mvn install -Pwildfly -Dwildfly.hostname=$(docker-machine ip swarm-node-01) -Dwildfly.username=admin -Dwildfly.password=Admin#007. . .Nov 29, 2015 12:11:14 AM org.xnio.Xnio <clinit> INFO: XNIO version 3.3.1.Final Nov 29, 2015 12:11:14 AM org.xnio.nio.NioXnio <clinit> INFO: XNIO NIO Implementation Version 3.3.1.Final Nov 29, 2015 12:11:15 AM org.jboss.remoting3.EndpointImpl <clinit> INFO: JBoss Remoting version 4.0.9.Final [INFO] Authenticating against security realm: ManagementRealm [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------. . .

    訪問應用

    既然WildFly和Couchbase服務器已經啟動,就可以訪問該應用程序。 您需要指定運行WildFly的計算機的IP地址:

    curl http://$(docker-machine ip swarm-node-01):8080/couchbase-javaee/resources/airline [{"travel-sample":{"id":10123,"iata":"TQ","icao":"TXW","name":"Texas Wings","callsign":"TXW","type":"airline","country":"United States"}}, {"travel-sample":{"id":10642,"iata":null,"icao":"JRB","name":"Jc royal.britannica","callsign":null,"type":"airline","country":"United Kingdom"}}, {"travel-sample":{"id":112,"iata":"5W","icao":"AEU","name":"Astraeus","callsign":"FLYSTAR","type":"airline","country":"United Kingdom"}}, {"travel-sample":{"id":1355,"iata":"BA","icao":"BAW","name":"British Airways","callsign":"SPEEDBIRD","type":"airline","country":"United Kingdom"}}, {"travel-sample":{"id":10765,"iata":"K5","icao":"SQH","name":"SeaPort Airlines","callsign":"SASQUATCH","type":"airline","country":"United States"}}, {"travel-sample":{"id":13633,"iata":"WQ","icao":"PQW","name":"PanAm World Airways","callsign":null,"type":"airline","country":"United States"}}, {"travel-sample":{"id":139,"iata":"SB","icao":"ACI","name":"Air Caledonie International","callsign":"AIRCALIN","type":"airline","country":"France"}}, {"travel-sample":{"id":13391,"iata":"-+","icao":"--+","name":"U.S. Air","callsign":null,"type":"airline","country":"United States"}}, {"travel-sample":{"id":1191,"iata":"UU","icao":"REU","name":"Air Austral","callsign":"REUNION","type":"airline","country":"France"}}, {"travel-sample":{"id":1316,"iata":"FL","icao":"TRS","name":"AirTran Airways","callsign":"CITRUS","type":"airline","country":"United States"}}]
    • github.com/arun-gupta/couchbase-javaee中記錄了此應用程序的完整REST API 集合 。
      • Docker上針對Java開發人員的最新說明。

        請享用!

    翻譯自: https://www.javacodegeeks.com/2015/12/docker-machine-swarm-compose-multi-container-multi-host-applications-couchbase-wildfly.html

    總結

    以上是生活随笔為你收集整理的适用于具有Couchbase和WildFly的多容器和多主机应用程序的Docker Machine,Swarm和Compose...的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。