天天看點

hyperledger-fabric1.1 單機多點部署(3)-部署peer0.org1節點

部落客最近部署fabric發現,fabric的部署很友善,同時官方提供了示範腳本,部落客在部署官方示範腳本end-2-end的時候,發現啟動環境是如此簡單流暢!!但也帶來了一個問題,因為腳本過于流暢和簡單,單機多節點的啟動的具體了解确變的複雜,為此部落客開始了手動搭建單機多節點的征程,同時記錄下來希望對大家有所幫助下面是此系列文章的目錄結構,供大家品嘗

hyperledger-fabric1.1 單機多點部署(1)-生成證書檔案 

hyperledger-fabric1.1 單機多點部署(2)-部署orderer節點

hyperledger-fabric1.1 單機多點部署(3)-部署peer0.org1節點

hyperledger-fabric1.1 單機多點部署(4)-搭建fabric網絡

hyperledger-fabric1.1 單機多點部署(5)-初步了解智能合約

hyperledger-fabric1.1 單機多點部署(6)-部署peer0.org2節點

有了Orderer排序服務啟動檔案,還需要專門為Peer節點所準備的docker-peer.yaml啟動檔案。

  docker-peer.yaml内部源碼如下

version: "2"

service:
  couchdb:
    container_name: couchdb
    image: hyperledger/fabric-couchdb
    # Comment/Uncomment the port mapping if you want to hide/expose the CouchDB service,
    # for example map it to utilize Fauxton User Inter千ace in dev environments.
    ports: 
     - "5984:5984"
  ca: 
    container_name: ca
    image: hyperledger/ca
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_NAME=ca
      - FABRIC_CA_SERVER_TLS_ENABLED=false
      - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem
      - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/2faa50f24805ad2aa198ebf90a33e8b26d3410d4f7cdb0907d80f4548c63eb08_sk
    ports: 
      - "7054:7054"
      command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/2faa50f24805ad2aa198ebf90a33e8b26d3410d4f7cdb0907d80f4548c63eb08_sk -b admin:adminpw -d'
      volumes:
      - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984

      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP

      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #the following setting star、ts chaincode containers on the same
      #bridge network as the peer
      # https://docs.docker、.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=aberic
      # - CORE_LOGGING_LEVEL=ERROR
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=aberic_default
      - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_GOSSIP_ENABLED=false
      - 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
    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
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports: 
      - 7051:7051
      - 7052:7052
      - 7053:7053
    depends_on:
      - couchdb
    networks:
      default:
        aliases:
          - aberic
    cli:
      container_name: cli
      image: hyperledger/fabric-tools
      tty: true
      environment:
        - GOPATH=/opt/gopath
        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
        - CORE_LOGGING_LEVEL=DEBUG
        - CORE_PEER_ID=cli
        - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
        - CORE_PEER_LOCALMSPID=Org1MSP
        - CORE_PEER_TLS_ENABLED=false
        - 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/[email protected]/msp
      working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
      volumes:
        - /var/run/:/host/var/run/
        - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
      depends_on:
        - peer0.org1.example.com
           

peer的啟動檔案包含較多,其中包含cli用戶端,CouchDB插件以及CA伺服器端插件。

注意!!!注意!!!

這其中有幾個由于個人生成配置檔案不同,需要修改的地方一處是FABRIC_CA_SERVER_TLS_KEYFILE 一部分command中最後一部分,這兩處以_sk結尾的檔案名需要替換成當初生成的檔案名,具體路徑如下圖2所示

hyperledger-fabric1.1 單機多點部署(3)-部署peer0.org1節點
hyperledger-fabric1.1 單機多點部署(3)-部署peer0.org1節點

為Peer節點所準備的docker-peer.yaml啟動檔案的編譯就到此為止接下來我們将開始搭建fabric網絡