0、说明


网络拓扑:


主机信息:

主机IP主机角色部署服务本例中终端颜色样式
192.168.56.129CA服务器

TLS-CA 、Org0 CA、Org1 CA

192.168.56.130Org0-OrdererOrderer

192.168.56.131Org1-peer1peer1.org1

192.168.56.132Org1-peer2peer2.org1

192.168.56.133Org2-peer1peer1.org2

192.168.56.134Org2-peer2peer2.org2





1、安装TLS CA

TLS CA用于颁发TLS证书。

TLS证书专用于加密各种过程的通信连接。

使用docker方式启动,配置文件如下:

我们先注册一些 Identity,以便后面使用注册的这些identity颁发TLS证书。要想进行注册,我们先enroll TLS CA的admin。

因为我们TLS CA启用了TLS,所以我们在enroll及注册时,需要指定TLS CA的根证书,本例为/root/hyperledger/tls/ca/crypto/ca-cert.pem。

同时我们指定一个FABRIC_CA_CLIENT_HOME来存放enroll的证书材料。

下面是注册过程:





2、区块链组织1 => Org1设置


2.1、设置Org1 CA

2.1.1、安装CA

每个组织都必须有自己的CA,来颁发enrollment证书。

这个CA用来颁发组织内peers、clients用的证书。

各个组织的CA创建属于各自组织的identity,并为每个identity颁发公钥和私钥。

这些密钥使得你所有的nodes和applications可以签名并验证他们的操作。

使用docker方式安装:

2.1.2、注册Org1相关的identity

作为参与区块链的组织Org1,我们需要注册相关的Identities。

我们将注册四个Identities, (Q_CF后续需要研究集成LDAP后如何注册)

Peer1

这里我们注册为peer1-org1

Peer2

这里我们注册为peer2-org1

Org1 Admin

组织的管理员,我们注册为admin1-org1

End User

终端用户,我们注册为user1-org1

要注册这些identity,我们首先要enroll Org1 CA的Admin。因为Org1 CA启用了TLS,所以我们需要将其根证书copy到运行enroll即register命令的机器上。


我们设置FABRIC_CA_CLIENT_HOME为/root/fabric-ca-client-home。enroll的所有证书材料等默认存放在$FABRIC_CA_CLIENT/msp中。

    • enroll
    • register



2.2、设置Org1 peers


在2.1.2步骤中,我们已经注册了Org1的两个peer。这里我们需要enroll他们,作为peer的Local MSP。

因为Org1的CA启用了TLS,所以,我们需要将Org1 CA的根证书copy到peer机器上。因为我们在2.1.2步骤,使用peer1机器进行enroll和register,因此在peer1机器上已经有此证书。在peer2机器上,我们还需要进行copy。

2.2.1、enroll peers的Local MSP

2.2.1.1、org1-peer1

这里,我们将FABRIC_CA_CLIENT_HOME设置为/root/fabric-ca-client-home/org1-peer1。

2.2.1.2、org1-peer2

首先,我们要将org1 CA的根证书copy到org1-peer2机器上,放置于/root/ca/org1/org1-ca-cert.pem。

然后,因为我们使用的机器是org1-peer2,我们将FABRIC_CA_HOME设置为/root/fabric-ca-client-home/org1-peer2。

2.2.2、enroll peers的TLS MSP

这里,我们需要enroll peers的TLS证书材料等。我们的TLS材料统一从TLS CA签发,同时TLS CA启用了TLS连接,因此,我们在peer1、peer2上都需要有TLS CA的根证书。

这里我们存放TLS CA根证书位置为/root/ca/tlsca

同时,为enroll 的TLS证书等材料设置单独的存放位置,指定FABRIC_CA_CLIENT_MSPDIR=tls-msp。然后分别对peer1、peer2进行enroll操作。

如果只指定FABRIC_CA_CLIENT_HOME,那么enroll的证书默认存放在$FABRIC_CA_CLIENT_HOME/msp下,

