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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

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

couchbase

該博客將說明如何使用Docker創(chuàng)建部署在多個(gè)主機(jī)上的多容器應(yīng)用程序。 這將使用Docker Machine,Swarm和Compose實(shí)現(xiàn)。

是的,這三個(gè)工具一起使這個(gè)博客變得更加有趣!

該圖說明了關(guān)鍵組件:

  • Docker Machine用于配置多個(gè)Docker主機(jī)
  • Docker Swarm將用于創(chuàng)建多主機(jī)集群
  • 使用Consul注冊(cè)/發(fā)現(xiàn)Docker Swarm集群中的每個(gè)節(jié)點(diǎn)
  • 多容器應(yīng)用程序?qū)⑹褂肈ocker Compose進(jìn)行部署
  • WildFly和Couchbase在不同的主機(jī)上配置
  • Docker多主機(jī)網(wǎng)絡(luò)用于WildFly和Couchbase進(jìn)行通信

此外,Maven用于配置Couchbase并將應(yīng)用程序部署到WildFly。

  • Docker上針對(duì)Java開發(fā)人員的最新說明。

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

使用Docker Machine創(chuàng)建發(fā)現(xiàn)服務(wù)

  • 創(chuàng)建將托管發(fā)現(xiàn)服務(wù)的計(jì)算機(jī): 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
  • 連接到此機(jī)器: eval $(docker-machine env consul-machine)
  • 使用以下Compose文件運(yùn)行Consul服務(wù): myconsul:image: progrium/consulrestart: alwayshostname: consulports:- 8500:8500command: "-server -bootstrap"

    該Compose文件位于https://github.com/arun-gupta/docker-images/blob/master/consul/docker-compose.yml 。

    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

    啟動(dòng)的容器可以驗(yàn)證為:

    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創(chuàng)建Docker Swarm集群

    Swarm與Machine完全集成在一起,因此這是最簡(jiǎn)單的入門方法。

  • 創(chuàng)建一個(gè)Swarm Master并指向Consul發(fā)現(xiàn)服務(wù): 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配置機(jī)器
  • --swarm-master將創(chuàng)建的Machine配置為Swarm master
  • --swarm-discovery定義發(fā)現(xiàn)服務(wù)的地址
  • --cluster-advertise在網(wǎng)絡(luò)上播發(fā)計(jì)算機(jī)
  • --cluster-store指定集群的分布式k / v存儲(chǔ)后端
  • --virtualbox-disk-size將創(chuàng)建的計(jì)算機(jī)的磁盤--virtualbox-disk-size設(shè)置為5GB。 這是必需的,以便可以在任何節(jié)點(diǎn)上下載WildFly和Couchbase映像。
  • 查找有關(guān)此機(jī)器的一些信息: 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":{}}

    請(qǐng)注意,磁盤大小為5GB。

  • 使用以下命令連接到主服務(wù)器: eval "$(docker-machine env --swarm swarm-master)"
  • 查找有關(guān)集群的一些信息: 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
  • 創(chuàng)建一個(gè)新計(jì)算機(jī)以加入該集群: 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

    請(qǐng)注意,此命令中未指定--swarm-master 。 這樣可以確保創(chuàng)建的計(jì)算機(jī)是工作程序節(jié)點(diǎn)。

  • 創(chuàng)建第二個(gè)Swarm節(jié)點(diǎn)以加入該集群: 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
  • 列出所有創(chuàng)建的計(jì)算機(jī): 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

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

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

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

    輸出顯示為:

    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個(gè)節(jié)點(diǎn)-一個(gè)Swarm主節(jié)點(diǎn)和2個(gè)Swarm 工作節(jié)點(diǎn)。 此群集中總共有4個(gè)容器在運(yùn)行-主節(jié)點(diǎn)和每個(gè)節(jié)點(diǎn)上有一個(gè)Swarm代理,主節(jié)點(diǎn)上還有一個(gè)運(yùn)行的swarm-agent-master。 可以通過連接到主數(shù)據(jù)庫(kù)并列出所有容器來驗(yàn)證這一點(diǎn)。

  • 使用以下命令列出集群中的節(jié)點(diǎn): 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啟動(dòng)應(yīng)用程序環(huán)境

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

  • 列出到目前為止Docker創(chuàng)建的所有網(wǎng)絡(luò): 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為每個(gè)主機(jī)自動(dòng)創(chuàng)建三個(gè)網(wǎng)絡(luò):

    網(wǎng)絡(luò)名稱目的
    bridge 容器連接的默認(rèn)網(wǎng)絡(luò)。 在所有Docker安裝中,這是docker0網(wǎng)絡(luò)。
    none 特定于容器的網(wǎng)絡(luò)堆棧
    host 在主機(jī)網(wǎng)絡(luò)堆棧上添加一個(gè)容器。 網(wǎng)絡(luò)配置與主機(jī)相同。


    這說明了九個(gè)網(wǎng)絡(luò),每個(gè)節(jié)點(diǎn)三個(gè),如該Swarm集群所示。

  • 使用Compose文件啟動(dòng)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服務(wù)具有由container_name定義的自定義容器名稱。 在WildFly啟動(dòng)期間創(chuàng)建新的環(huán)境變量COUCHBASE_URI時(shí)使用此名稱。
  • arungupta/wildfly-admin映像是因?yàn)樗鼘ildFly的管理綁定到所有網(wǎng)絡(luò)接口,此外還公開了端口9990。這使WildFly Maven插件可用于部署應(yīng)用程序。該文件的源位于https://github.com/github .com / arun-gupta / docker-images / blob / master / wildfly-couchbase-javaee7 / docker-compose.yml 。
  • 該應(yīng)用程序環(huán)境可以通過以下方式啟動(dòng):

    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集群創(chuàng)建一個(gè)覆蓋網(wǎng)絡(luò)。 可以通過再次列出網(wǎng)絡(luò)來驗(yàn)證:

    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

    創(chuàng)建了三個(gè)新的網(wǎng)絡(luò):

  • 連接到多主機(jī)網(wǎng)絡(luò)的容器會(huì)自動(dòng)連接到docker_gwbridge網(wǎng)絡(luò)。 此網(wǎng)絡(luò)允許容器在其群集之外具有外部連接,并在每個(gè)工作節(jié)點(diǎn)上創(chuàng)建。
  • 創(chuàng)建了一個(gè)新的覆蓋網(wǎng)絡(luò)wildflycouchbasejavaee7 。 連接到不同的Swarm節(jié)點(diǎn)并檢查其上是否存在疊加網(wǎng)絡(luò)。讓我們以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覆蓋網(wǎng)絡(luò)存在于所有計(jì)算機(jī)上。 這確認(rèn)為Swarm群集創(chuàng)建的覆蓋網(wǎng)絡(luò)已添加到群集中的每個(gè)主機(jī)。 docker_gwbridge僅在運(yùn)行應(yīng)用程序容器的機(jī)器上存在。

    閱讀有關(guān)Docker Networks的更多信息。

  • 驗(yàn)證WildFly和Couchbase是否正在運(yùn)行: 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
  • 配置應(yīng)用程序和數(shù)據(jù)庫(kù)

  • 克隆https://github.com/arun-gupta/couchbase-javaee.git 該工作空間包含一個(gè)簡(jiǎn)單的Java EE應(yīng)用程序,該應(yīng)用程序部署在WildFly上,并通過Couchbase中的travel-sample存儲(chǔ)桶提供REST API。
  • 可以使用REST API配置Couchbase服務(wù)器。 該應(yīng)用程序包含一個(gè)Maven配置文件,該配置文件允許使用travel-sample存儲(chǔ)桶配置Couchbase服務(wù)器。 可以通過以下方式調(diào)用: 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. . .
  • 通過指定三個(gè)參數(shù)將應(yīng)用程序部署到WildFly:
  • 運(yùn)行WildFly的主機(jī)IP地址
  • WildFly管理領(lǐng)域中用戶的用戶名
  • WildFly管理領(lǐng)域中指定的用戶密碼
  • 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] ------------------------------------------------------------------------. . .

    訪問應(yīng)用

    既然WildFly和Couchbase服務(wù)器已經(jīng)啟動(dòng),就可以訪問該應(yīng)用程序。 您需要指定運(yùn)行WildFly的計(jì)算機(jī)的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中記錄了此應(yīng)用程序的完整REST API 集合 。
      • Docker上針對(duì)Java開發(fā)人員的最新說明。

        請(qǐng)享用!

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

    couchbase

    總結(jié)

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

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。