安装过程最好有翻墙软件,会节省很多时间

安装前置软件

yum install git

yum install golang

下载安装脚本

mkdir fabric && cd fabric


wget  https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh

chmod +x bootstrap.sh

./bootstrap.sh

脚本会下载2.2.0版本的fabric镜像,二进制文件和样例代码

启动测试网络

设置golang模块下载代理

go env -w GOPROXY=https://goproxy.cn,direct

启动网络

cd ~/fabric/fabric-samples/test-network
./network.sh up

创建通道

./network.sh createChannel

部署链码

./network.sh deployCC

Org1 调用链码

cd ~/fabric/fabric-samples/test-network
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051


peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'

Org1查询链码

peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'

Org1 提交交易

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'

Org2 查询交易

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051


peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'

区块链浏览器

下载镜像

docker pull hyperledger/explorer

docker pull hyperledger/explorer-db

下载、拷贝配置文件


mkdir explorer && cd explorer

wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/examples/net1/config.json

wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/examples/net1/connection-profile/first-network.json -P connection-profile

wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/docker-compose.yaml

cp -r ~/fabric/fabric-samples/test-network/organizations ~/fabric/fabric-samples/

修改配置文件的卷挂载

vi docker-compose.yaml


version: '2.1'

volumes:
  pgdata:
  walletstore:

networks:
  mynetwork.com:
    external:
      name: net_test # 此处修改为test_network 启动的网络,使他们在同一个网络

services:

  explorerdb.mynetwork.com:
    image: hyperledger/explorer-db:latest
    container_name: explorerdb.mynetwork.com
    hostname: explorerdb.mynetwork.com
    environment:
      - DATABASE_DATABASE=fabricexplorer
      - DATABASE_USERNAME=hppoc
      - DATABASE_PASSWORD=password
    healthcheck:
      test: "pg_isready -h localhost -p 5432 -q -U postgres"
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - 5432:5432   #暴露端口 
    networks:
      - mynetwork.com

  explorer.mynetwork.com:
    image: hyperledger/explorer:latest
    container_name: explorer.mynetwork.com
    hostname: explorer.mynetwork.com
    environment:
      - DATABASE_HOST=explorerdb.mynetwork.com
      - DATABASE_DATABASE=fabricexplorer
      - DATABASE_USERNAME=hppoc
      - DATABASE_PASSWD=password
      - LOG_LEVEL_APP=debug
      - LOG_LEVEL_DB=debug
      - LOG_LEVEL_CONSOLE=info
      - LOG_CONSOLE_STDOUT=true
      - DISCOVERY_AS_LOCALHOST=false
    volumes:
      - ./config.json:/opt/explorer/app/platform/fabric/config.json
      - ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile
      - ./organizations:/tmp/crypto
      - walletstore:/opt/wallet
    command: sh -c "node /opt/explorer/main.js && tail -f /dev/null"
    ports:
      - 8080:8080
    depends_on:
      explorerdb.mynetwork.com:
        condition: service_healthy
    networks:
      - mynetwork.com

启动 区块链浏览器

docker-compose up -d

打开区块链浏览器


http://192.168.72.129:8080/#/login

输入账户 exploreradmin/exploreradminpw

浏览器

upload successful



区块链      fabric fabric 2.2.0

本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!