如果同时指定了FABRIC_CA_CLIENT_HOME和FABRIC_CA_CLIENT_MSPDIR,那么enroll的证书存放在$FABRIC_CA_CLIENT_HOME/$FABRIC_CA_CLIENT_MSPDIR下。

然后,我们将tls-ca/keystore中的sk文件重命名为key.pem,这将有益于后期的引用。


2.2.3、enroll peers的组织Admin


这时,Org1的所有的peers都已经enrolled。接下来需要enroll Org1的admin identity。admin identity的职责有诸如安装、实例化chaincode等等。

我们将FABRIC_CA_CLIENT_HOME设置为/root/fabric-ca-client-home/org1_admin_msp。

因为我们是从Org1 CA enroll admin ,同时Org1 CA启用了TLS,因此我们需要使用Org1 CA的根证书。我们之前已经放置在了/root/ca/org1/org1-ca-cert.pem。

然后,将enroll的signcerts/cert.pem copy到Peer(peer1、peer2)的Local MSP下admincerts文件夹中。

2.2.4、Peer1 各种MSP概览


2.3、启动Org1的peers

 

我们已经enroll了Org1的所有peer和org admin,以及TLS,现在已经可以启动peers了。

我们使用docker的方式启动。

peer1-org1:
  container_name: peer1-org1
  image: hyperledger/fabric-peer
  environment:
    - CORE_PEER_ID=peer1-org1
    - CORE_PEER_ADDRESS=0.0.0.0:7051
    - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
    - CORE_PEER_LOCALMSPID=org1MSP
    - CORE_PEER_MSPCONFIGPATH=/root/fabric-ca-client-home/org1-peer1/msp
    - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    #- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca
    - FABRIC_LOGGING_SPEC=debug
    - CORE_PEER_TLS_ENABLED=true
    - CORE_PEER_TLS_CERT_FILE=/root/fabric-ca-client-home/org1-peer1/tls-msp/signcerts/cert.pem
    - CORE_PEER_TLS_KEY_FILE=/root/fabric-ca-client-home/org1-peer1/tls-msp/keystore/key.pem
    - CORE_PEER_TLS_ROOTCERT_FILE=/root/fabric-ca-client-home/org1-peer1/tls-msp/tlscacerts/tls-192-168-56-129-7052.pem
    - CORE_PEER_GOSSIP_USELEADERELECTION=true
    - CORE_PEER_GOSSIP_ORGLEADER=false
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=0.0.0.0:7051
    - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
  working_dir: /opt/hyperledger/fabric/org1/peer1
  ports:
    - 7051:7051
  volumes:
    - /var/run:/host/var/run
    - /root/fabric-ca-client-home/org1-peer1/msp:/root/fabric-ca-client-home/org1-peer1/msp
    - /root/fabric-ca-client-home/org1-peer1/tls-msp:/root/fabric-ca-client-home/org1-peer1/tls-msp



