hyperledger fabric 1.4 kafk 部署

hyperledger fabric 1.4 kafk 部署

本人只有一台服务器,所以全部做在一台机器上了,多台参考链接:https://www.cnblogs.com/llongst/p/9608886.html
参考https://blog.csdn.net/baidu_25845567/article/details/83240748
本人是阿里云服务器,所以会出现异常,解决参考链接:https://blog.csdn.net/scylhy/article/details/82634322

cd /opt
mkdir golang
cd golang
wget https://studygolang.com/dl/golang/go1.10.3.linux-amd64.tar.gz
tar -zvxf go1.10.3.linux-amd64.tar.gz
  • 1.3.1 配置go语言环境
#vi /etc/profile
export GOROOT=/opt/golang/go
export PATH=$GOROOT/bin:$PATH
export GOPATH=/opt/gopath
  • 1.3.2 让配置文件起作用
source /etc/profile
  • 1.3.3 查看版本与环境变量
go version
go env
  • 1.3 安装git
go env
  • 2. 安装fabric

  • 2.1 下载fabric镜像

wget https://raw.githubusercontent.com/hyperledger/fabric/release-1.4/scripts/bootstrap.sh
chmod u+x bootstrap.sh
./bootstrap.sh

其中如果遇到网络原因下不了https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.4.1/hyperledger-fabric-linux-amd64-1.4.1.tar.gz
就把图中注解掉,只下载镜像。(然后重新打开多次尝试就成功了)
在这里插入图片描述

  • 2.2 准备生成证书和配置区块文件

  • 2.2.1 crypto-config.yaml


OrdererOrgs:

  - Name: Orderer
    Domain: example.com
    Specs:
      - Hostname: orderer0
      - Hostname: orderer1
      - Hostname: orderer2

PeerOrgs:

 - Name: Org1
    Domain: org1.example.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1
 
 - Name: Org2
    Domain: org2.example.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1
  • 2.2.2 configtx.yaml
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

---
################################################################################
#
#   Section: Organizations
#
#   - This section defines the different organizational identities which will
#   be referenced later in the configuration.
#
################################################################################
Organizations:

    # SampleOrg defines an MSP using the sampleconfig.  It should never be used
    # in production but may be used as a template for other definitions
    - &OrdererOrg
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: OrdererOrg

        # ID to load the MSP definition as
        ID: OrdererMSP

        # MSPDir is the filesystem path which contains the MSP configuration
        MSPDir: crypto-config/ordererOrganizations/example.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('OrdererMSP.admin')"

    - &Org1
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org1MSP

        # ID to load the MSP definition as
        ID: Org1MSP

        MSPDir: crypto-config/peerOrganizations/org1.example.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org1MSP.admin')"

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org1.example.com
              Port: 7051

    - &Org2
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org2MSP

        # ID to load the MSP definition as
        ID: Org2MSP

        MSPDir: crypto-config/peerOrganizations/org2.example.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org2MSP.admin')"

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org2.example.com
              Port: 7051

################################################################################
#
#   SECTION: Capabilities
#
#   - This section defines the capabilities of fabric network. This is a new
#   concept as of v1.1.0 and should not be utilized in mixed networks with
#   v1.0.x peers and orderers.  Capabilities define features which must be
#   present in a fabric binary for that binary to safely participate in the
#   fabric network.  For instance, if a new MSP type is added, newer binaries
#   might recognize and validate the signatures from this type, while older
#   binaries without this support would be unable to validate those
#   transactions.  This could lead to different versions of the fabric binaries
#   having different world states.  Instead, defining a capability for a channel
#   informs those binaries without this capability that they must cease
#   processing transactions until they have been upgraded.  For v1.0.x if any
#   capabilities are defined (including a map with all capabilities turned off)
#   then the v1.0.x peer will deliberately crash.
#
################################################################################
Capabilities:
    # Channel capabilities apply to both the orderers and the peers and must be
    # supported by both.  Set the value of the capability to true to require it.
    Global: &ChannelCapabilities
        # V1.1 for Global is a catchall flag for behavior which has been
        # determined to be desired for all orderers and peers running v1.0.x,
        # but the modification of which would cause incompatibilities.  Users
        # should leave this flag set to true.
        V1_1: true

    # Orderer capabilities apply only to the orderers, and may be safely
    # manipulated without concern for upgrading peers.  Set the value of the
    # capability to true to require it.
    Orderer: &OrdererCapabilities
        # V1.1 for Order is a catchall flag for behavior which has been
        # determined to be desired for all orderers running v1.0.x, but the
        # modification of which  would cause incompatibilities.  Users should
        # leave this flag set to true.
        V1_1: true

    # Application capabilities apply only to the peer network, and may be safely
    # manipulated without concern for upgrading orderers.  Set the value of the
    # capability to true to require it.
    Application: &ApplicationCapabilities
        # V1.1 for Application is a catchall flag for behavior which has been
        # determined to be desired for all peers running v1.0.x, but the
        # modification of which would cause incompatibilities.  Users should
        # leave this flag set to true.
        V1_2: true

