Scenario : The orderer nodes of the original raft mechanism are not enough and need to be dynamically expanded.
Prerequisites : A successfully running network [can perform chaincode update and query operations]
Author environment :
System environment - fabric2.3, docker20 series, java smart contract
Network environment - 3 virtual machines have been built [Virtual machine 1: orderer Virtual machine 2: peer1.org1 orderer1 Virtual machine 3: peer1.org2] The following is replaced by VM1 VM2 VM3
Expected goal: Add orderer2 in VM3
————————————————Practice begins——————————————————
1. First generate the certificate file of the orderer2 node
Method: 1 Use the built-in tool cryptogen of the fabric system to generate 2 Use fabric-ca to generate
This article uses the first
1 First modify crypto-config.yaml
Inject the modified configuration file into the initial file cryptogen extend --input crypto-config --config ./crypto-config.yaml
[ The key point is to use the system environment of the orderer node ] This is mine. Everyone needs to modify their own file names.
Now you need to join the system channel [but you cannot apply the channel directly, an error will be reported]
export ORDERER_TLSCA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/traceability.com/orderers/orderer.traceability.com/msp/tlscacerts/tlsca.traceability.com-cert.pem
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/traceability.com/users/[email protected]/tls.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/traceability.com/users/[email protected]/msp/
export CORE_PEER_LOCALMSPID="OrdererMSP"
export CH_NAME=fabric.channel
2 Get the latest configuration block peer channel fetch config config_block.pb -o orderer.traceability.com:7050 -c $CH_NAME --tls --cafile $ORDERER_TLSCA
3 Extract valid data from config_block.pb and convert it into editable json format configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config. json
4 To generate a new block configuration file modified_config.json, two modifications are required [Just copy config.json]
即 cp config.json modified_config.json
first place
Add the new orderer2 certificate after orderer1 . Server.cert needs to be converted to base64 encoding.
cat crypto-config/ordererOrganizations/traceability.com/orderers/orderer2.traceability.com/tls/server.crt | base64 > cert.txt where you can view the certificate details
second place
5 对俩个json进行编码 configtxlator proto_encode --input modified_config.json --type common.Config --output config.pb configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb
6 Calculate the difference between the two files configtxlator compute_update --channel_id fabric.channel --original config.pb --updated modified_config.pb --output config_update.pb
7 Decode the file differences and add header information for updating the configuration:
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
echo '{"payload":{"header":{"channel_header":{"channel_id":"fabric.channel", "type":3}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . > config_update_in_envelope.json [注意type为新增orderer序列]
8 Convert the encapsulated json file back to pb format file
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output config_update_in_envelope.pb
9 Sign the file to update the configuration
peer channel signconfigtx -f updated_envelope.pb
10 Submit update request
peer channel update -f channel-artifacts/updated_envelope.pb -c byfn-sys-channel -o orderer1.example.com:7050 --tls true --cafile $ORDERER_CA
After successful submission, the following appears:
Repeat the above process in the same way, and switch the system channel CH_NAME (fabric.channel) to the application channel mychannel.
Finally start the orderer2.yaml file written
Wait a moment and print the log to see that the online launch is successful and the raft cluster becomes 3.
The same is true for dynamically adding org organizations.