peer2-org1:
  container_name: peer2-org1
  image: hyperledger/fabric-peer
  environment:
    - CORE_PEER_ID=peer2-org1
    - CORE_PEER_ADDRESS=0.0.0.0:7051
    - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
    - CORE_PEER_LOCALMSPID=org1MSP
    - CORE_PEER_MSPCONFIGPATH=/root/fabric-ca-client-home/org1-peer2/msp
    - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    #- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca
    - FABRIC_LOGGING_SPEC=debug
    - CORE_PEER_TLS_ENABLED=true
    - CORE_PEER_TLS_CERT_FILE=/root/fabric-ca-client-home/org1-peer2/tls-msp/signcerts/cert.pem
    - CORE_PEER_TLS_KEY_FILE=/root/fabric-ca-client-home/org1-peer2/tls-msp/keystore/key.pem
    - CORE_PEER_TLS_ROOTCERT_FILE=/root/fabric-ca-client-home/org1-peer2/tls-msp/tlscacerts/tls-192-168-56-129-7052.pem
    - CORE_PEER_GOSSIP_USELEADERELECTION=true
    - CORE_PEER_GOSSIP_ORGLEADER=false
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=0.0.0.0:7051
    - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
    - CORE_PEER_GOSSIP_BOOTSTRAP=192.168.56.131:7051
    # 这里的192.168.56.131,是peer1的地址,peer1在enroll TLS msp时需要将这个IP加入到csr.hosts中,否则会报错cannot validate certificate for 192.168.56.131 because it doesn't contain any IP SANs
  working_dir: /opt/hyperledger/fabric/org1/peer2
  ports:
    - 7051:7051
  volumes:
    - /var/run:/host/var/run
    - /root/fabric-ca-client-home/org1-peer2/msp:/root/fabric-ca-client-home/org1-peer2/msp
    - /root/fabric-ca-client-home/org1-peer2/tls-msp:/root/fabric-ca-client-home/org1-peer2/tls-msp






3、区块链组织2 => Org2设置


3.1、设置组织2 CA

3.1.1、安装CA

每个组织都必须有自己的CA,来颁发enrollment证书。

这个CA用来颁发组织内peers、clients用的证书。

各个组织的CA创建属于各自组织的identity,并为每个identity颁发公钥和私钥。

这些密钥使得你所有的nodes和applications可以签名并验证他们的操作。

使用docker方式安装:

3.1.2、注册Org2相关的identity

作为参与区块链的组织Org2,我们需要注册相关的Identities。

我们将注册四个Identities, (Q_CF后续需要研究集成LDAP后如何注册)

Peer1

这里我们注册为peer1-org2

Peer2

这里我们注册为peer2-org2

Org1 Admin

组织的管理员,我们注册为admin1-org2

End User

终端用户,我们注册为user1-org2

 

要注册这些identity,我们首先要enroll Org1 CA的Admin。因为Org1 CA启用了TLS,所以我们需要将其根证书copy到运行enroll即register命令的机器上。

我们设置FABRIC_CA_CLIENT_HOME为/root/fabric-ca-client-home。enroll的所有证书材料等默认存放在$FABRIC_CA_CLIENT/msp中。

enroll:

register:


3.2、设置Org2的peers

3.2.1、enroll peers的LOCAL MSP

我们在3.1.2章节已经register了一些identity,现在我们将使用CA启动时的超管identity来enroll peers,以作为peers的本地MSP。

  • org2-peer1

    因为Org2 CA启用了TLS,因此我们需要指定—tls.certfiles为Org2 CA的根证书,如果执行enroll命令的本地没有这个证书,则需要copy一份。/root/ca/org2/org2-ca-cert.pem。

    我们将FABRIC_CA_CLIENT_HOME设置为/root/fabric-ca-client-home/org2-peer1,这里将存放enroll peer1的一些证书材料等。



  • org2-peer2

    同样,这里也需要有Org2 CA 的根证书。我们这里为/root/ca/org2/org2-ca-cert.pem。

    在peer2上,我们将FABRIC_CA_CLIENT_HOME设置为/root/fabric-ca-client-home/org2-peer2,这里将存放enroll peer2的一些证书材料等。



3.2.2、enroll peers的TLS MSP

这里,我们需要enroll peers的TLS证书材料等。我们的TLS材料统一从TLS CA签发,同时TLS CA启用了TLS连接,因此,我们在peer1、peer2上都需要有TLS CA的根证书。

这里我们存放TLS CA根证书位置为/root/ca/tlsca

同时,为enroll 的TLS证书等材料设置单独的存放位置,指定FABRIC_CA_CLIENT_MSPDIR=tls-msp。然后分别对peer1、peer2进行enroll操作。

如果只指定FABRIC_CA_CLIENT_HOME,那么enroll的证书默认存放在$FABRIC_CA_CLIENT_HOME/msp下,

