超级账本(hyperledger)生产多节点部署

环境准备

* 安装docker
* 安装docker-compose
* 安装mysql
* 安装node
* 安装dnsmasq

架构设计

四台服务器
docker0 ca1       couchdb0 zk0  kafka0 peer0-org1 order0 cli
docker1 ca2       couchdb1 zk1  kafka1 peer1-org1 order1
docker2           couchdb2 zk2  kafka2 peer0-org2 order2
docker3           couchdb3      kafka3 peer1-org2

下载代码

git clone https://github.com/hyperledger/blockchain-explorer

创建网络

docker network create fabricdockercomposesvt_default -d bridge #默认创建该网络
多机部署采用host模式 对应peer产生对应chaincode的docker容器会采用该网络(fabricdockercomposesvt_default)

安装dnsmasq 请将ipx改为对应的服务器ip

ip1 zookeeper0 kafka0 ca1 peer0.org1.example.com orderer0.example.com couchdb0
ip2 zookeeper1 kafka1 ca2 peer1.org1.example.com orderer1.example.com couchdb1 ca.org2.example.com
ip3 zookeeper2 kafka2 couchdb2 peer0.org2.example.com orderer3.example.com
ip4 kafka3 couchdb3 peer1.org2.example.com


修改docker dns
OPTIONS=' --log-driver=journald --signature-verification=false --dns=$dnsmasqip'

生成证书

cd blockchain-explorer/fabric-docker-compose-svt
bash generateArtifacts.sh mychannel

修改配置文件

cat docker-compose-cli.yaml-1
version: '2'

 services: ca1: image: hyperledger/fabric-ca environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server  - FABRIC_CA_SERVER_CA_NAME=ca-org1  - FABRIC_CA_SERVER_TLS_ENABLED=${ENABLE_TLS}  - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem  - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/c107bc25921f005ce49b8ebe7389d51b1391998497d5c06d7760b7ce57b8df4c_sk  ports: - "7054:7054"  command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/c107bc25921f005ce49b8ebe7389d51b1391998497d5c06d7760b7ce57b8df4c_sk -b admin:adminpw -d' volumes: - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config  network_mode: host container_name: ca_peerOrg1 zookeeper0: extends: file: base/docker-compose-base.yaml service: zookeeper0 network_mode: host container_name: zookeeper0 kafka0: extends: file: base/docker-compose-base.yaml service: kafka0 container_name: kafka0 network_mode: host depends_on: - zookeeper0  orderer0.example.com: extends: file: base/docker-compose-base.yaml service: orderer0.example.com container_name: orderer0.example.com network_mode: host depends_on: - kafka0  peer0.org1.example.com: container_name: peer0.org1.example.com network_mode: host extends: file: base/docker-compose-base.yaml service: peer0.org1.example.com cli: container_name: cli image: hyperledger/fabric-testenv tty: true network_mode: host 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=${ENABLE_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/Admin@org1.example.com/msp  working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: bash -c 'sleep 30000000000000000000000' volumes: - /var/run/:/host/var/run/  - ./examples:/opt/gopath/src/github.com/hyperledger/fabric/examples  - ./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
cat docker-compose-couch.yaml-1
version: '2'

 services: couchdb0: container_name: couchdb0 image: hyperledger/fabric-couchdb network_mode: host # Uncomment the port mapping if you want to expose the CouchDB service, # for example to utilize Fauxton User Interface in dev environments. ports: - "5984:5984"  peer0.org1.example.com: environment: - CORE\_LEDGER\_STATE_STATEDATABASE=CouchDB  - CORE\_LEDGER\_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984  network_mode: host depends_on: - couchdb0
