(D) Fabric2.0 Channel Practice

List of:
(a) HyperLedger Fabric 2.0-release test network deployment
(two) Fabric2.0 first-network generates configuration instructions
(three) Fabric2.0 startup script configures network analysis
(four) Fabric2.0 Channel Practice

After the completion of the last chapter of a 5orderer2org4peer Fabric2.0 based network structures, it is next channel Fabric2.0 practice, the
channel practice 2.0 includes two sub-channels and create a node joins the channel, we will be based on first

1. Create a channel is ready

Create a 1.1 channel configuration file

As the first-network directory configtx.yaml already exists, if you need to modify the channel configuration, back up the original configtx.yaml, modify channel configuration.

1.2 Environmental ready

Open the console, execute the following command

  • Set binary file configtxgen directory to the environment variable, easy call
 export PATH=${PWD}/../bin:${PWD}:$PATH
  • Set the environment variable FABRIC_CFG_PATH to configtx.yaml directory
 export FABRIC_CFG_PATH=${PWD}

1.3 to create a channel file tx

Execute the following command console

  configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel2.tx -channelID channel2

-outputCreateChannelTx: tx output file path
-channelID: Channel ID

Results of the:
Here Insert Picture Description

2. Create channel

Originally created channel is created by cli client, the 2.0 binary files can be created directly by the difference between binary and cli, in addition to the difference between the surface of the form, in fact, are the same, except that the cli environment variables set the start a default, such as certificate path peer using binary, then it directly in the console settings coding environment to view details about fabric-samples / test-network script, not described in detail here, then we still use relatively quickly create cli a test channel.

Into the container cli

docker exec -it cli bash

After entering:
Here Insert Picture Description
Because cli the channel-artifacts that have been mapped to the first-network channel-artifacts host to establish a ~ / /, so the above documents there is the new channel under the directory cli

Here Insert Picture Description

In the current directory, enter the command:

 peer channel create -o orderer.example.com:7050 -c channel2 -f ./channel-artifacts/channel2.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

自定义的话只需要修改 -o 参数排序节点服务域名端口 -c 通道ID -f 通道文件所在路径 -tls 是否启用tls -cafile ca路径

Console data results are as follows, it indicates the channel is successfully created
Here Insert Picture Description
in the current directory appears passage block file as follows:
Here Insert Picture Description

3. Add channel node

Cli provided a connection node objects need only set the appropriate environment variables, the current node is set cli peer0.org1.example.com

Enter the command, view the environment variables

env|grep CORE

Output Results:
Here Insert Picture Description
The need to modify the node only needs to modify the above configuration environment variable corresponding node, is now added to the channel peer0.org1.example.com

Console Enter the following command:

 peer channel join -b channel2.block

-b 区块文件路径

Console output as a result, represents a successful join node
Here Insert Picture Description

View Sort node log is as follows
Here Insert Picture Description
sorting node writes a new block, creating a raft cluster for the channel.

4. Verify node is added channels

Console input

 peer channel list

Console output is as follows:
you can see the current node has been added to channel2

Here Insert Picture Description

5. Summary

In terms of the channel, compared to the operation of the client 1.x no change, the relevant channel policy configuration consistent with 1.4, change is the underlying consensus, originally created channel is to create a block, to open a subscription Topic in kafka, now 2.0 it is a channel created a raft cluster service channel transaction to achieve consistency. Script above mainly with reference script / script.sh in first-network.

Published 10 original articles · won praise 7 · views 1407

Guess you like

Origin blog.csdn.net/qq_28540443/article/details/104314377