如果同时指定了FABRIC_CA_CLIENT_HOME和FABRIC_CA_CLIENT_MSPDIR,那么enroll的证书存放在$FABRIC_CA_CLIENT_HOME/$FABRIC_CA_CLIENT_MSPDIR下。

然后,我们将tls-ca/keystore中的sk文件重命名为key.pem,这将有益于后期的引用。


3.2.3、enroll Org2的Admin

这时,Org2的所有的peers都已经enrolled。接下来需要enroll Org2的admin identity。admin identity的职责有诸如安装、实例化chaincode等等。

我们将FABRIC_CA_CLIENT_HOME设置为/root/fabric-ca-client-home/org2_admin_msp。

因为我们是从Org2 CA enroll admin ,同时Org2 CA启用了TLS,因此我们需要使用Org2 CA的根证书。我们之前已经放置在了/root/ca/org2/org2-ca-cert.pem。

然后,将enroll的signcerts/cert.pem copy到Peer(peer1、peer2)的Local MSP下admincerts文件夹中。


3.2.4、peer1各类MSP概览


3.3、启动Org2的Peers

使用docker的方式i启动

peer1-org2:
  container_name: peer1-org2
  image: hyperledger/fabric-peer
  environment:
    - CORE_PEER_ID=peer1-org2
    - CORE_PEER_ADDRESS=0.0.0.0:7051
    - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
    - CORE_PEER_LOCALMSPID=org2MSP
    - CORE_PEER_MSPCONFIGPATH=/root/fabric-ca-client-home/org2-peer1/msp
    - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    #- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca
    - FABRIC_LOGGING_SPEC=debug
    - CORE_PEER_TLS_ENABLED=true
    - CORE_PEER_TLS_CERT_FILE=/root/fabric-ca-client-home/org2-peer1/tls-msp/signcerts/cert.pem
    - CORE_PEER_TLS_KEY_FILE=/root/fabric-ca-client-home/org2-peer1/tls-msp/keystore/key.pem
    - CORE_PEER_TLS_ROOTCERT_FILE=/root/fabric-ca-client-home/org2-peer1/tls-msp/tlscacerts/tls-192-168-56-129-7052.pem
    - CORE_PEER_GOSSIP_USELEADERELECTION=true
    - CORE_PEER_GOSSIP_ORGLEADER=false
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=0.0.0.0:7051
    - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
  working_dir: /opt/hyperledger/fabric/fabric/org2/peer1
  ports:
    - 7051:7051
  volumes:
    - /var/run:/host/var/run
    - /root/fabric-ca-client-home/org2-peer1/msp:/root/fabric-ca-client-home/org2-peer1/msp
    - /root/fabric-ca-client-home/org2-peer1/tls-msp:/root/fabric-ca-client-home/org2-peer1/tls-msp


peer2-org2:
  container_name: peer2-org2
  image: hyperledger/fabric-peer
  environment:
    - CORE_PEER_ID=peer2-org2
    - CORE_PEER_ADDRESS=0.0.0.0:7051
    - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
    - CORE_PEER_LOCALMSPID=org2MSP
    - CORE_PEER_MSPCONFIGPATH=/root/fabric-ca-client-home/org2-peer2/msp
    - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    #- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca
    - FABRIC_LOGGING_SPEC=debug
    - CORE_PEER_TLS_ENABLED=true
    - CORE_PEER_TLS_CERT_FILE=/root/fabric-ca-client-home/org2-peer2/tls-msp/signcerts/cert.pem
    - CORE_PEER_TLS_KEY_FILE=/root/fabric-ca-client-home/org2-peer2/tls-msp/keystore/key.pem
    - CORE_PEER_TLS_ROOTCERT_FILE=/root/fabric-ca-client-home/org2-peer2/tls-msp/tlscacerts/tls-192-168-56-129-7052.pem
    - CORE_PEER_GOSSIP_USELEADERELECTION=true
    - CORE_PEER_GOSSIP_ORGLEADER=false
    - CORE_PEER_GOSSIP_EXTERNALENDPOINT=0.0.0.0:7051
    - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
    - CORE_PEER_GOSSIP_BOOTSTRAP=192.168.56.133:7051
  working_dir: /opt/hyperledger/fabric/fabric/org2/peer2
  ports:
    - 7051:7051
  volumes:
    - /var/run:/host/var/run
    - /root/fabric-ca-client-home/org2-peer2/msp:/root/fabric-ca-client-home/org2-peer2/msp
    - /root/fabric-ca-client-home/org2-peer2/tls-msp:/root/fabric-ca-client-home/org2-peer2/tls-msp







