6.启动配置网络节点 docker-compose启动文件

章节目录

1.hyperledger-fabric 介绍和资料整理
2.服务环境准备
3.安装fabric 二进制源码程序
4.生成fabric身份信息文件(证书)
5.生成系统通道初始区块文件
6.启动配置网络节点 docker-compose启动文件
7.将组织加入通道
8.安装合约
configtx.yaml 详解
crypto-config.yaml配置详解

1.配置网络文件

1.1在项目根目录创建 docker 文件夹

mkdir docker

chmod -R 7777 docker

完成路径:/home/hyperledgerFabric/qkl_01/docker-compose-ymh- xxxx.yaml

文件夹下创建以下5个文件:

docker-compose-ymh-cli.yaml  # 客户端
docker-compose-ymh-orderer0.yaml # 排序orderer0节点
docker-compose-ymh-orderer1.yaml # 排序orderer1节点
docker-compose-ymh-org1-1peer.yaml # 组织1
docker-compose-ymh-org2-1peer.yaml # 组织2

1.2启动/停止 docker-compose网络

1.2.1 启动
docker-compose -f docker-compose-ymh-cli.yaml up -d  # 客户端
docker-compose -f docker-compose-ymh-orderer0.yaml  up -d  # 排序orderer0节点
docker-compose -f docker-compose-ymh-orderer1.yaml  up -d  # 排序orderer1节点
docker-compose -f docker-compose-ymh-org1-1peer.yaml  up -d  # 组织1
docker-compose -f docker-compose-ymh-org2-1peer.yaml   up -d  # 组织2/
1.2.2 停止
docker-compose -f docker-compose-ymh-cli.yaml down  # 客户端
docker-compose -f docker-compose-ymh-orderer0.yaml  down  # 排序orderer0节点
docker-compose -f docker-compose-ymh-orderer1.yaml  down  # 排序orderer1节点
docker-compose -f docker-compose-ymh-org1-1peer.yaml  down  # 组织1
docker-compose -f docker-compose-ymh-org2-1peer.yaml   down  # 组织2/
1.2.3 查看日志
## docker日志进程
docker logs -f --tail 100 orderer0.ymh.com (实时)
docker logs -f orderer1.ymh.com
12.4 进入容器
# 进入容器
docker exec -it fabric-cli bash
docker exec -it peer0.org1.ymh.com /bin/sh
# 退出容器
exit

2.docker-compose-ymh-cli.yaml # 客户端配置内容

version: '2.0'

services:

    cli:
        image: hyperledger/fabric-tools:2.4.4
        restart: always
        container_name: fabric-cli
        hostname: fabric-cli
        tty: true
        extra_hosts:
            - "orderer0.ymh.com:127.0.0.1"
            - "orderer1.ymh.com:127.0.0.1"
            - "peer0.org1.ymh.com:127.0.0.1"
            - "peer0.org2.ymh.com:127.0.0.1"
        environment:
            - CORE_PEER_ID=fabric-cli
            - CORE_PEER_ADDRESS=peer0.org1.ymh.com:2051 # default to operate on peer0.org1
            - CORE_PEER_LOCALMSPID=Org1MSP
            - CORE_PEER_TLS_CERT_FILE=/home/hyperledgerFabricqkl_01/crypto-config/peerOrganizations/org1.ymh.com/peers/peer0.org1.ymh.com/tls/server.crt
            - CORE_PEER_TLS_KEY_FILE=/home/hyperledgerFabricqkl_01/crypto-config/peerOrganizations/org1.ymh.com/peers/peer0.org1.ymh.com/tls/server.key
            - CORE_PEER_TLS_ROOTCERT_FILE=/home/hyperledgerFabricqkl_01/crypto-config/peerOrganizations/org1.ymh.com/peers/peer0.org1.ymh.com/tls/ca.crt
            - CORE_PEER_MSPCONFIGPATH=/home/hyperledgerFabricqkl_01/crypto-config/peerOrganizations/org1.ymh.com/users/Admin@org1.ymh.com/msp
            - FABRIC_LOGGING_SPEC=DEBUG
            - FABRIC_LOGGING_FORMAT=%{color}[%{id:03x} %{time:01-02 15:04:05.00 MST}] [%{module}] %{shortfunc} -> %{level:.4s}%{color:reset} %{message}
            - CORE_PEER_TLS_ENABLED=true  # to enable TLS, change to true
            - ORDERER_CA=/home/hyperledgerFabricqkl_01/crypto-config/ordererOrganizations/shineyue.com/orderers/orderer0.ymh.com/msp/tlscacerts/tlsca.ymh.com-cert.pem
        volumes:
            - ../config/crypto-config.yaml:/home/hyperledgerFabricqkl_01/crypto-config.yaml
            - ../config/configtx.yaml:/home/hyperledgerFabricqkl_01/configtx.yaml
            - ../crypto-config:/home/hyperledgerFabricqkl_01/crypto-config
            - ../channel-artifacts:/tmp/channel-artifacts
            - ../chaincode:/home/hyperledgerFabricqkl_01/chaincode
            - ../fabric-cil:/home/hyperledgerFabricqkl_01/fabric-cil
            - ../shell:/home/hyperledgerFabricqkl_01/shell
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
        command: bash -c 'cd /tmp; source scripts/func.sh; while true; do sleep 20170504; done'

