Fabric多机部署

准备工作

  1. 本次只准备了两台电脑,一个orderer一个peer,修改两台电脑的hosts,194为orderer,109为peer

    192.168.2.194 orderer.flt.cn
    192.168.2.109 peer0.dev.flt.cn
    
    
  2. 新建一个文件夹a_test,用来存放生成的文件(之后用的)

  3. 将bin文件夹和configtx.yamlcrypto-config.yaml拷进来,并新建crypto-config文件夹存放生成的文件

  4. 生成证书等文件:

./bin/cryptogen generate --config=./crypto-config.yaml --output ./crypto-config

crypto-config下出现ordererOrganizationspeerOrganizations文件夹

  1. 生成创世块gensisblock

    ./bin/configtxgen -configPath=./ -profile SampleInsecureSolo -channelID gm-orderer-syschannel -outputBlock ./genesisblock
    
  2. 生成通道配置文件gmchannel.tx

    ./bin/configtxgen -configPath=./ -profile SampleSingleMSPChannel -outputCreateChannelTx gmchannel.tx -channelID gmchannel```
    
  3. 生成锚节点配置文件DevMSPanchors.tx

    ./bin/configtxgen -configPath=./ -profile SampleSingleMSPChannel -outputAnchorPeersUpdate DevMSPanchors.tx -channelID gmchannel -asOrg DevMSP```
    
  4. 最终a_test目录如下:

    bin configtx.yaml crypto-config.yaml crypto-config genesisblock gmchannel.tx

    DevMSPanchors.tx

配置orderer

  1. 新建一个orderer文件夹,我的建在/opt/orderer,之后的操作都在这个目录下

  2. a_test/crypto-config/ordererOrganizations/flt.cn/orderers/orderer.flt.cn目录下的msp文件夹和tls文件夹拷贝进来,将a_test下的创世块genesisblocka_test/bin下的orderer二进制文件拷贝进来

  3. orderer.yaml拷进来,其中几个路径需要修改
    在这里插入图片描述
    这是之后生成的数据路径


在这里插入图片描述
tls证书文件路径,指定orderer目录下的tls


在这里插入图片描述

创世块,MSP,都指定为orderer目录下的,当前为orderer节点,MSPIDOrdererMSP


  1. 然后就可以启动orderer./orderer

配置 peer0.dev.flt.cn

  1. 在另一台机器上新建peer目录:opt/peer

  2. a_test/crypto-config/peerOrganizations/dev.flt.cn/peers/peer0.dev.flt.cn下的msptls,以及bin目录下的peer二进制文件拷贝进来

  3. core.yaml拷进来,依然是注意文件路径:
    在这里插入图片描述


在这里插入图片描述


在这里插入图片描述

  1. id要对应:
    在这里插入图片描述

在这里插入图片描述


在这里插入图片描述


在这里插入图片描述

  1. 最后peer目录有:
    在这里插入图片描述

  2. 配置无误,就可启动peer./peer node start

配置client

  1. 我将client放在了peer机器上,路径/opt/Admin@dev.flt.cn

  2. client用的msptls复制过来,在a_test/crypto-config/peerOrganizations/dev.flt.cn/users/Admin@dev.flt.cn

  3. peer二进制文件复制过来,将a_test/crypto-config/ordererOrganizations/flt.cn/tlsca复制过来

  4. 复制过来一个core.yaml,还需要a_test下的DevMSPanchors.tx,gmchannel.tx

  5. 新建一个peer.sh脚本,在里面写一些配置参数:

    #!/bin/bash
    PATH=`pwd`:$PATH
    
    export FABRIC_CFG_PATH=`pwd`
    
    export CORE_PEER_ADDRESS=peer0.dev.flt.cn:7051
    export CORE_PEER_LOCALMSPID=DevMSP
    export CORE_PEER_MSPCONFIGPATH=msp
    
    export CORE_PEER_TLS_ENABLED=true
    export CORE_PEER_TLS_CERT_FILE=tls/client.crt
    export CORE_PEER_TLS_KEY_FILE=tls/client.key
    export CORE_PEER_TLS_ROOTCERT_FILE=tls/ca.crt
    
    export CORE_LOGGING_LEVEL=DEBUG
    
    peer $*
    
  6. 新建一个channel,只需要启动一个orderer节点,执行后会生成gmchannel.block

    ./peer.sh channel create \
    --orderer orderer.flt.cn:7050 \
    --channelID gmchannel \
    --file gmchannel.tx \
    --tls true \
    --cafile tlsca/tlsca.flt.cn-cert.pem
    
  7. 将peer加入到channel中:

    ./peer.sh channel join -b gmchannel.block
    
  8. 设置org的锚节点:

    ./peer.sh channel update \
    --orderer orderer.flt.cn:7050 \
    --channelID gmchannel \
    --file DevMSPanchors.tx \
    --tls true \
    --cafile tlsca/tlsca.flt.cn-cert.pem
    
  9. 安装智能合约(此处安装的是fabric-sample中的例子):

    ./peer.sh chaincode install \
    -n mycc -v 1.0 \
    -p github.com/hyperledger/fabric-samples/chaincode/fabcar/go
    
  10. 初始化合约:

    ./peer.sh chaincode instantiate \
     -o orderer.flt.cn:7050 \
     --tls true \
     --cafile tlsca/tlsca.flt.cn-cert.pem \
     -C gmchannel \
     -n mycc -v 1.0 \
     -c '{"Args":[""]}' -P "OR('DevMSP.member','MarketMSP.member')"
    
  11. 可以执行查询:

    ./peer chaincode invoke \
    -o orderer.flt.cn:7050 \
    --tls true \
    --cafile tlsca/tlsca.flt.cn-cert.pem \
    -C gmchannel \
    -n mycc \
    --peerAddresses peer0.dev.flt.cn:7051 \
    --tlsRootCertFiles tls/ca.crt \
    -c '{"function":"initLedger","Args":[""]}'
    
    
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值