一、基础环境配置
1、win10下安装git、vagrant、virualbox安装(相关资料自行查阅)
2、下载vagrant需要的box镜像
1、下载centos7对应的box放到h:\vagrant\box中:(https://vagrantcloud.com/centos/boxes/7/versions/2004.01/providers/virtualbox.box)并把virtualbox.box改名为centos7.box
3、vagrant中新建centos环境
1、打开git下面的Git bash.exe这个比较好用,好像linux指令和win10 cmd指令都可识别。在新建h:\vagrant\centos7目录,在git bash中进入该目录,此时显示目录为/h/vagrant/centos7.
2、在git bash中/h/vagrant/centos7目录中:
#查看已有的box列表,之前没添加过的话,此时会显示空*
vagrant box list
#添加我们下载的centos box,此时运行上面的list命令就会看到我们添加的box
vagrant box add centos7 /h/vagrant/box/centos7.box
3、进入到/h/vagrant/centos7目录,在这个目录下面建立我们的centos环境
#初始化centos7配置文件,会在当前目录下面生成Vagrantfile这个文件 ,这个文件包含后面所有的虚拟机的配置信息,按需求查资料修改配置文件
#(https://blog.csdn.net/u011781521/article/details/80291765)*
vagrant init centos7
#*启动虚拟机 *
vagrant up
#*默认进入的是vagrant用户,密码也是vagrant *
vagrant ssh
#修改root 密码后面操作都用root用户完成
#可以修改配置直接以root用户登录,感觉没必要,就默认登录,再切换到root用户,需要配置root密码
图片.png
#在root用户下安装更新
yum upate
#安装vagrant磁盘分配插件,后面可以修改Vagrantfile修改分配的磁盘大小,不安装无法识别Vagrantfile中的disksize关键字
vagrant plugin install vagrant-disksize
图片.png
-修改Vagrantfile 修改分配内存和磁盘空间,磁盘我分了100G,内存我分了8G,自己根据自己的情况分配
图片.png
图片.png
-重启centos7让修改的配置生效
#*关闭box*
vagrant halt
#*启动box*
vagrant up
#在root用户下安装所需要 的基础包
yum install -y git wget curl vim
#打包当前的box,备用也可以共享给其它人用,再加上Vagrantfile,就可以生成 和自己一模一样的环境,我还是把这个box放移动到/h/vagrant/box目录下面备用
vagrant package --output my-fabric-centos-7-base.box
图片.png
4、运行环境安装
1、需要安装go、java、maven、docker、 docker-compose
对应版本为:
图片.png
#go
tar -C /usr/local -zxf go1.15.5.linux-amd64.tar.gz
#java
mkdir /usr/local/java/
tar -zxvf jdk-8u271-linux-x64.tar.gz -C /usr/local/java/
#maven
mkdir /usr/local/maven/
tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /usr/local/maven/
#设置环境变量
vim /etc/profile
#添加以下内容:
#go
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
#java
export JAVA_HOME=/usr/local/java/jdk1.8.0_271
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
#maven
export MAVEN_HOME=/usr/local/maven/apache-maven-3.6.3
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
使环境变量生效
source /etc/profile
查看版本:
图片.png
2、docker环境
#卸载旧版本
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
#安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
#设置稳定的仓库
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#安装 Docker Engine-Community
yum install docker-ce docker-ce-cli containerd.io
#启动Docker
systemctl start docker
#查看Docker版本
docker version
#设置加速镜像
#在/etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)
#腾讯云:https://mirror.ccs.tencentyun.com
#阿里云:https://svaken38.mirror.aliyuncs.com
#网易云:http://hub-mirror.c.163.com
{
"registry-mirrors": ["https://svaken38.mirror.aliyuncs.com"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
3、docker-compose环境
#用daocloud下载
curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
#赋予权限
chmod +x /usr/local/bin/docker-compose
#查看版本
docker-compose version
4、备份基础环境box
vagrant package --output ../box/centos7-base-env-over.box
5、fabric安装
1、下载源码
#fabric需要go来编译,所以放到go工作目录下
mkdir -p ~/go/src/github.com/hyperledger
cd ~/go/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git
#上述github地址下载太慢,可以尝试下面码云上这个地址
#https://gitee.com/luxiaojun0605/fabric.git
2、下载完成后会得到一个fabric文件夹,进入fabric/scripts目录可以看到一个bootstrap.sh脚本,直接执行bootstrap.sh脚本,就会自动进行fabric相关文件和镜像的下载
因涉及到github上面下载包,所以此过程会很漫长,为了节省时间,我们可以拆分脚本中内容分别下载
这里下载的瓶颈主要是pullBinaries二进制文件,所以我们先把他注释后运行bootstrap.sh脚本文件进行fabric-samples文件夹的下载和镜像文件的拉取
-先注释点pullBinaries
if [ "$SAMPLES" == "true" ]; then
echo
echo "Clone hyperledger/fabric-samples repo"
echo
cloneSamplesRepo
fi
if [ "$BINARIES" == "true" ]; then
echo
echo "Pull Hyperledger Fabric binaries"
echo
#pullBinaries
fi
if [ "$DOCKER" == "true" ]; then
echo
echo "Pull Hyperledger Fabric docker images"
echo
pullDockerImages
fi
-修改下载版本为2.2.0 ca版本为1.4.7(如果不修改运行bootstrap.sh的时候需要加2.2.0 1.4.7)这个地方不修改下载的时候会中断。。。。
# if version not passed in, default to latest released version
VERSION=2.2.0
# if ca version not passed in, default to latest released version
CA_VERSION=1.4.7
ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
MARCH=$(uname -m)
#不修改的时候运行下面的程序
#./bootstrap.sh 2.2.0 1.4.7
#代码如下:
[root@localhost scripts]# ./bootstrap.sh 2.2.0 1.4.7
Clone hyperledger/fabric-samples repo
===> Changing directory to fabric-samples
fabric-samples v2.2.0 does not exist, defaulting master
Pull Hyperledger Fabric binaries
Pull Hyperledger Fabric docker images
FABRIC_IMAGES: peer orderer ccenv tools baseos
===> Pulling fabric Images
====> hyperledger/fabric-peer:2.2.0
2.2.0: Pulling from hyperledger/fabric-peer
Digest: sha256:81efaab943387820815c9b9bd3e3bec9d262365e635bac6f500a287fb3e873e7
Status: Image is up to date for hyperledger/fabric-peer:2.2.0
docker.io/hyperledger/fabric-peer:2.2.0
====> hyperledger/fabric-orderer:2.2.0
2.2.0: Pulling from hyperledger/fabric-orderer
Digest: sha256:bb97a8e80b53d9f32c3b850ae3b55bab57bf3cc9483978a471a5bee0ac49728e
Status: Image is up to date for hyperledger/fabric-orderer:2.2.0
docker.io/hyperledger/fabric-orderer:2.2.0
====> hyperledger/fabric-ccenv:2.2.0
2.2.0: Pulling from hyperledger/fabric-ccenv
Digest: sha256:4ec2f71fbcd52a1e6717f5eb20f82452c24352faa2dcd08d3941e0bf2438610b
Status: Image is up to date for hyperledger/fabric-ccenv:2.2.0
docker.io/hyperledger/fabric-ccenv:2.2.0
====> hyperledger/fabric-tools:2.2.0
2.2.0: Pulling from hyperledger/fabric-tools
Digest: sha256:d328c63a5ca2e9d27e74ee43d17fcfada9937961d5e70433a1d66352f6e7b652
Status: Image is up to date for hyperledger/fabric-tools:2.2.0
docker.io/hyperledger/fabric-tools:2.2.0
====> hyperledger/fabric-baseos:2.2.0
2.2.0: Pulling from hyperledger/fabric-baseos
Digest: sha256:6584eb096bb3cf495e4c2ebf162ed7c1be45157b89662c0d407bfd9adc036d66
Status: Image is up to date for hyperledger/fabric-baseos:2.2.0
docker.io/hyperledger/fabric-baseos:2.2.0
===> Pulling fabric ca Image
====> hyperledger/fabric-ca:1.4.7
1.4.7: Pulling from hyperledger/fabric-ca
b8f262c62ec6: Pull complete
56b16818f60b: Pull complete
707812f2aa2d: Pull complete
400ab1f52b57: Pull complete
1e32346b61cd: Pull complete
d1832ac8c002: Pull complete
cb7ebebf613a: Pull complete
6af9a3114ec8: Pull complete
Digest: sha256:9418ea351bfbef4bf2bca34bcd77305bdb9a45d2c1aab3237c08c17da0b4d1dd
Status: Downloaded newer image for hyperledger/fabric-ca:1.4.7
docker.io/hyperledger/fabric-ca:1.4.7
===> List out hyperledger docker images
hyperledger/fabric-tools 2.2 5eb2356665e7 4 months ago 519MB
hyperledger/fabric-tools 2.2.0 5eb2356665e7 4 months ago 519MB
hyperledger/fabric-tools latest 5eb2356665e7 4 months ago 519MB
hyperledger/fabric-peer 2.2 760f304a3282 4 months ago 54.9MB
hyperledger/fabric-peer 2.2.0 760f304a3282 4 months ago 54.9MB
hyperledger/fabric-peer latest 760f304a3282 4 months ago 54.9MB
hyperledger/fabric-orderer 2.2 5fb8e97da88d 4 months ago 38.4MB
hyperledger/fabric-orderer 2.2.0 5fb8e97da88d 4 months ago 38.4MB
hyperledger/fabric-orderer latest 5fb8e97da88d 4 months ago 38.4MB
hyperledger/fabric-ccenv 2.2 aac435a5d3f1 4 months ago 586MB
hyperledger/fabric-ccenv 2.2.0 aac435a5d3f1 4 months ago 586MB
hyperledger/fabric-ccenv latest aac435a5d3f1 4 months ago 586MB
hyperledger/fabric-baseos 2.2 aa2bdf8013af 4 months ago 6.85MB
hyperledger/fabric-baseos 2.2.0 aa2bdf8013af 4 months ago 6.85MB
hyperledger/fabric-baseos latest aa2bdf8013af 4 months ago 6.85MB
hyperledger/fabric-ca 1.4 743a758fae29 6 months ago 154MB
hyperledger/fabric-ca 1.4.7 743a758fae29 6 months ago 154MB
hyperledger/fabric-ca latest 743a758fae29 6 months ago 154MB
下载hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz
下载hyperledger-fabric-linux-amd64-2.2.0.tar.gz
这两个文件就是上面注释掉的二进行制文件下载
对应链接为:
https://github.com/hyperledger/fabric/releases/download/v2.2.0/hyperledger-fabric-linux-amd64-2.2.0.tar.gz
https://github.com/hyperledger/fabric-ca/releases/download/v1.4.7/hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz
下载好后放到vagrant的共享目录,重启centos7在centos7中移动至fabric-samples目录中;我这边用的默认共享目录是win10的Vagrantfile目录对应box的/vagrant/目录(也可以用其它方式把文件传到box中),再把fabric-samples文件上移一层到/go/src/github.com/hyperledger/fabric(原来在/go/src/github.com/hyperledger/fabric/script这个目录),并分别解压这两个文件得到bin目录;代码如下
[root@localhost setupfile]# cd /vagrant/
[root@localhost vagrant]# ll
total 4
drwxr-xr-x. 2 vagrant vagrant 241 Nov 22 10:09 setupfile
-rw-r--r--. 1 vagrant vagrant 3220 Nov 22 02:19 Vagrantfile
[root@localhost vagrant]# cd setupfile/
[root@localhost setupfile]# ll
total 391908
-rw-r--r--. 1 vagrant vagrant 9506321 Nov 22 04:37 apache-maven-3.6.3-bin.tar.gz
-rw-r--r--. 1 vagrant vagrant 120900442 Nov 22 04:47 go1.15.5.linux-amd64.tar.gz
-rw-r--r--. 1 vagrant vagrant 24751722 Nov 22 10:08 hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz
-rw-r--r--. 1 vagrant vagrant 76283052 Nov 22 10:08 hyperledger-fabric-linux-amd64-2.2.0.tar.gz
-rw-r--r--. 1 vagrant vagrant 143142634 Nov 22 04:34 jdk-8u271-linux-x64.tar.gz
-rw-r--r--. 1 vagrant vagrant 26724009 Nov 22 04:36 Python-3.9.0.tgz
[root@localhost setupfile]# cp hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz ~/go/src/github.com/hyperledger/fabric/fabric-samples/
[root@localhost setupfile]# cp hyperledger-fabric-linux-amd64-2.2.0.tar.gz ~/go/src/github.com/hyperledger/fabric/fabric-samples/ [root@localhost setupfile]# cd ~/go/src/github.com/hyperledger/fabric/fabric-samples/
[root@localhost fabric-samples]# tar -zxf hyperledger-fabric-linux-amd64-2.2.0.tar.gz
[root@localhost fabric-samples]# tar -zxf hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz
[root@localhost fabric-samples]# ll
total 99104
drwxr-xr-x. 11 root root 254 Nov 22 06:32 asset-transfer-basic
drwxr-xr-x. 4 root root 64 Nov 22 06:32 asset-transfer-events
drwxr-xr-x. 6 root root 108 Nov 22 06:32 asset-transfer-ledger-queries
drwxr-xr-x. 4 root root 56 Nov 22 06:32 asset-transfer-private-data
drwxr-xr-x. 5 root root 103 Nov 22 06:32 asset-transfer-sbe
drwxr-xr-x. 4 root root 56 Nov 22 06:32 asset-transfer-secured-agreement
drwxr-xr-x. 4 root root 73 Nov 22 06:32 auction
drwxr-xr-x. 2 1001 1001 171 Jul 9 13:24 bin
drwxr-xr-x. 8 root root 118 Nov 22 06:32 chaincode
-rw-r--r--. 1 root root 398453 Nov 22 06:32 CHANGELOG.md
drwxr-xr-x. 4 root root 65 Nov 22 06:32 ci
-rw-r--r--. 1 root root 597 Nov 22 06:32 CODE_OF_CONDUCT.md
-rw-r--r--. 1 root root 109 Nov 22 06:32 CODEOWNERS
drwxr-xr-x. 3 root root 111 Nov 22 06:32 commercial-paper
drwxr-xr-x. 2 1001 1001 64 Jul 9 13:24 config
-rw-r--r--. 1 root root 935 Nov 22 06:32 CONTRIBUTING.md
drwxr-xr-x. 6 root root 126 Nov 23 01:50 fabcar
drwxr-xr-x. 4 root root 109 Nov 22 06:32 high-throughput
-rw-r--r--. 1 root root 24751722 Nov 23 01:16 hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz
-rw-r--r--. 1 root root 76283052 Nov 23 01:17 hyperledger-fabric-linux-amd64-2.2.0.tar.gz
drwxr-xr-x. 4 root root 55 Nov 22 06:32 interest_rate_swaps
-rw-r--r--. 1 root root 11358 Nov 22 06:32 LICENSE
-rw-r--r--. 1 root root 1748 Nov 22 06:32 MAINTAINERS.md
drwxr-xr-x. 2 root root 4096 Nov 22 06:32 off_chain_data
-rw-r--r--. 1 root root 7003 Nov 22 06:32 README.md
drwxr-xr-x. 2 root root 26 Nov 22 06:32 scripts
-rw-r--r--. 1 root root 1035 Nov 22 06:32 SECURITY.md
drwxr-xr-x. 3 root root 24 Nov 22 06:32 test-application
drwxr-xr-x. 8 root root 202 Nov 22 06:32 test-network
drwxr-xr-x. 4 root root 71 Nov 22 06:32 token-erc-20
drwxr-xr-x. 3 root root 43 Nov 22 06:32 token-utxo
[root@localhost fabric-samples]# ll bin
total 208192
-rwxr-xr-x. 1 1001 1001 20521776 Jul 9 13:23 configtxgen
-rwxr-xr-x. 1 1001 1001 17012791 Jul 9 13:23 configtxlator
-rwxr-xr-x. 1 1001 1001 13192504 Jul 9 13:23 cryptogen
-rwxr-xr-x. 1 1001 1001 17452108 Jul 9 13:23 discover
-rwxr-xr-x. 1 1001 1001 22950608 May 14 2020 fabric-ca-client
-rwxr-xr-x. 1 1001 1001 30278008 May 14 2020 fabric-ca-server
-rwxr-xr-x. 1 1001 1001 12197048 Jul 9 13:24 idemixgen
-rwxr-xr-x. 1 1001 1001 31417504 Jul 9 13:23 orderer
-rwxr-xr-x. 1 1001 1001 48145696 Jul 9 13:24 peer
关闭box打包
vagrant package --output ../box/centos7-fabric2.2.0-base.box
现在完整的fabric2.2.0环境搭建好了
这里面的很多内容参考了(https://www.cnblogs.com/luxiaojun/p/13453664.html)
后续进行测试网络的运行等
网友评论