主頁 > 區塊鏈 > Fabric1.4.1多機部署

Fabric1.4.1多機部署

2021-09-29 08:26:26 區塊鏈

多機部署

1. 搭建環境

本文使用的是Fabric 1.4版本,搭建solo模式的4+1的架構:1Order,4Peer,機器之間的網路需要互通,保證五臺機子上的Fabric網路可以正常運行,舉例說明如下:

域名ip
orderer.example.com172.18.4.49
peer0.org1.example.com172.18.4.33
peer1.org1.example.com172.18.4.34
peer0.org2.example.com172.18.4.35
peer1.org2.example.com172.18.4.36

Fabric 的環境搭建程序不再詳解,例子中的order節點和4個peer節點放在5臺不同機子上,我們搭建的程序共使用三臺:order1臺 + 組織1的peer0和peer1一臺,組織2的peer0和peer1一臺,

2. 多機環境搭建

只在Orderer節點的機子上修改組態檔,最后通過scp命令將組態檔復制到其余四臺機子,保證所有的節點所使用的組態檔都是相同的,

本文使用 first-network 這個檔案夾內的組態檔來修改為自己所需要的組態檔,(位于fabric同級目錄的fabric-samples官方樣例下的first-network)

2.1 準備組態檔(只在Order節點操作)

#step1 進入到first-network檔案夾的上一級目錄
cd ~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/
#step2 拷貝first-network檔案夾,并命名為first
cp -r first-network/ first
#step3 進入到first檔案夾內
cd first
#step4 洗掉此次多機環境搭建使用不到的檔案,檔案夾內剩余的檔案有
.
├── base
│   ├── docker-compose-base.yaml
│   └── peer-base.yaml
├── channel-artifacts
├── configtx.yaml
├── crypto-config.yaml
├── docker-compose-cli.yaml
├── docker-compose-couch.yaml

本文就對以上檔案進行修改搭建自己的Fabric多機網路
由于官方的 first-network 中的組態檔中使用的就是4+1的架構,所以我們可以直接生成所需要的證書檔案,創世區塊,通道組態檔,

2.2 生成相關組態檔(只在Order節點操作)

#step1 生成證書檔案
cryptogen generate --config=./crypto-config.yaml
#step2 生成創世區塊  首先要確保channel-artifacts檔案夾存在,如果不存在需要手動創建,不然會報錯
configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
#step3 生成通道組態檔  其中通道名mychannel可以修改為自己的
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
#step4 生成錨節點組態檔
#========Org1=============
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
##========Org2=============
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP

在這里插入圖片描述

在這里插入圖片描述

完成后在 channel-artifacts 中應該有以下幾個檔案:

在這里插入圖片描述

2.3 修改節點組態檔(只提醒一次:所有檔案內容的格式不能變,前面空格的數量必須和原檔案一致)

2.3.1 base/docker-compose-base.yaml(Order主機)

刪掉order.example.com下image項的冒號

在這里插入圖片描述

下面內容暫不需要修改!!!(因為我們是多機環境,不存在埠沖突問題暫時用不到)

peer0.org1.example.com:
    container_name: peer0.org1.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:8051  #這里更改為7051,因為我們是多機環境,不存在埠沖突問題
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org1.example.com:/var/hyperledger/production
    ports:
      - 7051:7051
 
  peer1.org1.example.com:
    container_name: peer1.org1.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer1.org1.example.com
      - CORE_PEER_ADDRESS=peer1.org1.example.com:8051   #  7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051    #7051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:8052  #7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052   #7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:8051  #7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
        - peer1.org1.example.com:/var/hyperledger/production
 
    ports:
      - 8051:8051   #這里不要忘記修改為   7051:7051
...
#只需要修改當前主機上需要啟動的節點的埠就可以,比如當前主機節點為peer0.org1.example.com,那么只需要修改peer0.org1...的埠資訊

2.3.2 docker-compose-cli.yaml(Order主機)

本文需要使用該檔案啟動節點,我們將該檔案復制一份,以orderer節點為例

#復制該檔案,并命名為docker-compose-orderer.yaml
cp docker-compose-cli.yaml docker-compose-orderer.yaml
#用編輯器打開該檔案
sudo vim docker-compose-orderer.yaml

