一.下载操作系统镜像
1.ubuntu下载地址
2.openEuler下载地址
本文下载openEuler如下版本
二.导入到vbox中
1. 虚拟机导入镜像
1. 新建虚拟机名称
2.分配内存
3.创建虚拟硬盘
4.分配硬盘大小
5.点击设置
6.设置-存储
点击右侧下三角箭头,选择下载的镜像
此处删除了os1.vdi添加控制器SATA,新增硬盘
7.设置-系统
调整启动顺序,将软驱的勾去掉
8. 设置-网络
这里选择桥接模式
9.点击OK后,点击启动
2.安装系统
回车或等待默认进入
等待运行完,按ESC可跳过校验
1.选择语言,这里选择中文
2.设置安装位置
勾选后点击完成
3. 设置网络,打开
3.设置root密码,点击完成
openEuler22
4.开始安装
注意:出现完成时候,此处关闭当前vbox窗口,打开设置–系统,修改启动顺序第一个为硬盘或者把软驱前面的勾取消。
重新点击vbox“启动”按钮
5.登录
等待没反应,直接敲几次回车
输入用户密码
root
openEuler22
三.用户规划
## 1.添加用户fabric
[root@localhost ~]# useradd fabric
## 修改密码
[root@localhost ~]# passwd fabric
更改用户 fabric 的密码 。
新的密码:
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
## wumima-1
## 设置sudo权限
[root@localhost ~]# visudo
## 在root下添加一行如下,保存退出
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
fabric ALL=(ALL) ALL
## 添加到docker组
[fabric@localhost opt]$ sudo usermod -a -G docker fabric
## 2. 添加docker用户
sudo usermod -a -G docker docker
## 系统语言中文改成英文
[fabric@localhost fabric-samples]$ sudo localectl set-locale LANG=en_US.UTF8
或者
[fabric@localhost fabric-samples]$ sudo vi /etc/locale.conf
重启
四.安装工具
1.安装ifconfig
yum search ifconfig
没找到则安装
yum -y install net-tools.x86_64
2.fabric环境准备
官方参考资料
这里使用yum安装
##备份yum.repos.d
[fabric@localhost opt]$ sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup
[fabric@localhost opt]$ sudo yum -y update
## 1.安装git
[root@localhost ~]$ su - fabric
[fabric@localhost ~]$ cd /opt
[fabric@localhost opt]$ sudo yum -y install git
[fabric@localhost opt]$ git --version
git version 2.33.0
## 2.安装curl(系统自带无需安装)
## 3.安装docker
[fabric@localhost opt]$ yum -y install docker
[fabric@localhost opt]$ docker --version
Docker version 18.09.0, build aa1eee8
## 4.安装docker-compose
[fabric@localhost opt]$ sudo yum -y install docker-compose
[fabric@localhost opt]$ docker-compose --version
docker-compose version 1.22.0, build f46880f
## 5.安装golang
[fabric@localhost opt]$ sudo yum -y install golang
[fabric@localhost opt]$ go version
go version go1.17.3 linux/amd64
## 6.安装jq
[fabric@localhost ~]$ sudo yum -y install jq
[fabric@localhost opt]$ jq --version
jq-1.6
## 7.安装libtoo
[fabric@localhost opt]$ sudo yum -y install libtool
[fabric@localhost opt]$ libtool --version
libtool (GNU libtool) 2.4.6
## 安装SoftHSM (TODO)
3.启动docker
## 启动docker
[fabric@localhost opt]$ sudo systemctl start docker
[fabric@localhost opt]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
## docker开机启动
[fabric@localhost opt]$ sudo systemctl enable docker
4.go环境变量配置
## 1. 设置go环境变量
[fabric@localhost opt]$ mkdir $HOME/go
[fabric@localhost opt]$ mkdir -p $GOPATH/src/github.com/hyperledger
## 由于是yum安装,找到GOROOT,GOPATH
[fabric@localhost opt]$ go env
## vi ~./bashrc
[fabric@localhost opt] vi ~/.bashrc
## 在最下方插入
export GOROOT=/usr/lib/golang
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
## 保存退出,生效环境变量
[fabric@localhost opt] source ~/.bashrc
5.拉取fabric相关项目
安装示例、二进制和 Docker 镜像
1.克隆 hyperledger/fabric-samples 仓库
2.检出适当的版本标签
3.将指定版本的 Hyperledger Fabric 平台特定二进制文件和配置文件安装到 fabric-samples 下的 /bin 和 /config 目录中
4.下载指定版本的 Hyperledger Fabric docker 镜像
## 进入目录
[fabric@localhost opt]$ cd $GOPATH/src/github.com/hyperledger
## 1.拉取fabric镜像
[fabric@localhost hyperledger]$ git clone https://github.com/hyperledger/fabric.git
[fabric@localhost fabric]$ cd fabric
## 查看远程分支
[fabric@localhost fabric]$ git branch -a
[fabric@localhost fabric]$ git tag
## 切换分支git checkout tag_name 取得对应tag的代码
## git checkout -b local_branch_name origin_branch_name
## 切换分支到2.3.3
[fabric@localhost fabric]$ git checkout v2.3.3
## 2.拉取fabric-samples
[fabric@localhost hyperledger]$ git clone https://github.com/hyperledger/fabric-samples.git
[fabric@localhost hyperledger]$ cd fabric-samples
[fabric@localhost fabric-samples]$ git checkout v2.3.0
## 3.拉取fabric-ca
[fabric@localhost hyperledger]$ git clone https://github.com/hyperledger/fabric-ca.git
[fabric@localhost fabric-ca]$ git tag
[fabric@localhost fabric-ca]$ git checkout v1.5.2
## 4.下载fabric二进制文件
[fabric@localhost hyperledger] wget https://github.com/hyperledger/fabric/releases/download/v2.3.3/hyperledger-fabric-linux-amd64-2.3.3.tar.gz
[fabric@localhost hyperledger]$ tar -xvf hyperledger-fabric-linux-amd64-2.3.3.tar.gz -C ./fabric-bin2.3/
## 5.下载fabric-ca二进制文件
[fabric@localhost hyperledger]$ wget https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
[fabric@localhost hyperledger]$ tar -xvf hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
## 6.将解压的文件复制到fabric-samples目录下
[fabric@localhost hyperledger]$ cp -r bin config ./fabric-samples/
## 7.设置环境变量
[fabric@localhost hyperledger]$ vi ~/.bashrc
## 添加如下,保存退出
export PATH=$PATH:$GOPATH/src/github.com/hyperledger/fabric-samples/bin
## 生效
[fabric@localhost hyperledger]$ source ~/.bashrc
## 8.验证ca是否配置正确
[fabric@localhost hyperledger]$ fabric-ca-client version
fabric-ca-client:
Version: 1.5.2
Go version: go1.16.7
OS/Arch: linux/amd64
## 9.拉取镜像,修改脚本
[fabric@localhost hyperledger]$ cd fabric/scripts/
[fabric@localhost scripts]$ vi bootstrap.sh
## true修改为false
SAMPLES=false
BINARIES=false
#################### 下载镜像 ###############
[fabric@localhost scripts]$ ./bootstrap.sh
Pull Hyperledger Fabric docker images
FABRIC_IMAGES: peer orderer ccenv tools baseos
===> Pulling fabric Images
====> hyperledger/fabric-peer:2.3.3
2.3.3: Pulling from hyperledger/fabric-peer
a0d0a0d46f8b: Pull complete
48d00a7269f1: Pull complete
cdc14355e7d6: Pull complete
56037e787534: Pull complete
efac144e8b4c: Pull complete
4655b4117f02: Pull complete
Digest: sha256:fc9a143aaf528e407817baf658aff3b258f632464ad32bcfd0d17054b352b782
Status: Downloaded newer image for hyperledger/fabric-peer:2.3.3
====> hyperledger/fabric-orderer:2.3.3
2.3.3: Pulling from hyperledger/fabric-orderer
a0d0a0d46f8b: Already exists
48d00a7269f1: Already exists
d58aaefbb8a4: Pull complete
4d79536ff546: Pull complete
0cd49346219e: Pull complete
e35c5a649c2f: Pull complete
12144512ae9a: Pull complete
Digest: sha256:e5192e8619b9b0abd03ec6ce8babe65493d7db7e71faee3c1c8714bddf19b507
Status: Downloaded newer image for hyperledger/fabric-orderer:2.3.3
====> hyperledger/fabric-ccenv:2.3.3
2.3.3: Pulling from hyperledger/fabric-ccenv
a0d0a0d46f8b: Already exists
31adcdaf11c8: Pull complete
b8b176561691: Pull complete
ffa5077b735b: Pull complete
2e51fde7a4ad: Pull complete
5cc8e298dd15: Pull complete
2321141fd763: Pull complete
fd5823e35fde: Pull complete
71974160e457: Pull complete
Digest: sha256:e95a727aed88456b496a4e4b1ddbc77e81c26a0cc7ff234c7d3d085dafd637cd
Status: Downloaded newer image for hyperledger/fabric-ccenv:2.3.3
====> hyperledger/fabric-tools:2.3.3
2.3.3: Pulling from hyperledger/fabric-tools
a0d0a0d46f8b: Already exists
31adcdaf11c8: Already exists
b8b176561691: Already exists
ffa5077b735b: Already exists
2e51fde7a4ad: Already exists
fa96723f2624: Pull complete
d34ad363c0cf: Pull complete
ab37c24ec85b: Pull complete
Digest: sha256:634c66833a264939b9920cfa0a47b028c20b39475d0bc7ca02841137ea2c4e86
Status: Downloaded newer image for hyperledger/fabric-tools:2.3.3
====> hyperledger/fabric-baseos:2.3.3
2.3.3: Pulling from hyperledger/fabric-baseos
a0d0a0d46f8b: Already exists
48d00a7269f1: Already exists
7fe902e02eda: Pull complete
error pulling image configuration: Get "https://registry-1.docker.io/v2/hyperledger/fabric-baseos/blobs/sha256:b35a8ef578c0a59b029ee3fd16b2c8606de87bbf0a9167cbae97c417e32e94e4": read tcp 192.168.0.103:46602->50.17.53.181:443: read: connection timed out
Error response from daemon: No such image: hyperledger/fabric-baseos:2.3.3
Error response from daemon: No such image: hyperledger/fabric-baseos:2.3.3
===> Pulling fabric ca Image
====> hyperledger/fabric-ca:1.5.2
Error response from daemon: Get "https://registry-1.docker.io/v2/hyperledger/fabric-ca/manifests/1.5.2": Get "https://auth.docker.io/token?scope=repository%3Ahyperledger%2Ffabric-ca%3Apull&service=registry.docker.io": context deadline exceeded
Error response from daemon: No such image: hyperledger/fabric-ca:1.5.2
Error response from daemon: No such image: hyperledger/fabric-ca:1.5.2
===> List out hyperledger docker images
hyperledger/fabric-tools 2.3 98fa0bfb0fd2 7 months ago 445MB
hyperledger/fabric-tools 2.3.3 98fa0bfb0fd2 7 months ago 445MB
hyperledger/fabric-tools latest 98fa0bfb0fd2 7 months ago 445MB
hyperledger/fabric-peer 2.3 a491b5ab42f6 7 months ago 53.3MB
hyperledger/fabric-peer 2.3.3 a491b5ab42f6 7 months ago 53.3MB
hyperledger/fabric-peer latest a491b5ab42f6 7 months ago 53.3MB
hyperledger/fabric-orderer 2.3 9e1952b8840d 7 months ago 35.4MB
hyperledger/fabric-orderer 2.3.3 9e1952b8840d 7 months ago 35.4MB
hyperledger/fabric-orderer latest 9e1952b8840d 7 months ago 35.4MB
hyperledger/fabric-ccenv 2.3 56fa403e02ee 7 months ago 502MB
hyperledger/fabric-ccenv 2.3.3 56fa403e02ee 7 months ago 502MB
hyperledger/fabric-ccenv latest 56fa403e02ee 7 months ago 502MB
######################## 报错,重新执行 ######################
[fabric@localhost scripts]$ ./bootstrap.sh
Pull Hyperledger Fabric docker images
FABRIC_IMAGES: peer orderer ccenv tools baseos
===> Pulling fabric Images
====> hyperledger/fabric-peer:2.3.3
2.3.3: Pulling from hyperledger/fabric-peer
Digest: sha256:fc9a143aaf528e407817baf658aff3b258f632464ad32bcfd0d17054b352b782
Status: Image is up to date for hyperledger/fabric-peer:2.3.3
====> hyperledger/fabric-orderer:2.3.3
2.3.3: Pulling from hyperledger/fabric-orderer
Digest: sha256:e5192e8619b9b0abd03ec6ce8babe65493d7db7e71faee3c1c8714bddf19b507
Status: Image is up to date for hyperledger/fabric-orderer:2.3.3
====> hyperledger/fabric-ccenv:2.3.3
2.3.3: Pulling from hyperledger/fabric-ccenv
Digest: sha256:e95a727aed88456b496a4e4b1ddbc77e81c26a0cc7ff234c7d3d085dafd637cd
Status: Image is up to date for hyperledger/fabric-ccenv:2.3.3
====> hyperledger/fabric-tools:2.3.3
2.3.3: Pulling from hyperledger/fabric-tools
Digest: sha256:634c66833a264939b9920cfa0a47b028c20b39475d0bc7ca02841137ea2c4e86
Status: Image is up to date for hyperledger/fabric-tools:2.3.3
====> hyperledger/fabric-baseos:2.3.3
2.3.3: Pulling from hyperledger/fabric-baseos
a0d0a0d46f8b: Already exists
48d00a7269f1: Already exists
7fe902e02eda: Already exists
Digest: sha256:3af16c343deaa5b837e2581b6b72523643e8572fd2981ed6bfea4a9fbf43bd20
Status: Downloaded newer image for hyperledger/fabric-baseos:2.3.3
===> Pulling fabric ca Image
====> hyperledger/fabric-ca:1.5.2
1.5.2: Pulling from hyperledger/fabric-ca
a0d0a0d46f8b: Already exists
ac8258c0aeb1: Pull complete
6c802cf1fa97: Pull complete
Digest: sha256:faa3b743d9ed391c30f518a7cc1168160bf335f3bf60ba6aaaf1aa49c1ed023e
Status: Downloaded newer image for hyperledger/fabric-ca:1.5.2
===> List out hyperledger docker images
hyperledger/fabric-ca 1.5 4ea287b75c63 7 months ago 69.8MB
hyperledger/fabric-ca 1.5.2 4ea287b75c63 7 months ago 69.8MB
hyperledger/fabric-ca latest 4ea287b75c63 7 months ago 69.8MB
hyperledger/fabric-tools 2.3 98fa0bfb0fd2 7 months ago 445MB
hyperledger/fabric-tools 2.3.3 98fa0bfb0fd2 7 months ago 445MB
hyperledger/fabric-tools latest 98fa0bfb0fd2 7 months ago 445MB
hyperledger/fabric-peer 2.3 a491b5ab42f6 7 months ago 53.3MB
hyperledger/fabric-peer 2.3.3 a491b5ab42f6 7 months ago 53.3MB
hyperledger/fabric-peer latest a491b5ab42f6 7 months ago 53.3MB
hyperledger/fabric-orderer 2.3 9e1952b8840d 7 months ago 35.4MB
hyperledger/fabric-orderer 2.3.3 9e1952b8840d 7 months ago 35.4MB
hyperledger/fabric-orderer latest 9e1952b8840d 7 months ago 35.4MB
hyperledger/fabric-ccenv 2.3 56fa403e02ee 7 months ago 502MB
hyperledger/fabric-ccenv 2.3.3 56fa403e02ee 7 months ago 502MB
hyperledger/fabric-ccenv latest 56fa403e02ee 7 months ago 502MB
hyperledger/fabric-baseos 2.3 b35a8ef578c0 7 months ago 6.87MB
hyperledger/fabric-baseos 2.3.3 b35a8ef578c0 7 months ago 6.87MB
hyperledger/fabric-baseos latest b35a8ef578c0 7 months ago 6.87MB
[fabric@localhost scripts]$
fabric二进制文件地址
hyperledger-fabric-linux-amd64-2.3.3.tar.gz
fabric-ca二进制文件地址
hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
五.使用Fabric的测试网络
## 进入fabric-samples的test-network目录
[fabric@localhost hyperledger]$ cd fabric-samples/test-network/
## 启动
[fabric@localhost test-network]$ ./network.sh up
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.3.3
DOCKER_IMAGE_VERSION=2.3.3
/home/fabric/go/src/github.com/hyperledger/fabric-samples/bin/cryptogen
Generating certificates using cryptogen tool
Creating Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Creating Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Creating Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generating CCP files for Org1 and Org2
Creating network "net_test" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating peer0.org2.example.com ... done
Creating orderer.example.com ... done
Creating peer0.org1.example.com ... done
Creating cli ... done
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33e9464f63e2 hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli
e7325d57f7b5 hyperledger/fabric-peer:latest "peer node start" 5 seconds ago Up 1 second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com
da7e82926c88 hyperledger/fabric-peer:latest "peer node start" 5 seconds ago Up 1 second 0.0.0.0:7051->7051/tcp peer0.org1.example.com
361537c6d991 hyperledger/fabric-orderer:latest "orderer" 5 seconds ago Up 2 seconds 0.0.0.0:7050->7050/tcp, 0.0.0.0:7053->7053/tcp orderer.example.com
## 查看运行的容器
[fabric@localhost test-network]$ docker ps -a
## 停止
[fabric@localhost test-network]$ ./network.sh down
六.补充
go代理设置(如需要)
go env -w GOPROXY=https://goproxy.cn
export GOPROXY=https://goproxy.cn