Relative to the v0.6 version, the 1.0 version of the change is large, not much to say here, just 1.0 environment to build their own share of white process for everyone. I hope we can help!
This one may be set up to write some of the rough in front of the environment, if in doubt, read the previous version V0.6 environment to build detailed steps.
A. Environmental preparation
Cloud server (CentOS7.2)
Go locale
docker installation
docker-compose Installation
II. Environment to build
Yum update
We guarantee packages are installed the latest version; upgrade all packages as well as software upgrades and system kernel
yum -y update
Installation Go locale
Go Chinese network: https://studygolang.com/dl
choose Linux systems 'go1.13.5.linux-amd64.tar.gz' download, use Xftp uploaded to the /usr/local
directory
and use the following command to decompress:
tar -zxvf go1.13.5.linux-amd64.tar.gz
Configuration environment variable vim /etc/profile
, add the following at the beginning of the file:
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
Reload the configuration file: source /etc/profile
Use go env
command to verify
Installation Docker
2.3.1 mounted reliance required docker
yum install -y yum-utils device-mapper-persistent-data lvm2
View docker version and install 2.3.2
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-18.03.1.ce
2.3.3 start docker, set up the boot and verify that the installation was successful
systemctl start docker
docker version
Installation docker-compose
2.4.1 install python-pip and upgrade, check the version
yum install -y python-pip
pip install --upgrade pip
pip --version
Download docker-compose
curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
Enter the /usr/local/bin
directory, permission to modify files downloaded
chmod +x docker-compose
Three .fabric source and image download
Download fabric Source
If you do not install git it, git to download
yum install git
Create a fabric source directory in the workspace Go in, go to the directory created for download (this step a long time, and if that fails you can try again, or you can replace the source)
mkdir -p /root/go/src/github.com/hyperledger/
cd /root/go/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric.git
进入下载的fabric
目录,然后查看我们所在的分支,再切换到v1.0.0分支
cd /usr/local/go/src/github.com/hyperledger/fabric/
git branch
git checkout v1.0.0
删除0.6版本的容器以及镜像
如果你从来没启动过其他版本的fabric网络的话,可忽略此步骤
查看所有容器并删除(需要保证你的docker是启动状态)
docker ps -a
docker rm -f $(docker ps -aq)
查看所有镜像并删除(需要保证你的docker是启动状态)
docker images -a
docker rmi -f $(docker images -aq)
下载fabric1.0.0镜像
回到我们上上一步,此时我们已经使用git checkout v1.0.0
切换到了v1.0.0分支,进入以下目录,执行官方提供的批量下载镜像的脚本即可
cd /root/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
等待下载完成后执行docker images
命令查看下载的镜像,如下图:
四.启动与测试
启动fabric网络
使用官方提供的自动化脚本进行启动和关闭,接下来我们启动官方提供的测试用例example02(注意:此时我们还在/root/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
目录下)
./network_setup.sh up
如果无报错,出现以下页面,则启动成功;如果有报错,则在最后,有笔者在搭建时遇到的错误,可进行参考。
测试
查询a的余额(-C:指定通道;-n:指定链码名称)
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
调用链码,a给b转账50元(-o:指定背书节点; tls=true:开启加密通信;cafile:指定证书文件的路径)
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","50"]}'
再一次查询a的余额
错误
这一部分只是记录笔者自己在搭建过程中遇到的错误,如有其他错误,请自行百度。
错误1:
解决方案:修改/etc/resolv.conf
文件,将options
开头的一行注释掉,修改后的文件如下图:
错误2:
解决方案:修改/root/go/src/github.com/hyperledger/fabric/examples/e2e_cli/base/
目录下的peer-bash.yaml
文件,修改名称为e2e_cli_default
,修改完如下图:
最后呢,说明一下,作者也是刚入坑的小白,这篇文章也就是记录一下原始搭建的过程,方便以后查看。如果对你有帮助的话,非常荣幸,如果有不对的地方,欢迎留言指正!