其他分享
首页 > 其他分享> > fabric1.4.3多机多节点部署(一)

fabric1.4.3多机多节点部署(一)

作者:互联网

fabric1.4.3多机多节点部署:

(一)项目环境
多机多节点指多台电脑上部署多个组织和节点,本案例部署一个排序(orderer)服务,两个组织(org1,org2)和四个节点(peer),每个组织包括两个节点,需要三台服务器,规划如下:

orderer.example.com 101.201.253.208

peer0.org1.example.com 123.56.48.16

peer1.org1.example.com 123.56.48.16

peer0.org2.example.com 39.96.115.136

peer1.org2.example.com 39.96.115.136

本文以orderer节点为例,先在101.201.253.208服务器上进行操作。三台服务器同时安装好基础fabric环境:在~/hy/fabric-samples目录。
1.创建并进入工作目录

cd ~/hy/fabric-samples
mkdir test && cd test

2.配置crypto-config.yaml,使用命令生成证书

vim crypto-config.yaml

OrdererOrgs:

  • Name: Orderer
    Domain: example.com
    Specs:
    • Hostname: orderer PeerOrgs:
  • Name: Org1
    Domain: org1.example.com
    EnableNodeOUs: true
    Template:
    Count: 2
    Users:
    Count: 1
  • Name: Org2
    Domain: org2.example.com
    EnableNodeOUs: true
    Template:
    Count: 2
    Users:
    Count: 1

$ cryptogen generate --config=./crypto-config.yaml

(此处若出现cryptogen 工具错误,需要配置环境变量或者把bin拷贝到test目录下)
3.配置configtx.yaml,生成创世区块与通道文件

vim configtx.yaml

Organizations:
- &OrdererOrg
    Name: OrdererOrg
    ID: OrdererMSP
    MSPDir: crypto-config/ordererOrganizations/example.com/msp
    Policies:
        Readers:
            Type: Signature
            Rule: "OR('OrdererMSP.member')"
        Writers:
            Type: Signature
            Rule: "OR('OrdererMSP.member')"
        Admins:
            Type: Signature
            Rule: "OR('OrdererMSP.admin')"

  - &Org1
    Name: Org1MSP
    ID: Org1MSP
    MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
    Policies:
        Readers:
            Type: Signature
            Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
        Writers:
            Type: Signature
            Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
        Admins:
            Type: Signature
            Rule: "OR('Org1MSP.admin')"
    AnchorPeers:
        - Host: peer0.org1.example.com
          Port: 7051

 - &Org2
    Name: Org2MSP
    ID: Org2MSP
    MSPDir: crypto-config/peerOrganizations/org2.example.com/msp
    Policies:
        Readers:
            Type: Signature
            Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
        Writers:
            Type: Signature
            Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
        Admins:
            Type: Signature
            Rule: "OR('Org2MSP.admin')"

    AnchorPeers:
        - Host: peer0.org2.example.com
          Port: 7051      
Capabilities:               
   Global: &ChannelCapabilities
      V1_1: true
   Orderer: &OrdererCapabilities
      V1_1: true
  Application: &ApplicationCapabilities
      V1_2: true   
Application: &ApplicationDefaults
  Organizations:
  Policies:
    Readers:
        Type: ImplicitMeta
        Rule: "ANY Readers"
    Writers:
        Type: ImplicitMeta
        Rule: "ANY Writers"
    Admins:
        Type: ImplicitMeta
        Rule: "MAJORITY Admins"
Capabilities:
    <<: *ApplicationCapabilities   Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
    - orderer.example.com:7050
BatchTimeout: 2s
BatchSize:
    MaxMessageCount: 10
    AbsoluteMaxBytes: 98 MB
    PreferredMaxBytes: 512 KB
Kafka:
    Brokers:
        - 127.0.0.1:9092
Organizations:
Policies:
    Readers:
        Type: ImplicitMeta
        Rule: "ANY Readers"
    Writers:
        Type: ImplicitMeta
        Rule: "ANY Writers"
    Admins:
        Type: ImplicitMeta
        Rule: "MAJORITY Admins"
    BlockValidation:
        Type: ImplicitMeta
        Rule: "ANY Writers"
Capabilities:
    <<: *OrdererCapabilities   Channel: &ChannelDefaults
Policies:
    Readers:
        Type: ImplicitMeta
        Rule: "ANY Readers"
    Writers:
        Type: ImplicitMeta
        Rule: "ANY Writers"
    Admins:
        Type: ImplicitMeta
        Rule: "MAJORITY Admins"
Capabilities:
    <<: *ChannelCapabilities   Profiles:
TwoOrgsOrdererGenesis:
    <<: *ChannelDefaults
    Orderer:
        <<: *OrdererDefaults
        Organizations:
            - *OrdererOrg
    Consortiums:
        SampleConsortium:
            Organizations:
                - *Org1
                - *Org2
TwoOrgsChannel:
    Consortium: SampleConsortium
    Application:
        <<: *ApplicationDefaults
        Organizations:
            - *Org1
            - *Org2

mkdir ./channel-artifacts
configtxgen -profile TwoOrgsOrdererGenesis -channelID testchannel
-outputBlock ./channel-artifacts/genesis.block
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx
./channel-artifacts/channel.tx -channelID testchannel

4.生成锚节点配置文件

configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate
./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg
Org1MSP configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate
./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg
Org2MSP

5.配置docker-compose-orderer.yaml文件
下面为了统一改名为docker-compose.yaml文件

vim docker-compose.yaml

version: ‘2’
networks:
byfn:
services:
orderer.example.com:
container_name: orderer.example.com
image: hyperledger/fabric-orderer
environment:
- GODEBUG=netdns=go
- FABRIC_LOGGING_SPEC=INFO
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
# enabled TLS
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
- ORDERER_KAFKA_TOPIC_REPLICATIONFACTOR=1
- ORDERER_KAFKA_VERBOSE=true
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
- ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
ports:
- 7050:7050
networks:
- byfn
extra_hosts:
- “peer0.org1.example.com:123.56.48.16”
- “peer1.org1.example.com:123.56.48.16”
- “peer0.org2.example.com:39.96.115.136”
- “peer1.org2.example.com:39.96.115.136”

6.启动Fabric网络

docker-compose -f docker-compose.yaml up

7.另开一个终端, 查看容器状态

docker ps

8.orderer节点启动成功后,拷贝生成文件到其它电脑

cd ~/hy/fabric-samples
scp -r test root@123.56.48.16:/root/hy/fabric-samples/
scp -r test root@39.96.115.136:/root/hy/fabric-samples/

到此为止oderer节点配置完毕。

标签:Type,ORDERER,Rule,节点,orderer,多机,fabric1.4,com,example
来源: https://blog.csdn.net/willzhengxian/article/details/116998675