我們只在這臺電腦上啟動orderer節點,所以關于peer節點的資訊用不到,我們將組態檔中多余的欄位洗掉,只留下這些內容

version: '2'
 
volumes:
  orderer.example.com:
 
networks:
  byfn:
 
services:
 
  orderer.example.com:
    extends:
      file:   base/docker-compose-base.yaml
      service: orderer.example.com
    container_name: orderer.example.com
    networks:
      - byfn

執行以下命令啟動Orderer節點

sudo docker-compose -f docker-compose-orderer.yaml up

可能問題:no such image: hyperledger/fabric-ordered::invalid reference format

**原因:**base/docker-compose-base.yaml沒有刪掉order.example.com下image的冒號

對于Order節點,關閉網路的命令:

sudo docker-compose -f docker-compose-orderer.yaml down --volumes

建議在每一次啟動網路之前都執行一次關閉網路的命令,

2.3.3 peer節點配置

以下以peer0.org1節點為例,其余peer節點操作相同

orderer 節點啟動成功后,我們使用 scp 命令將 first 檔案夾傳輸到 peer0.org1節點服務器,

#step1 進入到上級目錄
cd ..
#step2 傳輸檔案
sudo scp -r first/ [peer0.org1節點主機名]@10.65.26.64:/home/[用戶名]/

比如對我來說,我運行以下指令

sudo scp -r first/ lzz@172.18.4.33:/home/lzz/

輸入peer0.org1節點主機登錄密碼后,在peer0.org1節點主機/home/[用戶名]下查看到first檔案夾,將first移動到fabric-samples內first-network同級目錄

然后,我們去peer0.org1節點主機,對 peer0.org1節點進行配置,同樣,我們復制一份 docker-compose-cli.yaml 檔案:

#step1:進入傳輸到的first檔案夾
cd ~/first
#step2:復制docker-compose-cli.yaml檔案 并命名為docker-compose-peer0-Org1.yaml
cp docker-compose-cli.yaml docker-compose-peer0-Org1.yaml
#step3:用編輯器打開該檔案
vim docker-compose-peer0-Org1.yaml

對于peer0.Org1節點,同樣,首先洗掉多余的部分,添加一些欄位,記得根據自己的情況修改cli 部分的路徑!如果你和默認一樣就不用改了,如果不同一定要修改!!否則后面會出現問題,最終檔案內容為:

  • volumes只保留當前節點

  • extra_hosts 欄位除了當前節點不寫,其他節點都寫(比如我的Org1的peer0、peer1放在一臺主機,那么當前主機的此檔案只寫orderer、peer0.org2、peer1.org2的配置ip)

  • cli下的image洗掉$IMAGE_TAG前面的冒號

  • cli下的environment、working_dir、volumes中存盤路徑要和我們具體情況對應

    默認檔案里的路徑是/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/…,我們要把中間的fabric/peer/crypto/替換為fabric-samples/first/crypto-config/()

  • depends_on保留當前節點、extra_hosts保留所有節點

version: '2'
 
volumes:               #只保留當前節點
  peer0.org1.example.com:
 
networks:
  byfn:
 
services:
 
  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    extends:
      file:  base/docker-compose-base.yaml
      service: peer0.org1.example.com
    networks:
      - byfn
    extra_hosts:       #=========需要添加的額外欄位,這里不寫當前節點
      - "orderer.example.com:172.18.4.49"
      - "peer1.org1.example.com:172.18.4.34"
      - "peer0.org2.example.com:172.18.4.35"
      - "peer1.org2.example.com:172.18.4.36"
 
  cli:
    container_name: cli
    image: hyperledger/fabric-tools$IMAGE_TAG #====洗掉此處$IMAGE_TAG前面的冒號
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - FABRIC_LOGGING_SPEC=DEBUG
      - 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
      #上面四處替換如下
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    #working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric-samples/first
    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
        # 上述四行替換如下
        - ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/
        - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric-samples/first/scripts/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric-samples/first/channel-artifacts
    depends_on:       #========只保留當前節點
      - peer0.org1.example.com
    networks:
      - byfn
    extra_hosts:       #=========所有節點,包括order
      - "orderer.example.com:172.18.4.49"
      - "peer0.org1.example.com:172.18.4.33"     #這里需要寫當前節點,因為cli容器需要與peer0.org1節點進行通信
      - "peer1.org1.example.com:172.18.4.34"
      - "peer0.org2.example.com:172.18.4.35"
      - "peer1.org2.example.com:172.18.4.36"
 

