1、安装Go并设置环境变量
# go 正常安装 且 环境变量设置成功正确
$ yum install -y golang
# 创建目录
$ mkdir -p /opt/gopath/src
$ mkdir -p /opt/gopath/bin
# 修改文件:
$ vim /etc/profile
# 在profile文件中设置
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/opt/gopath
export PATH=$PATH:$GOPATH/bin
# 导出环境变量
$ source /etc/profile
2、fabric
- 下载fabric源码
$ cd $GOPATH/../src
$ mkdir -p github.com/hyperledger
$ cd github.com/hyperledger
$ git clone git@github.com:hyperledger/fabric.git
$ cd fabric
$ git checkout release-1.0
- 安装cryptogen、configtxgen
# 生成(安装) cryptogen至$GOPATH/bin目录下
$ cd common/tools/cryptogen
$ go install --tags=nopkcs11
# 生成(安装)configtxgen至$GOPATH/bin目录下
$ cd common/configtx/tool/configtxgen
$ go install --tags=nopkcs11
# 查看
$ cd $GOPATH/bin
$ ll
# $GOPATH/目录下内容
-rwxr-xr-x. 1 root root 16171339 Mar 25 01:08 configtxgen
-rwxr-xr-x. 1 root root 8633543 Mar 25 01:09 cryptogen
3、fabric-samples
- 下载并执行相关操作
$ cd $GOPATH/src/github.com/hyperledger
$ git clone git@github.com:hyperledger/fabric-samples.git
$ cd fabric-samples/
# 因为fabric使用的是release-1.0版本,这里也使保持一样
$ git checkout release-1.0
$ cd first-network
# 生成证书、创世区块。。。
# 注意:这里的参数-i 1.0.0特别重要,以为之前我们fabric和fabirc-sample都是1.0版本,
# cryptogen和configtxgen都是基于release1.0版本编译安装的,这里的fabric镜像也得是1.0.0
$ ./byfn.sh -m generate -c mychannel -s couchdb -i 1.0.0
# 确认 y
- 脚本执行结果如下
Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10'
Continue (y/n)? y
proceeding ...
/opt/gopath/bin/cryptogen
##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
org1.example.com
org2.example.com
/opt/gopath/bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
2020-03-25 01:40:10.342 CST [common/configtx/tool] main -> INFO 001 Loading configuration
2020-03-25 01:40:10.361 CST [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block
2020-03-25 01:40:10.362 CST [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block
#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2020-03-25 01:40:10.375 CST [common/configtx/tool] main -> INFO 001 Loading configuration
2020-03-25 01:40:10.378 CST [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2020-03-25 01:40:10.378 CST [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx
#################################################################
####### 生成组织锚节点,是每个组织对外的节点 ##########
####### Generating anchor peer update for Org1MSP ##########
#################################################################
2020-03-25 01:40:10.392 CST [common/configtx/tool] main -> INFO 001 Loading configuration
2020-03-25 01:40:10.395 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2020-03-25 01:40:10.395 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
2020-03-25 01:40:10.431 CST [common/configtx/tool] main -> INFO 001 Loading configuration
2020-03-25 01:40:10.434 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2020-03-25 01:40:10.434 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
4、了解first-network项目
first-network项目文件介绍
drwxr-xr-x. 6 root root 4096 Mar 25 01:40 .
drwxr-xr-x. 11 root root 257 Mar 25 01:23 ..
# 是docker-compose 的公共服务
drwxr-xr-x. 2 root root 60 Mar 25 01:23 base
# 启动脚本
-rwxr-xr-x. 1 root root 15108 Mar 25 01:23 byfn.sh
drwxr-xr-x. 2 root root 111 Mar 25 01:40 channel-artifacts
-rw-r--r--. 1 root root 5013 Mar 25 01:23 configtx.yaml
drwxr-xr-x. 4 root root 59 Mar 25 01:40 crypto-config
-rw-r--r--. 1 root root 3858 Mar 25 01:23 crypto-config.yaml
# docker-compose文件,用于启动网络
-rw-r--r--. 1 root root 3015 Mar 25 01:23 docker-compose-cli.yaml
-rw-r--r--. 1 root root 4604 Mar 25 01:23 docker-compose-couch.yaml
-rw-r--r--. 1 root root 2883 Mar 25 01:21 docker-compose-e2e-template.yaml
-rw-r--r--. 1 root root 3091 Mar 25 01:40 docker-compose-e2e.yaml
# 存储环境变量
-rw-r--r--. 1 root root 42 Mar 25 01:21 .env
-rw-r--r--. 1 root root 335 Mar 25 01:21 README.md
# 存储测试脚本(创建通道,加入通道,安装链码,实例化链码,链码交互工作)
drwxr-xr-x. 2 root root 23 Mar 25 01:23 scripts
了解生成的配置文件目录
$ cd /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/crypto-config
# 查看
$ ll
# 配置文件,按组织分目录
drwxr-xr-x. 3 root root 25 Mar 25 01:40 ordererOrganizations
drwxr-xr-x. 4 root root 54 Mar 25 01:40 peerOrganizations
# 1、查看排序组织
$ cd ordererOrganizations
# 查看,有一个排序节点
drwxr-xr-x. 7 root root 69 Mar 25 01:40 example.com
$ cd example.com
# 查看
drwxr-xr-x. 2 root root 112 Mar 25 01:40 ca
drwxr-xr-x. 5 root root 57 Mar 25 01:40 msp
drwxr-xr-x. 3 root root 33 Mar 25 01:40 orderers
drwxr-xr-x. 2 root root 115 Mar 25 01:40 tlsca
drwxr-xr-x. 3 root root 31 Mar 25 01:40 users
# 2、查看peer组织
# 回到first-network/crypto-config目录
$ cd peerOrganizations
# 查看,有2个组织
drwxr-xr-x. 7 root root 66 Mar 25 01:40 org1.example.com
drwxr-xr-x. 7 root root 66 Mar 25 01:40 org2.example.com
$ cd org1.example.com
# 查看
drwxr-xr-x. 2 root root 117 Mar 25 01:40 ca
drwxr-xr-x. 5 root root 57 Mar 25 01:40 msp
drwxr-xr-x. 4 root root 66 Mar 25 01:40 peers
drwxr-xr-x. 2 root root 120 Mar 25 01:40 tlsca
drwxr-xr-x. 4 root root 66 Mar 25 01:40 users
了解创建的通道(channel)目录
# 先回到first-network/
$ cd channel-artifacts
# 查看当前目录,tree
.
├── channel.tx
├── genesis.block
├── Org1MSPanchors.tx
└── Org2MSPanchors.tx
0 directories, 4 files