本文参考:http://www.lijiaocn.com/%E9%A1%B9%E7%9B%AE/2018/04/26/hyperledger-fabric-deploy.html  学习。

1、准备工作:

准备了两台阿里云ecs  A,B两台机器。:centOs7.2系统。

规划: 打算部署一个order节点,两个peer节点。peer分属两个不同的组织。

A机IP orderer.example.com 7050
A机IP peer0.org1.example.com
B机IP peer0.org2.example.com

1)首先将AB两台机器的hosts文件添加上面的内容。

2)两台机器安装docker:

yum install -y docker 
systemctl start docker (启动docker)

3) A机器安装go

4)启动peer 需要准备镜像,AB机器上分别执行

docker pull hyperledger/fabric-javaenv:x86_64-1.1.0
docker pull hyperledger/fabric-ccenv:x86_64-1.1.0
docker pull hyperledger/fabric-baseos:x86_64-0.4.6\

2:下载相关源码

1.创建文件夹  fabric-deploy 存放源码。

2.cd  fabric-deploy

wget 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
解压 tar -xvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz
解压完有 bin 和config两个文件夹
$ ls bin/
configtxgen configtxlator cryptogen get-byfn.sh get-docker-images.sh orderer peer $ ls config/
configtx.yaml core.yaml orderer.yaml


3.准备证书

证书的作用是确保每个节点,成员都是受认可的。证书的生成方式有两种:一种用cryptogen命令生成,一种是通过fabric-ca服务生成。因为源码自带的cyptogen,且这种方法比较简单,这里介绍cyptogen方式生成证书。

1.首先创建创建一个证书的配置文件  crypto-config.yaml,这里配置了两个组织,org1的Count是2,表示两个peer:

OrdererOrgs:
- Name: Orderer
Domain: example.com
Specs:
- Hostname: orderer
PeerOrgs:
- Name: Org1
Domain: org1.example.com 组织名称
Template:
Count: 1 peer节点数量
Users:
Count: 1 用户数量
- Name: Org2
Domain: org2.example.com
Template:
Count: 1
Users:
Count: 1

执行cyptogen 生成对应数量的证书:

./bin/cryptogen generate --config=crypto-config.yaml --output ./certs
cert目录项生成两个证书
$ ls ./certs/
ordererOrganizations peerOrganizations

  证书文件说明:

这里目录中的内容是用于orderer.example.com的,里面有两个子目录tlsmsp

$ tree certs/ordererOrganizations/example.com/orderers/orderer.example.com/
certs/ordererOrganizations/example.com/orderers/orderer.example.com/
|-- msp
| |-- admincerts
| | -- Admin@example.com-cert.pem
| |-- cacerts
| | -- ca.example.com-cert.pem
| |-- keystore
| | -- 16da15d400d4ca4b53d369b6d6e50a084d4354998c3b4d7a0934635d3907f90f_sk
| |-- signcerts
| | -- orderer.example.com-cert.pem
| -- tlscacerts
| -- tlsca.example.com-cert.pem
-- tls
|-- ca.crt
|-- server.crt
-- server.key

tls目录中的内容很好理解,它是order对外服务时使用的私钥(server.key)和证书(server.crt),ca.crt是签注这个证书的CA,需要提供给发起请求的一端。

msp中有五个目录,对区块链进行操作时需要使用这些文件。

msp/admincerts中存放的是用户证书,使用该证书的用户对orderer.example.com具有管理权限。

msp/cacerts是签署msp/signcerts中用户证书的ca,可以用来校验用户的证书:

$ cd ./certs/ordererOrganizations/example.com/orderers/orderer.example.com/msp/
$ openssl verify -CAfile ./cacerts/ca.example.com-cert.pem admincerts/Admin\@example.com-cert.pem
admincerts/Admin@example.com-cert.pem: OK

msp/keystore是orderer.example.com操作区块,进行签署时使用的的私钥。

msp/signcerts是orderer.example.com提供其它组件用来核实它的签署的公钥。

msp/tlscacerts文件与tls/ca.crt相同。

这里需要特别提到的是msp/admincerts,在使用fabric时,你可能会发现有些操作需要admin权限,例如在某个peer上安装合约。

那么管理员是如何认定的?就是看当前用户的证书是不是在msp/admincerts目录中。

这个目录中的内容目前是(版本1.1.x)启动时加载的,因此如果在里面添加或删除文件后,需要重启使用到它的组件。

ordererOrganizations/example.com/还有其它几个目录:

ca  msp  orderers  tlsca  users

