Hyperledger Fabric系列之二:2.2.1部署-环境搭建-Centos7
1、安装curl:# yum install curl安装成功后查看版本:# curl --version2、安装wget和xz#yum install wget xz3、安装docker和docker-compose:docker安装参照docker-ce的安装手册,它与docker-compose也有版本对应关系。这里安装的是docker-ce:18.06.3-ce,docker-compos
1、安装curl:
# yum install curl
安装成功后查看版本:
# curl --version
2、安装wget和xz
#yum install wget xz
3、安装docker和docker-compose:
docker安装参照docker-ce的安装手册,它与docker-compose也有版本对应关系。
这里安装的是docker-ce:18.06.3-ce,docker-compose version 1.29.2
安装成功后查看版本:# docker -version
curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
# 查看版本号
docker-compose -v
4、go语言环境。安装后查看版本:# go version
注意:centos7不能安装太新的go版本,
本人系统版本:CentOS Linux release 7.9.2009 (Core)
内核版本:Linux version 3.10.0-1160.el7.x86_64
GCC版本: 4.8.5 20150623 (Red Hat 4.8.5-44)
安装:GO1.17.5时运行报错,后来改装:GO1.15.15.
对应安装的Fabric版本可以是2.2.X版本,2.2的版本是个LTS版本。
装2.2.3也试也,其中在部署docker镜像时找不到nodeenv的镜像。
2.2.2版本没有linx版本的CA发行包hyperledger-fabric-ca-linux-amd64-1.4.9.tar.gz
vi /etc/profile
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=/opt/workspace/gowork
export PATH=$PATH:$GOPATH/bin
# 生效环境变量
source /etc/profile
5.、node.js运行环境以及npm。安装完后查看版本:
这里安装的是nodejs14.18.2版本,
软件包地址:https://npm.taobao.org/mirrors/node/v14.18.2/node-v14.18.2-linux-x64.tar.xz
cd /usr/local/
mkdir nodejs
cd nodejs
wget https://npm.taobao.org/mirrors/node/v14.18.2/node-v14.18.2-linux-x64.tar.xz
yum install xz
xz -d node-v14.18.2-linux-x64.tar.xz
tar -xvf node-v14.18.2-linux-x64.tar
cd node-v14.18.2-linux-x64
# 建立软连接,变为全局
ln -s /usr/local/nodejs/node-v14.18.2-linux-x64/bin/npm /usr/local/bin/
ln -s /usr/local/nodejs/node-v14.18.2-linux-x64/bin/node /usr/local/bin/
vim /etc/profile
# 以下两个路径为加入nodejs路径
export NODE_HOME=/usr/local/nodejs/node-v14.18.2-linux-x64
export PATH=$NODE_HOME/bin:$PATH
# 配置生效
source /etc/profile
node -v
6、安装git
yum install -y git
7.Fabric安装
7.1拉取源码:
mkdir -p /opt/workspace/gowork/hyperledger
cd /opt/workspace/gowork/hyperledger
git clone https://github.com/hyperledger/fabric.git
cd fabric
#切换tag
git tag
git checkout v2.2.1
7.2启动安装程序
cd scripts/
./bootstrap.sh
执行后会在当前目录多了一个fabric-samples的目录。
这里下载发行包二进制文件会经常中途断开,可以下载代码后,发行包通过用浏览器下载上传后解压,包:hyperledger-fabric-ca-linux-amd64-1.4.9.tar.gz和
hyperledger-fabric-linux-amd64-2.2.1.tar.gz
下载后把文件上传到:$GOPATH/hyperledger/fabric/scripts/fabric-samples目录下并解压
如果是手动解压还需要手装下载docker镜像
7.3手动下载docker镜像
./bootstrap.sh -sb
执行完成用docker images查看,如下图所示:
[root@bogon scripts]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hyperledger/fabric-nodeenv 2.2 8d164f92ca34 14 months ago 294MB
hyperledger/fabric-nodeenv 2.2.1 8d164f92ca34 14 months ago 294MB
hyperledger/fabric-nodeenv latest 8d164f92ca34 14 months ago 294MB
hyperledger/fabric-javaenv 2.2 f7b2f8cce0e4 15 months ago 407MB
hyperledger/fabric-javaenv 2.2.1 f7b2f8cce0e4 15 months ago 407MB
hyperledger/fabric-javaenv latest f7b2f8cce0e4 15 months ago 407MB
hyperledger/fabric-ca 1.4 dbbc768aec79 15 months ago 158MB
hyperledger/fabric-ca 1.4.9 dbbc768aec79 15 months ago 158MB
hyperledger/fabric-tools 2.2 e9b802fadb41 15 months ago 519MB
hyperledger/fabric-tools 2.2.1 e9b802fadb41 15 months ago 519MB
hyperledger/fabric-tools latest e9b802fadb41 15 months ago 519MB
hyperledger/fabric-peer 2.2 ece149884124 15 months ago 55MB
hyperledger/fabric-peer 2.2.1 ece149884124 15 months ago 55MB
hyperledger/fabric-peer latest ece149884124 15 months ago 55MB
hyperledger/fabric-orderer 2.2 78a16ddd2cf4 15 months ago 38.4MB
hyperledger/fabric-orderer 2.2.1 78a16ddd2cf4 15 months ago 38.4MB
hyperledger/fabric-orderer latest 78a16ddd2cf4 15 months ago 38.4MB
hyperledger/fabric-ccenv 2.2 8e554c280cac 15 months ago 586MB
hyperledger/fabric-ccenv 2.2.1 8e554c280cac 15 months ago 586MB
hyperledger/fabric-ccenv latest 8e554c280cac 15 months ago 586MB
hyperledger/fabric-baseos 2.2 0b99d26b26ad 15 months ago 6.85MB
hyperledger/fabric-baseos 2.2.1 0b99d26b26ad 15 months ago 6.85MB
hyperledger/fabric-baseos latest 0b99d26b26ad 15 months ago 6.85MB
7.4启动test-network测试网络:
cd ./fabric-samples/test-network
./network.sh up
如果启动报错,可以查看一下./fabric-samples/test-network/bin下的所有文件有没有执行权限
查看运行结果:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68254cfb67b3 hyperledger/fabric-tools:latest "/bin/bash" About an hour ago Up About an hour cli
5cfb42cc55ef hyperledger/fabric-peer:latest "peer node start" About an hour ago Up About an hour 0.0.0.0:7051->7051/tcp peer0.org1.example.com
210ffb713a8d hyperledger/fabric-orderer:latest "orderer" About an hour ago Up About an hour 0.0.0.0:7050->7050/tcp orderer.example.com
2c635b967e10 hyperledger/fabric-peer:latest "peer node start" About an hour ago Up About an hour 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com
至此,fabric测试网络test-network部署成功。
8.使用测试网络
8.1创建channel
使用network.sh脚本创建来一个连接org1和org2组织并加入他们peer的通道,命令如下:
./network.sh createChanne 或者:./network.sh createChanne -c channel1
-c channelName 表示通道指定名称,出现如下结尾内容表示创建成功:
2022-01-07 02:35:43.118 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-01-07 02:35:43.130 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
Anchor peer set for org 'Org2MSP' on channel 'channel1'
Channel 'channel1' joined
8.2在通道上启动链码
使用network.sh创建通道之后,可以使用以下命令在通道上启动链码(默认使用go语言):
./network.sh deployCC
可以指定语言,加-l ,比如我用java,命令如下:
./network.sh deployCC -l java
[root@bogon test-network]# ./network.sh deployCC
deploying chaincode on channel 'mychannel'
executing with the following
- CHANNEL_NAME: mychannel
- CC_NAME: NA
- CC_SRC_PATH: NA
- CC_SRC_LANGUAGE: NA
- CC_VERSION: 1.0
- CC_SEQUENCE: 1
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5
- VERBOSE: false
No chaincode name was provided. Valid call example: ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
Deploying chaincode failed
[root@bogon test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
deploying chaincode on channel 'mychannel'
executing with the following
- CHANNEL_NAME: mychannel
- CC_NAME: basic
- CC_SRC_PATH: ../asset-transfer-basic/chaincode-go
- CC_SRC_LANGUAGE: go
- CC_VERSION: 1.0
- CC_SEQUENCE: 1
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5
- VERBOSE: false
Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go
更多推荐
所有评论(0)