3.docker-compose-ymh-orderer0.yaml # 排序orderer0节点

version: '2.0'

services:

    orderer0.ymh.com:  # There can be multiple orderers
  
        image: hyperledger/fabric-orderer:2.4.4
        restart: always
        container_name: orderer0.ymh.com
        hostname: orderer0.ymh.com
        ports:
            - "2050:2050"
            - "3441:3441"
        extra_hosts:
            - "orderer0.ymh.com:127.0.0.1"
            - "orderer1.ymh.com:127.0.0.1"
            - "peer0.org1.ymh.com:127.0.0.1"
            - "peer0.org2.ymh.com:127.0.0.1"
        environment:
            - FABRIC_LOGGING_SPEC=INFO
            - FABRIC_LOGGING_FORMAT="%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}"
            - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 # default: 127.0.0.1
            - ORDERER_GENERAL_LISTENPORT=2050
            - ORDERER_GENERAL_BOOTSTRAPMETHOD=file # default: provisional
            - ORDERER_GENERAL_BOOTSTRAPFILE/home/hyperledgerFabric/qkl_01/orderer.genesis.block # by default, all materials should be put under $FABRIC_CFG_PATH, which defaults to /etc/hyperledger/fabric
            - ORDERER_GENERAL_LOCALMSPID=OrdererMSP # default: DEFAULT
            - ORDERER_GENERAL_LOCALMSPDIR/home/hyperledgerFabric/qkl_01/msp
            - ORDERER_GENERAL_LEDGERTYPE=file
            #- ORDERER_GENERAL_LEDGERTYPE=json  # default: file
            - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:3441  # operation RESTful API
            - ORDERER_METRICS_PROVIDER=prometheus  # prometheus will pull metrics from orderer via /metrics RESTful API
            #- ORDERER_RAMLEDGER_HISTORY_SIZE=100  #only useful when use ram ledger
            # enabled TLS
            - ORDERER_GENERAL_TLS_ENABLED=true # default: false
            - ORDERER_GENERAL_TLS_PRIVATEKEY/home/hyperledgerFabric/qkl_01/tls/server.key
            - ORDERER_GENERAL_TLS_CERTIFICATE/home/hyperledgerFabric/qkl_01/tls/server.crt
            - ORDERER_GENERAL_TLS_ROOTCAS=[/home/hyperledgerFabric/qkl_01/tls/ca.crt]
            # Only required by raft mode
            - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY/home/hyperledgerFabric/qkl_01/tls/server.key
            - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE/home/hyperledgerFabric/qkl_01/tls/server.crt
            - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/home/hyperledgerFabric/qkl_01/tls/ca.crt]
            - ORDERER_GENERAL_CLUSTER_SENDBUFFERSIZE=10
        volumes:
            - /var/hyperledger_relay/productionorderer0_relay:/var/hyperledger/production
            - ../crypto-config/ordererOrganizations/shineyue.com/orderers/orderer0.ymh.com/msp:/home/hyperledgerFabric/qkl_01/msp
            - ../crypto-config/ordererOrganizations/shineyue.com/orderers/orderer0.ymh.com/tls/:/home/hyperledgerFabric/qkl_01/tls
            - ../channel-artifacts/orderer.genesis.block:/home/hyperledgerFabric/qkl_01/orderer.genesis.block
        expose:
            - "2050"  # gRPC
            - "3441"  # Operation REST
        command: orderer start

