在各众多学弟和作者的一通瞎捣鼓下,我们又做了一点微小的工作。现在记录下多节点部署的一些事情。
本文主要参考http://www.cnblogs.com/studyzy/p/7237287.html
这次瞎捣鼓一共用了5台服务器,具体参数如下,具体ip地址以ip0,ip1……代替:
ip | 节点标志 | hostname | organization |
ip0 | orderer | orderer.example.cn | orderer |
ip1 | sp0 | peer0.org1.example.cn | org1 |
ip2 | sp1 | peer1.org1.example.cn | org1 |
ip3 | sp2 | peer0.org2.example.cn | org2 |
ip4 | sp3 | peer1.org2.example.cn | org2 |
首先选定一台服务器作为orderer节点,假设其ip为ip0,以下操作都在orderer上完成
cd /opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli/
generateArtifacts.sh mychannel
设置docker-compose-peer.yaml和docker-compose-order.yaml文件。还是在e2e_cli下。
cp docker-compose-cli.yaml docker-compose-peer.yaml
cp docker-compose-cli.yaml docker-compose-orderer.yaml
分别对两个文件修改
docker-compose-peer.yaml修改如下:
把peer1.org1,peer0.org2,peer2.org2的配置删除,
peer0.org1加上orderer的影射,
cli下的command删掉,
cli的depends_on:只保留peer0.org1
加上extra_hosts
最后如下
# Copyright IBM Corp. All Rights Reserved.
#
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org1.example.com
extra_hosts:
- "orderer.example.com:ip0"
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.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
volumes:
- /var/run/:/host/var/run/
- ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./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.org1.example.com
extra_hosts:
- "orderer.example.com:ip0"
- "peer0.org1.example.com:ip1"
- "peer1.org1.example.com:ip2"
- "peer0.org2.example.com:ip3"
- "peer1.org2.example.com:ip4"
docker-compose-orderer.yaml如下修改:
只保留orderer的配置
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
services:
orderer.example.com:
extends:
file: base/docker-compose-base.yaml
service: orderer.example.com
container_name: orderer.example.com
修改base/docker-compose-base.yaml文件,将所有peer的端口映射都改为相同的
这是原来的:
ports:
- 7051:7051
- 7052:7052
- 7053:7053
……
ports:
- 8051:7051
- 8052:7052
- 8053:7053
……
ports:
- 9051:7051
- 9052:7052
- 9053:7053
……
ports:
- 10051:7051
- 10052:7052
- 10053:7053
改成
ports:
- 7051:7051
- 7052:7052
- 7053:7053
……
ports:
- 7051:7051
- 7052:7052
- 7053:7053
……
ports:
- 7051:7051
- 7052:7052
- 7053:7053
……
ports:
- 7051:7051
- 7052:7052
- 7053:7053
最后把e2e_cli复制到四个peer上。
在peer上对docker-compose-peer.yaml做一点微小的改动
以peer1.org1.example.com为例,改成:(主要是peer0换成peer1,加上peer0的映射)
version: '2'
services:
peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org1.example.com
extra_hosts:
- "orderer.example.com:ip0"
- "peer0.org1.example.com:ip1"
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=peer1.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/peer1.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/peer1.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/peer1.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
volumes:
- /var/run/:/host/var/run/
- ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./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:
- peer1.org1.example.com
extra_hosts:
- "orderer.example.com:ip0"
- "peer0.org1.example.com:ip1"
- "peer1.org1.example.com:ip2"
- "peer0.org2.example.com:ip3"
- "peer1.org2.example.com:ip4"
现在回到orderer下,先启动orderer
docker-compose -f docker-compose-orderer.yaml up -d
可以看到启动了两个镜像
来到peer下,启动peer
docker-compose -f docker-compose-peer.yaml up -d