淄博团购网站建设,莱芜户型优化培训班,做7寸照片的网站,好的html5网站模板目录 一、参考文档二、环境依赖三、Fabric源码安装3.1、创建链目录3.2、下载源码3.3、修改安装脚本3.4、开始安装3.4.1、执行安装脚本3.4.2、手动下载ca和二进制配置包 四、启动测试网络五、使用测试网络5.1、创建应用通道5.2、部署链码5.3、发送交易 六、关闭测试网络 一、参考… 目录 一、参考文档二、环境依赖三、Fabric源码安装3.1、创建链目录3.2、下载源码3.3、修改安装脚本3.4、开始安装3.4.1、执行安装脚本3.4.2、手动下载ca和二进制配置包 四、启动测试网络五、使用测试网络5.1、创建应用通道5.2、部署链码5.3、发送交易 六、关闭测试网络 一、参考文档 hyperledger超级账本官方文档地址https://hyperledger-fabric.readthedocs.io/en/release-2.2/ hyperledger中文文档https://hyperledgercn.github.io/hyperledgerDocs/
二、环境依赖
ubuntu 20.04.1go version go1.16.3 linux/amd64git version 2.25.1docker 20.10.17docker-compose 1.29.2
三、Fabric源码安装
3.1、创建链目录
mkdir -p $GOPATH/src/github.com/hyperledger3.2、下载源码
cd $GOPATH/src/github.com/hyperledger
git clone https://gitee.com/hyperledger/fabric.git -b v2.2.03.3、修改安装脚本
vim $GOPATH/src/github.com/hyperledger/fabric/scripts/bootstrap.sh把 https://github.com/hyperledger/fabric-samples.git 修改为 https://gitee.com/hyperledger/fabric-samples.git注释 pullBinaries
3.4、开始安装
3.4.1、执行安装脚本
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/
./bootstrap.sh若报错
Pull Hyperledger Fabric docker imagesFABRIC_IMAGES: peer orderer ccenv tools nodeenv baseos javaenvPulling fabric Imageshyperledger/fabric-peer:2.2.0
Error response from daemon: error parsing HTTP 408 response body: invalid character looking for beginning of value: htmlbodyh1408 Request Time-out/h1\nYour browser didnt send a complete request in time.\n/body/html\n
Error response from daemon: No such image: hyperledger/fabric-peer:2.2.0
Error response from daemon: No such image: hyperledger/fabric-peer:2.2.0hyperledger/fabric-orderer:2.2.0
2.2.0: Pulling from hyperledger/fabric-orderer
error parsing HTTP 408 response body: invalid character looking for beginning of value: htmlbodyh1408 Request Time-out/h1\nYour browser didnt send a complete request in time.\n/body/html\n
Error response from daemon: No such image: hyperledger/fabric-orderer:2.2.0
Error response from daemon: No such image: hyperledger/fabric-orderer:2.2.0hyperledger/fabric-ccenv:2.2.0则尝试调整/etc/docker/daemon.json
{registry-mirrors: [http://hub-mirror.c.163.com,https://registry.docker-cn.com,https://docker.mirrors.ustc.edu.cn]
}sudo systemctl daemon-reload
sudo systemctl restart docker3.4.2、手动下载ca和二进制配置包
下载bootstrap.sh中指定的对应版本ca和二进制配置的包
# VERSION2.2.0
wget https://github.com/hyperledger/fabric/releases/download/v2.2.0/hyperledger-fabric-linux-amd64-2.2.0.tar.gz
# CA_VERSION1.4.7
wget https://github.com/hyperledger/fabric-ca/releases/download/v1.4.7/hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz复制到fabric-samples目录
tar -zxvf hyperledger-fabric-linux-amd64-2.2.0.tar.gz
tar -zxvf hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz
cp -r bin fabric-samples/
cp -r config fabric-samples/四、启动测试网络
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
# cryptogen启动方式
./network.sh up
# ca-server启动方式
# ./network.sh up -ca日志
Starting nodes with CLI timeout of 5 tries and CLI delay of 3 seconds and using database leveldb with crypto from cryptogen
LOCAL_VERSION2.2.0
DOCKER_IMAGE_VERSION2.2.0
/usr/local/software/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/../bin/cryptogen
Generating certificates using cryptogen tool
Creating Org1 Identitiescryptogen generate --config./organizations/cryptogen/crypto-config-org1.yaml --outputorganizations
org1.example.comres0
Creating Org2 Identitiescryptogen generate --config./organizations/cryptogen/crypto-config-org2.yaml --outputorganizations
org2.example.comres0
Creating Orderer Org Identitiescryptogen generate --config./organizations/cryptogen/crypto-config-orderer.yaml --outputorganizationsres0
Generating CCP files for Org1 and Org2
/usr/local/software/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/../bin/configtxgen
Generating Orderer Genesis blockconfigtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2023-11-01 16:23:18.229 CST [common.tools.configtxgen] main - INFO 001 Loading configuration
2023-11-01 16:23:18.244 CST [common.tools.configtxgen.localconfig] completeInitialization - INFO 002 orderer type: etcdraft
2023-11-01 16:23:18.244 CST [common.tools.configtxgen.localconfig] completeInitialization - INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:500ms election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216
2023-11-01 16:23:18.244 CST [common.tools.configtxgen.localconfig] Load - INFO 004 Loaded configuration: /usr/local/software/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/configtx/configtx.yaml
2023-11-01 16:23:18.246 CST [common.tools.configtxgen] doOutputBlock - INFO 005 Generating genesis block
2023-11-01 16:23:18.247 CST [common.tools.configtxgen] doOutputBlock - INFO 006 Writing genesis blockres0
Creating network fabric_test with the default driver
Creating volume docker_orderer.example.com with default driver
Creating volume docker_peer0.org1.example.com with default driver
Creating volume docker_peer0.org2.example.com with default driver
Creating peer0.org1.example.com ... done
Creating orderer.example.com ... done
Creating peer0.org2.example.com ... done
Creating cli ... done
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
677082ab5dc4 hyperledger/fabric-tools:latest /bin/bash 1 second ago Up Less than a second cli
9e567df423f2 hyperledger/fabric-peer:latest peer node start 3 seconds ago Up 1 second 0.0.0.0:9051-9051/tcp, :::9051-9051/tcp, 7051/tcp, 0.0.0.0:19051-19051/tcp, :::19051-19051/tcp peer0.org2.example.com
30248ff4a8c7 hyperledger/fabric-orderer:latest orderer 3 seconds ago Up Less than a second 0.0.0.0:7050-7050/tcp, :::7050-7050/tcp, 0.0.0.0:17050-17050/tcp, :::17050-17050/tcp orderer.example.com
884783874fcc hyperledger/fabric-peer:latest peer node start 3 seconds ago Up 1 second 0.0.0.0:7051-7051/tcp, :::7051-7051/tcp, 0.0.0.0:17051-17051/tcp, :::17051-17051/tcp peer0.org1.example.com看到docker的2个peer节点容器、1个orderer节点容器和客户端tools容器都正常运行测试网络启动成功。
五、使用测试网络
5.1、创建应用通道
使用network.sh脚本在org1和org2之间创建通道并加入他们的对等节点执行以下命令创建一个通道
./network.sh createChannel -c mychannel5.2、部署链码
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-java -ccl java5.3、发送交易
配置环境变量
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-networkexport PATH${PWD}/../bin:$PATH
# 该目录下包含peer节点的core.yaml
export FABRIC_CFG_PATH$PWD/../config/# 客户端连接peer0
export CORE_PEER_TLS_ENABLEDtrue
export CORE_PEER_LOCALMSPIDOrg1MSP
export CORE_PEER_TLS_ROOTCERT_FILE${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH${PWD}/organizations/peerOrganizations/org1.example.com/users/Adminorg1.example.com/msp
export CORE_PEER_ADDRESSlocalhost:7051发交易初始化资产调用链码的初始化方法InitLedger
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c {function:InitLedger,Args:[]}查询初始化后的资产调用链码的GetAllAssets方法
peer chaincode query -C mychannel -n basic -c {Args:[GetAllAssets]}六、关闭测试网络
./network.sh down