HyperLedger Fabric 多机部署(一)
本文参考: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.准备证书
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的,里面有两个子目录tls和msp:
$ 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 多机部署(一)的更多相关文章
- HyperLedger Fabric 多机部署(二)
启动各个节点: ./orderer order节点启动方式 ./peer node start peer节点启动方式 Admin@org1.example.com 使用hyperledger fabr ...
- 基于docker的 Hyperledger Fabric 多机环境搭建(上)
环境:ubuntu 16.04 Docker 17.04.0-ce go 1.7.4 consoul v0.8.0.4 ======================================= ...
- 基于docker的 Hyperledger Fabric 多机环境搭建(下)
Docker环境部署见上一篇博客:http://www.cnblogs.com/cnblogs-wangzhipeng/p/6994541.html. 我们部署分布式容器服务后就要在上面部署Fabri ...
- Fabric 1.0的多机部署
Fabric1.0已经正式发布一段时间了,官方给出的单机部署的脚本也很完备,基本上傻瓜式的一键部署,直接运行官方的network_setup.sh up即可.但是在实际生产环境,我们不可能把所有的节点 ...
- HyperLedger Fabric 学习思路分享
HyperLedger Fabric 学习思路分享 HyperLedger Fabric最初是由Digital Asset和IBM公司贡献的.由Linux基金会主办的一个超级账本项目,它是一个目前非常 ...
- Hyperledger Fabric基础知识
文章目录 什么是Hyperledger Fabric? Hyperledger架构是怎么工作的? Hyperledger交易如何执行 总结 Hyperledger Fabric基础知识 本文我们会介绍 ...
- HyperLedger Fabric 1.4 多机多节点部署(10.3)
多机多节点指在多台电脑上部署多个组织和节点,本案例部署一个排序(orderer)服务,两个组织(org1,org2)和四个节点(peer),每个组织包括两个节点,需要五台计算机,计算机配置如下: 多机 ...
- Hyperledger fabric 1.3版本的安装部署(原创多机多Orderer部署
首先,我们在安装前,要考虑一个问题 Hyperledger Fabric,通过指定的节点进行背书授权,才能完成交易的存储 延伸开来,就是为了实现容错.高并发.易扩展,需要zookeeper来选择排序引 ...
- Centos7 HyperLedger Fabric 1.4 生产环境部署
Kafka生产环境部署案例采用三个排序(orderer)服务.四个kafka.三个zookeeper和四个节点(peer)组成,共准备八台服务器,每台服务器对应的服务如下所示: kafka案例网络拓扑 ...
随机推荐
- CodeForces - 799B T-shirt buying 【贪心】
题目链接 http://codeforces.com/problemset/problem/799/B 题意 给出N件衣服 pi 表示 第i件衣服的价格 ai 表示 第i件衣服的前面的颜色 bi 表示 ...
- Java多线程系列 基础篇10 wait/notify/sleep/yield/join
1.Object类中的wait()/notify()/notifyAll() wait(): 让当前线程处于Waiting状态并释放掉持有的对象锁,直到其他线程调用此对象的线程notify()/not ...
- 《avascript 高级程序设计(第三版)》 ---第三章 基本概念2
1.乘性操作符: 1)*法操作法: Infinity * 0 = NaN Infinity * 非零 = Infinity 或 - Infinity 2)/法操作符: Infinity / In ...
- Struts2 输入校验 第四弹
ActionSupport 里面有一个validate.可以重写里面你的方法. 校验执行流程: 1)首先进行类型转化 2)然后进行输入校验(执行validate方法) 3)如果在上述过程中出现了任何错 ...
- EOF的使用
1.我疑惑了 char a[20]; while(scanf("%s",a)!=EOF){ cout<<"hello"<<endl; } ...
- python 列表之队列
列表实现队列操作(FIFO),可以使用标准库里的 collections.deque,deque是double-ended quene的缩写,双端队列的意思,它可以实现从队列头部快速增加和取出对象. ...
- 取分组TOPN好理解案例
- 如何将 Python 程序打包成 .exe 文件?
有不少订阅本公众号的朋友都不是玩 Python,甚至都不是计算机相关专业的,当我给他们一个 Python 程序时,他们是完全不知道该怎么运行的. 于是我想是不是可以将我的程序打包成可执行文件,直接运行 ...
- P2936(BZOJ3396) [USACO09JAN]全流Total Flow[最大流]
题 裸题不多说,在网络流的练习题里,你甚至可以使用暴力. #include<bits/stdc++.h> using namespace std; typedef long long ll ...
- 如何加快建 index 索引 的时间
朋友在500w的表上建索引,半个小时都没有结束.所以就讨论如何提速. 一.先来看一下创建索引要做哪些操作:1. 把index key的data 读到内存==>如果data 没在db_cache ...