Fabric 1.4.2 動(dòng)態(tài)添加orderer節(jié)點(diǎn)

本文演示如何在raft共識(shí)啟動(dòng)的fabric網(wǎng)絡(luò)中動(dòng)態(tài)添加orderer節(jié)點(diǎn),fabric版本v1.4.2锡移。
為方便實(shí)驗(yàn)呕童,使用fabric-samples/first-network/腳本演示,且默認(rèn)您有一定的fabric基礎(chǔ)了解罩抗。

下載源碼

git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples/first-network/
git checkout v1.4.2

修改配置

  • 修改crypto-config.yaml文件拉庵,增加orderer6配置- Hostname: orderer6,用于生成orderer6節(jié)點(diǎn)的msp套蒂、tls等(生產(chǎn)環(huán)境用fabric-ca生成)
OrdererOrgs:
  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: example.com
    # ---------------------------------------------------------------------------
    # "Specs" - See PeerOrgs below for complete description
    # ---------------------------------------------------------------------------
    Specs:
      - Hostname: orderer
      - Hostname: orderer2
      - Hostname: orderer3
      - Hostname: orderer4
      - Hostname: orderer5
      - Hostname: orderer6

  • 修改docker-compose-cli.yaml文件钞支,增加config文件映射- ./config:/opt/gopath/src/github.com/hyperledger/fabric/peer/config/,方便后面文件修改
cli:
    container_name: cli
    image: hyperledger/fabric-tools:$IMAGE_TAG
    tty: true
    stdin_open: true
    environment:
      - SYS_CHANNEL=$SYS_CHANNEL
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #- FABRIC_LOGGING_SPEC=DEBUG
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/chaincode
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
        - ./config:/opt/gopath/src/github.com/hyperledger/fabric/peer/config/
    depends_on:
      - orderer.example.com
      - peer0.org1.example.com
      - peer1.org1.example.com
      - peer0.org2.example.com
      - peer1.org2.example.com
    networks:
      - byfn

啟動(dòng)fabric網(wǎng)絡(luò)

./byfn.sh up -o etcdraft -c mychannel -s couchdb -i 1.4.2

更新配置

  • 進(jìn)入cli容器操刀,設(shè)置全局環(huán)境變量
docker exec -it cli bash
### Global env
CHANNEL_NAME=mychannel
CORE_PEER_TLS_ENABLED=true
FABRIC_LOGGING_SPEC=INFO
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

