fabric的启动需要用到的配置文件,是采用cryptogen、configtxgen二进制工具产生的,因此,在介绍配置信息时,优先需要了解这2个工具的来源。
可见,以上2个工具的重要性;为了获得者2个工具,这边提供了2种获取方式:
前者可以通过下载源码,直接进行编译,适用于fabric的orderer、peer等都是通过下载源码直接编译获得,因此编译所需要的各种工具及配置也已经齐全,在这个前提下进行编译得到cryptogen、configtxgen很是方便;
若使用的orderer、peer等都是采用官方的hyperledger/orderer等镜像进行直接启动的,则建议直接下载对应平台、版本编译好的二进制文件。
本文采用方式2
为了快速的下载镜像、二进制文件,同样有2种方式:
为了日后存档,及多机部署,因此我采用方式2,这里提供了2种方式的下载;
方式1支持直接在Linux下通过curl命令下载;
curl -sSL https://github.com/hyperledger/fabric/blob/master/scripts/bootstrap.sh | bash -s 1.1.0
通过curl
命令下载,必须支持https
的访问,因此curl
版本低的话可能会报错,需要更新curl
。
方式2通过在windows下载后,上传到Linux服务器;
https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.1.0/hyperledger-fabric-linux-amd64-1.1.0.tar.gz
打开浏览器,输入上面下载链接进行下载,由于本机使用Linux-amd64,下载的是1.1.0版本的,下载的版本需根据你具体的系统配置相关,自行修改即可。下载后的文件名为hyperledger-fabric-linux-amd64-1.1.0.tar.gz
,通过以下解压命令得到bin目录及子文件:
tar -xzvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz
bin目录文件内容如下:
tomato@ubuntu:bin$ tree
.
|-- configtxgen
|-- configtxlator
|-- cryptogen
|-- get-docker-images.sh
|-- orderer
`-- peer
0 directories, 6 files
为了能在非bin目录正常使用上面的二进制的文件,因此需要将上面的6个文件分别创建Linux的软连接ln -s
,将目录切换到bin目录下,连接命令如下:
ln -s cryptogen /usr/bin
ln -s configtxlator /usr/bin
ln -s configtxgen /usr/bin
ln -s orderer /usr/bin
ln -s peer /usr/bin
更简便者,直接把上面的可执行文件拷贝到/usr/bin
目录下。
cryptogen命令为是便捷产生orderer、peer的证书,为后续加入channel、交易签名等提供数字签名所需要的证书。
cryptogen
为了能正常使用,需要配合crypto-config.yaml
的文件使用。该文件可以配置org、peer、orderer的节点信息进行统一管理,以下是本人的配置信息,配置了3个org机构、orderer的domain为zeuslook.com、每个机构有2个Peer节点,如果没有集合fabric-ca
,为了日后业务开展,可以生成大批量『大批机构、大批peer节点』的证书:
OrdererOrgs:
- Name: Orderer
Domain: zeuslook.com
Specs:
- Hostname: orderer
PeerOrgs:
- Name: Org1
Domain: org1.zeuslook.com
Template:
Count: 2
Users:
Count: 0
- Name: Org2
Domain: org2.zeuslook.com
Template:
Count: 2
Users:
Count: 0
- Name: Org3
Domain: org3.zeuslook.com
Template:
Count: 2
Users:
Count: 0
有了以上命令,就可以通过cryptogen
命令生成证书:
cryptogen generate --config=./crypto-config.yaml
执行了以上操作后,会在当前的crypto-config
目录下生成对应的文件,为了保证每次数据的正确性,建议每次生成时都删除掉该目录下的配置信息,新生成的文件目录结构如下:
tomato@ubuntu:crypto-config$ tree -L 4
.
|-- ordererOrganizations
| `-- zeuslook.com
| |-- ca
| | |-- 75f8eae45073bf9cab573f05e37a0914d6735ca2dc2bc49d498c3aa06f1721c4_sk
| | `-- ca.zeuslook.com-cert.pem
| |-- msp
| | |-- admincerts
| | |-- cacerts
| | `-- tlscacerts
| |-- orderers
| | `-- orderer.zeuslook.com
| |-- tlsca
| | |-- 4f4655a1be02fe2b97670f62de8674280abd13f083df61561d020b4e555b470b_sk
| | `-- tlsca.zeuslook.com-cert.pem
| `-- users
| `-- [email protected]
`-- peerOrganizations
|-- org1.zeuslook.com
| |-- ca
| | |-- 9fc5b582c08fff830c66c0b042a1c2802a36a2d1309bd4a28967e6671e6ad9d7_sk
| | `-- ca.org1.zeuslook.com-cert.pem
| |-- msp
| | |-- admincerts
| | |-- cacerts
| | `-- tlscacerts
| |-- peers
| | |-- peer0.org1.zeuslook.com
| | `-- peer1.org1.zeuslook.com
| |-- tlsca
| | |-- 55bc5fa06d887adfc18226682ef27cff90dfbe3a223e9dcb80132092d0a60a8d_sk
| | `-- tlsca.org1.zeuslook.com-cert.pem
| `-- users
| `-- [email protected]
|-- org2.zeuslook.com
| |-- ca
| | |-- 3b3a86672487e87473f6e0c6c08de392b4605de4e27a7219864a093b73972c43_sk
| | `-- ca.org2.zeuslook.com-cert.pem
| |-- msp
| | |-- admincerts
| | |-- cacerts
| | `-- tlscacerts
| |-- peers
| | |-- peer0.org2.zeuslook.com
| | `-- peer1.org2.zeuslook.com
| |-- tlsca
| | |-- 29b239e903ab70e403edf9bb89f1f5408e44c7d80550b15a4284e2db3c929d62_sk
| | `-- tlsca.org2.zeuslook.com-cert.pem
| `-- users
| `-- [email protected]
`-- org3.zeuslook.com
|-- ca
| |-- ca.org3.zeuslook.com-cert.pem
| `-- ff27fee4850d56aae2a52f008e8bad74416612c08858d0bddd80a4dca2c3cda4_sk
|-- msp
| |-- admincerts
| |-- cacerts
| `-- tlscacerts
|-- peers
| |-- peer0.org3.zeuslook.com
| `-- peer1.org3.zeuslook.com
|-- tlsca
| |-- f8c39c4f957f1830034adb5cd0b0013ac956d82c49020f6b36fcb620c9f4ccdb_sk
| `-- tlsca.org3.zeuslook.com-cert.pem
`-- users
`-- [email protected]
49 directories, 16 files
由上面信息可以看出,正确的生产了3个Org机构及每个机构下对应2个Peer节点、1个ca节点、1个Orderer节点。记住_sk
结尾的文件,后续会使用到!
恭喜你已经成功的生成了证书!
configtxgen命令是为了生成传世块及交易配置块信息,为后续Order的启动、Peer加入channel提供配置信息。
configtxgen
配合其配置文件configtx.yaml
一起使用,该配置文件可以同时配置多个属性值,我的配置文件内容如下:
Profiles:
ComposerOrdererGenesis:
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Consortiums:
ComposerConsortium:
Organizations:
- *Org1
- *Org2
ComposerChannel:
Consortium: ComposerConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: crypto-config/ordererOrganizations/zeuslook.com/msp
AdminPrincipal: Role.MEMBER
- &Org1
Name: Org1
ID: Org1MSP
MSPDir: crypto-config/peerOrganizations/org1.zeuslook.com/msp
AdminPrincipal: Role.MEMBER
AnchorPeers:
- Host: peer0.org1.zeuslook.com
Port: 7051
- &Org2
Name: Org2
ID: Org2MSP
MSPDir: crypto-config/peerOrganizations/org2.zeuslook.com/msp
AdminPrincipal: Role.MEMBER
AnchorPeers:
- Host: peer0.org2.zeuslook.com
Port: 7051
Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
- orderer.zeuslook.com:7050
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 98 MB
PreferredMaxBytes: 512 KB
Kafka:
Brokers:
- 127.0.0.1:9092
Organizations:
Application: &ApplicationDefaults
Organizations:
其中,配置选项ComposerOrdererGenesis
是为了创建orderer的创世块;配置选项ComposerChannel
是为了生成交易的配置文件tx
。现在有了configtx.yaml
的配置文件及其二进制文件configtxgen
,可以生成具体的创世块和交易配置块了。
export FABRIC_CFG_PATH=$PWD
configtxgen -profile ComposerOrdererGenesis -outputBlock ./composer-genesis.block
输出结果: tomato@ubuntu:composer$ configtxgen -profile ComposerOrdererGenesis -outputBlock ./composer-genesis.block
2018-06-04 16:42:23.360 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-06-04 16:42:23.388 CST [common/tools/configtxgen] doOutputBlock -> INFO 002 Generating genesis block
2018-06-04 16:42:23.389 CST [common/tools/configtxgen] doOutputBlock -> INFO 003 Writing genesis block
说明:configtxgen获取配置文件configtx.yaml
的配置选项ComposerOrdererGenesis
,生成创世块为composer-genesis.block
保存在当期的目录下,该文件在Orderer的启动时,需要使用到。
configtxgen -profile ComposerChannel -outputCreateChannelTx ./composer-channel.tx -channelID composerchannel
输出结果:
tomato@ubuntu:composer$ configtxgen -profile ComposerChannel -outputCreateChannelTx ./composer-channel.tx -channelID composerchannel
2018-06-04 16:43:08.538 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-06-04 16:43:08.570 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2018-06-04 16:43:08.644 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 003 Writing new channel tx
说明:
configtxgen获取配置文件configtx.yaml
的配置选项ComposerChannel
,生成交易配置块composer-channel.tx
保存在当期的目录下,该文件在创建channel时,需要使用到,从而得到通道块配置(如composer-channel.block
),peer节点再通过此通道块配置加入到具体的通道中,曾经在这里与创世块纠结、试错了许久。
composer自带了startFabric.sh
启动脚本,该命令会读取yaml的配置文件docker-compose-dev.yaml
文件。启动脚本会启动orderer、ca、2个机构的Peer、couchdb,最后通过交易配置块,创建通道composerchannel
信息,并加入该通道,成功的启动输出结果如下:
Development only script for Hyperledger Fabric control
Running 'stopFabric.sh'
FABRIC_VERSION is unset, assuming hlfv11
FABRIC_START_TIMEOUT is unset, assuming 15 (seconds)
tomato@ubuntu:fabric-dev-servers$ ./startFabric.sh
Development only script for Hyperledger Fabric control
Running 'startFabric.sh'
FABRIC_VERSION is unset, assuming hlfv11
FABRIC_START_TIMEOUT is unset, assuming 15 (seconds)
Removing peer0.org2.zeuslook.com ... done
Removing peer1.org2.zeuslook.com ... done
Removing peer0.org1.zeuslook.com ... done
Removing peer1.org1.zeuslook.com ... done
Removing ca.org2.zeuslook.com ... done
Removing ca.org1.zeuslook.com ... done
Removing orderer.zeuslook.com ... done
Removing couchdb ... done
Removing network composer_default
Creating network "composer_default" with the default driver
....
2018-06-04 09:31:45.366 UTC [msp/identity] Sign -> DEBU 005 Sign: digest: E8219E6F9ADA5651B9032E4120463B4AAC0E17205A423E0031739465CE49ABE1
2018-06-04 09:31:45.963 UTC [channelCmd] executeJoin -> INFO 006 Successfully submitted proposal to join channel
2018-06-04 09:31:45.963 UTC [main] main -> INFO 007 Exiting.....
最后的docker进程如下:
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET
b476044e84dd ca.org1.zeuslook.com 0.00% 5.43MiB / 1.925GiB 0.28% 8.76kB
39546c964030 couchdb 0.28% 92.84MiB / 1.925GiB 4.71% 27.8kB
d7aaf4b22228 ca.org2.zeuslook.com 0.00% 5.477MiB / 1.925GiB 0.28% 6.83kB
3132408986b0 orderer.zeuslook.com 0.01% 8.098MiB / 1.925GiB 0.41% 18.3kB
a6e1fd4ce4c0 peer0.org1.zeuslook.com 1.39% 40.79MiB / 1.925GiB 2.07% 797kB
165aea4a5587 peer1.org2.zeuslook.com 1.37% 29.7MiB / 1.925GiB 1.51% 8.43kB
67b95dd93a1c peer0.org2.zeuslook.com 1.46% 29.65MiB / 1.925GiB 1.50% 8.21kB
7a53d68b2db6 peer1.org1.zeuslook.com 1.59% 28.65MiB / 1.925GiB 1.45% 8.18kB