Fabric 环境搭建和重装

发布于 2021-04-06 17:52:48 字数 4236 浏览 1431 评论 0

Fabric 自带的 VM 空间太小,改用 box bento/ubuntu-16.4 重建。

$ cd /e/vagrant9/ambari-vagrant
$ git clone https://github.com/hyperledger/fabric.git
$ cd fabric/devenv

值修改Vagrantfile使用空间为40G的新box:

#  config.vm.box = "ubuntu/xenial64"
  config.vm.box = "bento/ubuntu-16.04"

新 box 的默认用户不再是 ubuntu,而是 vagrant。导致devenv/setup.sh需要改,将脚本中ubuntu用户改成vagrant。这个文件在VM中映射为了/hyperledger/devenv/setup.sh

由于 GWF 的存在,golang 官方被封,需要翻墙。而且翻墙后一些CURL管道不管用。解决办法在这里

包括下面的这个命令也需要设置http_proxy:

cd $GOPATH/src/github.com/hyperledger/fabric
make clean gotools

安装 fabric-samples 库

$ cd /opt
$ git clone -b master https://github.com/hyperledger/fabric-samples.git
$ cd fabric-samples
$ curl -sSL https://goo.gl/6wtTN5 | bash 
($ curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0-preview)

为了加快安装速度,可以用docker save/load命令从其他环境中导出fabric的相关docker镜像:

docker save hyperledger/fabric-javaenv:x86_64-1.0.4 > /vagrant/fabric-javaenv-1.0.4
docker load < /vagrant/fabric-javaenv-1.0.4

安装 composer

使用用户vagrant,需要翻墙和设置 http_proxy。

curl -O https://hyperledger.github.io/composer/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh
./prereqs-ubuntu.sh

安装 composer-cli 等二进制包。由于需要在/usr/local/bin下建composer的符号链接,导致报告没有权限,解决办法:

$ npm install --unsafe-perm --verbose -g composer-cli

安装composer-rest-server需要sudo权限,加上--unsafe-perm也不行,yo也是这样。

安装fabric-tools,即composer自带的fabric环境,特点是带CA和couchdb镜像。
执行./downloadFabric.sh./startFabric.sh时发现需要sudo权限。解决办法是把当前用户vagrant加入到docker组:

sudo gpasswd -a ${USER} docker
sudo service docker restart

第二天 composer 出错

$ composer network ping --card admin@food-supply
Error: Failed to load connector module "composer-connector-hlfv1" for connection type "hlfv1". Cannot find module '/usr/local/lib/node_modules/composer-cli/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'

解决办法[1]:

cd /usr/local/lib/node_modules/composer-cli
npm rebuild --unsafe-perm

问题解决。

完整启动过程

1.启动 Fabric(fabric-tools)

cd ~/fabric-tools
./startFabric.sh

2.启动业务网络

cd ~/BlockchainPublicRegulationFabric-Food
composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName food-supply
composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile dist/food-supply.bna
composer network ping --card admin@food-supply

3.启动 composer-playground

composer-playground

然后用浏览器访问localhost:8080。然后连接到food-supply业务网络。

4.启动 composer-rest-server

composer-rest-server

业务网络卡片输入admin@food-supply,不用命名空间,不启用认证,启用事件广播,不用TLS。
用浏览器访问localhost:3000可以进入它自带的Swagger-UI。

5.启动 blockchain-explorer

cd ~/blockchain-explorer
./start.sh

用浏览器进入http://localhost:8081/就可以看到blockchain-explorer的界面。

如果fabric-tools被重新启动,需要执行第2步“启动业务网络”后,blockchain-explorer才能重新显示账本内容。

用 pyresttest 进行功能或基准测试

cd ~/pyresttest
pyresttest http://localhost:3000 test.yaml

peer 命令查看一些信息

这个fabric环境未启用TLS。设置环境变量:

export CORE_PEER_MSPCONFIGPATH=/home/vagrant/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
export CORE_PEER_LOCALMSPID="Org1MSP"

执行 peer 命令:

$ peer channel list
...
INFO 003 composerchannel
$ peer channel fetch newest 1.block -o localhost:7050 -c composerchannel

后一个命令获取通道 composerchannel 的最新区块保存到 1.block 文件中。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

JSmiles

生命进入颠沛而奔忙的本质状态,并将以不断告别和相遇的陈旧方式继续下去。

0 文章
0 评论
84959 人气
更多

推荐作者

qq_FjTq5B

文章 0 评论 0

18273202778

文章 0 评论 0

WordPress小学生

文章 0 评论 0

〃温暖了心ぐ

文章 0 评论 0

迷乱花海

文章 0 评论 0

niuniu

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文