In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to deploy a custom network in Fabric2.0. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.
This section plans that the Fabric platform consists of 3 order nodes, 2 organizations, 4 peer nodes, and each organization has two peer nodes. The consensus mechanism of Fabric2.0 only supports the raft protocol. The consensus achieved by this protocol must be at least 3 nodes, and the number of nodes is preferably odd.
All operations in this section are performed in the / usr/local/src/hyperleger/fabric/scripts/fabric-samples/first-network directory.
Set the relevant environment variables before doing any subsequent operations.
Export PATH=$ {PWD} /.. / bin:$ {PWD}: $PATHexport FABRIC_CFG_PATH=$ {PWD} 3.1 generate certificates
Fabric platform is a licensed block chain platform, which realizes the access and operation rights of platform participants to platform resources through digital certificates, so that the network has higher security.
Certificate generation requires the use of the cryptogen tool and the configuration file crypto-config.yaml. According to the node plan of the platform, modify (remember to back up) the crypto-config.yaml as follows:
In the figure above, the Order organization defines three nodes: the orderer,orderer2,orderer3,peer organization consists of two organizations, Org1 and Org2, each consisting of two nodes, including Admin users and a regular user.
After the configuration file has been modified, run the following command directly to complete the certificate generation for the order node, peer node, administrator, and user.
Cryptogen generate-config=./crypto-config.yaml
After successful execution, the crypto-config directory is generated under the current directory, and the directory structure is shown in the following figure:
3.2 Genesis Block
The generation of Genesis blocks requires the use of the configtxgen tool and the configuration file configtx.yaml. According to the node plan of the platform, modify (remember to back up) as follows:
Comment the configuration related to orderer4 and orderer5, because the fabric network planned for this article contains only three order nodes.
After the configuration file has been modified, execute the following command:
Configtxgen-profile SampleMultiNodeEtcdRaft-channelID byfn-sys-channel-outputBlock. / channel-artifacts/genesis.block
After successful execution, the Genesis block file genesis.block will be generated in the channel-artifacts directory.
For the generation of creation blocks, there is an obvious difference between fabric1.x and fabric2.0. Note the profile parameter value of the above command.
3.3 generate a channel transaction profile
For the generation of channel transaction profiles, there is no obvious difference between fabric1.x and fabric2.0, and the commands and configuration files used are the same as those used to generate creation blocks.
Execute the following command to complete the creation of the channel transaction profile.
Configtxgen-profile TwoOrgsChannel-outputCreateChannelTx. / channel-artifacts/channel.tx-channelID mychannel
After successful execution, the channel transaction profile channel.tx is generated under the channel-artifacts directory.
3.4 generate Anchor Node profile
For the generation of anchor node configuration files, there is no obvious difference between fabric1.x and fabric2.0, and the commands and configuration files used are the same as those used to generate Genesis blocks.
Execute the following command to complete the creation of the Org1 and Org2 organization anchor node configuration files.
# generate Org1 anchor node configuration file configtxgen-profile TwoOrgsChannel-outputAnchorPeersUpdate. / channel-artifacts/Org1MSPanchors.tx-channelID mychannel-asOrg Org1MSP# generate Org2 anchor node configuration file configtxgen-profile TwoOrgsChannel-outputAnchorPeersUpdate. / channel-artifacts/Org2MSPanchors.tx-channelID mychannel-asOrg Org2MSP
After successful execution, two anchor node configuration files, Org1MSPanchors.tx and Org2MSPanchors.tx, are generated in the channel-artifacts directory.
3.5 start & stop the network
The Fabric network service starts in docker mode, involving commands docker-compose and configuration files docker-compose-cli.yaml, docker-compose-etcdraft2.yaml, docker-compose-ca.yaml.
The fabric network planned in this paper includes 10 docker services: 4 peer node services, 3 order node services, 2 CA services and 1 cli service.
Modify the configuration file docker-compose-etcdraft2.yaml and comment out the relevant configurations of orderer4 and orderer5.
Execute the following command to start 3 order node services, 1 cli node service, 4 peer node services, and 2 CA node services.
# configure environment variables, CA node must export BYFN_CA1_PRIVATE_KEY=$ (cd crypto-config/peerOrganizations/org1.example.com/ca & & ls\ * _ sk) export BYFN_CA2_PRIVATE_KEY=$ (cd crypto-config/peerOrganizations/org2.example.com/ca & & ls\ * _ sk) # start docker-compose- f docker-compose-cli.yaml-f docker-compose-etcdraft2.yaml-f docker-compose-ca.yaml up-d according to the specified configuration file
The command execution log is shown in the following figure:
View the running docker service, as shown in the following figure:
Stop the network from executing the command:
Docker-compose- f docker-compose-cli.yaml-f docker-compose-etcdraft2.yaml-f docker-compose-ca.yaml down
All node services on the Fabric platform are started normally. The configuration files generated in sections 3.1-3.4 are prepared for subsequent transaction operations. Subsequent operations need to go to the cli container to execute relevant commands.
3.6 create a channel
Channel is a feature of Fabric, which can realize business isolation and multi-chain operation logically on a block chain platform.
To create a tunnel, you need to enter the cli container and execute the following command:
# connect to cli service docker exec-it cli bash# define CA file path ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem # create channel information peer channel create-o orderer.example.com:7050-c mychannel-f. / channel-artifacts/channel.tx-- tls true-- cafile $ORDERER_CA# will generate Move the file to the channel-artifacts folder to join the mv mychannel.block channel-artifacts/3.7 peer node in the channel
In the previous step, we created a channel named mychannel, but the channel cannot be traded without any peer nodes joined. This section adds all four nodes of the two organizations to the mychannel channel.
By looking at the environment variables, the configuration of the org1.peer0 used by the current cli container.
According to the current configuration, we execute the following command to first add the org1.peer0 node to the mychannel channel.
Peer channel join-b channel-artifacts/mychannel.block
The result of successful execution is shown in the following figure:
Switch nodes and add org1.peer1 to the mychannel channel.
# switching node org1.peer1source scripts/utils.shsetGlobals 1 "adds the current node to the channel peer channel join-b channel-artifacts/mychannel.block
Referring to the method of switching nodes mentioned above, two nodes organized by org2 are also added to the channel.
# switching node org2.peer0source scripts/utils.shsetGlobals 0 "adding current node to channel peer channel join-b channel-artifacts/mychannel.block# switching node org2.peer1setGlobals 1" adding current node to channel peer channel join-b channel-artifacts/mychannel.block
At this point, 4 nodes of the two organizations have joined the mychannel channel.
3.8 Update the anchor node
Anchor node is a special peer node in an organization, through which the communication between nodes in different organizations can be realized. Usually an anchor node is set up for each organization, and the anchor node is set for the org1 and org2 organizations respectively. This article assumes that the peer0 node in the organization is set as the anchor node.
# switch to org1.peer0 node setGlobals 0 setting environment variable ORDERER_CAORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem# update setting anchor node peer channel update-o orderer.example.com:7050-c mychannel-f. / channel-artifacts/Org2MSPanchors.tx-- tls true-- cafile $ORDERER_CA# switch to org2. Peer0 node setGlobals 0 setting environment variable ORDERER_CAORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem# update setting anchor node peer channel update-o orderer.example.com:7050-c mychannel-f. / channel-artifacts/Org2MSPanchors.tx-- tls true-- cafile $ORDERER_CA
The successful execution of the update command results as shown in the following figure:
Through our efforts, we manually configured and started a fabric network, including 3 orderer nodes, 2 organizations 4 peer nodes, 2 ca nodes, 1 cli node, 1 channel mychannel. These are all the contents of the article "how to deploy a Custom Network in Fabric2.0". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.