Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Hyperledger Fabric 1.4 how to deploy a Kafka cluster

2025-02-21 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 the Hyperledger Fabric 1.4Kafka cluster, which is very detailed and has certain reference value. Interested friends must read it!

The construction of Hyperledger Fabric block chain network is notoriously tedious. This tutorial will show you how to deploy a hyperledger fabric blockchain cluster network with multiple sorting nodes and peer nodes distributed on four hosts, along with source code and configuration file downloads.

1. Service structure

The topology of the Hyperledger Fabric network we are going to build is as follows:

The network consists of the following services:

1 organization: org1.example.com

3 peer nodes: peer0.example.com, peer1.example.com, peer2.example.com

1 CA node: ca.example.com

3 sort nodes: order0.example.com, order1.example.com, order2.example.com

3 zookeeper nodes: zookeeper0, zookeeper1, zookeeper2

4 kafka nodes: kafka0, kafka1, kafka2, kafka3

2. Deployment Services 2.1 deploy ca, orderer and kafka

As shown in the figure above, first deploy the CA node, the sort node, the kafka node, and the zookeeper node on server1, using the docker-compose file docker-compose-kafka.yml:

# deploy ca, zookeerper, kafka and orderers on server0docker-compose-f deployment/docker-compose-kafka.yml up-d

In the docker-compose file, we define the extra_hosts attribute for the ca and orderer services, which contains information for all peer nodes. Because ca and orderer may need to communicate with peer nodes, they need to know about peer nodes. Peers is deployed on different hosts, so we can define hosts for peer0, peer1, and peer2 in the extra_hosts field.

Extra_hosts:-"peer0.org1.example.com:172.31.26.5"-"peer1.org1.example.com:172.31.20.177"-"peer2.org1.example.com:172.31.27.143" 2.2 deploy peer0 and cli0

We deploy peer0 and cli0 on server2, where cli0 will be connected to peer0. The docker-compose files used are docker-compose-peer0.yml and docker-compose-cli.yml:

# deploy peer0docker-compose-f deployment/docker-compose-peer0.yml up-d # deploy cli0docker-compose-f deployment/docker-compose-cli0.yml up-d

In docker-compose-peer0.yml, we define the following extra_hosts field, which contains the host information for all sort nodes, peer1, and peer2. The main reason for adding additional peer information is that the peer uses the gossip protocol to broadcast blocks to other peer.

Extra_hosts:-"orderer0.example.com:172.31.25.198"-"orderer1.example.com:172.31.25.198"-"orderer2.example.com:172.31.25.198"-"ca.example.com:172.31.25.198"-"peer1.org1.example.com:172.31.20.177"-"peer2.org1.example.com:172.31.27.143"

The host information of the sort node is included in the docker-compose-cli0.yml because the cli command needs to communicate with the sort node when executing the transaction:

Extra_hosts:-"orderer0.example.com:172.31.25.198"-"orderer1.example.com:172.31.25.198"-"orderer2.example.com:172.31.25.198" 2.3 deploy peer1 and cli1

Next, we deploy peer1 and cli1 on server3:

# deploy peer1docker-compose-f deployment/docker-compose-peer1.yml up-d # deploy cli1docker-compose-f deployment/docker-compose-cli1.yml up-d

The extra_hosts in docker-compose-peer1.yml contains information about sort node hosts and other peer node hosts (peer0 and peer2). The extra_hosts field in docker-compose-cli.yml defines the host information for the sort node.

2.4 deployment of peer2 and cli2

Finally, we deploy peer2 and cli2 on server4:

# deploy peer2docker-compose-f deployment/docker-compose-peer2.yml up-d # deploy cli2docker-compose-f deployment/docker-compose-cli2.yml up-d

You also need to specify extra_hosts in the docker-compose file.

3. Configure the channel

Now that the service deployment is complete, you need to configure the channel.

3.1 create a channel

By accessing peer0 on server2, execute the following command to create a channel:

