1.基础工具准备
- sudo apt-get install tree
- sudo apt-get install jq
- sudo apt install curl
- sudo apt install git
- sudo apt install vim
2.Docker和Docker Compose安装
-
如果有旧版本,卸掉
$ sudo apt-get remove docker docker-engine docker.io containerd runc
-
设置存储库:
更新
apt
软件包索引并安装软件包以允许apt
通过HTTPS使用存储库:$ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
添加Docker的官方GPG密钥:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
使用以下命令来设置稳定的存储库:
$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
安装docker engine:
更新
apt
程序包索引,并安装最新版本的Docker Engine和容器,或转到下一步以安装特定版本:$ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io
要安装特定版本的Docker Engine,请在存储库中列出可用版本,然后选择并安装:
一个。列出您的仓库中可用的版本:
$ apt-cache madison docker-ce docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages ...
使用第二列中的版本字符串安装特定版本,例如
5:18.09.1~3-0~ubuntu-xenial
。$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
通过运行
hello-world
映像来验证是否正确安装了Docker Engine 。$ sudo docker run hello-world
-
安装docker compose
# 下载Docker Compose二进制文件 $ sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose $ sudo chmod +x /usr/local/bin/docker-compose
3.Go安装
因为当时虚拟机github上不了,所以主机下载了go的压缩包,然后通过主机和虚拟机共享文件实现的。go需要解压在/usr/local下
配置go环境变量:
cd /etc
sudo vim profile
#键盘输入O
#在文件末尾加入
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/opt/gopath
#键盘按住esc输入wq!
#使环境变量生效
source /etc/profile
4.Fabric安装
-
将fabric-samples下载到
$GOPATH/src/github.com/hyperledger
目录中mkdir -p $GOPATH/src/github.com/hyperledger cd $GOPATH/src/github.com/hyperledger # 克隆fabric-samples项目并切换到v1.4tag git clone https://github.com/hyperledger/fabric-samples.git cd fabric-samples git checkout -b sample v1.4.0
-
安装Fabric Binaries和Fabric相关的Docker镜像
cd $GOPATH/src/github.com/hyperledger/fabric-samples/scripts # 安装Fabric、Fabric-ca以及第三方Docker镜像(./bootstrap.sh <fabric> <fabric-ca> <thirdparty>) ./bootstrap.sh 1.4.0 1.4.0 0.4.14
值得注意的是,如果由于网络问题,此处通过
bootstrap.sh
脚本安装可能会出错,此时可进行手动安装。安装步骤如下:-
将指定版本的Hyperledger Fabric特定于平台的二进制文件和配置文件安装到fabric-samples的bin和config目录中
wget https://github.com/hyperledger/fabric/releases/download/v1.4.0/hyperledger-fabric-linux-amd64-1.4.0.tar.gz wget https://github.com/hyperledger/fabric-ca/releases/download/v1.4.0/hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz tar xzvf hyperledger-fabric-linux-amd64-1.4.0.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/ tar xzvf hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/ #向/etc/profile中写入环境变量 sudo echo 'export PATH=$GOPATH/src/github.com/hyperledger/fabric-samples/bin:$PATH' >> /etc/profile #使环境变量生效 source /etc/profile
-
下载相关Docker镜像
# 下载Fabric相关镜像(fabric-peer、fabric-orderer、fabric-ccenv、fabric-tools),此处以fabric-peer镜像为例,其他镜像同理 docker pull hyperledger/fabric-peer:1.4.0 docker tag hyperledger/fabric-peer:1.4.0 hyperledger/fabric-peer:latest # 下载Fabric第三方镜像(fabric-couchdb、fabric-kafka、fabric-zookeeper),此处以fabric-couchdb为例,其他镜像同理 docker pull hyperledger/fabric-couchdb:0.4.14 docker tag hyperledger/fabric-couchdb:0.4.14 hyperledger/fabric-couchdb:latest # 下载Fabric CA镜像 docker pull hyperledger/fabric-ca:1.4.0 docker tag hyperledger/fabric-ca:1.4.0 hyperledger/fabric-ca:latest
-
(可选)镜像的备份与恢复
# 将上述Docker镜像存储到fabric-images文件中 docker save $(docker images | grep fabric | grep latest | awk '{print $1}') -o fabric-images # 若需要多机部署,则通过下列命令将其分发到其他机器 scp fabric-images ubuntu@192.168.70.21:~ # 在192.168.70.21上加载上述镜像 docker load -o fabric-images
-
-
通过运行
Build your first network
样例来进行测试、cd $GOPATH/src/github.com/hyperledger/fabric-samples/first-network # 编译通过Golang开发的chaincode并启动相关的容器 ./byfn.sh up ./byfn.sh up -l node ./byfn.sh up -o kafka #停止first-network网络中所有的容器,删除crypto材料和4个artifacts(genesis.block、mychannel.block、Org1MSPanchor.tx、Org2MSPanchor.tx)以及chaincode镜像 ./byfn.sh down
- 将下载的fabric相关的安装文件(包括
fabric-samples
、hyperledger-fabric-linux-amd64-1.4.0.tar.gz
、hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz
和fabric-images
)汇总到一个文件夹并进行压缩生成fabric-offline-install.tar.gz
5.Fabric离线安装
如何通过Fabric安装章节提到的fabric-offline-install.tar.gz
来离线安装Fabric。
tar xzvf fabric-offline-install.tar.gz
cd fabric-offline-install
cp -rf fabric-samples $GOPATH/src/github.com/hyperledger
tar xzvf hyperledger-fabric-linux-amd64-1.4.0.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/
tar xzvf hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/
sudo echo 'export PATH=$GOPATH/src/github.com/hyperledger/fabric-samples/bin:$PATH' >> /etc/profile
source /etc/profile
docker load -i fabric-images