PEER0_ORG1_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
PEER0_ORG2_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
  • 更新系統(tǒng)channel配置
    1.設(shè)置OrdererMSP
    export CORE_PEER_LOCALMSPID=OrdererMSP
    export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp/
    
    2.獲取byfn-sys-channel最新配置塊文件config_block.pb
    mkdir -p config/system/
    peer channel fetch config config/system/config_block.pb -o orderer.example.com:7050 -c byfn-sys-channel --tls --cafile $ORDERER_CA
    
    3.從config_block.pb中提取有效的數(shù)據(jù)烁挟,并轉(zhuǎn)換成可編輯json格式
    configtxlator proto_decode --input config/system/config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config/system/config.json
    
    4.修改config.json里面的orderer配置
    建議使用IDE,比如VsCode或EditPlus等來編輯骨坑,復(fù)制config/system/config.jsonconfig/system/config_updated.json撼嗓,搜索.example.com增加orderer6相關(guān)配置
                      {
                        "client_tls_cert": "YOUR ORDERER6 TLS SERVER CERT",
                        "host": "orderer6.example.com",
                        "port": 7050,
                        "server_tls_cert": "YOUR ORDERER6 TLS SERVER CERT"
                      }
    
          "OrdererAddresses": {
            "mod_policy": "/Channel/Orderer/Admins",
            "value": {
              "addresses": [
                "orderer.example.com:7050",
                "orderer2.example.com:7050",
                "orderer3.example.com:7050",
                "orderer4.example.com:7050",
                "orderer5.example.com:7050",
                "orderer6.example.com:7050"
              ]
            },
            "version": "0"
        }
    
    其中YOUR ORDERER6 TLS SERVER CERT可通過腳本或者其他base64工具轉(zhuǎn)換得到柬采,然后copy到上述位置
    cat crypto-config/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/server.crt|base64
    
    5.把前后的兩個(gè)json文件重新轉(zhuǎn)換回pb類型文件
    configtxlator proto_encode --input config/system/config.json --type common.Config > config/system/config_block_origin.pb
    configtxlator proto_encode --input config/system/config_updated.json --type common.Config > config/system/config_block_updated.pb
    
    6.比較前后兩個(gè)pb文件的差異,得到改動(dòng)部分
    configtxlator compute_update --channel_id byfn-sys-channel --original config/system/config_block_origin.pb --updated config/system/config_block_updated.pb > config/system/config_diff.pb
    
    7.把配置變化部分轉(zhuǎn)化為json文件
    configtxlator proto_decode --input config/system/config_diff.pb --type common.ConfigUpdate > config/system/config_diff.json
    
    8.為上述json文件添加頭部信息(Header)且警,封裝成一個(gè)完整的config update請(qǐng)求粉捻,注意channel_id設(shè)置為byfn-sys-channel
    echo '{"payload":{"header":{"channel_header":{"channel_id":"byfn-sys-channel", "type":2}},"data":{"config_update":'$(cat config/system/config_diff.json)'}}}' | jq . > config/system/config_diff_envelope.json
    
    9.把封裝好的json文件轉(zhuǎn)換回pb格式文件
    configtxlator proto_encode --input config/system/config_diff_envelope.json --type common.Envelope > config/system/config_diff_envelope.pb
    
    10.簽名
    peer channel signconfigtx -f config/system/config_diff_envelope.pb
    
    11.提交修改請(qǐng)求到orderer
    peer channel update -f config/system/config_diff_envelope.pb -c byfn-sys-channel -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA
    
  • 更新自定義mychannel配置
    1.設(shè)置OrdererMSP
    export CORE_PEER_LOCALMSPID=OrdererMSP
    export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp/
    
    2.獲取mychannel最新配置塊文件config_block.pb
    mkdir -p config/mychannel/
    peer channel fetch config config/mychannel/config_block.pb -o orderer.example.com:7050 -c mychannel --tls --cafile $ORDERER_CA
    
    3.從config_block.pb中提取有效的數(shù)據(jù),并轉(zhuǎn)換成可編輯json格式
    configtxlator proto_decode --input config/mychannel/config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config/mychannel/config.json
    
    4.修改config.json里面的orderer配置
    與系統(tǒng)channel配置文件修改類似斑芜,復(fù)制config/mychannel/config.jsonconfig/mychannel/config_updated.json,并修改肩刃。tls_cert、host與上述一致杏头。
                      {
                        "client_tls_cert": "YOUR ORDERER6 TLS SERVER CERT",
                        "host": "orderer6.example.com",
                        "port": 7050,
                        "server_tls_cert": "YOUR ORDERER6 TLS SERVER CERT"
                      }
    
          "OrdererAddresses": {
            "mod_policy": "/Channel/Orderer/Admins",
            "value": {
              "addresses": [
                "orderer.example.com:7050",
                "orderer2.example.com:7050",
                "orderer3.example.com:7050",
                "orderer4.example.com:7050",
                "orderer5.example.com:7050",
                "orderer6.example.com:7050"
              ]
            },
            "version": "0"
        }
    
    5.把前后的兩個(gè)json文件重新轉(zhuǎn)換回pb類型文件
    configtxlator proto_encode --input config/mychannel/config.json --type common.Config > config/mychannel/config_block_origin.pb
    configtxlator proto_encode --input config/mychannel/config_updated.json --type common.Config > config/mychannel/config_block_updated.pb
    
    6.比較前后兩個(gè)pb文件的差異盈包,得到改動(dòng)部分
    configtxlator compute_update --channel_id mychannel --original config/mychannel/config_block_origin.pb --updated config/mychannel/config_block_updated.pb > config/mychannel/config_diff.pb
    
    7.把配置變化部分轉(zhuǎn)化為json文件
    configtxlator proto_decode --input config/mychannel/config_diff.pb --type common.ConfigUpdate > config/mychannel/config_diff.json
    
    8.為上述json文件添加頭部信息(Header),封裝成一個(gè)完整的config update請(qǐng)求醇王,注意channel_id設(shè)置為mychannel
    echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":'$(cat config/mychannel/config_diff.json)'}}}' | jq . > config/mychannel/config_diff_envelope.json
    
    9.把封裝好的json文件轉(zhuǎn)換回pb格式文件
    configtxlator proto_encode --input config/mychannel/config_diff_envelope.json --type common.Envelope > config/mychannel/config_diff_envelope.pb
    
    10.簽名
    peer channel signconfigtx -f config/mychannel/config_diff_envelope.pb
    
    11.提交修改請(qǐng)求到orderer
    peer channel update -f config/mychannel/config_diff_envelope.pb -c mychannel -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA
    

啟動(dòng)orderer6節(jié)點(diǎn)

  • cli容器內(nèi)獲取系統(tǒng)channel最新配置塊文件(channel-artifacts/genesis_updated.block)
export CORE_PEER_LOCALMSPID=OrdererMSP
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp/

peer channel fetch config channel-artifacts/genesis_updated.block -o orderer.example.com:7050 -c byfn-sys-channel --tls --cafile $ORDERER_CA
  • fabric-samples/first-network目錄添加docker-compose-orderer6.yaml文件呢燥,內(nèi)容如下
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

