注释讲解:
# 客户端docker容器启动之后, go的工作目录
- GOPATH=/opt/gopath # 不需要修改
# docker容器启动之后, 对应的守护进程的本地套接字, 不需要修改
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=INFO # 日志级别
- CORE_PEER_ID=cli # 当前客户端节点的ID, 自己指定
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051 # 客户端连接的peer节点
- CORE_PEER_LOCALMSPID=Org1MSP # 组织ID
- CORE_PEER_TLS_ENABLED=true # 通信是否使用tls加密
- 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
实际配置:
cli:
container_name: cli
image: hyperledger/fabric-tools:latest
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
#- CORE_LOGGING_LEVEL=DEBUG
- CORE_LOGGING_LEVEL=INFO
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.orggo.zjnu.com:7051
- CORE_PEER_LOCALMSPID=OrgGoMSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.zjnu.com/peers/peer0.orggo.zjnu.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.zjnu.com/peers/peer0.orggo.zjnu.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.zjnu.com/peers/peer0.orggo.zjnu.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.zjnu.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/chaincode
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on:
- orderer.zjnu.com
- peer0.orggo.zjnu.com
- peer1.orggo.zjnu.com
- peer0.orgcpp.zjnu.com
- peer1.orgcpp.zjnu.com
networks:
- byfn
注释讲解:
- ORDERER_GENERAL_LOGLEVEL=INFO # 日志级别
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 # orderer节点监听的地址
- ORDERER_GENERAL_GENESISMETHOD=file # 创始块的来源, 指定file来源就是文件中
# 创始块对应的文件, 这个不需要改
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP # orderer节点所属的组的ID
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp # 当前节点的msp账号路径
# enabled TLS
- ORDERER_GENERAL_TLS_ENABLED=true # 是否使用tls加密
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key # 私钥
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt # 证书
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] # 根证书
实际配置:
docker-compose-cli.yaml
orderer.zjnu.com:
extends:
file: base/docker-compose-base.yaml
service: orderer.zjnu.com
container_name: orderer.zjnu.com
networks:
- byfn
docker-compose-base.yaml
orderer.zjnu.com:
container_name: orderer.zjnu.com
image: hyperledger/fabric-orderer:latest
environment:
- ORDERER_GENERAL_LOGLEVEL=INFO
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
# enabled TLS
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ../crypto-config/ordererOrganizations/zjnu.com/orderers/orderer.zjnu.com/msp:/var/hyperledger/orderer/msp
- ../crypto-config/ordererOrganizations/zjnu.com/orderers/orderer.zjnu.com/tls/:/var/hyperledger/orderer/tls
- orderer.zjnu.com:/var/hyperledger/production/orderer
ports:
- 7050:7050
- CORE_PEER_ID=peer0.orggo.test.com # 当前peer节点的名字, 自己起
# 当前peer节点的地址信息
- CORE_PEER_ADDRESS=peer0.orggo.test.com:7051
# 启动的时候, 指定连接谁, 一般写自己就行
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.orggo.test.com:7051
# 为了被其他节点感知到, 如果不设置别的节点不知有该节点的存在
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.orggo.test.com:7051
- CORE_PEER_LOCALMSPID=OrgGoMSP
# docker的本地套接字地址, 不需要改
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
# 当前节点属于哪个网络,这里的zjnu_fabric是因为docker-compose.yaml所在的目录名而定的
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=zjnu_fabric_byfn
- CORE_LOGGING_LEVEL=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true # 释放自动选举leader节点
- CORE_PEER_GOSSIP_ORGLEADER=false # 当前不是leader
- CORE_PEER_PROFILE_ENABLED=true # 在peer节点中有一个profile服务
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
启动docker-compose使用的配置文件 - docker-compose.yaml
# docker-compose.yaml
version: '2'
volumes:
orderer.zjnu.com:
peer0.orggo.zjnu.com:
peer1.orggo.zjnu.com:
peer0.orgcpp.zjnu.com:
peer1.orgcpp.zjnu.com:
networks:
byfn:
services:
orderer.zjnu.com:
extends:
file: base/docker-compose-base.yaml
service: orderer.zjnu.com
container_name: orderer.zjnu.com
networks:
- byfn
peer0.orggo.zjnu.com:
container_name: peer0.orggo.zjnu.com
extends:
file: base/docker-compose-base.yaml
service: peer0.orggo.zjnu.com
networks:
- byfn
peer1.orggo.zjnu.com:
container_name: peer1.orggo.zjnu.com
extends:
file: base/docker-compose-base.yaml
service: peer1.orggo.zjnu.com
networks:
- byfn
peer0.orgcpp.zjnu.com:
container_name: peer0.orgcpp.zjnu.com
extends:
file: base/docker-compose-base.yaml
service: peer0.orgcpp.zjnu.com
networks:
- byfn
peer1.orgcpp.zjnu.com:
container_name: peer1.orgcpp.zjnu.com
extends:
file: base/docker-compose-base.yaml
service: peer1.orgcpp.zjnu.com
networks:
- byfn
cli:
container_name: cli
image: hyperledger/fabric-tools:latest
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
#- CORE_LOGGING_LEVEL=INFO
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.orggo.zjnu.com:7051
- CORE_PEER_LOCALMSPID=OrgGoMSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.zjnu.com/peers/peer0.orggo.zjnu.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.zjnu.com/peers/peer0.orggo.zjnu.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.zjnu.com/peers/peer0.orggo.zjnu.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.zjnu.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/chaincode
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on:
- orderer.zjnu.com
- peer0.orggo.zjnu.com
- peer1.orggo.zjnu.com
- peer0.orgcpp.zjnu.com
- peer1.orgcpp.zjnu.com
networks:
- byfn
被docker-compose.yaml
依赖的文件 - base/docker-compose-base.yaml
# base/docker-compose-base.yaml
version: '2'
services:
orderer.itcast.com:
container_name: orderer.zjnu.com
image: hyperledger/fabric-orderer:latest
environment:
- ORDERER_GENERAL_LOGLEVEL=INFO
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
# enabled TLS
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ../crypto-config/ordererOrganizations/zjnu.com/orderers/orderer.zjnu.com/msp:/var/hyperledger/orderer/msp
- ../crypto-config/ordererOrganizations/zjnu.com/orderers/orderer.zjnu.com/tls/:/var/hyperledger/orderer/tls
- orderer.zjnu.com:/var/hyperledger/production/orderer
# /var/lib/docker/volumes/order.zjnu.com
ports:
- 7050:7050
peer0.orggo.zjnu.com:
container_name: peer0.orggo.zjnu.com
extends:
file: peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer0.orggo.zjnu.com
- CORE_PEER_ADDRESS=peer0.orggo.zjnu.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.orggo.zjnu.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.orggo.zjnu.com:7051
- CORE_PEER_LOCALMSPID=OrgGoMSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/orggo.zjnu..com/peers/peer0.orggo.zjnu.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/orggo.zjnu..com/peers/peer0.orggo.zjnu.com/tls:/etc/hyperledger/fabric/tls
- peer0.orggo.zjnu..com:/var/hyperledger/production
ports:
- 7051:7051
- 7053:7053
peer1.orggo.zjnu.com:
container_name: peer1.orggo.zjnu.com
extends:
file: peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer1.orggo.zjnu.com
- CORE_PEER_ADDRESS=peer1.orggo.zjnu.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.orggo.zjnu.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.orggo.zjnu.com:7051
- CORE_PEER_LOCALMSPID=OrgGoMSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/orggo.zjnu.com/peers/peer1.orggo.zjnu.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/orggo.zjnu.com/peers/peer1.orggo.zjnu.com/tls:/etc/hyperledger/fabric/tls
- peer1.orggo.zjnu.com:/var/hyperledger/production
ports:
- 8051:7051
- 8053:7053
peer0.orgcpp.zjnu.com:
container_name: peer0.orgcpp.zjnu.com
extends:
file: peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer0.orgcpp.zjnu.com
- CORE_PEER_ADDRESS=peer0.orgcpp.zjnu.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.orgcpp.zjnu.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.orgcpp.zjnu.com:7051
- CORE_PEER_LOCALMSPID=OrgCppMSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/orgcpp.zjnu.com/peers/peer0.orgcpp.zjnu.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/orgcpp.zjnu.com/peers/peer0.orgcpp.zjnu.com/tls:/etc/hyperledger/fabric/tls
- peer0.orgcpp.zjnu.com:/var/hyperledger/production
ports:
- 9051:7051
- 9053:7053
peer1.orgcpp.zjnu.com:
container_name: peer1.orgcpp.zjnu.com
extends:
file: peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer1.orgcpp.zjnu.com
- CORE_PEER_ADDRESS=peer1.orgcpp.zjnu.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.orgcpp.zjnu.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.orgcpp.zjnu.com:7051
- CORE_PEER_LOCALMSPID=OrgCppMSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/orgcpp.zjnu.com/peers/peer1.orgcpp.zjnu.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/orgcpp.zjnu.com/peers/peer1.orgcpp.zjnu.com/tls:/etc/hyperledger/fabric/tls
- peer1.orgcpp.zjnu.com:/var/hyperledger/production
ports:
- 10051:7051
- 10053:7053
被 ``docker-compose-base.yaml依赖的文件 -
base/peer-base.yaml`
# base/peer-base.yaml
version: '2'
services:
peer-base:
image: hyperledger/fabric-peer:latest
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
# the following setting starts chaincode containers on the same
# bridge network as the peers
# https://docs.docker.com/compose/networking/
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=zjnu_fabric_byfn
- CORE_LOGGING_LEVEL=INFO
#- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_PROFILE_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
注:因为在前面的章节有启动官方给的示例,所以节点的端口会被占用,需要进入到fabric-network里面执行关掉节点的指令,之后再回到我们自己搭建的目录里执行。