4、排序组织 => Org0设置

4.1、安装Orderer Org CA

4.1.1、安装CA

每个组织都必须有自己的CA,来颁发enrollment证书。

这个CA用来颁发组织内peers、clients用的证书。

各个组织的CA创建属于各自组织的identity,并为每个identity颁发公钥和私钥。

这些密钥使得你所有的nodes和applications可以签名并验证他们的操作。

使用docker方式安装:

4.1.2、注册Orderer相关的Identities

作为管理Order的组织Org0,我们需要注册相关的Identities。

我们将注册两个Identities, (Q_CF后续需要研究集成LDAP后如何注册)

Orderer

排序节点本身需要其对应的Identity,我们注册为orderer1-org0,

Orderer admin

排序节点的管理员,也需要注册Identity,注册为admin-org0,可以理解为提供排序服务的组织里的管理员用户。

 

在注册之前,我们首先要enroll Org0 CA的管理员账户,enroll操作就相当于获取这个用户的身份,只有enroll了合适权限的用户,才能继续进行注册的工作。

同时,因为Org0 CA启用了TLS,那么我们要连接到它,需要有它的根证书。即第二步中生成的ca-cert.pem。它在其CA服务器的位置是$FABRIC_CA_SERVER_HOME/ca-cert.pem。

我们需要将它copy到我们需要执行enroll及register的机器上。如下所示,我们进行了copy并重命名为org0-ca-cert.pem:

然后我们设置FABRIC_CA_CLIENT_HOME,以存放相关证书(默认会在这个HOME下创建msp文件夹),并开始进行enroll及register。

      • enroll:
      • register:

        简要说明:

        id.type:identity的类型,例如orderer、admin、peer等,Q_CF后续需要详述。

        id.attrs:identity的属性,Q_CF后续需要详述.


4.2、设置Orderer

4.2.1、enroll orderer的LOCAL MSP

上一步我们已经在CA中注册了type为orderer的identity,现在我们要enroll这个identity来创建orderer。这就是local orderer MSP。

4.2.2、enroll orderer的TLS MSP

然后,我们需要获得TLS证书(第一步中的TLS CA已经注册了orderer类型的identity,专门用于信息传输使用)。

同样,我们需要有TLS CA的根证书,以用来连接TLS CA服务器。我们将它copy到orderer节点上并重命名/root/ca/tlsca/tls-ca-cert.pem。

同时,我们可以为TLS的MSP指定单独的存放位置:export FABRIC_CA_CLIENT_MSPDIR=tls-msp,这个指定的文件夹位于FABRIC_CA_CLIENT_HOME下。

如果只指定FABRIC_CA_CLIENT_HOME,那么enroll的证书默认存放在$FABRIC_CA_CLIENT_HOME/msp下,

如果同时指定了FABRIC_CA_CLIENT_HOME和FABRIC_CA_CLIENT_MSPDIR,那么enroll的证书存放在$FABRIC_CA_CLIENT_HOME/$FABRIC_CA_CLIENT_MSPDIR下。

然后,我们将tls-map下enroll的keystore重命名为key.pem。