volumes:
  orderer6.example.com:

networks:
  byfn:

services:

  orderer6.example.com:
    extends:
      file: base/peer-base.yaml
      service: orderer-base
    container_name: orderer6.example.com
    networks:
    - byfn
    volumes:
        - ./channel-artifacts/genesis_updated.block:/var/hyperledger/orderer/orderer.genesis.block
        - ./crypto-config/ordererOrganizations/example.com/orderers/orderer6.example.com/msp:/var/hyperledger/orderer/msp
        - ./crypto-config/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/:/var/hyperledger/orderer/tls
        - orderer6.example.com:/var/hyperledger/production/orderer
    ports:
    - 12050:7050


  • 啟動(dòng)orderer6
IMAGE_TAG=1.4.2 docker-compose -f docker-compose-orderer6.yaml up -d
docker ps -a|grep orderer6
#查看orderer6 log
docker logs -f orderer6.example.com

驗(yàn)證orderer6節(jié)點(diǎn)

  • 在cli容器里設(shè)置peer0環(huán)境變量
#peer0 env
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID=Org1MSP

CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
  • peer invoke 提交到orderer.example.com:7050節(jié)點(diǎn)
#查詢a
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
90
#執(zhí)行 a b 10
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles $PEER0_ORG1_CA --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles $PEER0_ORG2_CA -c '{"Args":["invoke","a","b","10"]}'
#查詢
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
80
  • peer invoke 提交到orderer6.example.com:7050節(jié)點(diǎn)
#查詢
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
80
#執(zhí)行 a b 5
peer chaincode invoke -o orderer6.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles $PEER0_ORG1_CA --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles $PEER0_ORG2_CA -c '{"Args":["invoke","a","b","5"]}'
#查詢
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
75

PS.官方文檔還有最后一步我沒有做,更新endpoint配置操作

Adding a new node to a Raft cluster

參考文檔:

如遇問題或有疑義隨時(shí)聯(lián)系寓娩,請(qǐng)多多關(guān)照

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末叛氨,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子根暑,更是在濱河造成了極大的恐慌力试,老刑警劉巖徙邻,帶你破解...
    沈念sama閱讀 221,198評(píng)論 6 514
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件排嫌,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡缰犁,警方通過查閱死者的電腦和手機(jī)淳地,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,334評(píng)論 3 398
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來帅容,“玉大人颇象,你說我怎么就攤上這事〔⑴牵” “怎么了遣钳?”我有些...
    開封第一講書人閱讀 167,643評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長麦乞。 經(jīng)常有香客問我蕴茴,道長,這世上最難降的妖魔是什么姐直? 我笑而不...
    開封第一講書人閱讀 59,495評(píng)論 1 296
  • 正文 為了忘掉前任倦淀,我火速辦了婚禮,結(jié)果婚禮上声畏,老公的妹妹穿的比我還像新娘撞叽。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,502評(píng)論 6 397
  • 文/花漫 我一把揭開白布愿棋。 她就那樣靜靜地躺著科展,像睡著了一般。 火紅的嫁衣襯著肌膚如雪糠雨。 梳的紋絲不亂的頭發(fā)上辛润,一...
    開封第一講書人閱讀 52,156評(píng)論 1 308
  • 那天,我揣著相機(jī)與錄音见秤,去河邊找鬼砂竖。 笑死,一個(gè)胖子當(dāng)著我的面吹牛鹃答,可吹牛的內(nèi)容都是我干的乎澄。 我是一名探鬼主播,決...
    沈念sama閱讀 40,743評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼测摔,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼置济!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起锋八,我...
    開封第一講書人閱讀 39,659評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤浙于,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后挟纱,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體羞酗,經(jīng)...
    沈念sama閱讀 46,200評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,282評(píng)論 3 340
  • 正文 我和宋清朗相戀三年紊服,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了檀轨。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,424評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡欺嗤,死狀恐怖参萄,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情煎饼,我是刑警寧澤讹挎,帶...
    沈念sama閱讀 36,107評(píng)論 5 349
  • 正文 年R本政府宣布,位于F島的核電站吆玖,受9級(jí)特大地震影響筒溃,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜衰伯,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,789評(píng)論 3 333
  • 文/蒙蒙 一铡羡、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧意鲸,春花似錦烦周、人聲如沸尽爆。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,264評(píng)論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽漱贱。三九已至,卻和暖如春夭委,著一層夾襖步出監(jiān)牢的瞬間幅狮,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,390評(píng)論 1 271
  • 我被黑心中介騙來泰國打工株灸, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留崇摄,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,798評(píng)論 3 376
  • 正文 我出身青樓慌烧,卻偏偏與公主長得像逐抑,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子屹蚊,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,435評(píng)論 2 359