Fabric动态加入组织思路解析

Fabric动态加入组织思路:

 

第一步  配置新组织 (前置条件:配置系统环境变量)

```bash
# cd ~/fabric/configs
# cp crypto-config.yaml new-crypto.yaml
# vim new-crypto.yaml
# /opt/fabric/bin/cryptogen generate --config=./new-crypto.yaml
```

第二步 将新生成组织生成json配置文件(configtxgen 需要1.1.0及以上版本)

```bash
# vim configtx.yaml (备注:这步是将新组织添加到配置中,configtxgen 将根据这个文件生成json)
# /opt/fabric/bin/configtxgen -printOrg org3 > ./channel-artifacts/org3.json
```
第三步 在操作服务器上安装 jq

```bash
#ubuntu install jq
apt update
apt install jq

#redhat (oniguruma-5.9.5-3.el7.x86_64.rpm jq-1.5-1.el7.x86_64.rpm)
yum install -y jq/*
```
第四步  启动 configtxlator 服务

```bash
# configtxlator start > log.log 2>&1 &
# export CONFIGTXLATOR_URL=http://127.0.0.1:7059
```
第五步 设置环境变量


```bash
# export ordererCa=~/fabric/configs/crypto-config/ordererOrganizations/baoquan.com/orderers/orderer1.baoquan.com/msp/tlscacerts/tlsca.baoquan.com-cert.pem
# export CHANNEL_NAME=mychannel
```

第六步 读取配置 config_block.pb
```bash
# peer channel fetch config config_block.pb -o orderer1.baoquan.com:7050 -c $CHANNEL_NAME --tls --cafile $ordererCa
```
第七步 将 config_block.pb 解码为 json文件

```bash
# curl -X POST --data-binary @config_block.pb "$CONFIGTXLATOR_URL/protolator/decode/common.Block" | jq . > config_block.json
```
第八步 合并org3.json到主配置
```bash
Now we isolate the current config specific information - this removes unnecessary elements from the block (header, channel info, signatures, etc...)
# jq .data.data[0].payload.data.config config_block.json > config.json

We will then append the org3 specific MSP/config material and write the output to an aptly named file - updated_config.json
# jq -s '.[0]*{"channel_group":{"groups":{"Application":{"groups": {"org3":.[1]}}}}}' config.json ../channel-artifacts/org3.json >&updated_config.json

So now we have two configuration JSON files - config.json & updated_config.json. We need to encode both back to proto format Original config to proto
# curl -X POST --data-binary @config.json "$CONFIGTXLATOR_URL/protolator/encode/common.Config" > config.pb

Updated config to proto
# curl -X POST --data-binary @updated_config.json "$CONFIGTXLATOR_URL/protolator/encode/common.Config" > updated_config.pb

Now we will calculate the delta between these two protos - this is what we are really after. We'll call it config_update.pb
# curl -X POST -F channel=$CHANNEL_NAME -F "original=@config.pb" -F "updated=@updated_config.pb" "${CONFIGTXLATOR_URL}/configtxlator/compute/update-from-configs" > config_update.pb

Parse this proto to JSON - i.e. decode the config update
# curl -X POST --data-binary @config_update.pb "$CONFIGTXLATOR_URL/protolator/decode/common.ConfigUpdate" | jq . > config_update.json

Now wrap it back in the envelope and put the header information back into the JSON
# echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel","type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' |jq . > config_update_in_envelope.json

Encode this guy
# curl -X POST --data-binary @config_update_in_envelope.json "$CONFIGTXLATOR_URL/protolator/encode/common.Envelope" > config_update_in_envelope.pb

Sign using the Org1 admin identity
# peer version 1.1.0
# peer channel signconfigtx -f config_update_in_envelope.pb
```
第九步 切换到Org2 admin peer节点 并设置环境变量

第十步 Now submit. We'll get the signature for free with this command

```bash
# peer channel update -f config_update_in_envelope.pb -c $CHANNEL_NAME -o orderer2.baoquan.com:7050 --tls true --cafile $ordererCa
```

第十一步 安装Org3节点并设置环境变量 (不要忘记hosts,新加节点也配置hosts)

第十二步 下载通道配置并加入

```bash
Now fetch the genesis block for the channel
# peer channel fetch 0 mychannel.block -o orderer1.baoquan.com:7050 -c $CHANNEL_NAME --tls --cafile $ordererCa

And join peer0 to the channel
# peer channel join -b mychannel.block

Install the source code onto the peer's file system (注意这里是2.0)
# peer chaincode install -n mycc -v 2.0 -p github.com/chaincode_example02/go/
```
第十三步 Org1 和 Org2的chaincode版本相应升级

(备注:各节点升级chaincode后报数据指纹不一致,解决办法是将编译后的chaincode文件拷贝到报错的服务器)

```bash
安装chaincode
# peer chaincode install -n mycc -v 2.0 -p github.com/chaincode_example02/go/

升级 chaincode 背书策略
# peer chaincode upgrade -o orderer1.baoquan.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ordererCa -C $CHANNEL_NAME -n mycc -v 2.0 -c '{"Args":["init","a","140","b","60"]}' -P "OR('Org1MSP.member','Org2MSP.member','Org3MSP.member')"

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乌苏舞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值