阿里云多机部署Fabric 1order节点多个peer节点

简介: Fabric
多机部署需要有N个固定的IP服务器地址,把order节点和peer节点放在不同的服务器上,如图所示
b88db1058df3a251c45af1cd0f18971acfe4a1af

1.首先,更改配置文件crypto-config.yaml

OrdererOrgs:
 
  - Name: Orderer
    Domain: example.com
PeerOrgs:

  - Name: Org1
    Domain: org1.example.com
    EnableNodeOUs: true
    Template:
      Count: 5
    Users:
      Count: 1

  - Name: Org2
    Domain: org2.example.com
    EnableNodeOUs: true
    Template:
      Count: 5
    Users:
      Count: 1

2.修改peer.yaml文件

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:

  couchdb:
    container_name: couchdb
    image: hyperledger/fabric-couchdb:x86_64-0.4.6
    # Comment/Uncomment the port mapping if you want to hide/expose the CouchDB service,
    # for example map it to utilize Fauxton User Interface in dev environments.
    ports:
      - "5984:5984"
      
  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=192.168.0.2:5984

      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_NETWORKID=fabric
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP

      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_default
      - CORE_VM_DOCKER_TLS_ENABLED=false
      # - CORE_LOGGING_LEVEL=ERROR
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
    volumes:
        - /var/run/:/host/var/run/
        - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/chaincode/go
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053
    depends_on:
      - couchdb
    extra_hosts:
     - "orderer.example.com:192.168.0.1"


  cli:
    container_name: cli
    image: hyperledger/fabric-tools
    tty: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # - CORE_LOGGING_LEVEL=ERROR
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_LOCALMSPTYPE=bccsp
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    volumes:
        - /var/run/:/host/var/run/
        - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/chaincode/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./config:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - peer0.org1.example.com
    extra_hosts:
     - "orderer.example.com:192.168.0.1"
     - "peer0.org1.example.com:192.168.0.2"

其他的peer节点修改 peer名称和ip地址就可以了
 extra_hosts:
     - "orderer.example.com:192.168.0.1"
     - "peer0.org1.example.com:192.168.0.2"

3.重新生成配置文件
生成证书
./bin/cryptogen generate --config=./crypto-config.yaml

生成创世区块
./bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./config/genesis.block

生成通道凭证
./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./config/mychannel.tx -channelID mychannel

4.启动order节点命令

docker-compose -f docker-compose-orderer.yaml up -d


5.启动peer节点命令,然后进入cli容器,创建Channel,生成mychannel.block文件,其他peer节点复制mychannel.block文件,启动peer节点后加入Channel即可,实现如下:

docker-compose -f docker-compose-peer.yaml up -d


启动cli容器

docker exec -it cli bash


创建Channel

ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

peer channel create -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/mychannel.tx --tls --cafile $ORDERER_CA


Peer加入Channel

peer channel join -b mychannel.block


用docker cp命令把mychannel.block文件复制到指定文件下,然后在复制到其他服务器

exit

docker cp xxxxxxxx:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block  /opt/gopath/src/github.com/hyperledger/fabric/config


6.进行智能合约部署,其他节点直接新建智能合约就可以了,不用实例化智能合约

新建智能合约voucher

peer chaincode install -n mycc  -v 1.0 -p github.com/hyperledger/fabric/chaincode/go/chaincode_example02


实例化智能合约

ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

 peer chaincode instantiate -o orderer0.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","A","200","B","400"]}' -P "OR('Org1MSP.member','Org2MSP.member')"


查询操作

 peer chaincode query -C mychannel -n mycc -c '{"Args":["query","A"]}'


转账操作

 peer chaincode invoke --tls --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","A","B","20"]}'


目录
相关文章
|
3月前
|
SQL 测试技术 流计算
EMR Remote Shuffle Service实践问题之Leader节点变化导致的中断如何解决
EMR Remote Shuffle Service实践问题之Leader节点变化导致的中断如何解决
|
3月前
|
Linux 微服务
【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)
【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)
|
3月前
|
安全 微服务
【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
|
3月前
|
Kubernetes 网络安全 Docker
在k8S中,Worker节点加入集群的过程是什么?
在k8S中,Worker节点加入集群的过程是什么?
|
4月前
分布式篇问题之集群(Cluster)模式主控节点的高可用性问题如何解决
分布式篇问题之集群(Cluster)模式主控节点的高可用性问题如何解决
|
Shell Go 区块链
阿里云多机部署Fabric 1order节点多个peer节点
阿里云多机部署Fabric 1order节点多个peer节点
252 1
|
Shell Go 区块链
阿里云单机Fabric 1个order1个peer部署步骤
阿里云单机Fabric 1个order1个peer部署步骤
197 1
|
Kubernetes 容器
为什么Kubernetes从节点会join失败
为什么Kubernetes从节点会join失败
1670 0
为什么Kubernetes从节点会join失败
|
Kubernetes Ubuntu 应用服务中间件
k8s学习四-部署节点加入集群
k8s学习四-部署节点加入集群
299 0
k8s学习四-部署节点加入集群
|
JSON Kubernetes 安全
Linkerd 2.10(Step by Step)—多集群通信
Linkerd 2.10(Step by Step)—多集群通信
276 0
Linkerd 2.10(Step by Step)—多集群通信