################################################################################
#
#   SECTION: Application
#
#   - This section defines the values to encode into a config transaction or
#   genesis block for application related parameters
#
################################################################################
Application: &ApplicationDefaults

    # Organizations is the list of orgs which are defined as participants on
    # the application side of the network
    Organizations:

    # Policies defines the set of policies at this level of the config tree
    # For Application policies, their canonical path is
    #   /Channel/Application/<PolicyName>
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"

    # Capabilities describes the application level capabilities, see the
    # dedicated Capabilities section elsewhere in this file for a full
    # description
    Capabilities:
        <<: *ApplicationCapabilities

################################################################################
#
#   SECTION: Orderer
#
#   - This section defines the values to encode into a config transaction or
#   genesis block for orderer related parameters
#
################################################################################
Orderer: &OrdererDefaults

    # Orderer Type: The orderer implementation to start
    # Available types are "solo" and "kafka"
    OrdererType: kafka

    Addresses:
        - orderer0.example.com:7050
        - orderer1.example.com:7050
        - orderer2.example.com:7050

    # Batch Timeout: The amount of time to wait before creating a batch
    BatchTimeout: 2s

    # Batch Size: Controls the number of messages batched into a block
    BatchSize:

        # Max Message Count: The maximum number of messages to permit in a batch
        MaxMessageCount: 10

        # Absolute Max Bytes: The absolute maximum number of bytes allowed for
        # the serialized messages in a batch.
        AbsoluteMaxBytes: 98 MB

        # Preferred Max Bytes: The preferred maximum number of bytes allowed for
        # the serialized messages in a batch. A message larger than the preferred
        # max bytes will result in a batch larger than preferred max bytes.
        PreferredMaxBytes: 512 KB

    Kafka:
        # Brokers: A list of Kafka brokers to which the orderer connects. Edit
        # this list to identify the brokers of the ordering service.
        # NOTE: Use IP:port notation.
        Brokers:
            - kafka0:9092
            - kafka1:9092
            - kafka2:9092
            - kafka3:9092

    # Organizations is the list of orgs which are defined as participants on
    # the orderer side of the network
    Organizations:

    # Policies defines the set of policies at this level of the config tree
    # For Orderer policies, their canonical path is
    #   /Channel/Orderer/<PolicyName>
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        # BlockValidation specifies what signatures must be included in the block
        # from the orderer for the peer to validate it.
        BlockValidation:
            Type: ImplicitMeta
            Rule: "ANY Writers"

    # Capabilities describes the orderer level capabilities, see the
    # dedicated Capabilities section elsewhere in this file for a full
    # description
    Capabilities:
        <<: *OrdererCapabilities

################################################################################
#
#   CHANNEL
#
#   This section defines the values to encode into a config transaction or
#   genesis block for channel related parameters.
#
################################################################################
Channel: &ChannelDefaults
    # Policies defines the set of policies at this level of the config tree
    # For Channel policies, their canonical path is
    #   /Channel/<PolicyName>
    Policies:
        # Who may invoke the 'Deliver' API
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        # Who may invoke the 'Broadcast' API
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        # By default, who may modify elements at this config level
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"


    # Capabilities describes the channel level capabilities, see the
    # dedicated Capabilities section elsewhere in this file for a full
    # description
    Capabilities:
        <<: *ChannelCapabilities

################################################################################
#
#   Profile
#
#   - Different configuration profiles may be encoded here to be specified
#   as parameters to the configtxgen tool
#
################################################################################
Profiles:

    TwoOrgsOrdererGenesis:
        <<: *ChannelDefaults
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2

    TwoOrgsChannel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
  • 2.2.3 生成公私钥和证书
./bin/cryptogen generate --config=./crypto-config.yaml
  • 2.2.4 生成创世区块
mkdir channel-artifacts
./bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
  • 2.2.5 生成通道配置区块
./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel
  • 2.2.6 更新锚节点
./bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
./bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
  • 3. docker compose 文件
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
 
version: '2'
 
services:

    zookeeper0:
        container_name: zookeeper0
        image: hyperledger/fabric-zookeeper
        restart: always       
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - ZOO_MY_ID=1
            - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888
        volumes:
            - ./data/zk0data/:/data/
            - ./data/zk0datalog/:/datalog/
            
    zookeeper1:
        container_name: zookeeper1
        image: hyperledger/fabric-zookeeper
        restart: always
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - ZOO_MY_ID=2
            - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888
        volumes:
            - ./data/zk1data/:/data/
            - ./data/zk1datalog/:/datalog/
            
    zookeeper2:
        container_name: zookeeper2
        image: hyperledger/fabric-zookeeper
        restart: always
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - ZOO_MY_ID=3
            - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888
        volumes:
            - ./data/zk2data/:/data/
            - ./data/zk2datalog/:/datalog/
 
    kafka0:
        container_name: kafka0
        image: hyperledger/fabric-kafka
        restart: always
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - KAFKA_MESSAGE_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
            - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
            - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
            - KAFKA_BROKER_ID=0
            - KAFKA_MIN_INSYNC_REPLICAS=2
            - KAFKA_DEFAULT_REPLICATION_FACTOR=3
            - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
        volumes:
            - ./data/kafka0logs/:/opt/kafka/logs
        depends_on:
            - zookeeper0
            - zookeeper1
            - zookeeper2
 
    kafka1:
        container_name: kafka1
        image: hyperledger/fabric-kafka
        restart: always
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - KAFKA_MESSAGE_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
            - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
            - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
            - KAFKA_BROKER_ID=1
            - KAFKA_MIN_INSYNC_REPLICAS=2
            - KAFKA_DEFAULT_REPLICATION_FACTOR=3
            - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
        volumes:
            - ./data/kafka1logs/:/opt/kafka/logs
        depends_on:
            - zookeeper0
            - zookeeper1
            - zookeeper2
 
    kafka2:
        container_name: kafka2
        image: hyperledger/fabric-kafka
        restart: always
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - KAFKA_MESSAGE_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
            - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
            - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
            - KAFKA_BROKER_ID=2
            - KAFKA_MIN_INSYNC_REPLICAS=2
            - KAFKA_DEFAULT_REPLICATION_FACTOR=3
            - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
        volumes:
            - ./data/kafka2logs/:/opt/kafka/logs
        depends_on:
            - zookeeper0
            - zookeeper1
            - zookeeper2
 
    kafka3:
        container_name: kafka3
        image: hyperledger/fabric-kafka
        restart: always
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - KAFKA_MESSAGE_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
            - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
            - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
            - KAFKA_BROKER_ID=3
            - KAFKA_MIN_INSYNC_REPLICAS=2
            - KAFKA_DEFAULT_REPLICATION_FACTOR=3
            - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
        volumes:
            - ./data/kafka3logs/:/opt/kafka/logs
        depends_on:
            - zookeeper0
            - zookeeper1
            - zookeeper2

    orderer0.example.com:
        container_name: orderer0.example.com
        image: hyperledger/fabric-orderer
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - ORDERER_GENERAL_LOGLEVEL=debug
            - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
            - ORDERER_GENERAL_LISTENPORT=7050
            - 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_RETRY_SHORTINTERVAL=1s
            - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
            - ORDERER_KAFKA_VERBOSE=true
            - ORDERER_KAFKA_BROKERS=[kafka0:9092,kafka1:9092,kafka2:9092,kafka3:9092]
            - ORDERER_OPERATIONS_LISTENADDRESS=orderer0.example.com:8443
            - ORDERER_METRICS_PROVIDER=prometheus
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric
        command: orderer
        volumes:
            - ./data/orderer0/var/hyperledger/:/var/hyperledger/
            - "./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block"
            - ./crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp:/var/hyperledger/orderer/msp
            - ./crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/:/var/hyperledger/orderer/tls
        ports:
            - 7050:7050
            - 8443:8443
        depends_on:
            - zookeeper0
            - zookeeper1
            - zookeeper2
            - kafka0
            - kafka1
            - kafka2
            - kafka3
      
    orderer1.example.com:
        container_name: orderer1.example.com
        image: hyperledger/fabric-orderer
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - ORDERER_GENERAL_LOGLEVEL=debug
            - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
            - ORDERER_GENERAL_LISTENPORT=7050
            - 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_RETRY_SHORTINTERVAL=1s
            - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
            - ORDERER_KAFKA_VERBOSE=true
            - ORDERER_KAFKA_BROKERS=[kafka0:9092,kafka1:9092,kafka2:9092,kafka3:9092]
            - ORDERER_OPERATIONS_LISTENADDRESS=orderer1.example.com:8443
            - ORDERER_METRICS_PROVIDER=prometheus
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric
        command: orderer
        volumes:
            - ./data/orderer1/var/hyperledger/:/var/hyperledger/
            - "./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block"
            - ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp:/var/hyperledger/orderer/msp
            - ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/:/var/hyperledger/orderer/tls
        ports:
            - 17050:7050
            - 18443:8443
        depends_on:
            - zookeeper0
            - zookeeper1
            - zookeeper2
            - kafka0
            - kafka1
            - kafka2
            - kafka3      
     
    orderer2.example.com:
        container_name: orderer2.example.com
        image: hyperledger/fabric-orderer
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - ORDERER_GENERAL_LOGLEVEL=debug
            - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
            - ORDERER_GENERAL_LISTENPORT=7050
            - 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_RETRY_SHORTINTERVAL=1s
            - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
            - ORDERER_KAFKA_VERBOSE=true
            - ORDERER_KAFKA_BROKERS=[kafka0:9092,kafka1:9092,kafka2:9092,kafka3:9092]
            - ORDERER_OPERATIONS_LISTENADDRESS=orderer2.example.com:8443
            - ORDERER_METRICS_PROVIDER=prometheus
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric
        command: orderer
        volumes:
            - ./data/orderer2/var/hyperledger/:/var/hyperledger/
            - "./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block"
            - ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/msp:/var/hyperledger/orderer/msp
            - ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/:/var/hyperledger/orderer/tls
        ports:
            - 27050:7050
            - 28443:8443
        depends_on:
            - zookeeper0
            - zookeeper1
            - zookeeper2
            - kafka0
            - kafka1
            - kafka2
            - kafka3     

    couchdb0:
        container_name: couchdb0
        image: hyperledger/fabric-couchdb
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
        #    volumes:
        #      - ./data/couchdb/data:/opt/couchdb/data
        ports:
            - "5984:5984"

    ca0:
        image: hyperledger/fabric-ca
        environment:
            - GODEBUG=netdns=go
            - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
            - FABRIC_CA_SERVER_CA_NAME=ca-org1
            - FABRIC_CA_SERVER_TLS_ENABLED=true
            - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem
            # 替换成你自己./crypto-config/peerOrganizations/org1.example.com/ca/路径下的
            - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/4695aa40e54c4a22a5a5bf2c6c79087aba7d29bcfdd2e2726608a02a54e7f1f9_sk
        ports:
            - "7054:7054"
        # 替换成你自己./crypto-config/peerOrganizations/org1.example.com/ca/路径下的
        command: sh -c 'fabric-ca-server start --cfg.affiliations.allowremove --cfg.identities.allowremove --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/4695aa40e54c4a22a5a5bf2c6c79087aba7d29bcfdd2e2726608a02a54e7f1f9_sk -b admin:adminpw -d'
        volumes:
            - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
            - ./data/ca0/:/etc/hyperledger/fabric-ca-server
        container_name: ca_peerOrg1            
          
    peer0.org1.example.com:
        container_name: peer0.org1.example.com
        image: hyperledger/fabric-peer
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
            - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984
            - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
            - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_default
            - 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_LOGGING_LEVEL=ERROR
            - CORE_LOGGING_LEVEL=info
            - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
            - CORE_PEER_GOSSIP_USELEADERELECTION=true
            - CORE_PEER_GOSSIP_ORGLEADER=false
            - CORE_PEER_PROFILE_ENABLED=false
            - CORE_PEER_TLS_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
            - CORE_OPERATIONS_LISTENADDRESS=peer0.org1.example.com:9443
            - CORE_METRICS_PROVIDER=prometheus
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
        command: peer node star
        volumes:
            - ./data/peer0org1/var/hyperledger/:/var/hyperledger/
            - /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
        ports:
            - 7051:7051
            - 7052:7052
            - 7053:7053
        depends_on:
            - couchdb0

  # peer1.org1.example.com:
    # container_name: peer1.org1.example.com
    # image: hyperledger/fabric-peer
    # environment:
    # - TZ=Asia/Shanghai    
      # - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=net_default
      # - CORE_PEER_ID=peer1.org1.example.com
      # - CORE_PEER_ADDRESS=peer1.org1.example.com:7051
      # - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:7052
      # - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      # - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:7051
      # - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
      # - CORE_PEER_LOCALMSPID=Org1MSP
      #- CORE_LOGGING_LEVEL=ERROR
      # - CORE_LOGGING_LEVEL=info
      # - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
      # - 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
      # - CORE_OPERATIONS_LISTENADDRESS=peer1.org1.example.com:9443
            # - CORE_METRICS_PROVIDER=prometheus
    # working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    # command: peer node start     
    # volumes:
    # - ./data/peer0org1/var/hyperledger/:/var/hyperledger/
        # - /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
    # ports:
      # - 8051:7051
      # - 8052:7052
      # - 8053:7053
          
    couchdb1:
        container_name: couchdb1
        image: hyperledger/fabric-couchdb
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
        #    volumes:
        #      - /data/couchdb/data:/opt/couchdb/data
        ports:
            - "6984:5984"       
        
    ca1:
        image: hyperledger/fabric-ca
        environment:
            - GODEBUG=netdns=go
            - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
            - FABRIC_CA_SERVER_CA_NAME=ca-org2
            - FABRIC_CA_SERVER_TLS_ENABLED=true
            - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem
            # 替换成你自己./crypto-config/peerOrganizations/org2.example.com/ca/路径下的
            - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/ed4599a5f5dfb0b879d4e659d5aea404ac45f80c69f9af677c76d7eb546e3ff1_sk
        ports:
            - "8054:7054"
        # 替换成你自己./crypto-config/peerOrganizations/org2.example.com/ca/路径下的
        command: sh -c 'fabric-ca-server start --cfg.affiliations.allowremove --cfg.identities.allowremove --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/ed4599a5f5dfb0b879d4e659d5aea404ac45f80c69f9af677c76d7eb546e3ff1_sk -b admin:adminpw -d'
        volumes:
            - ./crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
            - ./data/ca1/:/etc/hyperledger/fabric-ca-server
        container_name: ca_peerOrg2
 
    peer0.org2.example.com:
        container_name: peer0.org2.example.com
        image: hyperledger/fabric-peer
        environment:
            - GODEBUG=netdns=go
            - TZ=Asia/Shanghai
            - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
            - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb1:5984
            - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
            - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_default
            - CORE_PEER_ID=peer0.org2.example.com
            - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
            - CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:7052
            - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
            - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
            - CORE_PEER_LOCALMSPID=Org2MSP
            #- CORE_LOGGING_LEVEL=ERROR
            - CORE_LOGGING_LEVEL=info
            - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
            - CORE_PEER_GOSSIP_USELEADERELECTION=true
            - CORE_PEER_GOSSIP_ORGLEADER=false
            - CORE_PEER_PROFILE_ENABLED=false
            - CORE_PEER_TLS_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
            - CORE_OPERATIONS_LISTENADDRESS=peer0.org2.example.com:9443
            - CORE_METRICS_PROVIDER=prometheus
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
        command: peer node start
        volumes:
            - ./data/peer0org2/var/hyperledger/:/var/hyperledger/
            - /var/run/:/host/var/run/
            - ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
            - ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
        ports:
            - 9051:7051
            - 9052:7052
            - 9053:7053
        depends_on:
            - couchdb1
 
 
    cli:
        container_name: cli
        image: hyperledger/fabric-tools
        tty: true
        environment:
            - GODEBUG=netdns=go
            - GOPATH=/opt/gopath
            - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
            - CORE_LOGGING_LEVEL=info
            - 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
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
        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/
            - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
        depends_on:
            - orderer0.example.com
            - orderer1.example.com
            - orderer2.example.com
            - peer0.org1.example.com
            - peer0.org2.example.com
  • 3.1 启动docker compose文件
docker-compose -f docker-compose.yaml up -d
  • 3.2 如果是阿里服务器
阿里云新服务器域名解析配置/etc/resonv.conf多了一项,解决办法就是注释掉option这一项
  • 3.3 创建channel
docker exec -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051" -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_TLS_ENABLED=true" -e "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" -e "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" -e "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" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer channel create -c mychannel -f channel-artifacts/mychannel.tx -o orderer0.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -t 60s
  • 3.4 peer0.org1.example.com加入channel
docker exec -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051" -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_TLS_ENABLED=true" -e "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" -e "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" -e "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" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer channel join -b mychannel.block

在这里插入图片描述
出现了问题,不知道啥原因,哎 阿里云坑

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值