主机 | IP地址 | 节点标识 | 节点域名 | 组织 |
---|---|---|---|---|
VM1 | 101.132.125.102 | ORDERER | orderer.example.com |
ORDERER |
VM2 | 101.132.180.5 | peer1 | peer0.org1.example.com |
ORG1 |
VM2 | 101.132.180.5 | peer2 | peer1.org1.example.com |
ORG1 |
VM3 | 106.14.126.23 | peer3 | peer0.org2.example.com |
ORG2 |
VM3 | 106.14.126.23 | peer4 | peer1.org2.example.com |
ORG2 |
byfn.sh up
单点分别执行成功docker-compose-cli.yaml
、scripts/script.sh
channel.block
到VM1,VM1将其分发到VM3节点为了方便操作,我们需要将byfn.sh
中的确认程序askProceed
docker-compose-cli.yaml
VM1 docker-compose-cli.yaml
version: '2'
volumes:
orderer.example.com:
networks:
byfn:
services:
orderer.example.com:
extends:
file: base/docker-compose-base.yaml
service: orderer.example.com
container_name: orderer.example.com
networks:
- byfn
VM2 docker-compose-cli.yaml
extra_hosts
来定位orderer节点peer
来暴露通道区块version: '2'
volumes:
peer0.org1.example.com:
peer1.org1.example.com:
networks:
byfn:
services:
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org1.example.com
networks:
- byfn
extra_hosts:
- "order.example.com:101.132.125.102"
peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org1.example.com
networks:
- byfn
cli:
container_name: cli
image: hyperledger/fabric-tools:$IMAGE_TAG
tty: true
stdin_open: true
environment:
- GODEBUG=netdns=go
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
#- FABRIC_LOGGING_SPEC=DEBUG
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
- 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
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode
- ./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
- ./peer/:/opt/gopath/src/github.com/hyperledger/fabric/peer/
depends_on:
- peer0.org1.example.com
- peer1.org1.example.com
networks:
- byfn
extra_hosts:
- "order.example.com:101.132.125.102"
VM3
extra_hosts
来定位orderer节点peer
来接收通道区块version: '2'
volumes:
peer0.org2.example.com:
peer1.org2.example.com:
networks:
byfn:
services:
peer0.org2.example.com:
container_name: peer0.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org2.example.com
networks:
- byfn
extra_hosts:
- "orderer.example.com:101.132.125.102"
peer1.org2.example.com:
container_name: peer1.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org2.example.com
networks:
- byfn
cli:
container_name: cli
image: hyperledger/fabric-tools:$IMAGE_TAG
tty: true
stdin_open: true
- GODEBUG=netdns=go
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
#- FABRIC_LOGGING_SPEC=DEBUG
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
- 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
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode
- ./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
- ./peer/:/opt/gopath/src/github.com/hyperledger/fabric/peer/
- /etc/hosts:/etc/hosts
depends_on:
- peer0.org2.example.com
- peer1.org2.example.com
networks:
- byfn
extra_hosts:
- "order.example.com:101.132.125.102"
byfn.sh
VM1
scripts/script.sh
function networkUp() {
checkPrereqs
# generate artifacts if they don't exist
if [ ! -d "crypto-config" ]; then
generateCerts
replacePrivateKey
generateChannelArtifacts
fi
if [ "${IF_COUCHDB}" == "couchdb" ]; then
if [ "$CONSENSUS_TYPE" == "kafka" ]; then
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_KAFKA -f $COMPOSE_FILE_COUCH up -d 2>&1
elif [ "$CONSENSUS_TYPE" == "etcdraft" ]; then
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_RAFT2 -f $COMPOSE_FILE_COUCH up -d 2>&1
else
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH up -d 2>&1
fi
else
if [ "$CONSENSUS_TYPE" == "kafka" ]; then
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_KAFKA up -d 2>&1
elif [ "$CONSENSUS_TYPE" == "etcdraft" ]; then
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_RAFT2 up -d 2>&1
else
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE up -d 2>&1
fi
fi
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start network"
exit 1
fi
if [ "$CONSENSUS_TYPE" == "kafka" ]; then
sleep 1
echo "Sleeping 10s to allow $CONSENSUS_TYPE cluster to complete booting"
sleep 9
fi
if [ "$CONSENSUS_TYPE" == "etcdraft" ]; then
sleep 1
echo "Sleeping 15s to allow $CONSENSUS_TYPE cluster to complete booting"
sleep 14
fi
# now run the end to end script
#docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE
if [ $? -ne 0 ]; then
echo "ERROR !!!! Test failed"
exit 1
fi
#删除远端材料并复制到子主机
set -x
ssh root@vm2 "cd ~/fabric-samples/panta-test/ && ./byfn.sh down && rm -rf channel-artifacts/* crypto-config/* peer/*"
ssh root@vm3 "cd ~/fabric-samples/panta-test/ && ./byfn.sh down && rm -rf channel-artifacts/* crypto-config/* peer/*"
set +x
scp -rq ./crypto-config root@vm2:~/fabric-samples/panta-test
scp -rq ./crypto-config root@vm3:~/fabric-samples/panta-test
scp -rq ./channel-artifacts root@vm2:~/fabric-samples/panta-test
scp -rq ./channel-artifacts root@vm3:~/fabric-samples/panta-test
set -x
ssh root@vm2 "cd ~/fabric-samples/panta-test/ && ./byfn.sh up -c $CHANNEL_NAME"
scp ./peer/*.block root@vm3:~/fabric-samples/panta-test/peer
ssh root@vm3 "cd ~/fabric-samples/panta-test/ && ./byfn.sh up -c $CHANNEL_NAME"
ssh root@vm2 "cd ~/fabric-samples/panta-test/ && docker exec cli scripts/invoke.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE"
#ssh root@vm3 "cd ~/fabric-samples/panta-test/ && docker exec cli scripts/invoke.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE"
set +x
VM2
networkUp
添加回传通道区块步骤# now run the end to end script
docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE
if [ $? -ne 0 ]; then
echo "ERROR !!!! Test failed"
exit 1
fi
scp ./peer/*.block root@vm1:~/fabric-samples/panta-test/peer
scripts/script.sh
VM2
joinChannel () {
for org in 1 ; do
for peer in 0 1; do
joinChannelWithRetry $peer $org
echo "===================== peer${peer}.org${org} joined channel '$CHANNEL_NAME' ===================== "
sleep $DELAY
echo
done
done
}
## Create channel
echo "Creating channel..."
createChannel
## Join all the peers to the channel
echo "Having all peers join the channel..."
joinChannel
## Set the anchor peers for each org in the channel
echo "Updating anchor peers for org1..."
updateAnchorPeers 0 1
#echo "Updating anchor peers for org2..."
#updateAnchorPeers 0 2
## Install chaincode on peer0.org1 and peer0.org2
echo "Installing chaincode on peer0.org1..."
installChaincode 0 1
echo "Install chaincode on peer1.org1..."
installChaincode 1 1
VM3作相同修改
invoke.sh
scripts/utils.sh
修改CAinstantiateChaincode 0 1
### Query chaincode on peer0.org1
##echo "Querying chaincode on peer0.org1..."
chaincodeQuery 0 1 100
#
## Invoke chaincode on peer0.org1 and peer0.org2
echo "Sending invoke transaction on peer0.org1...peer0.org2..."
chaincodeInvoke 0 1 0 2
## Query on chaincode on peer1.org2, check if the result is 90
echo "Querying chaincode on peer1.org2..."
chaincodeQuery 1 2 90