Hyperledger Fabric 环境搭建及Fabric 测试网络使用(区块链、联盟链)

一篇博文体验Hyperledger Fabric区块链

系统环境(CentOS):

[root@localhost ~]# cat /proc/version
Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020

官网手册:

https://www.hyperledger.org/use/fabric

环境搭建(纯命令精简汇总版)

# 1 基础软件安装
# 1.1 git安装
[root@localhost ~]# yum install git
# 1.2 curl安装
[root@localhost ~]# yum install curl
# 1.3 docker安装
[root@localhost ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io
# 1.4 docker-compose安装
[root@localhost ~]# systemctl stop firewalld 
[root@localhost ~]# sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
[root@localhost ~]# sudo chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# sudo systemctl start docker
[root@localhost ~]# sudo systemctl enable docker
# 1.5 go安装
[root@localhost ~]# yum install epel-release
[root@localhost ~]# yum install go
[root@localhost test-network]# go env -w GOPROXY=https://goproxy.io,direct
[root@localhost test-network]# go env -w GO111MODULE=on
# 1.6 jq安装
[root@localhost ~]# yum install jq

# 2 安装 Fabric 和 Fabric 示例
# 2.1 创建工作目录
[root@localhost ~]# mkdir -p mkdir -p $HOME/go/src/github.com/fabric
[root@localhost ~]# cd $HOME/go/src/github.com/fabric
# 2.1 下载 Fabri
[root@localhost fabric]#  git clone https://hub.fastgit.org/hyperledger/fabric.git
# 2.2 下载Docker镜像
[root@localhost fabric]# cd fabric/scripts/
[root@localhost scripts]# sudo ./bootstrap.sh -b -s
# 2.3 下载Fabric 示例
[root@localhost scripts]# git clone https://hub.fastgit.org/hyperledger/fabric-samples.git
# 2.3 下载二进制文件
[root@localhost scripts]# cd /opt
[root@localhost opt]# yum install wget
[root@localhost opt]# wget https://github.91chifun.workers.dev//https://github.com/hyperledger/fabric/releases/download/v2.3.2/hyperledger-fabric-linux-amd64-2.3.2.tar.gz
[root@localhost opt]# wget https://github.91chifun.workers.dev//https://github.com/hyperledger/fabric-ca/releases/download/v1.5.0/hyperledger-fabric-ca-linux-amd64-1.5.0.tar.gz
[root@localhost opt]# tar -zxvf hyperledger-fabric-linux-amd64-2.3.2.tar.gz  -C $HOME/go/src/github.com/fabric/fabric/scripts/fabric-samples/
[root@localhost opt]# tar -zxvf hyperledger-fabric-ca-linux-amd64-1.5.0.tar.gz -C $HOME/go/src/github.com/fabric/fabric/scripts/fabric-samples/

# 3 运行测试网络
# 3.1 进入test-network目录
[root@localhost test-network]# cd $HOME/go/src/github.com/fabric/fabric/scripts/fabric-samples/test-network
# 3.2 重启下Docker容器
[root@localhost test-network]# systemctl restart  docker
# 3.3 删除先前可能运行的网络
[root@localhost test-network]# ./network.sh down
# 3.4 启动测试网络
[root@localhost test-network]# ./network.sh up

# 4 体验测试网络
# 4.1 创建频道
[root@localhost test-network]# ./network.sh createChannel
启用链码
[root@localhost test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

# 4.2 添加环境变量(test-network)目录下执行
[root@localhost test-network]# 
export PATH=${
   
   PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
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/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${
   
   PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${
   
   PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051

# 4.3 初始化账本资产
[root@localhost test-network]# 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":[]}'
#4.4 查看所有账本资产
[root@localhost test-network]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

A&long@2020

多一份打赏,多一份共享。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值