国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

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

發(fā)布時(shí)間:2021-08-15 18:37 來(lái)源: 閱讀:0 作者:落塵曦 欄目: 服務(wù)器 歡迎投稿:712375056

consul基本概念

server模式和client模式
server模式和client模式是consul節點(diǎn)的類(lèi)型;client不是指的用戶(hù)客戶(hù)端。

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

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

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

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

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

  •  集群包含三個(gè)server:node1, node2, node3
  • 集群包含一個(gè)client:node4;并且在client上提供web UI訪(fǎng)問(wèn)服務(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 members
Node   Address          Status  Type    Build  Protocol  DC   Segment
node1  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>

 訪(fǎng)問(wèn)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訪(fǎng)問(wèn)的例子

$ 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 foo
Hello foo
$ docker exec -t node4 consul kv get -detailed foo/foo1
CreateIndex      124
Flags            0
Key              foo/foo1
LockIndex        0
ModifyIndex      124
Session          -
Value            Hello foo1
$ docker exec -t node4 consul kv get -keys -separator="" foo
foo
foo/foo1
foo/foo2
foo/foo2/foo21
$ docker exec -t node4 consul kv get not-a-real-key
Error! No key exists at: not-a-real-key

以上就是使用docker compose搭建consul集群環(huán)境的詳細內容,更多關(guān)于docker compose集群環(huán)境的資料請關(guān)注腳本之家其它相關(guān)文章!

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

精品少妇人妻AV免费久久久| 激情内射亚洲一区二区三区| 色综合色综合色综合色欲| 无码日韩精品国产AV| 免费观看亚洲人成网站| 成本人妻片无码中文字幕免费|