4.2.3、enroll Org0的Admin


4.2.4、Orderer各类MSP概览

我们需要将org0_admin_msp的Org0 Admin签名证书放置在Local  MSP中的admincerts文件夹中:


所以,最终MSP总览图如下:

4.3、创建genesis block和channel transaction


Orderer的启动需要有创世块。

4.3.1、准备MSP

在orderer主机上,我们需要收集所有参与组织的相关MSP,

我们新建如下结构目录来存放相关MSP:

4.3.2、准备configtx.yaml

#######################################################################
#
#   Section: Organizations
#
#   - This section defines the different organizational identities 
#   which will be referenced later in the configuration.
#   - 这部分定义了不同组织的identities,后续配置的时候需要用到
#
#######################################################################
Organizations:

  - &org0
     Name: org0
     # ID to load the MSP definition as
     ID: org0MSP
     #MSPDir is the filesystem path which contains the MSP configuration
     MSPDir: /root/msp/org0
  
  - &org1
     Name: org1
     # ID to load the MSP definition as
     ID: org1MSP
     #MSPDir is the filesystem path which contains the MSP configuration
     MSPDir: /root/msp/org1
     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: peer1-org1
          Port: 7051
  
  - &org2
     Name: org2
     # ID to load the MSP definition as
     ID: org2MSP
     #MSPDir is the filesystem path which contains the MSP configuration
     MSPDir: /root/msp/org2
     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: peer1-org2
          Port: 7051
  
#######################################################################
#
#   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:

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

  OrgsOrdererGenesis:
     Orderer:
        # Orderer Type: The orderer implementation to start
        # Available types are "solo" and "kafka"
        OrdererType: solo
        Addresses:
          #- orderer1-org0:7050
          - 192.168.56.130: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:
                
        # Kafka:
        #   # Brokers: A list of Kafka brokers to 
        #      which the orderer connects
        #   # NOTE: Use IP:port notation
        #   Brokers:
        #     - 127.0.0.1:9092
        # Organizations is the list of orgs which are defined as 
        # participants on the orderer side of the network
        Organizations:
          - *org0
  
     Consortiums:
       SampleConsortium:
         Organizations:
           - *org1
           - *org2
  
  OrgsChannel:
     Consortium: SampleConsortium
     Application:
        <<: *ApplicationDefaults
        Organizations:
          - *org1
          - *org2


4.3.3、创建genesis block 和 channel transaction


4.4、启动Orderer

使用docker方式启动

orderer1-org0:
  container_name: orderer1-org0
  image: hyperledger/fabric-orderer
  environment:
    - ORDERER_HOME=/tmp/hyperledger/orderer
    - ORDERER_HOST=orderer1-org0
    - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
    - ORDERER_GENERAL_GENESISMETHOD=file
    - ORDERER_GENERAL_GENESISFILE=/root/configtx/genesis.block
    - ORDERER_GENERAL_LOCALMSPID=org0MSP
    - ORDERER_GENERAL_LOCALMSPDIR=/root/fabric-ca-client-home/msp
    - ORDERER_GENERAL_TLS_ENABLED=true
    - ORDERER_GENERAL_TLS_CERTIFICATE=/root/fabric-ca-client-home/tls-msp/signcerts/cert.pem
    - ORDERER_GENERAL_TLS_PRIVATEKEY=/root/fabric-ca-client-home/tls-msp/keystore/key.pem
    - ORDERER_GENERAL_TLS_ROOTCAS=[/root/fabric-ca-client-home/tls-msp/tlscacerts/tls-192-168-56-129-7052.pem]
    - ORDERER_GENERAL_LOGLEVEL=debug
- ORDERER_DEBUG_BROADCASTTRACEDIR=data/logs
  ports:
    - 7050:7050
  volumes:
    - /root/configtx:/root/configtx
    - /root/fabric-ca-client-home/msp:/root/fabric-ca-client-home/msp
