fabric1.4.2 migrated from kafka to raft (command version)
See in detail the principles on which implementation depends. https://blog.csdn.net/qq_42750537/article/details/96428765
This article is used to record specific orders and problems encountered.
Constructing RatfMetadata
Get available configurations
1) Creating a raft-based network (v1.4.2) requires the same certificate file as the existing kafka network
2) Execute the Create Channel -> Execute Transaction commands in the new raft network
3) Execute the following commands to pull the configuration information of the system channel
Switching environment export CORE_PEER_LOCALMSPID="OrdererMSP" export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/addorg/crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem export CH_NAME=testchainid export CONFIGTXLATOR_URL=http://127.0.0.1:7059 configtxlator start > log.log 2>&1 & echo $CH_NAME //Generating Readable Configuration Block Files peer channel fetch config config_block.pb -o orderer1.example.com:7050 -c $CH_NAME --tls --cafile $ORDERER_CA curl -X POST --data-binary @config_block.pb "$CONFIGTXLATOR_URL/protolator/decode/common.Block" | jq . > config_block.json jq .data.data[0].payload.data.config config_block.json> config.json
Building Metadata
1) Open config.json. Search Consensus Type.
2) Remove the Consensus Type section and modify the status to STATE_MAINTENANCE. Save as file raft.json
Enter Maintenance Status
Converting the configuration of each channel in the kafak-fabric network
Execute the following commands
1.Switching environment 2.Generating Readable Configuration Block Files 3.Modify configuration block information jq ".channel_group.groups.Orderer.values.ConsensusType.value.state = \"STATE_MAINTENANCE\"" config.json > modified_config.json 4.Combine the modified information with the original configuration information curl -X POST --data-binary @config.json "$CONFIGTXLATOR_URL/protolator/encode/common.Config" > config.pb curl -X POST --data-binary @modified_config.json "$CONFIGTXLATOR_URL/protolator/encode/common.Config" > modified_config.pb curl -X POST -F channel=$CH_NAME -F "original=@config.pb" -F "updated=@modified_config.pb" "${CONFIGTXLATOR_URL}/configtxlator/compute/update-from-configs" > config_update.pb curl -X POST --data-binary @config_update.pb "$CONFIGTXLATOR_URL/protolator/decode/common.ConfigUpdate" | jq . > config_update.json echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CH_NAME'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . > config_update_in_envelope.json curl -X POST --data-binary @config_update_in_envelope.json "$CONFIGTXLATOR_URL/protolator/encode/common.Envelope" > config_update_in_envelope.pb 5.Get more than half of the organizational signatures (only signature commands are written here) export CORE_PEER_LOCALMSPID=OrdererMSP export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto-config/ordererOrganizations/example.com/users/Admin\@example.com/msp export CORE_PEER_ADDRESS=peer0.org1:7051 export CORE_PEER_TLS_ENABLED=true export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/ca.crt export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto-config/ordererOrganizations/ecample.com/orderers/orderer1.example.com/tls/server.key export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/addorg/crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt peer channel signconfigtx -f config_update_in_envelope.pb 6.Update configuration peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer1.example.com:7050 --tls true --cafile $ORDERER_CA pkill configtxlator
Switch export CH_NAME = other user channels to perform the above actions in turn
Back up files and shut down the server
1. Optional, mainly rollback when migration fails in production environments. Test environments are not executable
Switch to Raft in Maintenance Mode
Create a new scripts folder and import raft.json that you prepared earlier.
Execute the following commands on each channel in turn
1.Switching environment 2.Generating Readable Configuration Block Files 3.Modify configuration block information jq -s '.[0]*{"channel_group":{"groups":{"Orderer": {"values": {"ConsensusType": .[1]}}}}}' config.json ./scripts/raft.json > modified_config.json 4.Combine the modified information with the original configuration information 5.Get more than half of the organizational signatures (only signature commands are written here) 6.Update configuration
Switch export CH_NAME = other user channels to perform the above actions in turn
Restart and validate leaders
Stop all sorting service nodes, stop all Kafka agents and Zookeepers, and then restart only sorting service nodes.
Start successfully to view the orderer log
Successful elections
Switch to normal mode
But at this time, the normal transaction can not be completed, and the fast configuration state needs to be switched to NORMAL.
Execute the following commands on each channel in turn
1.Switching environment 2.Generating Readable Configuration Block Files 3.Modify configuration block information jq ".channel_group.groups.Orderer.values.ConsensusType.value.state = \"STATE_NORMAL\"" config.json > modified_config.json 4.Combine the modified information with the original configuration information 5.Get more than half of the organizational signatures (only signature commands are written here) 6.Update configuration
Switch export CH_NAME = other user channels to perform the above actions in turn
After completing this process, the sorting service can now accept all transactions across all channels. If you stop peers and applications as recommended, you can restart them now.
Problem Point Record
1. Sort Node Restart Error Reporting: no such hosts:
Reason for the problem: The mapping of the original fabric network orderer image does not contain the mapping of orderer nodes
Solution: Enter the orderer container and add the orderer node mapping
2: Sort node restart error reporting, tls connection failed
Reason: The tls-related configuration of the original yaml file is identified by kafka, and raft is not recognized. New raft identifiable configuration is required
The solution is to provide export updates to the orderer container for the corresponding configuration. Then restart the container.