4.docker-compose-ymh-orderer1.yaml # 排序orderer1节点

version: '2.0'

services:

    orderer1.ymh.com:
        image: hyperledger/fabric-orderer:2.4.4
        restart: always
        container_name: orderer1.ymh.com
        hostname: orderer1.ymh.com
        ports:
            - "3050:3050"
            - "4441:4441"
        extra_hosts:
            - "orderer0.ymh.com:127.0.0.1"
            - "orderer1.ymh.com:127.0.0.1"
            - "peer0.org1.ymh.com:127.0.0.1"
            - "peer0.org2.ymh.com:127.0.0.1"
        environment:
            - FABRIC_LOGGING_SPEC=INFO
            - FABRIC_LOGGING_FORMAT="%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}"
            - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 # default: 127.0.0.1
            - ORDERER_GENERAL_LISTENPORT=3050
            - ORDERER_GENERAL_BOOTSTRAPMETHOD=file # default: provisional
            - ORDERER_GENERAL_BOOTSTRAPFILE=/home/hyperledgerFabric/qkl_01/orderer.genesis.block # by default, all materials should be put under $FABRIC_CFG_PATH, which defaults to /etc/hyperledger/fabric
            - ORDERER_GENERAL_LOCALMSPID=OrdererMSP # default: DEFAULT
            - ORDERER_GENERAL_LOCALMSPDIR=/home/hyperledgerFabric/qkl_01/msp
            - ORDERER_GENERAL_LEDGERTYPE=file
            #- ORDERER_GENERAL_LEDGERTYPE=json  # default: file
            - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:4441  # operation RESTful API
            - ORDERER_METRICS_PROVIDER=prometheus  # prometheus will pull metrics from orderer via /metrics RESTful API
            #- ORDERER_RAMLEDGER_HISTORY_SIZE=100  #only useful when use ram ledger
            # enabled TLS
            - ORDERER_GENERAL_TLS_ENABLED=true # default: false
            - ORDERER_GENERAL_TLS_PRIVATEKEY=/home/hyperledgerFabric/qkl_01/tls/server.key
            - ORDERER_GENERAL_TLS_CERTIFICATE=/home/hyperledgerFabric/qkl_01/tls/server.crt
            - ORDERER_GENERAL_TLS_ROOTCAS=[/home/hyperledgerFabric/qkl_01/tls/ca.crt]
            # Only required by raft mode
            - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/home/hyperledgerFabric/qkl_01/tls/server.key
            - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/home/hyperledgerFabric/qkl_01/tls/server.crt
            - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/home/hyperledgerFabric/qkl_01/tls/ca.crt]
            - ORDERER_GENERAL_CLUSTER_SENDBUFFERSIZE=10
        volumes:
            - /var/hyperledger_relay/productionorderer1_relay:/var/hyperledger/production
            - ../crypto-config/ordererOrganizations/shineyue.com/orderers/orderer1.ymh.com/msp:/home/hyperledgerFabric/qkl_01/msp
            - ../crypto-config/ordererOrganizations/shineyue.com/orderers/orderer1.ymh.com/tls/:/home/hyperledgerFabric/qkl_01/tls
            - ../channel-artifacts/orderer.genesis.block:/home/hyperledgerFabric/qkl_01/orderer.genesis.block
        expose:
            - "3050"  # gRPC
            - "4441"  # Operation REST
        command: orderer start

5.docker-compose-ymh-org1-1peer.yaml # 组织1

version: '2.0'

