实验第五节——channel相关操作

Posted 想学习安全的小白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验第五节——channel相关操作相关的知识,希望对你有一定的参考价值。

一、创建channel操作

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 利用环境变量设置cli的证书,这是使用org1-peer0的身份来创建channel,命令:
export org=1
export peer=0
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 判断是否需要使用tls,输出环境变量CORE_PEER_TLS_ENABLED的值,命令:echo $CORE_PEER_TLS_ENABLED
  2. 若第4步,输出值=true,则创建channel命令:peer channel create -c businesschannel -o orderer0.example.com:7050 -f channel-artifacts/businesschannel.tx --timeout 90s --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/ca.crt
  3. 若第四步,输出值=false,则创建channel命令:peer channel create -c businesschannel -o orderer0.example.com:7050 -f channel-artifacts/businesschannel.tx --timeout 90s
  4. 创建后,会在当前/tmp目录下生成一个businesschannel.block文件,接下来就是用此文件(创世区块文件),将每个peer加入到通道businesschannel中
  5. 创建channel只需在某一个peer上执行一次即可,但join channel则需要在每一个peer上执行join操作

二、将peer加入通道

2.1、将org1-peer0加入channel

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置环境变量,使用org1-peer0身份
export org=1
export peer=0
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 将org1-peer0加入channel,命令:peer channel join -b businesschannel.block

2.2、将org1-peer1加入channel

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置环境变量,使用org1-peer1身份
export org=1
export peer=1
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 将org1-peer1加入channel,命令:peer channel join -b businesschannel.block

2.3、将org2-peer0加入channel

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置环境变量,使用org2-peer0身份
export org=2
export peer=0
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 将org2-peer0加入channel,命令:peer channel join -b businesschannel.block

2.4、将org2-peer1加入channel

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置环境变量,使用org2-peer1身份
export org=2
export peer=1
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 将org2-peer1加入channel,命令:peer channel join -b businesschannel.block

三、查看每个peer加入的channel

3.1、检查org1-peer0加入的channel

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置环境变量,使用org1-peer0身份
export org=1
export peer=0
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 检查org1-peer0加入的channel,命令:peer channel list

3.2、检查org1-peer1加入的channel

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置环境变量,使用org1-peer1身份
export org=1
export peer=1
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 检查org1-peer1加入的channel,命令:peer channel list

3.3、检查org2-peer0键入的channel

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置环境变量,使用org2-peer0身份
export org=2
export peer=0
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 检查org2-peer0加入的channel,命令:peer channel list

3.4、检查org2-peer1加入的channel

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置环境变量,使用org2-peer1身份
export org=2
export peer=1
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 检查org2-peer1加入的channel,命令:peer channel list

四、查看channel的信息

  1. 进入cli容器,命令:docker exec -it fabric-cli /bin/bash
  2. 进入容器的tmp目录,命令:cd /tmp
  3. 设置某一个节点的身份,这里使用org2-peer1的身份
export org=2
export peer=1
export CORE_PEER_LOCALMSPID=Org$orgMSP
export CORE_PEER_ADDRESS=peer$peer.org$org.example.com:7051
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/users/Admin@org$org.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org$org.example.com/peers/peer$peer.org$org.example.com/tls/ca.crt
  1. 执行查询命令:peer channel getinfo -c businesschannel,-c后面的参数为ogr2-peer1加入的channel名

以上是关于实验第五节——channel相关操作的主要内容,如果未能解决你的问题,请参考以下文章

Linux内核第五节 20135332武西垚

CISCO网络基础小实验第五节

第五节课 课堂总结

《Linux内核分析》 第五节 扒开系统调用的三层皮(下)

(计算机组成原理)第五章中央处理器-第五节2:指令流水线影响因素和分类及多发技术

概述-第五节3:计算机网络体系结构之相关专业术语