fabric1.4动态删除组织(删除peer节点)

说明:

官方文档只说明了如何去新增组织 没有操作删除组织的操作详情,这篇文章简单记录一下如何去操作

官方文档只说明了如何去新增组织 没有操作删除组织的操作详情,这篇文章简单记录一下如何去操作

Step1. 准备

 
1\. 一切操作都在cli 容器里执行
2\. docker exec -it cli bash   //此命令进入cli容器里
3\. 执行操作必须是管理员身份(Admin) 

Step2. 更新配置块

1. 设置环境变量

变量根据自己实际更改(此处以官方通道mychannel 组织Org3 为例)
在此不解释变量含义了
 
export 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  
export CHANNEL_NAME=mychannel

2. 执行获取配置块命令

 
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME  --tls  --cafile $ORDERER_CA

执行命令之后显示最后显示下面两行代表成功 13这个数字只代表第几个块 如果数字不一样是正常的
 
2020-05-21 08:34:04.540 UTC [cli.common] readBlock -> INFO 045 Received block: 13
2020-05-21 08:34:04.540 UTC [channelCmd] fetch -> INFO 046 Retrieving last config block: 13

3. 具体对配置块操作

1). 解析配置块 获取配置信息

 
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >config.json

2). 此处删除组织信息

此处Org3MSP根据自己需求的组织MSPID更改相对应名称
 
jq 'del(.channel_group.groups.Application.groups.Org3MSP)'  config.json > modified_config.json

3). 将上面两步产生的 json文件 重新编码成pb文件

 
configtxlator proto_encode --input config.json --type common.Config --output config.pb

 
configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb

4). 计算两个pb文件差异 输出新的pb文件

 
configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output del_Org3MSP_update.pb

5). 把上一步pb转json 为了封装信封使用

 
configtxlator proto_decode --input del_Org3MSP_update.pb --type common.ConfigUpdate | jq . > del_Org3MSP_update.json

6). 封装信封

 
echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL_NAME'", "type":2}},"data":{"config_update":'$(cat del_Org3MSP_update.json)'}}}' | jq . >del_Org3MSP_update_in_envelope.json

7). json 转pb 最后生成准备提交文件

 
configtxlator proto_encode --input del_Org3MSP_update_in_envelope.json --type common.Envelope --output del_Org3MSP_update_in_envelope.pb

Step3. 对pb文件进行签名

 
这里签名 是指当前通道所有组织 包含准备要删除的组织 (因为这是举例 所以是三个组织 如果是4个5个 那么下面签名需要4个5个组织签名)
友情提示:一定注意环境变量  一定注意环境变量 一定注意环境变量
证书路径  节点地址 端口  改成与自己对应的

1. org1签名

 
export CORE_PEER_LOCALMSPID="Org1MSP"

export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp

export CORE_PEER_ADDRESS=peer0.org1.example.com:7051

 
peer channel signconfigtx -f del_Org3MSP_update_in_envelope.pb

2. org2 签名

 
export CORE_PEER_LOCALMSPID="Org2MSP"

export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp

export CORE_PEER_ADDRESS=peer0.org2.example.com:9051

 
peer channel signconfigtx -f del_Org3MSP_update_in_envelope.pb

3. org3签名

 
export CORE_PEER_LOCALMSPID="Org3MSP"

export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp

export CORE_PEER_ADDRESS=peer0.org3.example.com:11051

 
peer channel signconfigtx -f del_Org3MSP_update_in_envelope.pb

Step4. 最后一步 提交更通道配置块

 
官方文档 是由最后组织节点去提交,去提交就代表已经去签名 但这里为了保险期间防止环境变量出现问题 在做一次环境变量由org1 Admin身份提交

 
export CORE_PEER_LOCALMSPID="Org1MSP"

export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp

export CORE_PEER_ADDRESS=peer0.org1.example.com:7051

提交命令
 
peer channel update -f del_Org3MSP_update_in_envelope.pb -c $CHANNEL_NAME -o orderer.example.com:7050 --tls --cafile $ORDERER_CA

Step5. 验证

1. 提交之后返回结果如下 执行成功

 
2020-05-21 08:45:35.711 UTC [channelCmd] update -> INFO 04a Successfully submitted channel update

2. 再一次验证

 
再一次通过 peer fetch 配置块  通过jq 工具解析json 查看是否已经没有组织了


原文:
https://www.jianshu.com/p/4ac1a6b18bff

posted @ 2021-04-22 11:06  jiftle  阅读(463)  评论(0编辑  收藏  举报