services:

    peer0.org1.ymh.com:
        image: hyperledger/fabric-peer:2.4.4
        restart: always
        container_name: peer0.org1.ymh.com
        hostname: peer0.org1.ymh.com
        ports:
            - "2051:2051"
            - "2052:2052"
            - "3442:3442"
        extra_hosts:
            - "orderer0.ymh.com:127.0.0.1"
            - "orderer1.ymh.com:127.0.0.1"
            - "peer0.org1.ymh.com:127.0.0.1"
            - "peer0.org2.ymh.com:127.0.0.1"
        environment:
            - FABRIC_LOGGING_SPEC=INFO
            - FABRIC_LOGGING_FORMAT="%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}"
            - CORE_PEER_ADDRESSAUTODETECT=false
            - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=host  # uncomment this to use specific network
            - CORE_PEER_GOSSIP_USELEADERELECTION=true
            - CORE_PEER_GOSSIP_ORGLEADER=false  # whether this node is the org leader, default to false
            - CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:3442  # operation RESTful API
            - CORE_METRICS_PROVIDER=prometheus  # prometheus will pull metrics from fabric via /metrics RESTful API
            - CORE_PEER_PROFILE_ENABLED=false
            - CORE_PEER_TLS_ENABLED=true
            - CORE_PEER_TLS_CLIENTAUTHREQUIRED=false
            - CORE_PEER_TLS_CERT_FILE=/home/hyperledgerFabric/qkl_01/tls/server.crt
            - CORE_PEER_TLS_KEY_FILE=/home/hyperledgerFabric/qkl_01/tls/server.key
            - CORE_PEER_TLS_ROOTCERT_FILE=/home/hyperledgerFabric/qkl_01/tls/ca.crt
            - CORE_PEER_TLS_CLIENTROOTCAS_FILES=/home/hyperledgerFabric/qkl_01/tls/ca.crt
            - CORE_PEER_MSPCONFIGPATH=/home/hyperledgerFabric/qkl_01/msp
            - CORE_CHAINCODE_BUILDER=hyperledger/fabric-ccenv:2.4.4
            - CORE_CHAINCODE_GOLANG_RUNTIME=hyperledger/fabric-baseos:2.4.4
            - CORE_CHAINCODE_JAVA_RUNTIME=hyperledger/fabric-javaenv:2.4
            - CORE_CHAINCODE_NODE_RUNTIME=hyperledger/fabric-nodeenv:2.4.4
            - CORE_PEER_ID=peer0.org1.ymh.com
            - CORE_PEER_ADDRESS=peer0.org1.ymh.com:2051
            - CORE_PEER_LISTENADDRESS=0.0.0.0:2051
            - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:2052
            - CORE_PEER_CHAINCODEADDRESS=peer0.org1.ymh.com:2052
            - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.ymh.com:2051
            - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.ymh.com:2051
            - CORE_PEER_LOCALMSPID=Org1MSP
            - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
            - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=peer0.org1.ymh.couchdb:5984
            - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin
            - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=adminpw
        volumes:
            - /var/hyperledger_relay/production_relayorg1:/var/hyperledger/production
            - /var/run/docker.sock:/var/run/docker.sock
            - ../crypto-config/peerOrganizations/org1.ymh.com/peers/peer0.org1.ymh.com/msp:/home/hyperledgerFabric/qkl_01/msp
            - ../crypto-config/peerOrganizations/org1.ymh.com/peers/peer0.org1.ymh.com/tls:/home/hyperledgerFabric/qkl_01/tls
        expose:
            - "2051"  # gRPC
            - "2052"  # chaincode
            - "3442"  # Operation REST
        #command: bash -c 'bash /tmp/peer_build.sh; peer node start'
        command: peer node start
        depends_on:
            - peer0.org1.ymh.couchdb
             
    peer0.org1.ymh.couchdb:
        image: couchdb:3.1.1
        container_name: peer0.org1.ymh.couchdb
        ports:
            - 2984:5984  # this is the restful API addr, can also access fauxton web ui thru http://localhost:5984/_utils/
        environment:
            - COUCHDB_USER=admin
            - COUCHDB_PASSWORD=adminpw

6.docker-compose-ymh-org2-1peer.yaml # 组织2

version: '2.0'

