$ sudo cp /etc/apt/source.list /etc/apt/source.list.bak
$ sudo vim /etc/apt/source.list
易源
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse阿里源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
搜狐源
deb http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
复制进去后,使用:wq
保存,然后使用如下命令更新一下
$ sudo apt-get install update
不推荐使用apt
的方式安装GO,原因是这样安装的版本比较老,推荐安装最新版的GO,具体安装命令如下
$ wegt https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz
/usr/local
目录下$ sudo tar -C usr/local -xzf go1.10.2.linux-amd64.tar.gz
$ vim ~/.profile
添加如下内容
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
#这里配置的GOPATH目录为家目录的的go文件夹
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
使用:wq
保存后使用如下命令将保存立即刷新
$ source ~/.profile
GOPATH
目录 由于在环境变量中配置了GOPATH
目录的位置,所以我们需要在家目录下创建该文件夹$ cd ~
$ mkdir go
$ go version
go version go1.10 linux/amd64
这里使用的Docker
的官方文档来安装docker
Docker
,需要先使用如下命令卸载$ sudo apt-get remove docker docker-engine docker.io
apt
包索引$ sudo apt-get update
apt
通过HTTPS使用远程库$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
若出现无法识别命令,可以先将该命令复制到一个文本文件中,将\
去掉,将所有语句放在同一行下,然后复制执行。
Docker
的官方GPG
密钥$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
$ sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb)
sub 4096R/F273FCD8 2017-02-22
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt
包索引$ sudo apt-get update
apt
安装docker-ce
$ sudo apt-get install docker-ce
$ docker version
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:17:20 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:15:30 2018
OS/Arch: linux/amd64
Experimental: false
安装完成之后,需要将当前用户添加到docker
用户组,然后为该用户添加sudo
权限
docker
用户组,可以使用如下命令创建一个GID
为999
,组名为docker
的用户组$ sudo groupadd –g 999 docker
docker
用户组并分配sudo
权限$ sudo usermod -aG docker ubuntu
注销后重新登录,然后添加阿里云的Docker Hub镜像(注意,不同版本的添加方法不同,见阿里云容器 Hub)
$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}
EOF
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
如果觉得阿里云镜像不好用,可以选择DaoClound的镜像,配置方式见DaoCloud官方文档
Docker-Compose
是支持通过模板脚本批量创建的一个组件。在安装 Docker-Compose
之前,需要安装Python-pip
python-pip
$ sudo apt-get python-pip
Docker-Compose
,这里使用的是国内的DaoClound加速器进行下载$ curl -L https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
Docker-Compose
文件夹移动到/usr/local/bin
目录下$ sudo mv ~/docker-compose /usr/local/bin/docker-compose
Docker-Compose
附上可执行权限$ chmod +x /usr/local/bin/docker-compose
GOPATH
下创建对应的目录$ mkdir -p ~/go/src/github.com/hyperledger
Git
命令将fabric
的源码从github上克隆下来$ cd ~/go/src/github.com/hyperledger
$ git clone https://github.com/hyperledger/fabric.git
v1.0.0
$ cd ~/go/src/github.com/hyperledger/fabric
$ git checkout v1.0.0
由于刚才设置了Docker Hub镜像的地址,并且官方文件中也提供了批量下载的脚本,所有我们只需运行下面命令即可
$ cd ~/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
REPOSITORY TAG IMAGE ID CREATED SIZE
dev-peer0.org1.example.com-marbles-v4 latest 089d43e100c9 5 hours ago 173MB
dev-peer0.org1.example.com-fabcar-1.0 latest 6047921ee993 7 hours ago 173MB
hyperledger/fabric-tools latest 0403fd1c72c7 10 months ago 1.32GB
hyperledger/fabric-tools x86_64-1.0.0 0403fd1c72c7 10 months ago 1.32GB
hyperledger/fabric-couchdb latest 2fbdbf3ab945 10 months ago 1.48GB
hyperledger/fabric-couchdb x86_64-1.0.0 2fbdbf3ab945 10 months ago 1.48GB
hyperledger/fabric-kafka latest dbd3f94de4b5 10 months ago 1.3GB
hyperledger/fabric-kafka x86_64-1.0.0 dbd3f94de4b5 10 months ago 1.3GB
hyperledger/fabric-zookeeper latest e545dbf1c6af 10 months ago 1.31GB
hyperledger/fabric-zookeeper x86_64-1.0.0 e545dbf1c6af 10 months ago 1.31GB
hyperledger/fabric-orderer latest e317ca5638ba 10 months ago 179MB
hyperledger/fabric-orderer x86_64-1.0.0 e317ca5638ba 10 months ago 179MB
hyperledger/fabric-peer latest 6830dcd7b9b5 10 months ago 182MB
hyperledger/fabric-peer x86_64-1.0.0 6830dcd7b9b5 10 months ago 182MB
hyperledger/fabric-Javaenv latest 8948126f0935 10 months ago 1.42GB
hyperledger/fabric-javaenv x86_64-1.0.0 8948126f0935 10 months ago 1.42GB
hyperledger/fabric-ccenv latest 7182c260a5ca 10 months ago 1.29GB
hyperledger/fabric-ccenv x86_64-1.0.0 7182c260a5ca 10 months ago 1.29GB
hyperledger/fabric-ca latest a15c59ecda5b 10 months ago 238MB
hyperledger/fabric-ca x86_64-1.0.0 a15c59ecda5b 10 months ago 238MB
hyperledger/fabric-baseos x86_64-0.3.1 4b0cab202084 12 months ago 157MB
出现以上结果说明镜像已经下载成功
e2e_cli
目录,并执行启动命令$ cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
$ ./network_setup.sh up
这个过程做了如下操作
1.编译生成Fabric公私钥,证书的程序,程序在目录:fabric/release/linux-amd64/bin下
2.基于configtx.yaml生成创世区块和通道相关信息,并保存到channel-artifacts文件夹中
3.基于crypto-config.yaml生成公私钥和证书信息,并保存在crypto-config文件夹中
4.基于docker-compose-cli.yaml启动1 Orderer + 4 Peer + 1 CLI的Fabric容器
5.在CLI启动的时候,会运行srcipt/script.sh文件,这个脚本文件包含了创建Channel,加入Channel,安装Example02,运行Example02等功能
我们以安装好的Example02
进行测试,在官方例子中,channel
的名字是mychannel
,链码的名字是mycc
,我们首先重新打开一个命令行,然后进入CLI
,
$ docker exec -it cli bash
a
账户的余额$ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
b
账户的余额$ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
b
账户的余额转100给a
账户,运行如下命令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","b","a","100"]}'
a
账户的余额$ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
b
账户的余额$ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
调用链码一切正常
CLI
容器root@4941e8bd4bd6:/opt/gopath/src/github.com/hyperledger/fabric/peer# exit
$ cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli
$ ./network_setup.sh down
至此,部署以及测试fabric
的环境已经全部完成,下一篇博客我将记录如何在此基础上部署及运行IBM官方区块链例子marbles(弹珠资产)
当前题目:基于Ubuntu16.04快速构建HyperledgerFabric网络
本文路径:http://www.shufengxianlan.com/qtweb/news39/430989.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联