Hyperledger First-network 分析

 

安装fabric-samples

git clone https://github.com/hyperledger/fabric-samples

cd first-network

byfn,sh -m generate 生成配置文件

byfn.sh -m up 启动网络

输出end 启动过程结束

关闭网路 byfn.sh -m down

cryptogen 工具

生成各种网络实体的加密材料(x509证书)。这些证书是身份的代表,它们允许在我们的网络实体进行交流和交易时进行签名/验证身份验证。

运行时需要一个crypto-config.yaml文件,

每个组织都配置了唯一的根证书(ca-cert),它将特定组件(peers和orders)绑定到该组织。通过为每一个组织分配唯一的CA证书,我们正在模仿一个经典的网络,这个网络中的成员将使用自己的证书颁发机构。

Hyperledger Fabric中的交易和通信是通过存储在keystore中的实体的私钥签名,然后通过公钥手段进行验证(signcerts)。

配置文件示例

cryptogen生成的证书和密钥将被保存到名为crypto-config的文件夹中。

手动生成文件

生成第一个区块

configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block

执行之前需要设置环境变量FABRIC_CFG_PATH configtx.yaml的路径

export FABRIC_CFG_PATH=$PWD

创建channel transaction配置

../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME

创建之前声明CHANNEL_NAME环境变量 指定channel名字

创建两个通道的锚节点

../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP

../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP

配置完毕 !

启动网络

CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=<pick_a_value> docker-compose -f docker-compose-cli.yaml up -d

-d 代表不输出log

通过docker-compose-cli.yaml 启动网络

创建&加入channel

docker exec -it cli bash 打开 cli 终端

使用peer channel create 创建一个channel

参数:

Usage:

peer channel create [flags]

Flags:

-c, --channelID string In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]*

-f, --file string Configuration transaction file generated by a tool such as configtxgen for submitting to orderer

-h, --help help for create

--outputBlock string The path to write the genesis block for the channel. (default ./<channelID>.block)

-t, --timeout duration Channel creation timeout (default 5s)

Global Flags:

--cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint

--certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint

--clientauth Use mutual TLS when communicating with the orderer endpoint

--connTimeout duration Timeout for client to connect (default 3s)

--keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint

--logging-level string Default logging level and overrides, see core.yaml for full syntax

-o, --orderer string Ordering service endpoint

--ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer.

--tls Use TLS when communicating with the orderer endpoint

创建channel 命令

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp

CORE_PEER_ADDRESS=peer0.org1.example.com:7051

CORE_PEER_LOCALMSPID="Org1MSP"

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

export CHANNEL_NAME=mychannel

peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

加入channel

peer channel join -b <channel-ID.block>

更新锚节点节点

peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt

peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

Good Job!

猜你喜欢

转载自blog.csdn.net/biyaun/article/details/82432435
今日推荐