修改完docker-compose-peer0-Org1.yaml后,打開base/peer-base.yaml:

  • 洗掉peer-base和orderer-base下$IMAGE_TAG前的冒號:
  • 修改services-environment-CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE={project_name}_byfn(已經修改,例如first_name)
  • 記得修改所有peer節點的first_byfn
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:
  peer-base:
    image: hyperledger/fabric-peer$IMAGE_TAG #===洗掉冒號
    environment:
      - GODEBUG=netdns=go
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=first_byfn
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start

  orderer-base:
    image: hyperledger/fabric-orderer$IMAGE_TAG #===洗掉冒號
    environment:
      - FABRIC_LOGGING_SPEC=INFO
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      # enabled TLS
      - ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_KAFKA_TOPIC_REPLICATIONFACTOR=1
      - ORDERER_KAFKA_VERBOSE=true
      - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer

peer0.org1的組態檔已經修改完畢,接下來我們啟動該節點:

sudo docker-compose -f docker-compose-peer0-Org1.yaml up

需要注意的是:如果后續操作有錯誤或者更新資訊,一定要使用

sudo docker-compose -f docker-compose-peer0-Org1.yaml down

先關閉網路然后再重新開啟網路生效,

啟動該節點后,如下表示成功啟動:

在這里插入圖片描述

如果沒有報錯的話,peer0.org1節點成功啟動,至于其他peer節點,只需要將 first 檔案夾使用 scp 命令復制到各個服務器上,按照該模板對組態檔進行修改即可,

3. 創建通道

3.1 創建通道

創建通道需要進入cli容器:(以peer0.org1節點為例)

在這里插入圖片描述

看到游標前的資訊由ubuntu變為xxxxxx則成功進入容器

