我对hyperledger fabric1.1.0的执着(五):solo多机部署

时间:2018-11-30作者:klpeng分类:IT综合浏览:806评论:0

默认已安装好fabric环境。

我这里用两台服务器,一个作为orderer节点(192.168.2.238),一个作为peer节点(192.168.2.118)

1、在orderer服务器进入fabric源码目录:cd /opt/gopath/src/github.com/hyperledger/fabric/

2、在fabric源码目录下创建aberic文件夹:mkdir aberic

3、上传1.1.0版本的二进制文件并解压,解压后得到bin文件夹,删除config文件夹,如图:

我对hyperledger fabric1.1.0的执着(五):solo多机部署

4、从fabric1.0版本中复制examples/e2e_cli目录下的configtx.yaml和crypto-config.yaml文件到aberic目录。

5、生成证书文件:./bin/cryptogen generate --config=./crypto-config.yaml

我对hyperledger fabric1.1.0的执着(五):solo多机部署

6、为configtxgen工具指定configtx.yaml文件的路径,设置环境变量,执行以下命令:

设置环境变量:

export FABRIC_CFG_PATH=$PWD

然后查看该目录是否正确:

 echo $PWD

最终结果如图:

我对hyperledger fabric1.1.0的执着(五):solo多机部署

7、在aberic文件夹下创建文件夹channel-artifacts。

# ./bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block

我对hyperledger fabric1.1.0的执着(五):solo多机部署

8、生成channelID为mychannel(可自定义)的tx文件:

./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel

我对hyperledger fabric1.1.0的执着(五):solo多机部署

9、在aberic目录下创建文件夹chaincode,再在chaincode文件夹下创建文件夹go。将官方demo(我用的fabric1.0版本)中的chaincode_example02示例上传到go目录下。最终结果如图:

我对hyperledger fabric1.1.0的执着(五):solo多机部署

10、将orderer节点的aberic目录复制到peer节点(即从192.168.2.238复制到192.168.2.118)

11、部署oederer节点

(11.1)编写docker-orderer.yaml文件,内容如下:

version: '2'

services:

  orderer.example.com:
    container_name: orderer.example.com
    image: hyperledger/fabric-orderer
    environment:
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=aberic_default
      # - ORDERER_GENERAL_LOGLEVEL=error
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      #- ORDERER_GENERAL_GENESISPROFILE=AntiMothOrdererGenesis
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      #- ORDERER_GENERAL_LEDGERTYPE=ram
      #- ORDERER_GENERAL_LEDGERTYPE=file
      # enabled TLS
      - ORDERER_GENERAL_TLS_ENABLED=false
      - 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]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    volumes:
    - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
    - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
    - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
    networks:
      default:
        aliases:
          - aberic
    ports:
      - 7050:7050

(11.2)启动orderer节点:

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

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(11.3)查看是否启动成功:

docker ps

我对hyperledger fabric1.1.0的执着(五):solo多机部署

12、部署peer0.org1节点

(12.1)编写docker-peer01.yaml文件,具体内容如下:

version: '2'

services:

  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 Interface in dev environments.
    ports:
      - "5984:5984"

  ca:
    container_name: ca
    image: hyperledger/fabric-ca
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_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/a27a29896dbaa927e4e8a212b91ea0189fedf591198b29cce9d2106782e8ee02_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/a27a29896dbaa927e4e8a212b91ea0189fedf591198b29cce9d2106782e8ee02_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=couchdb:5984

      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_NETWORKID=aberic
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_CHAINCODELISTENADDRESS=peer0.org1.example.com: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 starts chaincode containers on the same
      # bridge network as the peers
      # 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_PROFILE_ENABLED=false
      - CORE_PEER_TLS_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
    extra_hosts:
    - "orderer.example.com:192.168.2.238"

  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=ERROR
      - 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/Admin@org1.example.com/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/aberic/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
    extra_hosts:
      - "orderer.example.com:192.168.2.238"
      - "peer0.org1.example.com:192.168.2.118"

(12.2)将文件上传至/opt/gopath/src/github.com/hyperledger/fabric/aberic目录并执行以下命令启动节点:

docker-compose -f docker-peer01.yaml up -d

我对hyperledger fabric1.1.0的执着(五):solo多机部署

启动完成后开始进行组网过程

(12.3)通过以下命令进入客户端进行对channel的相关操作:

docker exec -it cli bash

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(12.4)创建channel

peer channel create -o orderer.example.com:7050 -c mychannel -t 50 -f ./channel-artifacts/mychannel.tx

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(12.5)peer节点加入该channel

peer channel join -b mychannel.block

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(12.6)安装智能合约:

peer chaincode install -n mychannel -p github.com/hyperledger/fabric/aberic/chaincode/go/chaincode_example02 -v 1.0

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(12.7)实例化chaincode:

peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mychannel -c '{"Args":["init","A","10","B","10"]}' -P "OR ('Org1MSP.member')" -v 1.0

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(12.8)查询A账户资产:peer chaincode query -C mychannel -n mychannel -c '{"Args":["query","A"]}'

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(12.9)查询B账户资产:peer chaincode query -C mychannel -n mychannel -c '{"Args":["query","B"]}'

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(12.10)将A账户转移2个资产到B账户:peer chaincode invoke -C mychannel -n mychannel -c '{"Args":["invoke", "A", "B", "2"]}'

我对hyperledger fabric1.1.0的执着(五):solo多机部署

(12.11)分别查询账户A和账户B资产如图:

我对hyperledger fabric1.1.0的执着(五):solo多机部署

查询结果为账户A为8个,比原来少了两个,账户B为12个,比原来多了两个。表示成功

打赏
文章版权声明:除非注明,否则均为彭超的博客原创文章,转载或复制请以超链接形式并注明出处。
相关推荐

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

猜你喜欢