创建自己的区块链网络 五
Posted 患孤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建自己的区块链网络 五相关的知识,希望对你有一定的参考价值。
目录
前言
上次我们修改了docker-compose-base.yaml,我还还需要修改最后一个文件便可以来编写启动网络的命令了。那么我们这里就来修改docker-compose-cli.yaml文件,这个配置文件是启动网络网络节点时候需要的,也就是使用docker启动了相应的容器作为网络节点。
修改文件
那么接下来我们就来修改下官方文件,首先看一下官方文件。
1、查看官方源文件
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'
volumes:
orderer.example.com:
peer0.org1.example.com:
peer1.org1.example.com:
peer0.org2.example.com:
peer1.org2.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
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org1.example.com
networks:
- byfn
peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org1.example.com
networks:
- byfn
peer0.org2.example.com:
container_name: peer0.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org2.example.com
networks:
- byfn
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
environment:
- SYS_CHANNEL=$SYS_CHANNEL
- 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/Admin@org1.example.com/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/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on:
- orderer.example.com
- peer0.org1.example.com
- peer1.org1.example.com
- peer0.org2.example.com
- peer1.org2.example.com
networks:
- byfn
2、修改文件
大家可以看到我们修改的东西无非还是那几样,域名与我们之前配置的对应就可以了,如果少了,就自行添加上,就这么简单。那么接下来我们就来着手来进行修改。
下面是修改过后的内容:
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# 1--将所有的example改为之前定义的slzce
# 2--将所有的org1改为之前定义的organization1
# 3--将所有的org2改为之前定义的organization2
# 4--将所有的peer0改为之前定义的node1
# 5--将所有的peer1改为之前定义的node2
# 6--将所有的channel-artifacts改为之前定义的config
# 6--添加节点
version: '2'
volumes:
orderer.slzce.com:
node1.organization1.slzce.com:
node2.organization1.slzce.com:
node1.organization2.slzce.com:
node2.organization2.slzce.com:
# 以下内容为添加的
node1.organization3.slzce.com:
node2.organization3.slzce.com:
# -------------------
networks:
byfn:
services:
orderer.slzce.com:
extends:
file: base/docker-compose-base.yaml
service: orderer.slzce.com
container_name: orderer.slzce.com
networks:
- byfn
node1.organization1.slzce.com:
container_name: node1.organization1.slzce.com
extends:
file: base/docker-compose-base.yaml
service: node1.organization1.slzce.com
networks:
- byfn
node2.organization1.slzce.com:
container_name: node2.organization1.slzce.com
extends:
file: base/docker-compose-base.yaml
service: node2.organization1.slzce.com
networks:
- byfn
node1.organization2.slzce.com:
container_name: node1.organization2.slzce.com
extends:
file: base/docker-compose-base.yaml
service: node1.organization2.slzce.com
networks:
- byfn
node2.organization2.slzce.com:
container_name: node2.organization2.slzce.com
extends:
file: base/docker-compose-base.yaml
service: node2.organization2.slzce.com
networks:
- byfn
# 以下内容为添加的
node1.organization3.slzce.com:
container_name: node1.organization3.slzce.com
extends:
file: base/docker-compose-base.yaml
service: node1.organization3.slzce.com
networks:
- byfn
node2.organization3.slzce.com:
container_name: node2.organization3.slzce.com
extends:
file: base/docker-compose-base.yaml
service: node2.organization3.slzce.com
networks:
- byfn
# ---------------------------
cli:
container_name: cli
# image: hyperledger/fabric-tools:$IMAGE_TAG 删除不必要的变量
image: hyperledger/fabric-tools
tty: true
stdin_open: true
environment:
- SYS_CHANNEL=$SYS_CHANNEL
- 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=node1.organization1.slzce.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP #这里注意点我们不需要修改他,如果你之前的id修改了才需要修改
- CORE_PEER_TLS_ENABLED=flase
# TLS 改为false并且删除下方
# - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/organization1.slzce.com/peers/node1.organization1.slzce.com/tls/server.crt
# - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/organization1.slzce.com/peers/node1.organization1.slzce.com/tls/server.key
# - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/organization1.slzce.com/peers/node1.organization1.slzce.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/organization1.slzce.com/users/Admin@organization1.slzce.com/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/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
# - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts 这里将channel-artifacts修改为config
- ./config:/opt/gopath/src/github.com/hyperledger/fabric/peer/config
depends_on:
- orderer.slzce.com
- node1.organization1.slzce.com
- node2.organization1.slzce.com
- node1.organization2.slzce.com
- node2.organization2.slzce.com
# 以下内容为添加的
- node1.organization3.slzce.com
- node2.organization3.slzce.com
# ------------------
networks:
- byfn
#修改完毕
结语
那么到这里我们所有的配置文件全部都修改完成了,那么后面我们就可以编写命令来跑网络了,是不是很期待。
以上是关于创建自己的区块链网络 五的主要内容,如果未能解决你的问题,请参考以下文章