- /root/fabric-ca-client-home/tls-msp:/root/fabric-ca-client-home/tls-msp






5、创建CLI容器

连接到peer需要使用CLI容器,这个容器包含了执行peer命令相关的可执行文件。我们应当为每个组织都创建一个CLI容器,在这里我们创建在组织内的peer1上。

(本次实验有一个docker问题,例如本机IP为192.168.1.11 , cli容器启动后无法访问宿主机的IP,暂不解决docker问题。因此建议将CLI容器建立在另外的机器上。)


我们使用docker方式启动CLI容器:

cli-org1:
   container_name: cli-org1
   image: hyperledger/fabric-tools
   tty: true
   stdin_open: true
   environment:
     - GOPATH=/opt/gopath
     - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
     - FABRIC_LOGGING_SPEC=DEBUG
     - CORE_PEER_ID=cli-org1
     - CORE_PEER_ADDRESS=192.168.56.131:7051
     - CORE_PEER_LOCALMSPID=org1MSP
     - CORE_PEER_TLS_ENABLED=true
     - CORE_PEER_TLS_ROOTCERT_FILE=/root/fabric-ca-client-home/org1-peer1/tls-msp/tlscacerts/tls-192-168-56-129-7052.pem
     - CORE_PEER_MSPCONFIGPATH=/root/fabric-ca-client-home/org1-peer1/msp
   working_dir: /opt/hyperledger/fabric/org1/peer1
   command: sh
   volumes:
     - /root/fabric-ca-client-home/org1-peer1/msp:/root/fabric-ca-client-home/org1-peer1/msp
     - /root/chaincode:/root/chaincode
     - /root/fabric-ca-client-home/org1-peer1/tls-msp:/root/fabric-ca-client-home/org1-peer1/tls-msp



cli-org2:
   container_name: cli-org2
   image: hyperledger/fabric-tools
   tty: true
   stdin_open: true
   environment:
     - GOPATH=/opt/gopath
     - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
     - FABRIC_LOGGING_SPEC=DEBUG
     - CORE_PEER_ID=cli-org2
     - CORE_PEER_ADDRESS=192.168.56.133:7051
     - CORE_PEER_LOCALMSPID=org2MSP
     - CORE_PEER_TLS_ENABLED=true
     - CORE_PEER_TLS_ROOTCERT_FILE=/root/fabric-ca-client-home/org2-peer1/tls-msp/tlscacerts/tls-192-168-56-129-7052.pem
     - CORE_PEER_MSPCONFIGPATH=/root/fabric-ca-client-home/org2-peer1/msp
   working_dir: /opt/hyperledger/fabric/org2/peer1
   command: sh
   volumes:
     - /root/fabric-ca-client-home/org2-peer1/msp:/root/fabric-ca-client-home/org2-peer1/msp
     - /root/chaincode:/root/chaincode
     - /root/fabric-ca-client-home/org2-peer1/tls-msp:/root/fabric-ca-client-home/org2-peer1/tls-msp








6、创建和加入channel


6.1、peer1-org1创建channel

我们通过cli容器来执行peer命令,进行channel的相关操作。

创建channel时,我们需要指定之前生成的channel.tx文件。这里我们放置在/root/chaincode下,这个目录可以自定义映射。

创建channel需要使用admin MSP。

如下命令在org1-cli容器中运行:

注意:组织admin MSP下也需要有admincert文件夹,将signcerts文件夹下的证书copy一份到admincert文件夹中,否则会报错:Cannot run peer because error when setting up MSP of type bccsp from directory /root/fabric-ca-client-home/org1_admin_msp/msp: administrators must be declared when no admin ou classification is set

必须给所有想加入这个channel的组织分发刚才生成的mychannel.block文件。

6.2、peer1-org1、 peer2-org1加入channel

6.3、peer1-org2、 peer2-org2加入channel



  • No labels