首先配置環境變數:(每次退出cli容器之后再次進入需要重新設定環境變數!!!

#當前cli容器默認配置是節點peer0,所以不需要其他配置資訊
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#創建通道資訊
peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile $ORDERER_CA
#看到如下資訊說明創建通道成功
2019-06-20 13:05:55.829 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-06-20 13:05:55.926 UTC [cli.common] readBlock -> INFO 002 Received block: 0
#將生成的檔案移動到channel-artifacts檔案夾中
mv mychannel.block channel-artifacts/

3.2 加入通道(全在peer0Org1的主機上切換身份進行)

#因為當前cli容器使用的是peer0的配置,所以可以直接將peer0加入通道 
peer channel join -b channel-artifacts/mychannel.block
#更新環境變數使其他節點也加入通道
#=========peer1.org1===========  注意這里埠要與上面檔案中配置的埠號相同
CORE_PEER_ADDRESS=peer1.org1.example.com:8051  
#=========peer0.org2============
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:9051
peer channel join -b channel-artifacts/mychannel.block 
#=========peer1.org2=============
CORE_PEER_ADDRESS=peer1.org2.example.com:10051
peer channel join -b channel-artifacts/mychannel.block
#退出容器
exit

在這里插入圖片描述

3.3 更新錨節點

CORE_PEER_TLS_ROOTCERT_FILE、CORE_PEER_MSPCONFIGPATH中路徑對應正確

#重新進入容器
sudo docker exec -it cli bash
#更新環境變數
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#========Org1================
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile $ORDERER_CA
#========Org2================
#更新環境變數
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:9051
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile $ORDERER_CA
#退出容器
exit

4. 鏈碼的安裝測驗

4.1 安裝鏈碼

所有節點的安裝鏈碼一定要在第一臺安裝鏈碼的機器上切換身份進行安裝!!!

請注意,鏈碼的安裝需要安裝在所有節點,這一步需要如同3.2一樣,在peer0Org1節點主機切換身份,四個節點均需要安裝鏈碼,因為鏈碼相當于工具,每個節點安裝后我們才能呼叫鏈碼介面

#進入容器
sudo docker exec -it cli bash
#更新環境變數
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#=========peer0.org1=========== 
#這里很有可能會出現路徑不存在的錯誤,解決方法是在容器內找到對應的鏈碼所在位置,然后替換當前鏈碼路徑
##比如本文中鏈碼路徑為/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode/chaincode_example02/go
##則將下面命令的路徑進行替換github.com/hyperledger/fabric-samples/chaincode/chaincode_example02/go/chaincode_example02
 
#peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/chaincode_example02/go/
#實體化鏈碼 該步驟創建了a,b兩個賬戶,其中a賬戶余額定義為100,b賬戶余額定義為200
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR      ('Org1MSP.member','Org2MSP.member')"
#這一步執行完畢后可以在其他節點上也安裝鏈碼
  • 如果出現問題:Error: error getting chaincode code mycc: path to chaincode does not exist ,再訂正一遍 docker-compose-peer0-Org1.yaml 中的路徑有沒有問題,把之前啟動的網路關閉,在重啟,

  • 如果在其他三個節點身份下,出現Error: Bad response: 500 - error installing chaincode code mycc :1.0(chaincode /var/hyperledger/production/chaincodes/mycc.1.0 exists),執行以下命令,重啟網路進行嘗試,(但其實這說明已經存在,并不用再次下載)

docker rmi -f $(docker ps -aq) 
docker volume prune

4.2 實體化鏈碼

在通道上實體化鏈碼,這會在通道上初始化鏈碼,為鏈碼指定背書策略,然后為目標節點啟動鏈碼容器,同時指定 -P “OR (‘Org1MSP.member’,‘Org2MSP.member’)” 作為策略,

ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric-samples/first/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 
 
#實體化鏈碼 該步驟創建了a,b兩個賬戶,其中a賬戶余額定義為100,b賬戶余額定義為200
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
#這一步執行完畢后可以在其他節點上也安裝鏈碼

4.3 呼叫鏈碼

#以peer0.org1為例
#首先進入cli容器
sudo docker exec -it cli bash
#執行以下命令進行查詢a賬戶余額
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
#如果命令列輸出100說明鏈碼成功呼叫.
 
#接下來我們發起一筆交易:通過peer0.org1節點將a賬戶余額轉賬給b20
peer chaincode invoke -o orderer.example.com:7050  --tls true --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
#然后登陸peer1.org1節點進行查詢
CORE_PEER_ADDRESS=peer1.org1.example.com:8051 
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
#如果輸出結果為:80
說明Fabric網路手動搭建成功
#退出容器
exit

如果出現問題:Error: error getting endorser client for channel: endorser client failed to connect to peer1.org2.example.com:10051: failed to create new connection: context deadline exceeded
解決方法:在 docker-compose-cli.yaml 中 cli 容器下,添加環境變數 GODEBUG=netdns=go,在 base/peer-base.yaml 中 peer-base 容器下,添加環境變數 GODEBUG=netdns=go
無效,

因為我們在每個節點都安裝了鏈碼,所以在實體化之后,我們就可以在不同peer節點主機去進行交易,也仍然可以通過一臺主機切換身份來進行操作,

5 總結

以上就是Fabric1.4.1的多機部署程序,

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/303930.html

標籤:區塊鏈

上一篇:方差互換(Variance Swap)定價推導及VIX相關介紹

下一篇:2021.09.27數字貨幣小計

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • JAVA使用 web3j 進行token轉賬

    最近新學習了下區塊鏈這方面的知識,所學不多,給大家分享下。 # 1. 關于web3j web3j是一個高度模塊化,反應性,型別安全的Java和Android庫,用于與智能合約配合并與以太坊網路上的客戶端(節點)集成。 # 2. 準備作業 jdk版本1.8 引入maven <dependency> < ......

    uj5u.com 2020-09-10 03:03:06 more
  • 以太坊智能合約開發框架Truffle

    前言 部署智能合約有多種方式,命令列的瀏覽器的渠道都有,但往往跟我們程式員的風格不太相符,因為我們習慣了在IDE里寫了代碼然后打包運行看效果。 雖然現在IDE中已經存在了Solidity插件,可以撰寫智能合約,但是部署智能合約卻要另走他路,沒辦法進行一個快捷的部署與測驗。 如果團隊管理的區塊節點多、 ......

    uj5u.com 2020-09-10 03:03:12 more
  • 谷歌二次驗證碼成為區塊鏈專用安全碼,你怎么看?

    前言 谷歌身份驗證器,前些年大家都比較陌生,但隨著國內互聯網安全的加強,它越來越多地出現在大家的視野中。 比較廣泛接觸的人群是國際3A游戲愛好者,游戲盜號現象嚴重+國外賬號安全應用廣泛,這類游戲一般都會要求用戶系結名為“兩步驗證”、“雙重驗證”等,平臺一般都推薦用谷歌身份驗證器。 后來區塊鏈業務風靡 ......

    uj5u.com 2020-09-10 03:03:17 more
  • 密碼學DAY1

    目錄 ##1.1 密碼學基本概念 密碼在我們的生活中有著重要的作用,那么密碼究竟來自何方,為何會產生呢? 密碼學是網路安全、資訊安全、區塊鏈等產品的基礎,常見的非對稱加密、對稱加密、散列函式等,都屬于密碼學范疇。 密碼學有數千年的歷史,從最開始的替換法到如今的非對稱加密演算法,經歷了古典密碼學,近代密 ......

    uj5u.com 2020-09-10 03:03:50 more
  • 密碼學DAY1_02

    目錄 ##1.1 ASCII編碼 ASCII(American Standard Code for Information Interchange,美國資訊交換標準代碼)是基于拉丁字母的一套電腦編碼系統,主要用于顯示現代英語和其他西歐語言。它是現今最通用的單位元組編碼系統,并等同于國際標準ISO/IE ......

    uj5u.com 2020-09-10 03:04:50 more
  • 密碼學DAY2

    ##1.1 加密模式 加密模式:https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html ECB ECB : Electronic codebook, 電子密碼本. 需要加密的訊息按照塊密碼的塊大小被分為數個塊,并對每個塊進 ......

    uj5u.com 2020-09-10 03:05:42 more
  • NTP時鐘服務器的特點(京準電子)

    NTP時鐘服務器的特點(京準電子) NTP時鐘服務器的特點(京準電子) 京準電子官V——ahjzsz 首先對時間同步進行了背景介紹,然后討論了不同的時間同步網路技術,最后指出了建立全球或區域時間同步網存在的問題。 一、概 述 在通信領域,“同步”概念是指頻率的同步,即網路各個節點的時鐘頻率和相位同步 ......

    uj5u.com 2020-09-10 03:05:47 more
  • 標準化考場時鐘同步系統推進智能化校園建設

    標準化考場時鐘同步系統推進智能化校園建設 標準化考場時鐘同步系統推進智能化校園建設 安徽京準電子科技官微——ahjzsz 一、背景概述隨著教育事業的快速發展,學校建設如雨后春筍,隨之而來的學校教育、管理、安全方面的問題成了學校管理人員面臨的最大的挑戰,這些問題同時也是學生家長所擔心的。為了讓學生有更 ......

    uj5u.com 2020-09-10 03:05:51 more
  • 位元幣入門

    引言 位元幣基本結構 位元幣基礎知識 1)哈希演算法 2)非對稱加密技術 3)數字簽名 4)MerkleTree 5)哪有位元幣,有的是UTXO 6)位元幣挖礦與共識 7)區塊驗證(共識) 總結 引言 上一篇我們已經知道了什么是區塊鏈,此篇說一下區塊鏈的第一個應用——位元幣。其實先有位元幣,后有的區塊 ......

    uj5u.com 2020-09-10 03:06:15 more
  • 北斗對時服務器(北斗對時設備)電力系統應用

    北斗對時服務器(北斗對時設備)電力系統應用 北斗對時服務器(北斗對時設備)電力系統應用 京準電子科技官微(ahjzsz) 中國北斗衛星導航系統(英文名稱:BeiDou Navigation Satellite System,簡稱BDS),因為是目前世界范圍內唯一可以大面積提供免費定位服務的系統,所以 ......

    uj5u.com 2020-09-10 03:06:20 more
