本文参考: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. 【python】python版本升级,从2.6.6升级到2.7.13

    centos6.5系统自带了2.6.6版本的python,有时候为了项目上的需要,需要将python版本升级到2.7.13,下面介绍了如何进行升级. 说明:python从2.6升级到2.7会引发很多问 ...

  2. Java for LeetCode 133 Clone Graph

    Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...

  3. 3D立方体旋转动画

    在线演示 本地下载

  4. ios浮层滑动不流畅解决方案

    前段时间做了一个浮层,但在ios上,浮层滑动不流畅,基本上是随着手指的移动而移动,经研究加上-webkit-overflow-scrolling: touch即可 eg: <!DOCTYPE h ...

  5. 【转载】帧缓冲驱动程序分析及其在BSP上的添加

    原文地址:(四)帧缓冲驱动程序分析及其在BSP上的添加 作者:gfvvz 一.BSP修改及其分析   1. BSP中直接配置的四个寄存器 S3C6410数据手册的第14.5部分是显示控制器的编程模型部 ...

  6. java高级特性增强

    第4天 java高级特性增强 今天内容安排: 1.掌握多线程 2.掌握并发包下的队列 3.了解JMS 4.掌握JVM技术 5.掌握反射和动态代理 java多线程增强 .1. java多线程基本知识 . ...

  7. python3 - 商品管理的程序,商品信息都存在一个json串里面

    商品管理的程序,商品信息都存在一个json串里面 1.查询商品信息 #校验商品是否存在 2.新增商品 # #校验商品是否存在 #校验价格是否合法 3.修改商品信息 ##校验商品是否存在 if chic ...

  8. hdu-5781 ATM Mechine(dp+概率期望)

    题目链接: ATM Mechine Time Limit: 6000/3000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Other ...

  9. Nginx均衡负载配置

    前言:Nginx也是一种服务器,反向代理服务器.单一tomcat能承受的并发访问量在150-200之间,还是在比较理想的情况下,当并发量超出这个范围,便需要Nginx实现多个tomcat的均衡负载,但 ...

  10. Ubuntu16.04上安装arm-linux-gcc4.4.3

    一.首先下载arm-linux-gcc-4.4.3.tar.gz安装包,安装包地址: http://www.cr173.com/soft/42654.html 二.解压安装包: sudo tar -z ...