Hyperledger Fabric1.4 多机部署(尚有问题暂未解决)

参考教程(主):https://www.cnblogs.com/cbkj-xd/p/11067814.html 作者触不可及,出处 https://www.cnblogs.com/cbkj-xd/
非常推荐!
其他参考教程:
https://segmentfault.com/a/1190000021387316
https://www.cnblogs.com/studyzy/p/7237287.html

本文根据上述参考教程的步骤进行实验操作,蓝色部分是自己的修改和问题解决,截图是自己的操作截图,有问题和我自己修改的部分用蓝色标注。
内容如有不妥之处联系我修改/删除。

目录

1. 搭建环境

2. 多机环境搭建

2.1 准备配置文件

2.2 生成相关配置文件

2.3 修改节点配置文件

2.3.1 base/docker-compose-base.yaml

2.3.2 docker-compose-cli.yaml

2.3.3 docker-compose-couch.yaml

4. 创建通道

4.1 创建通道

 4.2 加入通道

4.3 更新锚节点

5. 链码的安装测试

5.1 安装链码

 5.2 实例化链码

5.3 调用链码

几个很有用的命令:


1. 搭建环境

本文使用的是Fabric 1.4版本,搭建solo模式的4+1的架构:1Order,4Peer,数据库使用CouchDb,所以这里需要五台机器。同时,五台机器的网络需要互通,这里使用的是五台虚拟机。系统使用Ubuntu18.04。并保证五台机子上的Fabric网络可以正常运行。

域名

ip

orderer.example.com 172.18.4.49
peer0.org1.example.com 172.18.4.33
peer1.org1.example.com 172.18.4.34
peer0.org2.example.com 172.18.4.35
peer1.org2.example.com 172.18.4.36

Fabric 的环境搭建过程不再详解

2. 多机环境搭建

这里本文只在Orderer节点的机子上修改配置文件,最后通过scp命令将配置文件复制到其余四台机子,保证所有的节点所使用的配置文件都是相同的。
在官方的例子中,已经有很多模板可以拿来进行修改,这里本文使用 first-network 这个文件夹内的配置文件来修改为自己所需要的配置文件。

2.1 准备配置文件

#step1 进入到first-network文件夹的上一级目录
cd ~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/
#step2 拷贝first-network文件夹,并命名为first
cp -r first-network/ first
#step3 进入到first文件夹内
cd first
#step4 删除此次多机环境搭建使用不到的文件,文件夹内剩余的文件有
.
├── base
│   ├── docker-compose-base.yaml
│   └── peer-base.yaml
├── channel-artifacts
├── configtx.yaml
├── crypto-config.yaml
├── docker-compose-cli.yaml
├── docker-compose-couch.yaml

本文就对以上文件进行修改搭建自己的Fabric多机网络
由于官方的 first-network 中的配置文件中使用的就是4+1的架构,所以我们可以直接生成所需要的证书文件,创世区块,通道配置文件。

2.2 生成相关配置文件

#step1 生成证书文件
cryptogen generate --config=./crypto-config.yaml
#step2 生成创世区块  首先要确保channel-artifacts文件夹存在,如果不存在需要手动创建,不然会报错
configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
#step3 生成通道配置文件  其中通道名mychannel可以修改为自己的
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
#step4 生成锚节点配置文件
#========Org1=============
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
##========Org2=============
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP

所有需要的配置文件全部建立完成,在 channel-artifacts 中应该有以下几个文件。

2.3 修改节点配置文件

2.3.1 base/docker-compose-base.yaml

这个文件中配置了所有节点的一些基本信息,我们需要修改的地方有(我的文件与教程中如下内容不太一样,我在此未做修改

peer0.org1.example.com:
    container_name: peer0.org1.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:8051  #这里更改为7051,因为我们是多机环境,不存在端口冲突问题
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org1.example.com:/var/hyperledger/production
    ports:
      - 7051:7051

  peer1.org1.example.com:
    container_name: peer1.org1.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer1.org1.example.com
      - CORE_PEER_ADDRESS=peer1.org1.example.com:8051   #  7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051    #7051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:8052  #7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052   #7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:8051  #7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
        - peer1.org1.example.com:/var/hyperledger/production

    ports:
      - 8051:8051   #这里不要忘记修改为   7051:7051
...
#只需要修改当前主机上需要启动的节点的端口就可以,比如当前主机节点为peer0.org1.example.com,那么只需要修改peer0.org1...的端口信息

2.3.2 docker-compose-cli.yaml

本文需要使用该文件启动节点,我们将该文件复制一份,以orderer节点为例

#复制该文件,并命名为docker-compose-orderer.yaml
cp docker-compose-cli.yaml docker-compose-orderer.yaml
#用编辑器打开该文件
sudo vim docker-compose-orderer.yaml

我们只在这台电脑上启动orderer节点,所以关于peer节点的信息用不到,我们将配置文件中多余的字段删除,只留下这些内容:

version: '2'

volumes:
  orderer.example.com:

networks:
  byfn:

services:

  orderer.example.com:
    extends:
      file
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值