在 Oracle Cloud Infrastructure 上运行 Hyperledger Fabric

首先

在年底阅读了以下内容后,我对区块链产生了兴趣。
比特币和区块链:支撑加密货币的技术
从那时起,我开始在工作中以及身边的云环境中准备 Hyperledger 环境。

OCI环境的设置

请参考以下内容设置OCI环境。
教程:尝试使用Oracle Cloud Infrastructure
免费试用环境已足够。可使用300美元(约合人民币35,000元)或30天。
免费试用 | Oracle Cloud
(注册时需要提供信用卡号和用于本人确认的电话号码(通过短信接收认证码)。
如果不升级账户,不会对信用卡进行任何费用。)

环境设置概述

hl0001.PNG
hl002.PNG

Hyperledger环境的设置

根据以下文件进行设置。
欢迎使用Hyperledger Fabric
前提条件

安装cURL

cURL 已经下载了最新版。

[opc@kokane-hl ~]$ sudo yum install -y curl
(省略)
Package curl-7.29.0-42.el7_4.1.x86_64 already installed and latest version

安装Docker

我将使用下面的参考进行安装,在存储库中进行安装。
获取 CentOS 上的Docker CE。

卸载旧版本

没有什么特别的。

[opc@kokane-hl ~]$ sudo yum remove docker docker-common docker-selinux docker-engine
Loaded plugins: fastestmirror, langpacks
No Match for argument: dockerdocker-commondocker-selinuxdocker-engine
No Packages marked for removal
不需要更新 yum-utils、device-mapper和lvm2。
[opc@kokane-hl ~]$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.us.oneandone.net
 * epel: dl.fedoraproject.org
 * extras: ftp.usf.edu
 * updates: repos-tx.psychz.net
Package yum-utils-1.1.31-42.el7.noarch already installed and latest version
Package device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64 already installed and latest version
Package 7:lvm2-2.02.171-8.el7.x86_64 already installed and latest version
Nothing to do
添加稳定版存储库
[opc@kokane-hl ~]$ sudo yum-config-manager --add-repo https://download.docker.co
m/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
更新 yum 软件包索引

出于礼貌的原因,我还是做一下。

[opc@kokane-hl ~]$ sudo yum makecache fast
Loaded plugins: fastestmirror, langpacks
base                                                     | 3.6 kB     00:00
docker-ce-stable                                         | 2.9 kB     00:00
epel/x86_64/metalink                                     |  16 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
docker-ce-stable/x86_64/primary_db                         |  11 kB   00:00
Loading mirror speeds from cached hostfile
 * base: mirror.us.oneandone.net
 * epel: dl.fedoraproject.org
 * extras: ftp.usf.edu
 * updates: repos-tx.psychz.net
Metadata Cache Created
Docker CE的安装
[opc@kokane-hl ~]$ sudo yum install -y docker-ce
(省略)
Installed:
  docker-ce.x86_64 0:17.12.0.ce-1.el7.centos

Dependency Installed:
  container-selinux.noarch 2:2.33-1.git86f33cd.el7
  libtool-ltdl.x86_64 0:2.4.2-22.el7_3