orderers中存放就签名分析的每个orderer组件的证书文件。

users中存放的用户的证书文件,与orderer.example.com中内容基本相同,不过tls目录中文件名变成了client.X

$ tree ordererOrganizations/example.com/users
ordererOrganizations/example.com/users
-- Admin@example.com
|-- msp
| |-- admincerts
| | -- Admin@example.com-cert.pem
| |-- cacerts
| | -- ca.example.com-cert.pem
| |-- keystore
| | -- 1ac3b40c9ddda7e7a0f724b18faa0ce6fdf3f9e9ff5eac59e1e3f9739499ac2d_sk
| |-- signcerts
| | -- Admin@example.com-cert.pem
| -- tlscacerts
| -- tlsca.example.com-cert.pem
-- tls
|-- ca.crt
|-- client.crt
-- client.key

certs/peerOrganizations中的内容与certs/ordererOrganizations中也基本相同,只不过它里面存放的是peer要使用的证书文件。

certs目录中的文件留着备用。

2.部署文件准备

每一个peer节点都有对应的文件,为了方便,这里先在fabric-deploy下面创建一个order.example.com 的文件夹

orderer.example.com


mkdir orderer.example.com
然后把所需要的文件放进去,后面在放到对应的服务器中启动节点。另外两个peer节点做同样的操作。
1、先将order需要的证书放进去:
cp bin/orderer orderer.example.com/
2.在创建order的配置文件:orderer.example.com/orderer.yaml:
General:
LedgerType: file
ListenAddress: 0.0.0.0
ListenPort: 7050 order对应的端口号
TLS:
Enabled: true
PrivateKey: ./tls/server.key
Certificate: ./tls/server.crt
RootCAs:
- ./tls/ca.crt
# ClientAuthEnabled: false
# ClientRootCAs:
LogLevel: debug
LogFormat: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
# GenesisMethod: provisional
GenesisMethod: file
GenesisProfile: SampleInsecureSolo
GenesisFile: ./genesisblock
LocalMSPDir: ./msp
LocalMSPID: OrdererMSP
Profile:
Enabled: false
Address: 0.0.0.0:6060
BCCSP:
Default: SW
SW:
Hash: SHA2
Security: 256
FileKeyStore:
KeyStore:
FileLedger:
Location: /opt/app/fabric/orderer/data order数据文件安装的位置
Prefix: hyperledger-fabric-ordererledger
RAMLedger:
HistorySize: 1000
Kafka:
Retry:
ShortInterval: 5s
ShortTotal: 10m
LongInterval: 5m
LongTotal: 12h
NetworkTimeouts:
DialTimeout: 10s
ReadTimeout: 10s
WriteTimeout: 10s
Metadata:
RetryBackoff: 250ms
RetryMax: 3
Producer:
RetryBackoff: 100ms
RetryMax: 3
Consumer:
RetryBackoff: 2s
Verbose: false
TLS:
Enabled: false
PrivateKey:
#File: path/to/PrivateKey
Certificate:
#File: path/to/Certificate
RootCAs:
#File: path/to/RootCAs
Version:

注意,orderer将被部署在目标机器的/opt/app/fabric/orderer目录中,如果要部署在其它目录中,需要修改配置文件中路径。

这里需要用到一个data目录,存放orderer的数据:

mkdir orderer.example.com/data

peer0.org1.example.com

peer 配置跟order相似:
mkdir peer0.org1.example.com
1.复制证书文件:

先将bin/peer以及证书复制到peer0.org1.example.com目录中。

