Fabric1.1动态添加组织节点

fabric版本为1.1以上,才可以动态添加组织

编写新增组织的配置文件

192.168.29.3

cd /www/fabric-deploy/github.com/hyperledger/fabric/mylc

mkdir org3-artifacts

cd org3-artifacts

vim org3-crypto.yaml

PeerOrgs:

  - Name: Org3

    Domain: org3.example.com

    EnableNodeOUs: true

    Template:

      Count: 2

    Users:

      Count: 1

cp ../configtx.yaml configtx.yaml

vim configtx.yaml

在configtx.yaml配置文件中新增创建通道的一些组织信息,新增组织在Organizations中写明,这里只增加了一个Org3

Organizations:

    - &Org3

        Name: Org3MSP

        ID: Org3MSP

        MSPDir: crypto-config/peerOrganizations/org3.example.com/msp

        AnchorPeers:

            - Host: peer0.org3.example.com

             Port: 7051

 

对于新增通道,通道文件创建依赖于profiles,根据自己需要添加不同组织

Profiles:



    NewOrgsChannel:

        Consortium: SampleConsortium

        Application:

            <<: *ApplicationDefaults

            Organizations:

                - *Org1

                - *Org2

                - *Org3

    OneOrgsChannel:

        Consortium: SampleConsortium

        Application:

            <<: *ApplicationDefaults

            Organizations:

                - *Org3

 

生成证书文件

获取org3证书

./../bin/cryptogen generate --config=./org3-crypto.yaml

 

生成org3的配置文件

根据新增组织获取组织信息,注意Org3Msp必须与你在configtx.yaml中新增组织名称一致

./../bin/configtxgen -printOrg Org3MSP -profile ./configtx.yaml > ../channel-artifacts/org3.json

 

获取原有网络的配置文件

192.168.29.4

进入cli

docker exec -it cli bash

 

cli中安装jq

apt update && apt install -y jq

 

配置环境变量

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

 

获取channel的配置文件

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

 

解码配置文件

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

 

从29.3机拷贝org3.json到29.4机

scp /www/fabric-deploy/github.com/hyperledger/fabric/mylc/channel-artifacts/org3.json [email protected]:/www/fabric-deploy/github.com/hyperledger/fabric/mylc/

 

将29.4机org3.json拷贝到docker中

docker cp /www/fabric-deploy/github.com/hyperledger/fabric/mylc/org3.json cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/

 

在原有的配置文件添加org3的配置

将之前获取的新增组织信息加入到通道信息json文件,利用jq工具生成含有3个orgs的配置文件mychannel_config.json

jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' mychannel.json ./channel-artifacts/org3.json > mychannel_config.json

 

将config.json转换为protobufs

configtxlator proto_encode --input mychannel.json --type common.Config > original_mychannel.pb

 

mychannel_config.json 转换为 protobufs

configtxlator proto_encode --input mychannel_config.json --type common.Config > modified_mychannel.pb

 

获取增量包并且补全,转换成二进制文件

根据original_mychannel.pb和modified_mychannel.pb计算出升级的mychannel_update.pb

configtxlator compute_update --channel_id mychannel --original original_mychannel.pb --updated modified_mychannel.pb > mychannel_update.pb

 

解码mychannel_update.pb -> json

configtxlator proto_decode --input mychannel_update.pb  --type common.ConfigUpdate > mychannel_update.json

 

生成配置升级的json并转换为protobufs

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

 

configtxlator proto_encode --input mychannel_update_envelope.json --type common.Envelope > mychannel_update_Org_envelope.pb

 

添加org3

现在我们有个升级交易的pb文件,现在需要必要的Admin用户签名才能真正应用升级,因为现有网络的修改策略为MAJORITY,所以必须网络中一半以上的节点同意才能升级.

192.168.29.4

原有组织对新加组织进行签名已获取认可

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/[email protected]/msp

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



peer channel signconfigtx -f mychannel_update_Org_envelope.pb

 

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/[email protected]/msp

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



peer channel signconfigtx -f mychannel_update_Org_envelope.pb

 

获取签名之后通知orderer更新通道信息

peer channel update -f ./mychannel_update_Org_envelope.pb -c mychannel -o orderer.example.com:7050 --tls --cafile $ORDERER_CA

 

org3加入Channel

192.168.29.3

 

启动org3的docker集群

vim docker-compose-base.yaml

  peer0.org3.example.com:
    container_name: peer0.org3.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org3.example.com
      - CORE_PEER_ADDRESS=peer0.org3.example.com:7051
      - CORE_PEER_CHAINCODELISTENADDRESS=peer0.org3.example.com:7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org3.example.com:7051
      - CORE_PEER_LOCALMSPID=Org3MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp:/etc/hyperledger/fabric/msp
        - ../org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053

vim docker-compose-peer.yaml

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:

  peer0.org3.example.com:
    container_name: peer0.org3.example.com
    extends:
      file:  base/docker-compose-base.yaml
      service: peer0.org3.example.com
    extra_hosts:
     - "orderer.example.com:192.168.29.3"

  cli:
    container_name: cli
    image: hyperledger/fabric-tools
    tty: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org3.example.com:7051
      - CORE_PEER_LOCALMSPID=Org3MSP
      - CORE_PEER_TLS_ENABLED=false
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
      - 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
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    volumes:
        - /var/run/:/host/var/run/
        - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/wtoiplc/chaincode/go
        - ./org3-artifacts/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - peer0.org3.example.com
    extra_hosts:
     - "orderer.example.com:192.168.29.3"
     - "peer0.org1.example.com:192.168.29.4"
     - "peer1.org1.example.com:192.168.29.5"
     - "peer0.org3.example.com:192.168.29.6"
     - "peer1.org3.example.com:192.168.29.7"
     - "peer0.org3.example.com:192.168.29.3"

 

docker-compose -f docker-compose-peer.yaml up –d

 

将29.3中org3.example.com拷贝给29.4机

scp -r /www/fabric-deploy/github.com/hyperledger/fabric/mylc/org3-artifacts/crypto-config/peerOrganizations/org3.example.com [email protected]:/www/fabric-deploy/github.com/hyperledger/fabric/mylc/crypto-config/peerOrganizations/

 

192.168.29.4

docker exec -it cli bash

修改容器的hosts,添加192.168.29.3 peer0.org3.example.com

echo "192.168.29.3 peer0.org3.example.com" >> /etc/hosts

 

加入Channel

CORE_PEER_LOCALMSPID="Org3MSP"

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

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/[email protected]/msp

CORE_PEER_ADDRESS=peer0.org3.example.com:7051



peer channel join -b mychannel.block

 

在29.3机上查看

升级Chaincode,配置org3的节点加入背书策略中

192.168.29.3

安装链码

peer chaincode install -n personcc -p github.com/hyperledger/fabric/mylc/chaincode/go/person -v 5.0

 

192.168.29.4

安装链码

peer chaincode install -n personcc -p github.com/hyperledger/fabric/mylc/chaincode/go/person -v 5.0

 

升级链码

peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n personcc -c '{"Args":[]}' -P "OR ('Org1MSP.member','Org2MSP.member','Org3MSP.member')" -v 5.0

 

192.168.29.3

peer chaincode query -C mychannel -n personcc -c '{"Args":["queryInfo","123xdfd"]}'

 

docker ps -a

猜你喜欢

转载自blog.csdn.net/yuch_hong/article/details/107463645