| 主机编号 | A | B | C | D |
| IP | 45.32.103.254 | 149.28.146.218 | 207.148.75.101 | 66.42.57.57 |
| 角色 |
orderer0.example.com zookeeper1 kafka1 |
orderer1.example.com zookeeper2 kafka2 |
peer0.org1.example.com zookeeper3 kafka3 |
peer1.org1.example.com |
所有主机操作系统均为CentOS 7 x64
s1:准备工作
修改主机A、B、C、D的/etc/hosts文件均如下 主要是把后面四行添加上
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 guest
::1 guest
45.32.103.254 A orderer0.example.com
149.28.146.218 B orderer1.example.com
207.148.75.101 C peer0.org1.example.com
66.42.57.57 D peer1.org1.example.com
关闭主机A、B、C、D防火墙
systemctl stop firewalld.service
内存不足可用如下方法扩充内存
mkdir /opt/images
dd if=/dev/zero of=/opt/images/swap bs=2048 count=2097152
mkswap /opt/images/swap
swapon /opt/images/swap
s2:在A、B、C主机安装java kafka运行依赖java环境
下载jdk-8u144-linux-x64.tar.gz并解压
tar -C /usr/local -zxvf jdk-8u144-linux-x64.tar.gz
修改/etc/profile 添加以下三行 配置java环境变量
export JAVA_HOME=/usr/local/jdk1.8.0_144
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar:.
然后执行
source /etc/profile
检查java是否安装成功
s3:在A、B、C主机安装kafka
下载kafka_2.10-0.10.2.0.tgz并解压
tar -C /usr/local -zxvf kafka_2.10-0.10.2.0.tgz
mv /usr/local/kafka_2.10-0.10.2.0 /usr/local/kafka
修改/usr/local/kafka/config/zookeeper.properties 添加或修改如下配置
dataDir=/usr/local/kafka/data/zookeeper
tickTime=2000
initLimit=5
syncLimit=2
server.1=A:2888:3888
server.2=B:2888:3888
server.3=C:2888:3888
创建路径/usr/local/kafka/data/zookeeper
mkdir -p /usr/local/kafka/data/zookeeper
对于主机A 执行
echo 1 > /usr/local/kafka/data/zookeeper/myid
对于主机B 执行
echo 2 > /usr/local/kafka/data/zookeeper/myid
对于主机C 执行
echo 3 > /usr/local/kafka/data/zookeeper/myid
修改/usr/local/kafka/config/server.properties
对于主机A做如下修改
broker.id=1
listeners=PLAINTEXT://A:9092
num.partitions=3
zookeeper.connect=A:2181,B:2181,C:2181
对于主机B做如下修改
broker.id=2
listeners=PLAINTEXT://B:9092
num.partitions=3
zookeeper.connect=A:2181,B:2181,C:2181
对于主机C做如下修改
broker.id=3
listeners=PLAINTEXT://C:9092
num.partitions=3
zookeeper.connect=A:2181,B:2181,C:2181
分别启动A、B、C主机zookeeper
nohup /usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties >> ~/zookeeper.log 2>&1 &
启动日志
在A、B、C主机分别启动kafka
nohup /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties>>~/kafka.log 2>&1 &
启动日志
s4:生成证书 创世区块 channel.tx
在A、B、C、D主机分别下载hyperledger-fabric-linux-amd64-1.1.0.tar.gz并解压
mkdir /opt/fabric
tar -C /opt/fabric -zxvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz
修改A、B、C、D主机的/etc/profile文件 添加
export PATH=/opt/fabric/bin:$PATH
然后执行
source /etc/profile
A主机/opt/fabric路径下创建crypto-config.yaml内容如下
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# ---------------------------------------------------------------------------
# "OrdererOrgs" - Definition of organizations managing orderer nodes
# ---------------------------------------------------------------------------
OrdererOrgs:
# ---------------------------------------------------------------------------
# Orderer
# ---------------------------------------------------------------------------
- Name: Orderer
Domain: example.com
# ---------------------------------------------------------------------------
# "Specs" - See PeerOrgs below for complete description
# ---------------------------------------------------------------------------
Specs:
- Hostname: orderer0
- Hostname: orderer1
# ---------------------------------------------------------------------------
# "PeerOrgs" - Definition of organizations managing peer nodes
# ---------------------------------------------------------------------------
PeerOrgs:
# ---------------------------------------------------------------------------
# Org1
# ---------------------------------------------------------------------------
- Name: Org1
Domain: org1.example.com
EnableNodeOUs: true
# ---------------------------------------------------------------------------
# "Specs"
# ---------------------------------------------------------------------------
# Uncomment this section to enable the explicit definition of hosts in your
# configuration. Most users will want to use Template, below
#
# Specs is an array of Spec entries. Each Spec entry consists of two fields:
# - Hostname: (Required) The desired hostname, sans the domain.
# - CommonName: (Optional) Specifies the template or explicit override for
# the CN. By default, this is the template:
#
# "{{.Hostname}}.{{.Domain}}"
#
# which obtains its values from the Spec.Hostname and
# Org.Domain, respectively.
# ---------------------------------------------------------------------------
# Specs:
# - Hostname: foo # implicitly "foo.org1.example.com"
# CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above
# - Hostname: bar
# - Hostname: baz
# ---------------------------------------------------------------------------
# "Template"
# ---------------------------------------------------------------------------
# Allows for the definition of 1 or more hosts that are created sequentially
# from a template. By default, this looks like "peer%d" from 0 to Count-1.
# You may override the number of nodes (Count), the starting index (Start)
# or the template used to construct the name (Hostname).
#
# Note: Template and Specs are not mutually exclusive. You may define both
# sections and the aggregate nodes will be created for you. Take care with
# name collisions
# ---------------------------------------------------------------------------
Template:
Count: 2
# Start: 5
# Hostname: {{.Prefix}}{{.Index}} # default
# ---------------------------------------------------------------------------
# "Users"
# ---------------------------------------------------------------------------
# Count: The number of user accounts _in addition_ to Admin
# ---------------------------------------------------------------------------
Users:
Count: 1
A主机/opt/fabric路径下创建configtx.yaml内容如下
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
---
################################################################################
#
# Section: Organizations
#
# - This section defines the different organizational identities which will
# be referenced later in the configuration.
#
################################################################################
Organizations:
# SampleOrg defines an MSP using the sampleconfig. It should never be used
# in production but may be used as a template for other definitions
- &OrdererOrg
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: OrdererOrg
# ID to load the MSP definition as
ID: OrdererMSP
# MSPDir is the filesystem path which contains the MSP configuration
MSPDir: crypto-config/ordererOrganizations/example.com/msp
- &Org1
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org1MSP
# ID to load the MSP definition as
ID: Org1MSP
MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer0.org1.example.com
Port: 7051
################################################################################
#
# SECTION: Application
#
# - This section defines the values to encode into a config transaction or
# genesis block for application related parameters
#
################################################################################
Application: &ApplicationDefaults
# Organizations is the list of orgs which are defined as participants on
# the application side of the network
Organizations:
################################################################################
#
# SECTION: Orderer
#
# - This section defines the values to encode into a config transaction or
# genesis block for orderer related parameters
#
################################################################################
Orderer: &OrdererDefaults
# Orderer Type: The orderer implementation to start
# Available types are "solo" and "kafka"
OrdererType: kafka
Addresses:
- orderer0.example.com:7050
- orderer1.example.com:7050
# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 2s
# Batch Size: Controls the number of messages batched into a block
BatchSize:
# Max Message Count: The maximum number of messages to permit in a batch
MaxMessageCount: 10
# Absolute Max Bytes: The absolute maximum number of bytes allowed for
# the serialized messages in a batch.
AbsoluteMaxBytes: 99 MB
# Preferred Max Bytes: The preferred maximum number of bytes allowed for
# the serialized messages in a batch. A message larger than the preferred
# max bytes will result in a batch larger than preferred max bytes.
PreferredMaxBytes: 512 KB
Kafka:
# Brokers: A list of Kafka brokers to which the orderer connects
# NOTE: Use IP:port notation
Brokers:
- A:9092
- B:9092
- C:9092
# Organizations is the list of orgs which are defined as participants on
# the orderer side of the network
Organizations:
################################################################################
#
# Profile
#
# - Different configuration profiles may be encoded here to be specified
# as parameters to the configtxgen tool
#
################################################################################
Profiles:
OneOrgOrdererGenesis:
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org1
OneOrgChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
A主机/opt/fabric路径下创建generate.sh用于生成证书 创世区块 channel.tx
#!/bin/bash
# 生成证书
if [ -d crypto-config ]; then rm -rf crypto-config/*; fi
cryptogen generate --config=crypto-config.yaml
if [ $? -ne 0 ]; then echo "failed to generate crypto"; exit 1; fi
# 生成创世区块
if [ ! -d channel-artifacts ]; then mkdir channel-artifacts; else rm -rf channel-artifacts/*; fi
configtxgen -profile OneOrgOrdererGenesis -outputBlock channel-artifacts/genesis.block
if [ $? -ne 0 ]; then echo "failed to generate genesis.block"; exit 1; fi
# 生成channel.tx
configtxgen -profile OneOrgChannel -outputCreateChannelTx channel-artifacts/channel.tx -channelID mychannel
if [ $? -ne 0 ]; then echo "failed to generate channel.tx"; exit 1; fi
然后在/opt/fabric路径执行
chmod +x generate.sh
./generate.sh
s5:A、B主机启动orderer
修改A、B主机/opt/fabric/config/orderer.yaml 并copy到/opt/fabric路径
ListenAddress: 0.0.0.0 # 25行
Enabled: true # 32行
GenesisMethod: file # 64行
GenesisProfile: OneOrgOrdererGenesis # 71行
GenesisFile: genesis.block # 76行
LocalMSPID: OrdererMSP # 88行
Location: /data/hyperledger/production/orderer # 137行
在A主机/opt/fabric路径执行
cp -r crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp ./
cp -r crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls ./
cp channel-artifacts/genesis.block ./
scp -r crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp [email protected]:/opt/fabric
scp -r crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls [email protected]:/opt/fabric
scp channel-artifacts/genesis.block [email protected]:/opt/fabric
分别在A、B主机启动orderer 在/opt/fabric路径执行启动命令
nohup orderer>>~/orderer.log 2>&1 &
启动日志
s6:C、D主机启动peer
修改C、D主机/opt/fabric/config/core.yaml 并copy到/opt/fabric路径
enabled: true # 262行
fileSystemPath: /data/hyperledger/production # 300行
localMspId: Org1MSP # 328行
在A主机/opt/fabric路径执行
scp -r crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp [email protected]:/opt/fabric
scp -r crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls [email protected]:/opt/fabric
scp -r crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp [email protected]:/opt/fabric
scp -r crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls [email protected]:/opt/fabric
分别在C、D主机启动peer 在/opt/fabric路径执行启动命令
nohup peer node start>>~/peer.log 2>&1 &
启动日志
s7:A主机安装golang
通过哪台主机连接peer节点就在哪台主机安装golang
A主机下载go1.10.linux-amd64.tar.gz并解压
tar -C /usr/local -zxvf go1.10.linux-amd64.tar.gz
A主机修改/etc/profile 添加
export PATH=/usr/local/go/bin:$PATH
然后执行
source /etc/profile
检查golang是否安装成功