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
./../bin/cryptogen generate --config=./org3-crypto.yaml
根据新增组织获取组织信息,注意Org3Msp必须与你在configtx.yaml中新增组织名称一致
./../bin/configtxgen -printOrg Org3MSP -profile ./configtx.yaml > ../channel-artifacts/org3.json
192.168.29.4
docker exec -it cli bash
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
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
scp /www/fabric-deploy/github.com/hyperledger/fabric/mylc/channel-artifacts/org3.json [email protected]:/www/fabric-deploy/github.com/hyperledger/fabric/mylc/
docker cp /www/fabric-deploy/github.com/hyperledger/fabric/mylc/org3.json cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/
将之前获取的新增组织信息加入到通道信息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
configtxlator proto_encode --input mychannel.json --type common.Config > original_mychannel.pb
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
configtxlator proto_decode --input mychannel_update.pb --type common.ConfigUpdate > mychannel_update.json
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
现在我们有个升级交易的pb文件,现在需要必要的Admin用户签名才能真正应用升级,因为现有网络的修改策略为MAJORITY,所以必须网络中一半以上的节点同意才能升级.
192.168.29.4
原有组织对新加组织进行签名已获取认可
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
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
peer channel update -f ./mychannel_update_Org_envelope.pb -c mychannel -o orderer.example.com:7050 --tls --cafile $ORDERER_CA
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机上查看
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