cat docker-compose-cli.yaml-2
version: '2'

 services: ca2: image: hyperledger/fabric-ca environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server  - FABRIC_CA_SERVER_CA_NAME=ca-org2  - FABRIC_CA_SERVER_TLS_ENABLED=${ENABLE_TLS}  - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem  - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/d296fe44924cd26f7bcceb8ce2aa2fa8fc9c724485baea33421f6b1f6b3d4950_sk  ports: - "8054:7054"  command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/d296fe44924cd26f7bcceb8ce2aa2fa8fc9c724485baea33421f6b1f6b3d4950_sk -b admin:adminpw -d' volumes: - ./crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config  network_mode: host container_name: ca_peerOrg2 zookeeper1: extends: file: base/docker-compose-base.yaml service: zookeeper1 network_mode: host container_name: zookeeper1 kafka1: extends: file: base/docker-compose-base.yaml service: kafka1 container_name: kafka1 network_mode: host depends_on: - zookeeper1  orderer1.example.com: extends: file: base/docker-compose-base.yaml service: orderer1.example.com network_mode: host container_name: orderer1.example.com depends_on: - kafka1  peer1.org1.example.com: container_name: peer1.org1.example.com network_mode: host extends: file: base/docker-compose-base.yaml service: peer1.org1.example.com
cat docker-compose-couch.yaml-2
version: '2'

 services: couchdb1: container_name: couchdb1 network_mode: host image: hyperledger/fabric-couchdb # Uncomment the port mapping if you want to expose the CouchDB service, # for example to utilize Fauxton User Interface in dev environments. ports: - "6984:5984" peer1.org1.example.com: network_mode: host environment: - CORE_LEDGER_STATE_STATEDATABASE=CouchDB - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb1:5984
cat docker-compose-cli.yaml-3
version: '2'

 services: zookeeper2: extends: file: base/docker-compose-base.yaml service: zookeeper2 network_mode: host container_name: zookeeper2 kafka2: extends: file: base/docker-compose-base.yaml service: kafka2 container_name: kafka2 network_mode: host depends_on: - zookeeper2 orderer2.example.com: extends: file: base/docker-compose-base.yaml service: orderer2.example.com network_mode: host container_name: orderer2.example.com depends_on: - kafka2 peer0.org2.example.com: container_name: peer0.org2.example.com network_mode: host extends: file: base/docker-compose-base.yaml service: peer0.org2.example.com
cat docker-compose-couch.yaml-3
version: '2'

 services: couchdb2: container_name: couchdb2 image: hyperledger/fabric-couchdb network_mode: host # Uncomment the port mapping if you want to expose the CouchDB service, # for example to utilize Fauxton User Interface in dev environments. ports: - "7984:5984" peer0.org2.example.com: network_mode: host environment: - CORE_LEDGER_STATE_STATEDATABASE=CouchDB - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb2:5984
cat docker-compose-cli.yaml-4
version: '2'

 services: kafka3: extends: file: base/docker-compose-base.yaml service: kafka3 network_mode: host container_name: kafka3 peer1.org2.example.com: network_mode: host container_name: peer1.org2.example.com extends: file: base/docker-compose-base.yaml service: peer1.org2.example.com
cat docker-compose-couch.yaml-4
version: '2'

 services: couchdb3: container_name: couchdb3 image: hyperledger/fabric-couchdb network_mode: host # Uncomment the port mapping if you want to expose the CouchDB service, # for example to utilize Fauxton User Interface in dev environments. ports: - "8984:5984" peer1.org2.example.com: network_mode: host environment: - CORE_LEDGER_STATE_STATEDATABASE=CouchDB - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb3:5984
分别在docker 1,2,3,4上启动docker-compose
docker-compose -f docker-compose-cli.yaml-${item} docker-compose-couch.yaml-${item}
docker ps -a 查看容器启动状态,确保所有组件启动正常,因为多机部署,无法保证依赖顺序,如果组件启动失败可以手动进行启动, docker start $containername


为了方便我们手动创建channel以及chaincode等资源 cli启动时未执行初始化操作,docker exec -it cli /bin/bash # ./scripts/script.sh
确保资源初始化成功

安装fabric-explorer

安装依赖包


cd fabric-explorer
npm install --registry https://registry.npm.taobao.org
cd explorer_client
npm install --registry https://registry.npm.taobao.org

如果node项目单独部署需要拷贝 证书,将channel-artifacts crypto-config拷贝到app/app/network-config.json中指定的位置
修改config.json中mysql的配置
如果在部署时指定了ENABLE_TLS=true则需要在config.json中修改"enableTls":true,此时使用的网络配置文件为app/network-config-tls.json 确保对应证书放在指定位置
启动 node main.js #最好每次清理tmp下fabric-client开头的目录,不然可能造成x509错误,这些目录会缓存证书信息

访问

阅读更多

更多精彩内容