Fabric multi-server cluster deployment
System environment:
centos 7.3
List of server addresses:
A: 10.36.8.106 peer0.org1.example.com
B: 10.36.8.107 peer1.org1.example.com
C: 10.36.8.108 peer0.org2.example.com
D: 10.36.8.109 peer1.org2.example .com
E: 10.36.8.222 orderer.example.com
Software environment:
Each server has to pass the single-server multi-node test (see the previous article) The
image download process can be optimized, only download one and then copy it to other machines
docker save `docker images | awk 'NR>1{print $1} '` -o images
scp images hosts:/tmp
Other machines load docker images
docker load -i images
After the single server test passes, all containers must be shut down, execute this
command./network_setup.sh down
Multi-server start configuration:
A:
1 Modify /etc/hosts, add route map
10.36.8.222 orderer.example.com
2 Modify docker-compose-cli.yaml (directory /opt/gopath/src/github.com/hyperledger/fabric /examples/e2e_cli)
By default, docker-compose-cli.yaml will start 6 services (containers), which are peer0.org1.example.com, peer1.org1.example.com, peer0.org2. example.com,
peer1.org2.example.com, orderer.example.com and cli, because each machine only runs one node corresponding to it, so you need to comment out the services that do not need to be started.
2.1
Except peer0.org1.example.com and cli service, all other services are annotated.
2.2
Add the mapping relationship to the volumes of the cli as follows (the purpose of adding this is mainly to generate a chain of authentication files in the peer directory for easy access):
- ./peer/:/opt/gopath/src/github.com /hyperledger/fabric/peer/
- /etc/hosts:/etc/hosts
2.3
Comment depends_on and command in cli :
depends_on:
#- orderer.example.com
- peer0.org1.example.com
#- peer1.org1.example.com
#- peer0.org2 .example.com
#- peer1.org2.example.com
#command: /bin/bash -c './scripts/script.sh CHANNELNAME;sleepTIMEOUT'
3 Modify base/peer-base.yaml and add volumes (convenient for the container to Access to order):
volumes:
-/etc/hosts:/etc/hosts
B:
1 Modify /etc/hosts, add route mapping
10.36.8.222 orderer.example.com
10.36.8.106 peer0.org1.example.com
2 Modify docker-compose-cli.yaml (directory /opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli)
2.1
Similar to VM1, except peer1.org1.example.com and cli service, all other services Notes.
2.2
Add the mapping relationship to the volumes of the cli:
- ./peer/:/opt/gopath/src/github.com/hyperledger/fabric/peer/
- /etc/hosts:/etc/hosts
2.3
Comment the depends_on and command:
depends_on:
#- orderer.example.com
#- peer0.org1.example.com
- peer1.org1.example.com
#- peer0.org2.example.com
#- peer1.org2.example.com
#command:/bin/bash -c './scripts/script.sh CHANNELNAME;sleepTIMEOUT
2.4
Modify the environment variable in cli
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
3 Modify base/peer-base.yaml, same as VM1 Modifications.
C:
1 Modify /etc/hosts, add route map
10.36.8.222 orderer.example.com
10.36.8.106 peer0.org1.example.com
2 Modify docker-compose-cli.yaml (directory /opt/gopath/src/github. com/hyperledger/fabric/examples/e2e_cli)
2.1 is
similar to VM1, except peer0.org2.example.com and cli service, all other services are annotated.
2.2
Add a mapping relationship to the volumes of the cli:
- ./peer/:/opt/gopath/src/github.com/hyperledger/fabric/peer/
- /etc/hosts:/etc/hosts
2.3
Comment depends_on and command in cli:
depends_on:
#- orderer.example.com
#- peer0.org1.example.com
#- peer1.org1.example.com
- peer0.org2 .example.com
#- peer1.org2.example.com
#command:/bin/bash -c './scripts/script.sh CHANNELNAME;sleepTIMEOUT
2.4
Modify the environment variables in the cli (the two variables CORE_PEER_TLS_CERT_FILE and CORE_PEER_TLS_KEY_FILE should not be modified )
CORE_PEER_LOCALMSPID=”Org2MSP”
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
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
3 Modify base/peer-base.yaml, the same as VM1.
D:
1 Modify /etc/hosts, add route map
10.36.8.222 orderer.example.com
10.36.8.108 peer0.org2.example.com
2 Modify docker-compose-cli.yaml (directory /opt/gopath/src/github. com/hyperledger/fabric/examples/e2e_cli)
2.1 is
similar to VM1, except peer1.org2.example.com and cliservice, all other services are annotated.
2.2
Add the mapping relationship to the volumes of the cli:
- ./peer/:/opt/gopath/src/github.com/hyperledger/fabric/peer/
- /etc/hosts:/etc/hosts
2.3
Comment the depends_on and command in the cli :
depends_on:
#- orderer.example.com
#- peer0.org1.example.com
#- peer1.org1.example.com
#- peer0.org2.example.com
- peer1.org2.example.com
#command:/bin /bash -c './scripts/script.sh CHANNELNAME;sleepTIMEOUT
2.4
Modify the environment variables in the cli (the two variables CORE_PEER_TLS_CERT_FILE, CORE_PEER_TLS_KEY_FILE should not be modified)
CORE_PEER_LOCALMSPID=”Org2MSP”
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
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
3 Modify base/peer -base.yaml, the same modification as VM1.
E:
Modify docker-compose-cli.yaml
to comment all other services except orderer, that is, only start orderer and the
basic configuration is completed.
Multi-server start
1: Choose one of the above machines to
cd /opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli
and execute ./generateArtifacts.sh to generate channel-artifacts/ and crypto-config/ Directory (which contains orderer and peer certificates, private keys, and tls certificates for communication encryption, which is generated by the configtx.yaml configuration file)
picture
Copy these two directories to all other machines
tar -zcf cert.tar .gz channel-artifacts crypto-config
scp cert.tar.gz 10.36.8.106:/tmp
directly overwrite whether other machines have them (because all machine certificates must be the same)
\cp -ar channel-artifacts/* /opt/gopath/ src/github.com/hyperledger/fabric/examples/e2e_cli/channel-artifacts/
\cp -ar crypto-config/* /opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/
2: Start the order node E first
docker-compose -f docker-compose-cli.yaml up -d
Use docker ps to check whether the container orderer.example.com exists
3: A and B belong to the same organization Org1MSP, C and D belong to the same organization Org2MSP, but A is the initial node of B , C is the initial node of D, so we have to start A and C
first. Here I start A
docker-compose -f docker-compose-cli.yaml up -d
docker ps Check whether the cli and peer0.org1.example.com containers exist
Enter the cli container
docker exec -it cli bash
The certificate used to authenticate the order
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
creates mychannel, which will generate a mychannel.block file in the current directory. If other nodes join the chain, this certificate file is required, so it needs to be copied to the same directory of all other nodes Down
peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile $ORDERER_CA
Add peer0.org1.example.com to mychannel:
peer channel join -b mychannel.block
to update the anchor peer information of org1 in mychannel:
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile $ ORDERER_CA
installs the chaincode example chaincode_example02 to peer0.org1.example.com:
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
Now the chaincode code has been installed to peer0 node on, but not instantiated to run. Next, configure other node
B first:
docker-compose -f docker-compose-cli.yaml up -d
docker exec -it cli bash
peer channel join -b mychannel.block
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
C:
docker-compose -f docker-compose-cli.yaml up -d
docker exec -it cli bash
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
peer channel join -b mychannel.block
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile $ORDERER_CA
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
D:
docker-compose -f docker-compose-cli.yaml up -d
docker exec -it cli bash
peer channel join -b mychannel.block
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
has been started so far
Start instantiation and debugging of multiple servers:
1 In addition to the order, select a
peer to instantiate chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c ' {"Args":["init","a","100","b","200"]}' -P "OR('Org1MSP.member','Org2MSP.member')"
to all other nodes The query can see the value just instantiated
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
And you will find that a new container
docker ps is generated
2 Transaction occurs: invoke
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a"," b","50"]}'
Re-query: whether the instantiated variable has changed
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
3 Update and
install the new version
peer chaincode install -n mycc -v 2.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
Initialize two variables in the new version
peer chaincode upgrade -o orderer.example.com:7050 - -tls true --cafile $ORDERER_CA -C mychannel -n mycc -v 2.0 -c '{"Args":["init","c","10","d","20"]}'
via new version to check whether the current value and the previous value are normal
peer chaincode query -C mychannel -n mycc -v 2.0 -c '{"Args":["query","c"]}'
peer chaincode query -C mychannel -n mycc -v 2.0 -c '{"Args":["query","a"]}'
and will spawn a new container of 2.0
Other nodes are updated synchronously through the orderer, but if other nodes want to modify and access, they must install the latest chaincode first , otherwise an error will be reported
peer chaincode install -n mycc -v 2.0 -p github.com/hyperledger/fabric/examples/chaincode /go/chaincode_example02
When some of the above nodes fail, you can
revisit the fabric root and modify the Makefile (/opt/gopath/src/github.com/hyperledger/fabric),
comment docker rmi, delete the image, this line
docker stop `docker ps |awk 'NR>1 {print $1}'`;docker rm `docker ps -a|awk 'NR>1{print $1}'`
make clean
create other chaincode under mychannel
Install chaincode on all nodes:
peer chaincode install -n twocc -v 1.0 -p github .com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
Optional node instantiation:
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
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n twocc -v 1.0 -c '{"Args":["init","e","100" ,"f","200"]}' -P "OR('Org1MSP.member','Org2MSP.member')"
just creates a new container every time a new chaincode instantiation is created, other nodes The container of this heart will also be created at the first query, so it takes a certain amount of time
Note: 1. Because the domain name of the intranet operation has to be written as host, so only need to add the necessary, the local startup is started as ipv6, if the local host writes itself based on ipv4, there will be no bind
host-192-168-1- 100 journal: panic: listen tcp 10.36.8.106:7052: bind: cannot assign requested address
2. When deleting and restarting, remember to delete the previously created chaincode image, otherwise an error will be reported if the previous one is re-initialized
3. If order certificate After reloading, you have to restart the order and all node-related containers
4. If there is a problem with the one initialized by an organization, restart all containers of this node, and delete the chain container and image created before, and re-enter the cli Console query will
recreate the container of this chain, otherwise other nodes under this organization can query and modify, but there will be no change, because the latest order message cannot be received
Docker operation command
docker rmi -f image id Force delete image
docker rmi -f `docker images |awk 'NR > 1{ print $3}'`
docker rm container id or name To delete a stopped container, the running state of the container must be stopped first
docker start/stop/restart name or id
docker ps -a |grep name |awk '{print $NF}'
docker stop `docker ps |awk 'NR>1{print $1}'`;docker rm `docker ps -a |awk 'NR>1{print $1}'`
docker ps -a Get all container information, -q Get all container ids (including all states)
docker inspect container id
docker logs container id Get log information of this container operation
docker commit container id job1 Save the state of the container as Mirror, the mirror name can only take characters [az] and numbers [0-9]
docker short book: https://www.jianshu.com/p/2217cfed29d7