services:

    peer0.org2.ymh.com:
        image: hyperledger/fabric-peer:2.4.4
        restart: always
        container_name: peer0.org2.ymh.com
        hostname: peer0.org2.ymh.com
        ports:
            - "3051:3051"
            - "3052:3052"
            - "4442:4442"
        extra_hosts:
            - "orderer0.ymh.com:127.0.0.1"
            - "orderer1.ymh.com:127.0.0.1"
            - "peer0.org1.ymh.com:127.0.0.1"
            - "peer0.org2.ymh.com:127.0.0.1"
        environment:
            - FABRIC_LOGGING_SPEC=INFO
            - FABRIC_LOGGING_FORMAT="%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}"
            - CORE_PEER_ADDRESSAUTODETECT=false
            - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=host  # uncomment this to use specific network
            - CORE_PEER_GOSSIP_USELEADERELECTION=true
            - CORE_PEER_GOSSIP_ORGLEADER=false  # whether this node is the org leader, default to false
            - CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:4442  # operation RESTful API
            - CORE_METRICS_PROVIDER=prometheus  # prometheus will pull metrics from fabric via /metrics RESTful API
            - CORE_PEER_PROFILE_ENABLED=false
            - CORE_PEER_TLS_ENABLED=true
            - CORE_PEER_TLS_CLIENTAUTHREQUIRED=false
            - CORE_PEER_TLS_CERT_FILE=/home/hyperledgerFabric/qkl_01/tls/server.crt
            - CORE_PEER_TLS_KEY_FILE=/home/hyperledgerFabric/qkl_01/tls/server.key
            - CORE_PEER_TLS_ROOTCERT_FILE=/home/hyperledgerFabric/qkl_01/tls/ca.crt
            - CORE_PEER_TLS_CLIENTROOTCAS_FILES=/home/hyperledgerFabric/qkl_01/tls/ca.crt
            - CORE_PEER_MSPCONFIGPATH=/home/hyperledgerFabric/qkl_01/msp
            - CORE_CHAINCODE_BUILDER=hyperledger/fabric-ccenv:2.4.4
            - CORE_CHAINCODE_GOLANG_RUNTIME=hyperledger/fabric-baseos:2.4.4
            - CORE_CHAINCODE_JAVA_RUNTIME=hyperledger/fabric-javaenv:2.4
            - CORE_CHAINCODE_NODE_RUNTIME=hyperledger/fabric-nodeenv:2.4.4
            - CORE_PEER_ID=peer0.org2.ymh.com
            - CORE_PEER_ADDRESS=peer0.org2.ymh.com:3051
            - CORE_PEER_LISTENADDRESS=0.0.0.0:3051
            - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:3052
            - CORE_PEER_CHAINCODEADDRESS=peer0.org2.ymh.com:3052
            - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.ymh.com:3051
            - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.ymh.com:3051
            - CORE_PEER_LOCALMSPID=Org2MSP
            - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
            - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=peer0.org2.ymh.couchdb:5984
            - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin
            - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=adminpw
        volumes:
            - /var/hyperledger_relay/production_relayorg2:/var/hyperledger/productionorg2
            - /var/run/docker.sock:/var/run/docker.sock
            - ../crypto-config/peerOrganizations/org2.ymh.com/peers/peer0.org2.ymh.com/msp:/home/hyperledgerFabric/qkl_01/msp
            - ../crypto-config/peerOrganizations/org2.ymh.com/peers/peer0.org2.ymh.com/tls:/home/hyperledgerFabric/qkl_01/tls
        expose:
            - "3051"  # gRPC
            - "3052"  # chaincode
            - "4442"  # Operation REST
        #command: bash -c 'bash /tmp/peer_build.sh; peer node start'
        command: peer node start
        depends_on:
            - peer0.org2.ymh.couchdb

    peer0.org2.ymh.couchdb:
        image: couchdb:3.1.1
        container_name: peer0.org2.ymh.couchdb
        ports:
            - 3984:5984  # this is the restful API addr, can also access fauxton web ui thru http://localhost:5984/_utils/
        environment:
            - COUCHDB_USER=admin
            - COUCHDB_PASSWORD=adminpw

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值