安装虚拟机和Ubuntu
参考以往博客
安装预备工具(以/opt目录为例)
安装vim:
sudo apt-get install vim
安装git:
sudo apt-get install git
安装CURL:
sudo apt-get install curl
安装wget:
sudo apt-get install wget
安装docker:
sudo apt-get -y install docker
安装docker-compose:
sudo apt-get -y install docker-compose
检查docker和docker-compose是否安装成功:
$ docker --version $ docker-compose --version
安装Go:
wget https://studygolang.com/dl/golang/go1.11.linux-amd64.tar.gztar xzvf go1.11.linux-amd64.tar.gz -C /usr/local
配置环境变量:
新建goenvset.sh文件添加如下内容:cat >> /etc/profile << EOFexport GOROOT=/usr/local/goexport GOARCH=amd64export GOOS=linuxexport GOPATH=/home/ubuntu/gopathexport GOBIN=$GOPATH/binexport PATH=$GOPATH/bin:$GOROOT/bin:$PATHEOF
执行操作:
# 执行已有的goenvset.sh向/etc/profile中写入相应的环境变量sudo chmod 705 goenvset.sh# 更改goenvset.sh的权限使其可执行sudo ./goenvset.sh# 执行goenvset.sh脚本# 使环境变量生效source /etc/profile
安装Fabric
1、将fabric-samples下载到$GOPATH/src/github.com/hyperledger
目录中
mkdir -p $GOPATH/src/github.com/hyperledgercd $GOPATH/src/github.com/hyperledger# 克隆fabric-samples项目并切换到v1.4taggit clone https://github.com/hyperledger/fabric-samples.gitcd fabric-samplesgit checkout -b sample v1.4.0
2.安装Fabric、Fabric-ca以及第三方Docker镜像
cd $GOPATH/src/github.com/hyperledger/fabric-samples/scripts# 安装Fabric、Fabric-ca以及第三方Docker镜像(./bootstrap.sh )./bootstrap.sh 1.4.0 1.4.0 0.4.14#若上个命令失败则手动安装#将指定版本的Hyperledger Fabric特定于平台的二进制文件和配置文件安装到fabric-samples的bin和config目录中wget https://github.com/hyperledger/fabric/releases/download/v1.4.0/hyperledger-fabric-linux-amd64-1.4.0.tar.gzwget https://github.com/hyperledger/fabric-ca/releases/download/v1.4.0/hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gztar xzvf hyperledger-fabric-linux-amd64-1.4.0.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/tar xzvf hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/#向/etc/profile中写入环境变量sudo echo 'export PATH=$GOPATH/src/github.com/hyperledger/fabric-samples/bin:$PATH' >> /etc/profile#使环境变量生效source /etc/profile
下载Docker镜像:
# 下载Fabric相关镜像(fabric-peer、fabric-orderer、fabric-ccenv、fabric-tools),此处以fabric-peer镜像为例,其他镜像同理docker pull hyperledger/fabric-peer:1.4.0docker tag hyperledger/fabric-peer:1.4.0 hyperledger/fabric-peer:latestdocker pull hyperledger/fabric-orderer:1.4.0docker tag hyperledger/fabric-orderer:1.4.0 hyperledger/fabric-orderer:latestdocker pull hyperledger/fabric-ccenv:1.4.0docker tag hyperledger/fabric-ccenv:1.4.0 hyperledger/fabric-ccenv:latestdocker pull hyperledger/fabric-tools:1.4.0docker tag hyperledger/fabric-tools:1.4.0 hyperledger/fabric-tools:latest# 下载Fabric第三方镜像(fabric-couchdb、fabric-kafka、fabric-zookeeper),此处以fabric-couchdb为例,其他镜像同理docker pull hyperledger/fabric-couchdb:0.4.14docker tag hyperledger/fabric-couchdb:0.4.14 hyperledger/fabric-couchdb:latestdocker pull hyperledger/fabric-kafka:0.4.14docker tag hyperledger/fabric-kafka:0.4.14 hyperledger/fabric-kafka:latestdocker pull hyperledger/fabric-zookeeper:0.4.14docker tag hyperledger/fabric-zookeeper:0.4.14 hyperledger/fabric-zookeeper:latest# 下载Fabric CA镜像docker pull hyperledger/fabric-ca:1.4.0docker tag hyperledger/fabric-ca:1.4.0 hyperledger/fabric-ca:latest
3.通过运行Build your first network
样例来进行测试
cd $GOPATH/src/github.com/hyperledger/fabric-samples/first-network# 编译通过Golang开发的chaincode并启动相关的容器./byfn.sh up报错解决:Error: error getting endorser client for channel: endorser client failed to connect to peer0.org1.example.com:7051: failed to create new connection: context deadline exceeded !!!!!!!!!!!!!!! After 10 attempts, peer0.org1 has failed to join channel 'mychanel'解决:https://blog.csdn.net/djklsajdklsajdlk/article/details/125588854./byfn.sh up -l node#以kafka启动./byfn.sh up -o kafka#停止first-network网络中所有的容器,删除crypto材料和4个artifacts(genesis.block、mychannel.block、Org1MSPanchor.tx、Org2MSPanchor.tx)以及chaincode镜像./byfn.sh down
这样就把官方fabric1.4的版本搞到了本地,我们可以在此基础上修改和使用。
参考:老师的fabric视频and
https://yongshengcao.blog.csdn.net/article/details/124291080