在ubuntu中打开终端,输入以下命令
更新软件源
sudo apt update
安装git
sudo apt install git
安装curl
sudo apt install curl
有提示输入y即可继续
获取安装docker-ce的脚本
curl -fsSL get.docker.com -o get-docker.sh
查看当前目录是否获取到了脚本
ls get*
执行脚本(安装需要一些时间)
sudo sh get-docker.sh
安装成功后试着run一下测试镜像
sudo docker run hello-world
看到这两句话就证明安装成功了
安装
sudo apt install docker-compose
安装成功后查看版本
docker-compose --version
docker下载链接
docker更换国内源
下面也有
1.创建或修改 /etc/docker/daemon.json 文件,修改为如下形式
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
国内加速地址有:
Docker中国区官方镜像
https://registry.docker-cn.com
网易
http://hub-mirror.c.163.com
ustc
https://docker.mirrors.ustc.edu.cn
中国科技大学
https://docker.mirrors.ustc.edu.cn
阿里云容器 服务
https://cr.console.aliyun.com/
之后重启docker服务
$ sudo service docker restart
2.DOCKER_OPTS="--registry-mirror=https://registry.docker-cn.com"
从该网站下载linux版本的go安装包:https://studygolang.com/dl
下载好后将压缩包解压到 /usr/local 目录下
然后执行以下命令
在根目录下创建一个go文件夹
mkdir $HOME/go
修改环境配置
vi ~/.bashrc
增加以下三条环境变量
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
让配置文件生效
source ~/.bashrc
查看go的版本
go version
注意版本必须都是1.2.0!
获取fabirc并切换版本
git clone https://gitee.com/arxin/fabric.git
git checkout -b v1.2.0
获取fabric-samples并切换版本
git clone -b master https://github.com/hyperledger/fabric-samples.git
git checkout -b v1.2.0
我这里提供的fabric是已经转存到码云上了,所以下载非常快√
fabric-samples文件不大,下载不算慢,所以没有转到码云,有需要的话自己可以转一下。也可以不用上面的git来获取,看下面↓
重点,我们还需要获取一份二进制工具,另外获取有点麻烦,我已经上传了好了,打包在fabric-samples里了,直接下载即可。
接下来是一个重中之重,很多人都还卡在下载fabric相关镜像这个步骤。
首先这是官方的bootstrap脚本,通过该脚本会一次性下载fabirc和fabric-sample还有docker镜像。如果只是依靠官方脚本,极其容易出现网络问题,导致中断报错,而且下载速度非常非常慢,失败几率很大。所以不推荐推荐直接用官方脚本下载。
https://github.com/hyperledger/fabric/blob/master/scripts/bootstrap.sh
fabirc和fabric-sample在之前我们已经下载好了,都是1.2.0版本的。
接下来就剩下docker镜像了,所以我们只需要从该脚本精简出下载镜像那部分的代码即可
请保存以下内容为bootstrap.sh
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# if version not passed in, default to latest released version
VERSION=2.1.0
# if ca version not passed in, default to latest released version
CA_VERSION=1.4.6
# current version of thirdparty images (couchdb, kafka and zookeeper) released
THIRDPARTY_IMAGE_VERSION=0.4.18
ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
MARCH=$(uname -m)
printHelp() {
echo "Usage: bootstrap.sh [version [ca_version [thirdparty_version]]] [options]"
echo
echo "options:"
echo "-h : this help"
echo "-d : bypass docker image download"
echo "-s : bypass fabric-samples repo clone"
echo "-b : bypass download of platform-specific binaries"
echo
echo "e.g. bootstrap.sh 2.1.0 1.4.6 0.4.18 -s"
echo "would download docker images and binaries for Fabric v2.1.0 and Fabric CA v1.4.6"
}
# dockerPull() pulls docker images from fabric and chaincode repositories
# note, if a docker image doesn't exist for a requested release, it will simply
# be skipped, since this script doesn't terminate upon errors.
dockerPull() {
#three_digit_image_tag is passed in, e.g. "1.4.6"
three_digit_image_tag=$1
shift
#two_digit_image_tag is derived, e.g. "1.4", especially useful as a local tag for two digit references to most recent baseos, ccenv, javaenv, nodeenv patch releases
two_digit_image_tag=$(echo $three_digit_image_tag | cut -d'.' -f1,2)
while [[ $# -gt 0 ]]
do
image_name="$1"
echo "====> hyperledger/fabric-$image_name:$three_digit_image_tag"
docker pull "hyperledger/fabric-$image_name:$three_digit_image_tag"
docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name"
docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name:$two_digit_image_tag"
shift
done
}
pullDockerImages() {
command -v docker >& /dev/null
NODOCKER=$?
if [ "${NODOCKER}" == 0 ]; then
FABRIC_IMAGES=(peer orderer ccenv tools)
case "$VERSION" in
1.*)
FABRIC_IMAGES+=(javaenv)
shift
;;
2.*)
FABRIC_IMAGES+=(nodeenv baseos javaenv)
shift
;;
esac
echo "FABRIC_IMAGES:" "${FABRIC_IMAGES[@]}"
echo "===> Pulling fabric Images"
dockerPull "${FABRIC_TAG}" "${FABRIC_IMAGES[@]}"
echo "===> Pulling fabric ca Image"
CA_IMAGE=(ca)
dockerPull "${CA_TAG}" "${CA_IMAGE[@]}"
echo "===> Pulling thirdparty docker images"
THIRDPARTY_IMAGES=(zookeeper kafka couchdb)
dockerPull "${THIRDPARTY_TAG}" "${THIRDPARTY_IMAGES[@]}"
echo
echo "===> List out hyperledger docker images"
docker images | grep hyperledger
else
echo "========================================================="
echo "Docker not installed, bypassing download of Fabric images"
echo "========================================================="
fi
}
DOCKER=true
SAMPLES=true
BINARIES=true
# Parse commandline args pull out
# version and/or ca-version strings first
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
VERSION=$1;shift
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
CA_VERSION=$1;shift
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
THIRDPARTY_IMAGE_VERSION=$1;shift
fi
fi
fi
# prior to 1.2.0 architecture was determined by uname -m
if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then
export FABRIC_TAG=${MARCH}-${VERSION}
export CA_TAG=${MARCH}-${CA_VERSION}
export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
else
# starting with 1.2.0, multi-arch images will be default
: "${CA_TAG:="$CA_VERSION"}"
: "${FABRIC_TAG:="$VERSION"}"
: "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}"
fi
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz
# then parse opts
while getopts "h?dsb" opt; do
case "$opt" in
h|\?)
printHelp
exit 0
;;
d) DOCKER=false
;;
s) SAMPLES=false
;;
b) BINARIES=false
;;
esac
done
if [ "$DOCKER" == "true" ]; then
echo
echo "Pull Hyperledger Fabric docker images"
echo
pullDockerImages
fi
使用该脚本前,务必配置好镜像加速器。
根据阿里云镜像加速器操作文档配置即可。
做好该配置后,我们才能高速下载docker镜像。
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://5r4g7vi9.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
脚本准备好了,加速器也配置好了。
那么可以开始执行脚本啦,注意版本号。
修改脚本权限
chmod 755 bootstrap.sh
执行脚本并指定版本号
sudo ./bootstrap.sh 1.2.0 1.2.0 0.4.10
很快下载完毕了
(完整镜像图)
接下来配置环境变量
环境变量配置路径务必按照自己本身的fabric-samples/bin路径配置
不一定和我这里的路径一样
vi ~/.bashrc
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:/home/hyperledger-fabric/fabric/fabric-samples/bin
source ~/.bashrc
在阿里云服务器搭建环境,必须要修改 /etc/resolv.conf 配置。
vi /etc/resolv.conf
将 options timeout:2 attempts:3 rotate single-request-reopen 这行内容在前面加上井号注释掉然后保存退出
先执行第一条语句生成相关的文件
./byfn.sh generate
./byfn.sh up
byfn.sh为启动这个网络的启动脚本
启动脚本中除建立一个包含4个节点和1个Order service的网络外
还会启动一个容器用来执行脚本在channel中加入节点部署和初始化chaincode
以及在部署的chaincode上执行交易,默认channel名称为mychannel
脚本程序会给网络实例生成数字证书和密钥
生成genesis block用来启动ordering service一些用来配置channel的配置交易。
第二条语句是启动网络
成功看到All Good和End的话,恭喜你,Hyperledger Fabric1.2环境搭建成功!!!
docker ps
使用该命令即可停止网络
./byfn.sh down
成功启动网络后是可以对默认账户进行转账查询等操作的,这些我就不在这里进行操作啦,大家可以自己研究。
好啦,如果你跟着本篇文章安装成功了希望给个评论点个赞噢~谢谢!