在搭建网络前,我们需要先安装Fabric 1.4的Docker镜像,Ubuntu系统的安装请参考以下教程:
[Ubuntu] Hyperledger Fabric 1.4 Docker 简便安装教程
这篇博客不局限于某一个特定系统,将会演示搭建如下内容:
ca.example.com
org.example.com
和用于orderer的example.com
orderer.example.com
peer0.org.example.com
peer1.org.example.com
我们将证书存放于~/fabric-ca-server/certs
目录下。
创建~/fabric-ca-server/crypto-config.yaml
文件,写入如下内容:
OrdererOrgs:
- Name: Orderer
Domain: example.com
Specs:
- Hostname: orderer
PeerOrgs:
- Name: Org
Domain: org.example.com
Template:
Count: 2
使用如下命令生成证书:
cd ~/fabric-ca-server
cryptogen generate --config=crypto-config.yaml --output ./certs
certs
文件夹目录较多,包含了CA、org、peer、Admin的证书,执行以下指令:
ls certs/peerOrganizations/org.example.com/ca
a9974248d4786756e919916795cb69b2889c56e4575d31c15af27b4d2927afde_sk ca.org.example.com-cert.pem
a9974248d4786756e919916795cb69b2889c56e4575d31c15af27b4d2927afde_sk
的文件名不是固定的,搭建CA时的配置文件需要修改成对应的文件名。
我们将把CA服务器部署在~/fabric-ca-server
目录下。
首先创建并进入这一目录:
mkdir ~/fabric-ca-server
cd ~/fabric-ca-server
使用以下配置文件,用户名为master
,密码为master
,FABRIC_CA_SERVER_CA_KEYFILE
需要根据文件名进行修改:
version: '2'
networks:
basic:
services:
ca.example.com:
image: hyperledger/fabric-ca
container_name: ca.example.com
ports:
- "7054:7054"
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.example.com
- FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org.example.com-cert.pem
- FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/a9974248d4786756e919916795cb69b2889c56e4575d31c15af27b4d2927afde_sk
volumes:
- ./fabric-ca-server:/etc/hyperledger/fabric-ca-server
- ./certs/peerOrganizations/org.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
command: sh -c 'fabric-ca-server start -b master:master'
networks:
- basic
将这一文件命名为docker-compose.yml
,并保存,执行以下命令将会启动一个运行在Docker容器中的CA服务器,如果需要前台运行,请移除-d
参数:
docker-compose up -d
使用管理员凭据连接CA服务器:
fabric-ca-client enroll -u http://master:master@localhost:7054
使用如下命令逐层创建orgorg.example.com
:
fabric-ca-client affiliation add com
fabric-ca-client affiliation add com.example
fabric-ca-client affiliation add com.example.org
可以使用以下命令查看org列表:
fabric-ca-client affiliation list
affiliation: .
affiliation: com
affiliation: com.example
affiliation: com.example.org
orderer将存放于~/fabric-orderer
目录,~/fabric-orderer/docker-compose.yml
写入如下内容:
version: '2'
networks:
basic:
services:
orderer.example.com:
container_name: orderer.example.com
image: hyperledger/fabric-orderer
environment:
- FABRIC_LOGGING_SPEC=info
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
command: orderer
ports:
- 7050:7050
volumes:
- ~/fabric-ca-server/certs/ordererOrganizations/example.com/orderers/orderer.example.com/:/etc/hyperledger/msp/orderer
networks:
- basic
使用如下命令启动orderer:
docker-compose up -d
peer0将存放于~/fabric-peer0
目录,~/fabric-peer0/docker-compose.yml
写入如下内容:
version: '2'
networks:
basic:
services:
peer0.org.example.com:
container_name: peer0.org.example.com
image: hyperledger/fabric-peer
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_PEER_ID=peer0.org.example.com
- FABRIC_LOGGING_SPEC=info
- CORE_CHAINCODE_LOGGING_LEVEL=info
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_ADDRESS=peer0.org.example.com:7051
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start
ports:
- 7051:7051
volumes:
- /var/run/:/host/var/run/
- ~/fabric-ca-server/certs/peerOrganizations/org.example.com/peers/peer0.org.example.com/msp:/etc/hyperledger/msp/peer
networks:
- basic
使用如下命令启动orderer:
docker-compose up -d
peer1同理即可。
可以使用以下命令查看Docker正在运行的容器:
docker ps -a
关闭时使用以下命令:
docker-compose down
【视频】超级账本HyperLedger:Fabric-CA的使用演示(两个组织一个Orderer三个Peer)
https://www.lijiaocn.com/项目/2018/05/04/fabric-ca-example.html
超级账本HyperLedger:FabricCA的基本概念与用法讲解
https://www.lijiaocn.com/项目/2018/04/27/hyperledger-fabric-ca-usage.html
【视频】超级账本HyperLedger:Fabric的全手动、多服务器部署教程
https://www.lijiaocn.com/项目/2018/04/26/hyperledger-fabric-deploy.html