說明:
官方文檔只說明了如何去新增組織 沒有操作刪除組織的操作詳情,這篇文章簡單記錄一下如何去操作
官方文檔只說明了如何去新增組織 沒有操作刪除組織的操作詳情,這篇文章簡單記錄一下如何去操作
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