cp bin/peer peer0.org1.example.com/
cp -rf certs/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/* peer0.org1.example.com/
2.添加配置文件 core.yaml
logging:
peer: debug
cauthdsl: warning
gossip: warning
ledger: info
msp: warning
policies: warning
grpc: error
format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
peer:
id: peer0.org1.example.com
networkId: dev
listenAddress: 0.0.0.0:7051
address: 0.0.0.0:7051
addressAutoDetect: false
gomaxprocs: -1
gossip:
bootstrap: 127.0.0.1:7051
bootstrap: peer0.org1.example.com:7051
useLeaderElection: true
orgLeader: false
endpoint:
maxBlockCountToStore: 100
maxPropagationBurstLatency: 10ms
maxPropagationBurstSize: 10
propagateIterations: 1
propagatePeerNum: 3
pullInterval: 4s
pullPeerNum: 3
requestStateInfoInterval: 4s
publishStateInfoInterval: 4s
stateInfoRetentionInterval:
publishCertPeriod: 10s
skipBlockVerification: false
dialTimeout: 3s
connTimeout: 2s
recvBuffSize: 20
sendBuffSize: 200
digestWaitTime: 1s
requestWaitTime: 1s
responseWaitTime: 2s
aliveTimeInterval: 5s
aliveExpirationTimeout: 25s
reconnectInterval: 25s
externalEndpoint: peer0.org1.example.com:7051
election:
startupGracePeriod: 15s
membershipSampleInterval: 1s
leaderAliveThreshold: 10s
leaderElectionDuration: 5s
events:
address: 0.0.0.0:7053
buffersize: 100
timeout: 10ms
tls:
enabled: true
cert:
file: ./tls/server.crt
key:
file: ./tls/server.key
rootcert:
file: ./tls/ca.crt
serverhostoverride:
fileSystemPath: /opt/app/fabric/peer/data
BCCSP:
Default: SW
SW:
Hash: SHA2
Security: 256
FileKeyStore:
KeyStore:
mspConfigPath: msp
localMspId: Org1MSP
profile:
enabled: true
listenAddress: 0.0.0.0:6060
vm:
endpoint: unix:///var/run/docker.sock
docker:
tls:
enabled: false
ca:
file: docker/ca.crt
cert:
file: docker/tls.crt
key:
file: docker/tls.key
attachStdout: false
hostConfig:
NetworkMode: host
Dns:
# - 192.168.0.1
LogConfig:
Type: json-file
Config:
max-size: "50m"
max-file: "5"
Memory: 2147483648
chaincode:
peerAddress:
id:
path:
name:
builder: $(DOCKER_NS)/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
golang:
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)
car:
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)
java:
Dockerfile: |
from $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
startuptimeout: 300s
executetimeout: 30s
mode: net
keepalive: 0
system:
cscc: enable
lscc: enable
escc: enable
vscc: enable
qscc: enable
logging:
level: info
shim: warning
format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
ledger:
blockchain:
state:
stateDatabase: goleveldb
couchDBConfig:
couchDBAddress: 127.0.0.1:5984
username:
password:
maxRetries: 3
maxRetriesOnStartup: 10
requestTimeout: 35s
queryLimit: 10000
history:
enableHistoryDatabase: true

注意,peer将被部署在目标机器的/opt/apt/fabric/peer目录中,如果要部署在其它目录中,需要修改配置文件中路径。

这里需要用到一个data目录,存放peer的数据:

mkdir peer0.org1.example.com/data

peer0.org2.example.com

跟peer0.org1.example.com 相同。、

4.开始部署

拷贝 orderer.example.com/到A机的/opt/app/fabric/orderer/

拷贝 peer0.org1.example.com/到A机的/opt/app/fabric/peer/

拷贝 peer0.org2.example.com/到B机的/opt/app/fabric/peer/

到这里 启动需要的文件基本准备完毕。查看 orderer.yaml 可以看到:

GenesisMethod: file
GenesisFile: ./genesisblock
GenesisProfile: SampleInsecureSolo 这几行代码。前两行配置了创世区块的获取方式,第一个区块的获取方式有多种,这里采用最简单的一种做法,用configtxgen生成。
创建一个 生成创世区块的需要的配置文件configtx.yaml:
Profiles:
TwoOrgsOrdererGenesis:
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org1
- *Org2
TwoOrgsChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
- *Org2
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: ./certs/ordererOrganizations/example.com/msp
- &Org1
Name: Org1MSP
ID: Org1MSP
MSPDir: ./certs/peerOrganizations/org1.example.com/msp
AnchorPeers:
- Host: peer0.org1.example.com
Port: 7051
- &Org2
Name: Org2MSP
ID: Org2MSP
MSPDir: ./certs/peerOrganizations/org2.example.com/msp
AnchorPeers:
- Host: peer0.org2.example.com
Port: 7051
Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
- orderer.example.com:7050
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 512 KB
Kafka:
Brokers:
- 127.0.0.1:9092
Organizations:
Application: &ApplicationDefaults
Organizations:

使用:

./bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./genesisblock 生成创世区块。  将生成的genesisblock文件放到 A机器order节点下。

 
 
 
 

HyperLedger Fabric 多机部署(一)的更多相关文章

  1. HyperLedger Fabric 多机部署(二)

    启动各个节点: ./orderer order节点启动方式 ./peer node start peer节点启动方式 Admin@org1.example.com 使用hyperledger fabr ...

  2. 基于docker的 Hyperledger Fabric 多机环境搭建(上)

    环境:ubuntu 16.04 Docker  17.04.0-ce go 1.7.4 consoul v0.8.0.4 ======================================= ...

  3. 基于docker的 Hyperledger Fabric 多机环境搭建(下)

    Docker环境部署见上一篇博客:http://www.cnblogs.com/cnblogs-wangzhipeng/p/6994541.html. 我们部署分布式容器服务后就要在上面部署Fabri ...

  4. Fabric 1.0的多机部署

    Fabric1.0已经正式发布一段时间了,官方给出的单机部署的脚本也很完备,基本上傻瓜式的一键部署,直接运行官方的network_setup.sh up即可.但是在实际生产环境,我们不可能把所有的节点 ...

  5. HyperLedger Fabric 学习思路分享

    HyperLedger Fabric 学习思路分享 HyperLedger Fabric最初是由Digital Asset和IBM公司贡献的.由Linux基金会主办的一个超级账本项目,它是一个目前非常 ...

  6. Hyperledger Fabric基础知识

    文章目录 什么是Hyperledger Fabric? Hyperledger架构是怎么工作的? Hyperledger交易如何执行 总结 Hyperledger Fabric基础知识 本文我们会介绍 ...

  7. HyperLedger Fabric 1.4 多机多节点部署(10.3)

    多机多节点指在多台电脑上部署多个组织和节点,本案例部署一个排序(orderer)服务,两个组织(org1,org2)和四个节点(peer),每个组织包括两个节点,需要五台计算机,计算机配置如下: 多机 ...

  8. Hyperledger fabric 1.3版本的安装部署(原创多机多Orderer部署

    首先,我们在安装前,要考虑一个问题 Hyperledger Fabric,通过指定的节点进行背书授权,才能完成交易的存储 延伸开来,就是为了实现容错.高并发.易扩展,需要zookeeper来选择排序引 ...

  9. Centos7 HyperLedger Fabric 1.4 生产环境部署

    Kafka生产环境部署案例采用三个排序(orderer)服务.四个kafka.三个zookeeper和四个节点(peer)组成,共准备八台服务器,每台服务器对应的服务如下所示: kafka案例网络拓扑 ...

随机推荐

  1. shell执行lua脚本传参数

    #lua test.lua 2 5arg[0]= test.lua arg[1]= 2arg[2]= 5 if arg[1] and arg[1] == "2" then prin ...

  2. echarts如何显示在页面上

    echarts如何显示在页面上 1.引入echarts的相关.js文件 <script src="js/echarts.min.js"></script> ...

  3. Matlab之rand(), randn(), randi()函数的使用方法

    1.  rand()函数用于生成取值在(0~1)之间均匀分布的伪随机数.rand(n):生成n*n的0~1之间的满足均匀分布的伪随机矩阵:rand(m,n):生成m*n的伪随机数:rand(m,n,' ...

  4. IDEAL葵花宝典:java代码开发规范插件 p3c

    前言: P3C插件 是阿里巴巴p3c项目组进行研发.这个项目组是阿里巴巴开发爱好者自发组织形成的虚拟项目组,根据<阿里巴巴Java开发规范>转化而成的自动化插件,并且实现了部分自动编程. ...

  5. 勤于思考:IE10不支持检测IE6的代码

    这句话 var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6); 在IE6~9都没问题 ...

  6. hdu 6121 Build a tree

    /** * 题意:一棵 n 个点的完全 k 叉树,结点标号从 0 到 n - 1,求以每一棵子树的大小的异或和. * 解法:k叉树,当k=1时,特判,用xorn函数,具体解释:http://blog. ...

  7. poj1637 Sightseeing tour[最大流+欧拉回路]

    混合图的欧拉回路定向问题. 顺便瞎说几句,有向图定欧拉回路的充要条件是每个点入度等于出度,并且图联通.无向图的话只要联通无奇点即可. 欧拉路径的确定应该是无向图联通且奇点数0个或2个,有向图忘了,好像 ...

  8. ACM学习历程—Hihocoder 1178 计数(位运算 && set容器)(hihoCoder挑战赛12)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB   描述 Rowdark是一个邪恶的魔法师.在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物,鱼丸. 魔法n能召 ...

  9. rman理论(一)

    1) 快照控制文件:开始备份后,RMAN 需要这些信息在备份操作期间保持一致,也就是说RMAN需要一个读取一致的控制文件视图. 除非RMAN 在备份持续时间内锁定控制文件,否则数据库会不断更新控制文件 ...

  10. Sleep 比对 (Win32API 与 STL )

    OutputDebugStringA("begin 1========"); for (int i = 0; i < 1800; i++) { Sleep(2); } Out ...