# create channel from peer0 on server2# it connects to orderer0docker exec-e "CORE_PEER_LOCALMSPID=Org1MSP"\-e "CORE_PEER_MSPCONFIGPATH=/var/hyperledger/users/Admin@org1.example.com/msp"\ peer0.org1.example.com peer channel create-o orderer0.example.com:7050-c mychannel-f / var/hyperledger/configs/channel.tx

Next, we will add all three peer nodes to the channel

3.2 add peer0 to the channel

Now connect to peer0 on server2 and execute the following command:

# join peer0 to channel# execute this command from server1docker exec-e "CORE_PEER_LOCALMSPID=Org1MSP"\-e "CORE_PEER_MSPCONFIGPATH=/var/hyperledger/users/Admin@org1.example.com/msp"\ peer0.org1.example.com peer channel join-b mychannel.block

The above command generates mychannel.block within the peer0 container.

Copy mychannel.block to peer1 and peer2# copy mychannel.block from peer0 to host (server2) docker cp peer0.org1.example.com:/mychannel.block. # transfer mychannel.block to server3 and server4 via scpscp-r mychannel.block ubuntu@172.31.20.177:scp-r mychannel.block ubuntu@172.31.27.143:# copy mychannel.block to peer1 and peer2# peer1 is on server3# peer2 is on server4docker cp mychannel.block peer1.org1.example.com:/mychannel.blockdocker cp mychannel. Block peer2.org1.example.com:/mychannel.block# remove mychannel.block from server2 Server3 and server4rm mychannel.block3.4 adds peer1 to the channel

You can now add peer1 on server3 to the channel:

# join peer1 to channel# execute this command from server3 machinedocker exec-e "CORE_PEER_LOCALMSPID=Org1MSP"-e "CORE_PEER_MSPCONFIGPATH=/var/hyperledger/users/Admin@org1.example.com/msp"\ peer1.org1.example.com peer channel join-b mychannel.block3.5 adds peer2 to the channel

Similarly, you can add peer2 on server4 to the channel:

# join peer2 to channel# execute this command from server4 machinedocker exec-e "CORE_PEER_LOCALMSPID=Org1MSP"-e "CORE_PEER_MSPCONFIGPATH=/var/hyperledger/users/Admin@org1.example.com/msp"\ peer2.org1.example.com peer channel join-b mychannel.block4, configure chain code 4.1 install chain code

The chain code is in the chaincode directory. We use cli to install chain codes on each peer node.

# install on peer0 on server2# cli container connects to peer0 docker exec-it cli peer chaincode install-n mycc-p github.com/chaincode-v vested install on peer1 on server3# cli container connects to peer1 docker exec-it cli peer chaincode install-n mycc-p github.com/chaincode-v Vogue install on peer2 on server4# cli container connects to peer2docker exec-it cli peer chaincode install-n mycc-p github.com/chaincode-v v04.2 instantiated chain code

Now you can instantiate the chain code. You only need to instantiate once on the channel. So we use cli0 on server2 for chain code instantiation:

# instantiate chaincode from peer0 on server2# it connects to orderer0 docker exec-it cli peer chaincode instantiate-o orderer0.example.com:7050\-C mychannel-n mycc github.com/chaincode-v v0-c'{"Args": ["a", "100"]}'5, transaction execution and query 5.1 execute transaction

We use cli0 on server2 to invoke the chain code transaction:

# invoke transaction from peer0 on server2# it connects to orderer0 on server1docker exec-it cli peer chaincode invoke-o orderer0.example.com:7050\-n mycc-c'{"Args": ["set", "a", "20"]}'- C mychannel5.2 query transactions

We use cli2 on server4 to query the transaction:

# query transaction from peer2 on server4docker exec-it cli peer chaincode query\-nmycc-c'{"Args": ["query", "a"]}'- C mychannel is all the content of this article "how to deploy Hyperledger Fabric 1.4 Kafka clusters". 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report