安装过程参照Hyperledger Fabric的官方文档,文档地址:
0x00 环境介绍,升级系统软件
搭建了一个vm,操作系统版本:
[root@fd240 ~]# cat /proc/version
Linux version 4.11.5-200.fc25.x86_64 (mockbuild@bkernel02.phx2.fedoraproject.org) (gcc version 6.3.1 20161221 (Red Hat 6.3.1-1) (GCC) ) #1 SMP Wed Jun 14 17:17:29 UTC 2017搭建完毕,配置好网络后,升级系统软件:
[root@fd240 ~]# dnf update
0x01 安装依赖项
安装docker
此步骤参照官方文档:
基本步骤如下:
添加docker的源:
$ sudo dnf config-manager \ --add-repo \ https://download.docker.com/linux/fedora/docker-ce.repo
更新dnf的包的索引:
sudo dnf makecache fast
安装:
sudo dnf install docker-ce
至少需要 Docker v1.12 以上版本。安装完之后检查版本号:
[root@fd240 ~]# docker -v
Docker version 17.03.1-ce, build c6d412e然后安装docker-compose:
使用curl方式安装,安装过程中会出错,安装过程及解决办法参考我的。
安装完毕后查看版本号:
[root@fd240 ~]# docker-compose version
docker-compose version 1.14.0-rc2, build 24dae73docker-py version: 2.3.0CPython version: 2.7.13OpenSSL version: OpenSSL 1.0.1t 3 May 2016安装go:
go的下载需要FQ,我安装的是这个版本:
下载完毕后,解压缩:
tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz
解压缩完毕后,配置环境变量:
[root@fd240 ~]# vim /etc/profile
增加下列配置:
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/goexport PATH=$PATH:$GOPATH/bin保存退出后,使之生效:
source /etc/profile
安装node.js,目前只支持 6.9.x版本的node.js, 但是7.x不支持。
我安装的是这个版本:
从上面的官方下载地址下载巨慢,我依然选择了正确的上网姿势。
下载完毕后,解压缩:
tar -xJvf node-v6.11.0-linux-x64.tar.xz
我是放到$HOME 下的,因为我使用的是root用户,所以是在/root目录下。这不是个好习惯,所以操作的时候你一定要谨慎,因为正如Fedora所说”权力越大,责任就越大“。
cd node-v6.11.0-linux-x64/
然后创建软连接:
ln -s /root/node-v6.11.0-linux-x64/bin/node /usr/local/bin/node
ln -s /root/node-v6.11.0-linux-x64/bin/npm /usr/local/bin/npm然后更新npm:
npm install npm@latest -g
查看已安装的node的版本:
[root@fd240 ~]# node -v
v6.11.00x02 安装Hyperledger Fabric
按照"搭建第一个网络"里的介绍来测试:
下面的这些步骤都需要你用正确的姿势上网, 我目前的搭配是: 安装ss的客户端,然后使用proxychains来代理shell, 安装proxychains的方法:
安装并设置完毕后, 运行:
proxychains4 bash
之后,你的本次shell会话中所有的连接都走了代理了.
好的,接下来继续:
迁出示例代码:
git clone https://github.com/hyperledger/fabric-samples.git
然后进入代码目录:
cd fabric-samples
然后下来安装二进制文件;
curl -sSL https://goo.gl/PabWJX | bash
这个时间是看你和你的服务器之间的速度了, 等待结束即可,一定得确保你是用正确的姿势上网的,不然这两步你都没办法成功.
我下载的已经是rc1版本的包了,前几天同时的还是alpha和beta,并且官方文档也在同步更改.
我本地库里下载好的镜像:
[root@fd240 ~]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEhyperledger/fabric-tools latest 85d6d3ca0a30 2 days ago 1.32 GBhyperledger/fabric-tools x86_64-1.0.0-rc1 85d6d3ca0a30 2 days ago 1.32 GBhyperledger/fabric-kafka latest dbb5796d915f 2 days ago 1.3 GBhyperledger/fabric-kafka x86_64-1.0.0-rc1 dbb5796d915f 2 days ago 1.3 GBhyperledger/fabric-zookeeper latest d2efbb01a999 2 days ago 1.31 GBhyperledger/fabric-zookeeper x86_64-1.0.0-rc1 d2efbb01a999 2 days ago 1.31 GBhyperledger/fabric-orderer latest 5ec6333eae10 2 days ago 179 MBhyperledger/fabric-orderer x86_64-1.0.0-rc1 5ec6333eae10 2 days ago 179 MBhyperledger/fabric-peer latest cf6bedc2935e 2 days ago 182 MBhyperledger/fabric-peer x86_64-1.0.0-rc1 cf6bedc2935e 2 days ago 182 MBhyperledger/fabric-javaenv latest 7cbe6aca3956 2 days ago 1.42 GBhyperledger/fabric-javaenv x86_64-1.0.0-rc1 7cbe6aca3956 2 days ago 1.42 GBhyperledger/fabric-ca latest cea779a46670 2 days ago 238 MBhyperledger/fabric-ca x86_64-1.0.0-rc1 cea779a46670 2 days ago 238 MBhyperledger/fabric-ccenv latest 13ed472038d2 2 days ago 1.29 GBhyperledger/fabric-ccenv x86_64-1.0.0-rc1 13ed472038d2 2 days ago 1.29 GB
0x03 测试
先进入first-network目录:
cd first-network
看一下脚本使用说明:
./byfn.sh -h
如果您选择不提供频道名称,则脚本将使用默认的mychannel名称。 CLI超时参数(用-t标志指定)是可选值; 如果您选择不设置它,则CLI脚本结束后将退出CLI容器。
创建:
./byfn.sh -m generate
启动:
./byfn.sh -m up
默认是60秒后退出. 使用-t 参数可以指定时间,例如:
./byfn.sh -m up -t 864000
我这里在执行上面两条命令的时候都出现了一些警告信息.但是最终还是成功执行完毕了:
========= All GOOD, BYFN execution completed =========== _____ _ _ ____ | ____| | \ | | | _ \ | _| | \| | | | | | | |___ | |\ | | |_| | |_____| |_| \_| |____/
如果你想停止网络的话, 运行下面的命令即可,当然现在我们不停止,继续测试:
./byfn.sh -m down
[root@fd240 first-network]# ./byfn.sh -m downStopping with channel 'mychannel' and CLI timeout of '10000'Continue (y/n)? yproceeding ...WARNING: The CHANNEL_NAME variable is not set. Defaulting to a blank string.WARNING: The TIMEOUT variable is not set. Defaulting to a blank string.Stopping peer0.org1.example.com ... doneStopping peer1.org1.example.com ... doneStopping peer0.org2.example.com ... doneStopping orderer.example.com ... doneStopping peer1.org2.example.com ... doneRemoving cli ... doneRemoving peer0.org1.example.com ... doneRemoving peer1.org1.example.com ... doneRemoving peer0.org2.example.com ... doneRemoving orderer.example.com ... doneRemoving peer1.org2.example.com ... doneRemoving network net_byfn1529eb06e34ab3a370df312e273c5a467ebeUntagged: dev-peer1.org2.example.com-mycc-1.0:latestDeleted: sha256:8956d45d168352dea31d87f04edc1d9f34bc3ca0eb252b84cb44a607cf467e13Deleted: sha256:a300ff593826845fc3f37020f7d58e7d437d7f73c6c4b65ea8c69917466b10c2Deleted: sha256:e2dd4be84d6e44020ae7b5bdd39b79d79c27e0a9968accbaf836ad1343af84e9Deleted: sha256:0e0313aa04f0bb0f36ad20dcc0ef7a551c3c367c33a494c5e612166887a7c034Deleted: sha256:2bf6cb6e8ac1fb3ba3e57ba0c68c501a5ad33fed5e8c12499f30d5663d190062Deleted: sha256:418485d6bf1587104a8da149f0aca34c39d2f918bbe46ebb99faff5c6e3fcb51Deleted: sha256:888f5aa1c8a2ac0c77f603d4615596d029283cb7bde123eb091453c75fabd861Untagged: dev-peer0.org1.example.com-mycc-1.0:latestDeleted: sha256:b58a292485c9c5b4da68f386f16e68293acd359291de6b91366d91723ffb4539Deleted: sha256:559e3d2ed00a62d04391098816f7e64fae22d570387e7803ce219e4dcf9740d8Deleted: sha256:d4ef0076f7bd41a531adf905797ddf9adcef1293d08a70dbb5390b6fbdb9af8fDeleted: sha256:353bc73b0c1820dad8a843dc45adcdac91fcfc60fb7b4b5a9285c135304ee000Deleted: sha256:c3a93a92e095820188f28ec7c3da9321395440575a0ebddc6bb132611e67563fDeleted: sha256:e5adc4ad9fb7421406a1569d289c2d28719fa0e701c0b11be2bc700c5055eb36Deleted: sha256:c67868aa025bfa7d183c5a1ba247d69be1a27cda71965deb37dc1c457167d09dUntagged: dev-peer0.org2.example.com-mycc-1.0:latestDeleted: sha256:7b936afdf0318126c3717970e8de7a16f015357b1c7049a68e85e38fa4bae233Deleted: sha256:699ed77d140a2ea756a3640deac9ffd974ffc6171255426c0733d8a69859e4d7Deleted: sha256:abcee9f3c60732acfc3c7d4726880869c5b9baea4ac208a6c47c2103cbe6cf2eDeleted: sha256:26729e91b6f4a9ab8178eb214faeec74cd06105c8e908125fbf2f111b8c8e0caDeleted: sha256:de987082ebc0969410072f3bf55bb1ca7f094b0e47540b23e905b483a8119e64Deleted: sha256:9cfd630b066875bb3c9677fd67a905dfee4b4a8269b3d06cdc372da270569383Deleted: sha256:d41355d4700c66467e926e121197428ae9150ca11369ca18caaa4b6b58cfcd89
进入节点的cli:
[root@fd240 first-network]# docker exec -it cli bash
root@33e3432d74b8:/opt/gopath/src/github.com/hyperledger/fabric/peer#设置环境变量:
export CHANNEL_NAME=mychannel
byfn.sh中往这个 mychannel里初始化了两个变量,a和b, 默认值是90. 就类似执行了下列命令:
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
下面我们执行一些操作:
查询:
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
应该返回90
减10:
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
应该返回200 OK
再查询:
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
应该返回80
升级1.0.0之后遇到的问题:
在执行
./byfn.sh -m up
时,遇到一个错误提示:
[root@fedora26test first-network]# ./byfn.sh -m upStarting with channel 'mychannel' and CLI timeout of '10000'Continue (y/n)? yproceeding ...Starting peer1.org2.example.com ... Starting peer1.org1.example.com ... Starting peer1.org2.example.comStarting peer0.org2.example.com ... Starting peer1.org1.example.comStarting peer0.org2.example.comStarting peer0.org1.example.com ... Starting orderer.example.com ... Starting peer0.org1.example.comStarting peer1.org2.example.com ... doneStarting cli ... Starting cli ... done/bin/bash: ./scripts/script.sh: Permission denied
我尝试把所有文件及子文件夹的权限都改为777,重新尝试执行脚本依然报这个错误。于是就怀疑是否是SELinux的问题,打开Fedora的SELinux的错误报告程序,果然发现了,关掉SELinux,重启机器,OK。