亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

使用docker compose搭建consul集群環(huán)境的例子

瀏覽:117日期:2024-10-26 16:32:37
consul基本概念

server模式和client模式server模式和client模式是consul節(jié)點(diǎn)的類型;client不是指的用戶客戶端。

server模式提供數(shù)據(jù)持久化功能。 client模式不提供持久化功能,并且實(shí)際上他也不工作,只是把用戶客戶端的請求轉(zhuǎn)發(fā)到server模式的節(jié)點(diǎn)。所以可以把client模式的節(jié)點(diǎn)想象成LB(load balance),只負(fù)責(zé)請求轉(zhuǎn)發(fā)。 通常server模式的節(jié)點(diǎn)需要配置成多個(gè)例如3個(gè),5個(gè)。而client模式節(jié)點(diǎn)個(gè)數(shù)沒有限制。

server模式啟動(dòng)的命令行參數(shù)

-server:表示當(dāng)前使用的server模式;如果沒有指定,則表示是client模式。 -node:指定當(dāng)前節(jié)點(diǎn)在集群中的名稱。 -config-dir:指定配置文件路徑,定義服務(wù)的;路徑下面的所有.json結(jié)尾的文件都被訪問;缺省值為:/consul/config。 -data-dir: consul存儲(chǔ)數(shù)據(jù)的目錄;缺省值為:/consul/data。 -datacenter:數(shù)據(jù)中心名稱,缺省值為dc1。 -ui:使用consul自帶的web UI界面 。 -join:加入到已有的集群中。 -enable-script-checks: 檢查服務(wù)是否處于活動(dòng)狀態(tài),類似開啟心跳。 -bind: 綁定服務(wù)器的ip地址。 -client: 客戶端可訪問ip,缺省值為:“127.0.0.1”,即僅允許環(huán)回連接。 -bootstrap-expect:在一個(gè)datacenter中期望的server節(jié)點(diǎn)數(shù)目,consul啟動(dòng)時(shí)會(huì)一直等待直到達(dá)到這個(gè)數(shù)目的server才會(huì)引導(dǎo)整個(gè)集群。這個(gè)參數(shù)的值在同一個(gè)datacenter的所有server節(jié)點(diǎn)上必須保持一致。

這里說明一下,另外一個(gè)參數(shù)-bootstrap,用來控制一個(gè)server是否運(yùn)行在bootstrap模式:當(dāng)一個(gè)server處于bootstrap模式時(shí),它可以選舉自己為leader;注意在一個(gè)datacenter中只能有一個(gè)server處于bootstrap模式。所以這個(gè)參數(shù)一般只能用在只有一個(gè)server的開發(fā)環(huán)境中,在有多個(gè)server的cluster產(chǎn)品環(huán)境中,不能使用這個(gè)參數(shù),否則如果多個(gè)server都標(biāo)記自己為leader那么會(huì)導(dǎo)致數(shù)據(jù)不一致。另外該標(biāo)記不能和-bootstrap-expect同時(shí)指定。

使用docker-compose來搭建如下的consul集群環(huán)境

集群包含三個(gè)server:node1, node2, node3 集群包含一個(gè)client:node4;并且在client上提供web UI訪問服務(wù)。.

編輯docker-compose.yml文件

version: ’2’networks: byfn: services: consul1: image: consul container_name: node1 command: agent -server -bootstrap-expect=3 -node=node1 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1 networks: - byfn consul2: image: consul container_name: node2 command: agent -server -retry-join=node1 -node=node2 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1 depends_on:- consul1 networks: - byfn consul3: image: consul container_name: node3 command: agent -server -retry-join=node1 -node=node3 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1 depends_on:- consul1 networks: - byfn consul4: image: consul container_name: node4 command: agent -retry-join=node1 -node=ndoe4 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1 -ui ports: - 8500:8500 depends_on:- consul2- consul3 networks: - byfn

啟動(dòng)服務(wù)

$ docker-compose up$ docker exec -t node1 consul membersNode Address Status Type Build Protocol DC Segmentnode1 172.21.0.2:8301 alive server 1.4.0 2 dc1 <all>node2 172.21.0.4:8301 alive server 1.4.0 2 dc1 <all>node3 172.21.0.3:8301 alive server 1.4.0 2 dc1 <all>ndoe4 172.21.0.5:8301 alive client 1.4.0 2 dc1 <default>

訪問http://127.0.0.1:8500

使用docker compose搭建consul集群環(huán)境的例子

注冊配置中心例子

spring: application: name: cloud-payment-service ####consul注冊中心地址 cloud: consul: enabled: true host: 127.0.0.1 port: 8500 discovery:hostname: 127.0.0.1prefer-ip-address: trueservice-name: ${spring.application.name}#healthCheckInterval: 15sinstance-id: ${spring.application.name}-8002enabled: true

KV訪問的例子

$ docker exec -t node4 consul kv put foo 'Hello foo'$ docker exec -t node4 consul kv put foo/foo1 'Hello foo1'$ docker exec -t node4 consul kv put foo/foo2 'Hello foo2'$ docker exec -t node4 consul kv put foo/foo21 'Hello foo21'$ docker exec -t node4 consul kv get fooHello foo$ docker exec -t node4 consul kv get -detailed foo/foo1CreateIndex 124Flags 0Key foo/foo1LockIndex0ModifyIndex 124Session -Value Hello foo1$ docker exec -t node4 consul kv get -keys -separator='' foofoofoo/foo1foo/foo2foo/foo2/foo21$ docker exec -t node4 consul kv get not-a-real-keyError! No key exists at: not-a-real-key

以上就是使用docker compose搭建consul集群環(huán)境的詳細(xì)內(nèi)容,更多關(guān)于docker compose集群環(huán)境的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Docker
相關(guān)文章:
主站蜘蛛池模板: 二级黄色毛片 | 正在播放国产夫妻 | 天天操综合网 | 成人在线免费视频观看 | 好爽好黄的视频 | 国产成人精品亚洲午夜麻豆 | 视频一区二区在线 | 九九热精品视频在线 | 在线日本人观看成本人视频 | 进来综合网 | 国产精品99久久99久久久看片 | 久久亚洲国产 | 香蕉视频 在线播放 | 91av一区| 国产 日韩 在线 亚洲 字幕 中文 | avtt加勒比手机版天堂网 | 成人在激情在线视频 | 国产一卡2卡3卡四卡高清 | 亚洲欧洲一区二区三区 | 国产网友自拍 | 国产色片在线观看 | 国产一区二区不卡免费观在线 | 欧美日韩一区二区三区在线观看 | 国产成人香蕉久久久久 | 99热国产这里只有精品免费 | 快使劲弄我视频在线播放 | 中文字幕乱码一区三区免费 | 天海翼一区二区三区高清视频 | 国产欧美日韩看片片在线人成 | 国产亚洲精品色一区 | 免费黄色资源 | 青青草99久久精品国产综合 | 久久性妇女精品免费 | 成人性视频在线三级 | 国产精品k | 国产日韩精品欧美一区喷水 | 中国黄色在线观看 | 欧美亚洲在线观看 | 久久精品91 | 日韩欧美视频一区 | 免费又爽又黄的禁片1000部 |