consul基本概念
server模式和client模式
成都創(chuàng)新互聯(lián)服務項目包括富順網(wǎng)站建設、富順網(wǎng)站制作、富順網(wǎng)頁制作以及富順網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,富順網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到富順省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!
server模式和client模式是consul節(jié)點的類型;client不是指的用戶客戶端。這里說明一下,另外一個參數(shù)-bootstrap,用來控制一個server是否運行在bootstrap模式:當一個server處于bootstrap模式時,它可以選舉自己為leader;注意在一個datacenter中只能有一個server處于bootstrap模式。所以這個參數(shù)一般只能用在只有一個server的開發(fā)環(huán)境中,在有多個server的cluster產(chǎn)品環(huán)境中,不能使用這個參數(shù),否則如果多個server都標記自己為leader那么會導致數(shù)據(jù)不一致。另外該標記不能和-bootstrap-expect同時指定。
使用docker-compose來搭建如下的consul集群環(huán)境集群包含三個server:node1, node2, node3 集群包含一個client:node4;并且在client上提供web UI訪問服務。.
編輯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
啟動服務$ 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
注冊配置中心例子spring: application: name: cloud-payment-service ####consul注冊中心地址 cloud: consul: enabled: true host: 127.0.0.1 port: 8500 discovery: hostname: 127.0.0.1 prefer-ip-address: true service-name: ${spring.application.name} #healthCheckInterval: 15s instance-id: ${spring.application.name}-8002 enabled: 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/foo1LockIndex 0ModifyIndex 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)境的詳細內(nèi)容,更多關(guān)于docker compose集群環(huán)境的資料請關(guān)注腳本之家其它相關(guān)文章!
本文標題:使用dockercompose搭建consul集群環(huán)境的例子
本文來源:http://chinadenli.net/article44/ssepee.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、品牌網(wǎng)站建設、網(wǎng)頁設計公司、軟件開發(fā)、網(wǎng)站內(nèi)鏈、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)