Complete!
启动Docker CE并运行hello-world进行验证。
[opc@kokane-hl ~]$ sudo systemctl start docker
[opc@kokane-hl ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

将 OPC 用户添加到 Docker 组中。

[opc@kokane-hl ~]$ sudo gpasswd -a opc docker
[opc@kokane-hl ~]$ sudo sytemctl restart docker

安装 Docker Compose

安装Docker Compose

[opc@kokane-hl ~]$ sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0   1297      0 --:--:-- --:--:-- --:--:--  1301
100 8280k  100 8280k    0     0  2729k      0  0:00:03  0:00:03 --:--:-- 3570k
[opc@kokane-hl ~]$ sudo chmod +x /usr/local/bin/docker-compose
[opc@kokane-hl ~]$ docker-compose --version
docker-compose version 1.18.0, build 8dd22a9

安装Go语言

请参考这些指南:参考Go编程语言在Linux、Mac OS X、FreeBSD系统上安装的tarball包。

下载 tarball 文件
[opc@kokane-hl ~]$ cd /tmp
[opc@kokane-hl tmp]$ wget https://dl.google.com/go/go1.9.2.linux-amd64.tar.gz
--2018-01-20 04:01:07--  https://dl.google.com/go/go1.9.2.linux-amd64.tar.gz
(省略)
2018-01-20 04:01:11 (26.4 MB/s) - ‘go1.9.2.linux-amd64.tar.gz’ saved [104247844/104247844]
将 tarball 解压到 /usr/local。
[opc@kokane-hl tmp]$ sudo tar -C /usr/local -xzf go1.9.2.linux-amd64.tar.gz
在这里添加路径

已将其添加至 .bash_profile。

[opc@kokane-hl ~]$ vi $HOME/.bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/go/bin
export PATH
[opc@kokane-hl ~]$ source $HOME/.bash_profile
确认启动
[opc@kokane-hl ~]$ go version
go version go1.9.2 linux/amd64
設置 GOPATH
[opc@kokane-hl ~]$ vi $HOME/.bash_profile
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
[opc@kokane-hl ~]$ source $HOME/.bash_profile
[opc@kokane-hl ~]$ echo $GOPATH
/home/opc/go

省略了node.js环境的安装。

由于似乎无法完成应用程序的开发部分,所以我会省略它。

安装 Git

我希望下載“示例腳本”,所以我要安裝git。
開始使用git 1.5 – 安裝Git。

[opc@kokane-hl ~]$ sudo yum install -y git-all
[opc@kokane-hl ~]$ git --version
git version 1.8.3.1
下载面料样品

超级账本面料示例

[opc@kokane-hl ~]$ mkdir -p $HOME/github.com/hyperledger
[opc@kokane-hl ~]$ cd $HOME/github.com/hyperledger
git clone https://github.com/hyperledger/fabric-samples.git
Cloning into 'fabric-samples'...
remote: Counting objects: 970, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 970 (delta 0), reused 0 (delta 0), pack-reused 968
Receiving objects: 100% (970/970), 337.53 KiB | 0 bytes/s, done.
Resolving deltas: 100% (383/383), done.
下载特定平台的二进制文件

接着上述内容,我们将下载docker镜像等。

[opc@kokane-hl local]$ sudo su
[root@kokane-hl local]$ mkdir -p /usr/local/hyperledger
[root@kokane-hl local]$ cd /usr/local/hyperledger
[root@kokane-hl hyperledger]# curl -sSL https://goo.gl/byy2Qj | bash -s 1.0.5
[root@kokane-hl hyperledger]# exit
[opc@kokane-hl bin]$ vi $HOME/.bash_profile
export PATH=$PATH:/usr/local/hyperledger/bin
[opc@kokane-hl bin]$ source $HOME/.bash_profile

查看Docker镜像时,可以看到一排排的Hyperledger Fabric镜像。

[root@kokane-hl hyperledger]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
hyperledger/fabric-tools       latest              6a8993b718c8        6 weeks ago         1.33GB
hyperledger/fabric-tools       x86_64-1.0.5        6a8993b718c8        6 weeks ago         1.33GB
hyperledger/fabric-couchdb     latest              9a58db2d2723        6 weeks ago         1.5GB
hyperledger/fabric-couchdb     x86_64-1.0.5        9a58db2d2723        6 weeks ago         1.5GB
hyperledger/fabric-kafka       latest              b8c5172bb83c        6 weeks ago         1.29GB
hyperledger/fabric-kafka       x86_64-1.0.5        b8c5172bb83c        6 weeks ago         1.29GB
hyperledger/fabric-zookeeper   latest              68945f4613fc        6 weeks ago         1.32GB
hyperledger/fabric-zookeeper   x86_64-1.0.5        68945f4613fc        6 weeks ago         1.32GB
hyperledger/fabric-orderer     latest              368c78b6f03b        6 weeks ago         151MB
hyperledger/fabric-orderer     x86_64-1.0.5        368c78b6f03b        6 weeks ago         151MB
hyperledger/fabric-peer        latest              c2ab022f0bdb        6 weeks ago         154MB
hyperledger/fabric-peer        x86_64-1.0.5        c2ab022f0bdb        6 weeks ago         154MB
hyperledger/fabric-javaenv     latest              50890cc3f0cd        6 weeks ago         1.41GB
hyperledger/fabric-javaenv     x86_64-1.0.5        50890cc3f0cd        6 weeks ago         1.41GB
hyperledger/fabric-ccenv       latest              33feadb8f7a6        6 weeks ago         1.28GB
hyperledger/fabric-ccenv       x86_64-1.0.5        33feadb8f7a6        6 weeks ago         1.28GB
hyperledger/fabric-ca          latest              002c9089e464        6 weeks ago         238MB
hyperledger/fabric-ca          x86_64-1.0.5        002c9089e464        6 weeks ago         238MB
hello-world                    latest              f2a91732366c        2 months ago        1.85kB

第一个网络

按照教程的步骤,试着操作一下。

建立您的第一个网络

构建你的第一个网络

[opc@kokane-hl ~]$ cd $HOME/github.com/hyperledger/fabric-samples/first-network
[opc@kokane-hl first-network]$ ./byfn.sh -m generate
Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10'
Continue (y/n)? y
proceeding ...
/usr/local/hyperledger/bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
org1.example.com
org2.example.com

/usr/local/hyperledger/bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
2018-01-20 06:51:43.653 GMT [common/configtx/tool] main -> INFO 001 Loading configuration
2018-01-20 06:51:43.682 GMT [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block
2018-01-20 06:51:43.684 GMT [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2018-01-20 06:51:43.713 GMT [common/configtx/tool] main -> INFO 001 Loading configuration
2018-01-20 06:51:43.716 GMT [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2018-01-20 06:51:43.716 GMT [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
2018-01-20 06:51:43.749 GMT [common/configtx/tool] main -> INFO 001 Loading configuration
2018-01-20 06:51:43.752 GMT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-01-20 06:51:43.752 GMT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
2018-01-20 06:51:43.780 GMT [common/configtx/tool] main -> INFO 001 Loading configuration
2018-01-20 06:51:43.783 GMT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-01-20 06:51:43.783 GMT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

[opc@kokane-hl first-network]$ ./byfn.sh -m up
Starting with channel 'mychannel' and CLI timeout of '10'
Continue (y/n)? y
proceeding ...
Creating peer0.org1.example.com ... done
Creating cli ... done
Creating peer0.org1.example.com ...
Creating peer1.org1.example.com ...
Creating orderer.example.com ...
Creating peer1.org2.example.com ...
Creating cli ...

 ____    _____      _      ____    _____
/ ___|  |_   _|    / \    |  _ \  |_   _|
\___ \    | |     / _ \   | |_) |   | |
 ___) |   | |    / ___ \  |  _ <    | |
|____/    |_|   /_/   \_\ |_| \_\   |_|

Build your first network (BYFN) end-to-end test

Channel name : mychannel
Creating channel...
========= All GOOD, BYFN execution completed ===========

(省略)
 _____   _   _   ____
| ____| | \ | | |  _ \
|  _|   |  \| | | | | |
| |___  | |\  | | |_| |
|_____| |_| \_| |____/

总结

只要有一套开发环境,像Docker、Git和Golang这样的工具就可以较容易地准备好环境。(我认为这一切变得相当简单了,这得归功于Docker镜像的准备和GitHub上的示例准备得很全。)
既然已经配置好了环境,我打算使用其他教程和资源,进一步实践和探索。

如果作为开发环境使用,以下也可能会很方便。
我试着用“Zero to Blockchain”(Hyperledger Fabric)的视频教程,使用一个可以轻松构建本地开发环境的shell。

然而,当需要真正部署时,由于对适合运行的环境不太了解,我觉得从实际角度来看,使用以下云服务来进行部署可能是合理的选择。 区块链云服务 | Oracle云
Oracle区块链云服务介绍资料

广告
将在 10 秒后关闭
bannerAds