最新发布
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:46:47 more
  • Hyperledger Fabric 使用 CouchDB 和復雜智能合約開發

    在上個實驗中,我們已經實作了簡單智能合約實作及客戶端開發,但該實驗中智能合約只有基礎的增刪改查功能,且其中的資料管理功能與傳統 MySQL 比相差甚遠。本文將在前面實驗的基礎上,將 Hyperledger Fabric 的默認資料庫支持 LevelDB 改為 CouchDB 模式,以實作更復雜的資料... ......

    uj5u.com 2023-04-16 07:28:31 more
  • .NET Core 波場鏈離線簽名、廣播交易(發送 TRX和USDT)筆記

    Get Started NuGet You can run the following command to install the Tron.Wallet.Net in your project. PM> Install-Package Tron.Wallet.Net 配置 public reco ......

    uj5u.com 2023-04-14 08:08:00 more
  • DKP 黑客分析——不正確的代幣對比率計算

    概述: 2023 年 2 月 8 日,針對 DKP 協議的閃電貸攻擊導致該協議的用戶損失了 8 萬美元,因為 execute() 函式取決于 USDT-DKP 對中兩種代幣的余額比率。 智能合約黑客概述: 攻擊者的交易:0x0c850f,0x2d31 攻擊者地址:0xF38 利用合同:0xf34ad ......

    uj5u.com 2023-04-07 07:46:09 more
  • Defi開發簡介

    Defi開發簡介 介紹 Defi是去中心化金融的縮寫, 是一項旨在利用區塊鏈技術和智能合約創建更加開放,可訪問和透明的金融體系的運動. 這與傳統金融形成鮮明對比,傳統金融通常由少數大型銀行和金融機構控制 在Defi的世界里,用戶可以直接從他們的電腦或移動設備上訪問廣泛的金融服務,而不需要像銀行或者信 ......

    uj5u.com 2023-04-05 08:01:34 more
  • solidity簡單的ERC20代幣實作

    // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; import "hardhat/console.sol"; //ERC20 同質化代幣,每個代幣的本質或性質都是相同 //ETH 是原生代幣,它不是ERC20代幣, ......

    uj5u.com 2023-03-21 07:56:29 more
  • solidity 參考型別修飾符memory、calldata與storage 常量修飾符C

    在solidity語言中 參考型別修飾符(參考型別為存盤空間不固定的數值型別) memory、calldata與storage,它們只能修飾參考型別變數,比如字串、陣列、位元組等... memory 適用于方法傳參、返參或在方法體內使用,使用完就會清除掉,釋放記憶體 calldata 僅適用于方法傳參 ......

    uj5u.com 2023-03-08 07:57:54 more
  • solidity注解標簽

    在solidity語言中 注釋符為// 注解符為/* 內容*/ 或者 是 ///內容 注解中含有這幾個標簽給予我們使用 @title 一個應該描述合約/介面的標題 contract, library, interface @author 作者的名字 contract, library, interf ......

    uj5u.com 2023-03-08 07:57:49 more
  • 評價指標:相似度、GAS消耗

    【代碼注釋自動生成方法綜述】 這些評測指標主要來自機器翻譯和文本總結等研究領域,可以評估候選文本(即基于代碼注釋自動方法而生成)和參考文本(即基于手工方式而生成)的相似度. BLEU指標^[^?88^^?^]^:其全稱是bilingual evaluation understudy.該指標是最早用于 ......

    uj5u.com 2023-02-23 07:27:39 more
  • 基于NOSTR協議的“公有制”版本的Twitter,去中心化社交軟體Damus

    最近,一個幽靈,Web3的幽靈,在網路游蕩,它叫Damus,這玩意詮釋了什么叫做病毒式營銷,滑稽的是,一個Web3產品卻在Web2的產品鏈上瘋狂傳銷,各方大佬紛紛為其背書,到底發生了什么?Damus的葫蘆里,賣的是什么藥? 注冊和簡單實用 很少有什么產品在用戶注冊環節會有什么噱頭,但Damus確實出 ......

    uj5u.com 2023-02-05 06:48:39 more