前言
前段时间根据官方文档梳理了 Frabic CA 部署流程 ,今天试着使用 Docker 在本地搭建 CA 网络。
实验过程
实验环境
Ubuntu 18.04.5 Desktop
- Docker version 19.03.12
- Docker Compose version 1.26.2
- Go version go1.15.1
拓扑结构
TLS CA
Org0:
Org1:
Org2:
准备工作
-
安装 docker、docker-compose、golang,按照各个官方的教程安装即可
-
创建临时目录 ~\fabric-network
,用于存放文件
1
| mkdir fabric-network && cd fabric-network
|
- 安装 fabric-ca-client
使用以下方法安装时总是失败x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| sudo apt install libtool libltdl-dev
go env -w GO111MODULE=on
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
go env | grep GOPROXY
go get -u github.com/hyperledger/fabric-ca/cmd/fabric-ca-client
|
直接下载压缩包解压(无 configtxgen 工具)
1 2 3 4 5
| wget https://github.com/hyperledger/fabric-ca/releases/download/v1.4.0/hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz
sudo tar -C /usr/local -xzf hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz
|
推荐方法
1 2 3 4 5
| wget https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh chmod +x bootstrap.sh
export PATH=/home/jck/fabric-network/fabric-samples/bin:$PATH
|
- docker-compose.yaml
官方提供的 docker-compose.rst 需要进行格式化和重命名。
本实验中整合的 docker-compose.yaml ,根据 container_name 按需启动容器
1
| docker-compose up -d container_name
|
TLS CA
搭建 TLS CA
1 2
| docker-compose up -d ca-tls
|
启动容器后完成初始化
- 生成配置文件
fabric-ca-server-config.yaml
- 生成公私钥
- 公钥证书
ca-cert.pem
- 私钥
/msp/keystore/*_sk
- 初始化数据库
fabric-ca-server.db
- 注册管理员账户(
tls-ca-admin:tls-ca-adminpw
)
登记 TLS CA 管理员
登记(Enroll)后获得 TLS CA 的根证书,以及 TLS CA 返回的公私钥。docker-compose 启动容器时在本地创建的文件夹是 root 权限,直接用 sudo
可以执行但比较麻烦,这里进行权限更改。
1 2 3 4 5 6 7 8 9 10 11
| sudo chown jck /tmp/hyperledger/
export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/fabric-ca-tls/admin
fabric-ca-client enroll -d -u https://tls-ca-admin:tls-ca-adminpw@0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
|
向 TLS CA 进行注册
为各个组织的节点向 TLS CA 进行注册
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| fabric-ca-client register -d --id.name peer1-org1 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
fabric-ca-client register -d --id.name peer2-org1 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
fabric-ca-client register -d --id.name peer1-org2 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
fabric-ca-client register -d --id.name peer2-org2 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
fabric-ca-client register -d --id.name orderer1-org0 --id.secret ordererPW --id.type orderer -u https://0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
fabric-ca-client register -d --id.name admin-org0 --id.secret org0AdminPW --id.type admin -u https://0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
fabric-ca-client register -d --id.name admin-org1 --id.secret org1AdminPW --id.type admin -u https://0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
fabric-ca-client register -d --id.name admin-org2 --id.secret org2AdminPW --id.type admin -u https://0.0.0.0:7052 --tls.certfiles /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem
|
ORG CA
搭建 ORG CA
和搭建 TLS CA 的方法如出一辙,容器启动后完成初始化工作
1
| docker-compose up -d org0 org1 org2
|
登记 ORG CA 管理员 | 向 ORG CA 进行注册
各个组织中的节点需要向组织 CA 进行注册
Org0
Org0 包含一个 Admin 节点和一个 Order 节点
1 2 3 4 5 6 7 8 9 10 11 12 13
|
export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/ca/crypto/ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/ca/admin
fabric-ca-client enroll -d -u https://org0-admin:org0-adminpw@0.0.0.0:7053 --tls.certfiles /tmp/hyperledger/org0/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name orderer1-org0 --id.secret ordererpw --id.type orderer -u https://0.0.0.0:7053 --tls.certfiles /tmp/hyperledger/org0/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name admin-org0 --id.secret org0adminpw --id.type admin --id.attrs "hf.Registrar.Roles=client,hf.Registrar.Attributes=*,hf.Revoker=true,hf.GenCRL=true,admin=true:ecert,abac.init=true:ecert" -u https://0.0.0.0:7053 --tls.certfiles /tmp/hyperledger/org0/ca/crypto/ca-cert.pem
|
Org1
Org1 包含一个 Admin 节点、一个 User 节点以及两个 Peer 节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/ca/crypto/ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/ca/admin
fabric-ca-client enroll -d -u https://org1-admin:org1-adminpw@0.0.0.0:7054 --tls.certfiles /tmp/hyperledger/org1/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name peer1-org1 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7054 --tls.certfiles /tmp/hyperledger/org1/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name peer2-org1 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7054 --tls.certfiles /tmp/hyperledger/org1/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name admin-org1 --id.secret org1AdminPW --id.type admin -u https://0.0.0.0:7054 --tls.certfiles /tmp/hyperledger/org1/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name user-org1 --id.secret org1UserPW --id.type client -u https://0.0.0.0:7054 --tls.certfiles /tmp/hyperledger/org1/ca/crypto/ca-cert.pem
|
Org2
Org2 包含一个 Admin 节点、一个 User 节点以及两个 Peer 节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/ca/crypto/ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/ca/admin
fabric-ca-client enroll -d -u https://org2-admin:org2-adminpw@0.0.0.0:7055 --tls.certfiles /tmp/hyperledger/org2/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name peer1-org2 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7055 --tls.certfiles /tmp/hyperledger/org2/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name peer2-org2 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7055 --tls.certfiles /tmp/hyperledger/org2/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name admin-org2 --id.secret org2AdminPW --id.type admin -u https://0.0.0.0:7055 --tls.certfiles /tmp/hyperledger/org2/ca/crypto/ca-cert.pem
fabric-ca-client register -d --id.name user-org2 --id.secret org2UserPW --id.type client -u https://0.0.0.0:7055 --tls.certfiles /tmp/hyperledger/org2/ca/crypto/ca-cert.pem
|
Org1
Org1-Peer1
向 Org1 CA 进行登记,获得所属组织的 ORG CA 证书
1 2 3 4 5 6 7 8 9 10 11
| mkdir -p /tmp/hyperledger/org1/peer1/assets/ca/ cp /tmp/hyperledger/org1/ca/crypto/ca-cert.pem /tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/peer1 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem export FABRIC_CA_CLIENT_MSPDIR=msp
fabric-ca-client enroll -d -u https://peer1-org1:peer1PW@0.0.0.0:7054 --tls.certfiles /tmp/hyperledger/org1/ca/crypto/ca-cert.pem
|
向 TLS CA 进行登记,获得 TLS 证书
1 2 3 4 5 6 7 8 9 10 11 12 13
| mkdir -p /tmp/hyperledger/org1/peer1/assets/tls-ca cp /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem /tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem
export FABRIC_CA_CLIENT_MSPDIR=tls-msp export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem
fabric-ca-client enroll -d -u https://peer1-org1:peer1PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer1-org1 --tls.certfiles /tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem
mv /tmp/hyperledger/org1/peer1/tls-msp/keystore/*_sk /tmp/hyperledger/org1/peer1/tls-msp/keystore/key.pem
|
Org1-Peer2
向 Org1 CA 进行登记,获得所属组织的 ORG CA 证书
1 2 3 4 5 6 7 8 9 10 11
| mkdir -p /tmp/hyperledger/org1/peer2/assets/ca/ cp /tmp/hyperledger/org1/ca/crypto/ca-cert.pem /tmp/hyperledger/org1/peer2/assets/ca/org1-ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/peer2 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer2/assets/ca/org1-ca-cert.pem export FABRIC_CA_CLIENT_MSPDIR=msp
fabric-ca-client enroll -d -u https://peer2-org1:peer2PW@0.0.0.0:7054 --tls.certfiles /tmp/hyperledger/org1/ca/crypto/ca-cert.pem
|
向 TLS CA 进行登记,获得 TLS 证书
1 2 3 4 5 6 7 8 9 10 11 12 13
| mkdir -p /tmp/hyperledger/org1/peer2/assets/tls-ca/ cp /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem /tmp/hyperledger/org1/peer2/assets/tls-ca/tls-ca-cert.pem
export FABRIC_CA_CLIENT_MSPDIR=tls-msp export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer2/assets/tls-ca/tls-ca-cert.pem
fabric-ca-client enroll -d -u https://peer2-org1:peer2PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer2-org1 --tls.certfiles /tmp/hyperledger/org1/peer2/assets/tls-ca/tls-ca-cert.pem
mv /tmp/hyperledger/org1/peer2/tls-msp/keystore/*_sk /tmp/hyperledger/org1/peer2/tls-msp/keystore/key.pem
|
Org1 Admin
向 Org1 CA 进行登记,获得所属组织的 ORG CA 证书
1 2 3 4 5 6 7
| export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/admin export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem export FABRIC_CA_CLIENT_MSPDIR=msp
fabric-ca-client enroll -d -u https://admin-org1:org1AdminPW@0.0.0.0:7054 --tls.certfiles /tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem
|
向 TLS CA 进行登记,获得 TLS 证书
1 2 3 4 5 6
| export FABRIC_CA_CLIENT_MSPDIR=tls-msp export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem
fabric-ca-client enroll -d -u https://admin-org1:org1AdminPW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts admin-org1 --tls.certfiles /tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem
|
创建 admincerts 文件夹,并复制证书。官方文档 有给出创建本地 MSP 需要包含的文件夹,admincerts 是必须有的。
1 2 3 4 5
| mkdir /tmp/hyperledger/org1/peer1/msp/admincerts cp /tmp/hyperledger/org1/admin/msp/signcerts/cert.pem /tmp/hyperledger/org1/peer1/msp/admincerts/org1-admin-cert.pem
mkdir /tmp/hyperledger/org1/peer2/msp/admincerts cp /tmp/hyperledger/org1/admin/msp/signcerts/cert.pem /tmp/hyperledger/org1/peer2/msp/admincerts/org1-admin-cert.pem
|
Org2
Org2-Peer1
向 Org2 CA 进行登记,获得所属组织的 ORG CA 证书
1 2 3 4 5 6 7 8 9 10 11
| mkdir -p /tmp/hyperledger/org2/peer1/assets/ca cp /tmp/hyperledger/org2/ca/crypto/ca-cert.pem /tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/peer1 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem export FABRIC_CA_CLIENT_MSPDIR=msp
fabric-ca-client enroll -d -u https://peer1-org2:peer1PW@0.0.0.0:7055 --tls.certfiles /tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem
|
向 TLS CA 进行登记,获得 TLS 证书
1 2 3 4 5 6 7 8 9 10 11 12 13
| mkdir /tmp/hyperledger/org2/peer1/assets/tls-ca cp /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem /tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem
export FABRIC_CA_CLIENT_MSPDIR=tls-msp export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem
fabric-ca-client enroll -d -u https://peer1-org2:peer1PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer1-org2 --tls.certfiles /tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem
mv /tmp/hyperledger/org2/peer1/tls-msp/keystore/*_sk /tmp/hyperledger/org2/peer1/tls-msp/keystore/key.pem
|
Org2-Peer2
向 Org2 CA 进行登记,获得所属组织的 ORG CA 证书
1 2 3 4 5 6 7 8 9 10 11
| mkdir -p /tmp/hyperledger/org2/peer2/assets/ca cp /tmp/hyperledger/org2/ca/crypto/ca-cert.pem /tmp/hyperledger/org2/peer2/assets/ca/org2-ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/peer2 export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer2/assets/ca/org2-ca-cert.pem export FABRIC_CA_CLIENT_MSPDIR=msp
fabric-ca-client enroll -d -u https://peer2-org2:peer2PW@0.0.0.0:7055 --tls.certfiles /tmp/hyperledger/org2/peer2/assets/ca/org2-ca-cert.pem
|
向 TLS CA 进行登记,获得 TLS 证书
1 2 3 4 5 6 7 8 9 10 11 12 13
| mkdir /tmp/hyperledger/org2/peer2/assets/tls-ca cp /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem /tmp/hyperledger/org2/peer2/assets/tls-ca/tls-ca-cert.pem
export FABRIC_CA_CLIENT_MSPDIR=tls-msp export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer2/assets/tls-ca/tls-ca-cert.pem
fabric-ca-client enroll -d -u https://peer2-org2:peer2PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer2-org2 --tls.certfiles /tmp/hyperledger/org2/peer2/assets/tls-ca/tls-ca-cert.pem
mv /tmp/hyperledger/org2/peer2/tls-msp/keystore/*_sk /tmp/hyperledger/org2/peer2/tls-msp/keystore/key.pem
|
Org2 Admin
向 Org2 CA 进行登记,获得所属组织的 ORG CA 证书
1 2 3 4 5 6 7
| export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/admin export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem export FABRIC_CA_CLIENT_MSPDIR=msp
fabric-ca-client enroll -d -u https://admin-org2:org2AdminPW@0.0.0.0:7055 --tls.certfiles /tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem
|
向 TLS CA 进行登记,获得 TLS 证书
1 2 3 4 5 6
| export FABRIC_CA_CLIENT_MSPDIR=tls-msp export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem
fabric-ca-client enroll -d -u https://admin-org2:org2AdminPW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts admin-org2 --tls.certfiles /tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem
|
创建 admincerts 文件夹,并复制证书
1 2 3 4 5
| mkdir /tmp/hyperledger/org2/peer1/msp/admincerts cp /tmp/hyperledger/org2/admin/msp/signcerts/cert.pem /tmp/hyperledger/org2/peer1/msp/admincerts/org2-admin-cert.pem
mkdir /tmp/hyperledger/org2/peer2/msp/admincerts cp /tmp/hyperledger/org2/admin/msp/signcerts/cert.pem /tmp/hyperledger/org2/peer2/msp/admincerts/org2-admin-cert.pem
|
启动 Peer 节点
1
| docker-compose up -d peer1-org1 peer2-org1 peer1-org2 peer2-org2
|
Org0
Org0-Order
向 Org0 CA 进行登记,获得所属组织的 ORG CA 证书
1 2 3 4 5 6 7 8 9 10 11
| mkdir -p /tmp/hyperledger/org0/orderer/assets/ca/ cp /tmp/hyperledger/org0/ca/crypto/ca-cert.pem /tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem
export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/orderer export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem export FABRIC_CA_CLIENT_MSPDIR=msp
fabric-ca-client enroll -d -u https://orderer1-org0:ordererpw@0.0.0.0:7053 --tls.certfiles /tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem
|
向 TLS CA 进行登记,获得 TLS 证书
1 2 3 4 5 6 7 8 9 10 11 12 13
| mkdir /tmp/hyperledger/org0/orderer/assets/tls-ca/ cp /tmp/hyperledger/fabric-ca-tls/crypto/ca-cert.pem /tmp/hyperledger/org0/orderer/assets/tls-ca/tls-ca-cert.pem
export FABRIC_CA_CLIENT_MSPDIR=tls-msp export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/tls-ca/tls-ca-cert.pem
fabric-ca-client enroll -d -u https://orderer1-org0:ordererPW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts orderer1-org0 --tls.certfiles /tmp/hyperledger/org0/orderer/assets/tls-ca/tls-ca-cert.pem
mv /tmp/hyperledger/org0/orderer/tls-msp/keystore/*_sk /tmp/hyperledger/org0/orderer/tls-msp/keystore/key.pem
|
Org0 Admin
向 Org0 CA 进行登记,获得所属组织的 ORG CA 证书
1 2 3 4 5 6 7
| export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/admin export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem export FABRIC_CA_CLIENT_MSPDIR=msp
fabric-ca-client enroll -d -u https://admin-org0:org0adminpw@0.0.0.0:7053 --tls.certfiles /tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem
|
向 TLS CA 进行登记,获得 TLS 证书
1 2 3 4 5 6
| export FABRIC_CA_CLIENT_MSPDIR=tls-msp export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem
fabric-ca-client enroll -d -u https://admin-org0:org0AdminPW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts admin-org0 --tls.certfiles /tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem
|
创建 admincerts 文件夹,并复制证书
1 2
| mkdir /tmp/hyperledger/org0/orderer/msp/admincerts cp /tmp/hyperledger/org0/admin/msp/signcerts/cert.pem /tmp/hyperledger/org0/orderer/msp/admincerts/orderer-admin-cert.pem
|
配置 MSP & 交易通道 & 创世区块
添加配置文件
在 Org0,Org1, Org2 所有 msp 目录下添加 config.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| NodeOUs: Enable: true ClientOUIdentifier: Certificate: cacerts/0-0-0-0-7053.pem OrganizationalUnitIdentifier: client PeerOUIdentifier: Certificate: cacerts/0-0-0-0-7053.pem OrganizationalUnitIdentifier: peer AdminOUIdentifier: Certificate: cacerts/0-0-0-0-7053.pem OrganizationalUnitIdentifier: admin OrdererOUIdentifier: Certificate: cacerts/0-0-0-0-7053.pem OrganizationalUnitIdentifier: orderer
|
创建后复制到相应文件夹
1 2 3 4 5 6
| cd /tmp/hyperledger touch config.yaml
echo org0/admin/msp org0/orderer/msp | xargs -n 1 cp config.yaml echo org1/admin/msp org1/peer1/msp org1/peer2/msp | xargs -n 1 cp config.yaml echo org2/admin/msp org2/peer1/msp org2/peer2/msp | xargs -n 1 cp config.yaml
|
msp 配置
整理文件夹,全部整合到 /tmp/hyperledger/configtx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| mkdir -p /tmp/hyperledger/configtx && cd /tmp/hyperledger/configtx mkdir org0 cp -r ../org0/admin/msp org0/
cd org0/msp mkdir tlscacerts && cd tlscacerts cp /tmp/hyperledger/org0/orderer/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem ./
cd /tmp/hyperledger/configtx mkdir org1 cp -r ../org1/admin/msp org1/
cd org1/msp mkdir tlscacerts && cd tlscacerts cp /tmp/hyperledger/org1/admin/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem ./
cd /tmp/hyperledger/configtx mkdir org2 cp -r ../org2/admin/msp org2/
cd org2/msp mkdir tlscacerts && cd tlscacerts cp /tmp/hyperledger/org2/admin/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem ./
|
目录结构如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| . ├── org0 │ └── msp │ ├── cacerts │ ├── config.yaml │ ├── IssuerPublicKey │ ├── IssuerRevocationPublicKey │ ├── keystore │ ├── signcerts │ ├── tlscacerts │ └── user ├── org1 │ └── msp │ ├── cacerts │ ├── config.yaml │ ├── IssuerPublicKey │ ├── IssuerRevocationPublicKey │ ├── keystore │ ├── signcerts │ ├── tlscacerts │ └── user └── org2 └── msp ├── cacerts ├── config.yaml ├── IssuerPublicKey ├── IssuerRevocationPublicKey ├── keystore ├── signcerts ├── tlscacerts └── user
|
创世区块和通道
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| cd /tmp/hyperledger/configtx touch configtx.yaml
cd /tmp/hyperledger/configtx mkdir system-genesis-block mkdir channel-artifacts
configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
export CHANNEL_NAME=mychannel configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/${CHANNEL_NAME}.tx -channelID ${CHANNEL_NAME}
export orgmsp=org1MSP configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/${orgmsp}anchors.tx -channelID ${CHANNEL_NAME} -asOrg ${orgmsp}
export orgmsp=org2MSP configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/${orgmsp}anchors.tx -channelID ${CHANNEL_NAME} -asOrg ${orgmsp}
|
启动 Order 节点 | 启动客户端
1
| docker-compose up -d orderer1-org0 cli-org1 cli-org2
|
创建并加入通道
Org1-CLI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| docker exec -it cli-org1 bash
export CHANNEL_NAME=mychannel export ORDERER_CA=/tmp/hyperledger/org0/orderer/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp
cd /tmp/hyperledger/configtx
peer channel create -o orderer1-org0:7050 -c ${CHANNEL_NAME} --ordererTLSHostnameOverride orderer1-org0 -f ./channel-artifacts/${CHANNEL_NAME}.tx --outputBlock ./channel-artifacts/${CHANNEL_NAME}.block --tls --cafile ${ORDERER_CA}
export CORE_PEER_ADDRESS=peer1-org1:7051 peer channel join -b ./channel-artifacts/mychannel.block
export CORE_PEER_ADDRESS=peer2-org1:7051 peer channel join -b ./channel-artifacts/mychannel.block
export CORE_PEER_LOCALMSPID=org1MSP peer channel update -o orderer1-org0:7050 --ordererTLSHostnameOverride orderer1-org0 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile $ORDERER_CA
|
Org2-CLI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| docker exec -it cli-org2 bash
export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp export CORE_PEER_ADDRESS=peer1-org2:7051 peer channel join -b ./channel-artifacts/mychannel.block
export CORE_PEER_ADDRESS=peer2-org2:7051 peer channel join -b ./channel-artifacts/mychannel.block
cd /tmp/hyperledger/configtx
export CHANNEL_NAME=mychannel export ORDERER_CA=/tmp/hyperledger/org0/orderer/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem export CORE_PEER_LOCALMSPID=org2MSP
peer channel update -o orderer1-org0:7050 --ordererTLSHostnameOverride orderer1-org0 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile $ORDERER_CA
|
链码测试
PASS
实验没有继续进行下去,整个区块链的逻辑还没捋清楚,接下来用官方的 test network 进行实验,同时学习 Fabric 区块链的整体逻辑。
总结
根据官方教程并没有好好做出来xd 一边摸索一边参照网上大佬的教程顺利做到这里。test1 和 test2 是实验中的命令整理,最终完成的实验的目录结构如下
可以理解 register 和 enroll ,目前来看 msp 和目录结构比较复杂容易混乱,弄清楚存放路径其他的操作基本上是一致的。
参阅