标签:合约 alt general rds ast hub -- instant contain
首先,我们在安装前,要考虑一个问题
Hyperledger Fabric,通过指定的节点进行背书授权,才能完成交易的存储
延伸开来,就是为了实现容错、高并发、易扩展,需要zookeeper来选择排序引擎处理记账的唯一性
我们这里选择kafka排序引擎并通过Kafka集群和zookeeper集群保证数据的一致性,实现排序功能
同时,为了排序服务器的稳定,采取多Orderer集群实现容错空间,
为此,我们采用了最基础的配置方案:两个组织,四个节点
两个CA服务器,三个Zookeeper服务器,四个Kafka服务器,3个Orderer服务器,4个Peer服务器
大家一看到这么多服务器,可能会吓一跳,那我们就把这些服务器优化一下,变成如下:
192.168.10.10:
ca.org1.chaincode.yourdomain,zookeeper0,kafka0,orderer0.chaincode.yourdomain,peer0.org1.chaincode.yourdomain
192.168.10.11:
ca.org2.chaincode.yourdomain,zookeeper1,kafka1,orderer1.chaincode.yourdomain,peer0.org2.chaincode.yourdomain
192.168.10.12:
zookeeper2,kafka2,orderer2.chaincode.yourdomain,peer1.org1.chaincode.yourdomain
192.168.10.13:
kafka3,peer1.org2.chaincode.yourdomain
这样就只要4台服务器了
其中分成两个组织,主要目的是告诉你,这个东西是可以把群体进行划分的,就像三层交换机里的vlan一样,
另外两个ca服务器主要是为了把组织的访问权限分离出来控制
还有就是把账本节点分别设置为peer0.org1,peer1.org1属于组织1,peer0.org2,peer1.org2属于组织2
如果比较难理解,那就把公司里的电脑当做peer,org当做不同部门,只要权限有,peer0.org1,peer0.org2,peer1.org1,peer1.org2是互通的(当然在业务范围内,这里只是举个例子),同时大家都可以保存同一个文件,
这里有一个细节,那就是要指定背书节点,否则公司里电脑太多了,你要每台电脑都去判断一下某一个文件有没有被修改,是不太合理的。这里我们会指定peer0.org1,peer0.org2作为背书节点,其他的自动同步新的更新(如果是跨公司有同一个业务,也可以指定各自公司的背书节点,防止一方对数据进行篡改)。
说了整体的框架,那么下面我们就来部署吧:
一、基础资料安装
首先我的服务器是Centos7.0,所以大家相关的命令自己调整哦
接下来配置各个服务器的域名解析:
vi /etc/hosts
写入以下内容:
192.168.10.10 ca.org1.chaincode.yourdomain orderer0.chaincode.yourdomain peer0.org1.chaincode.yourdomain
192.168.10.11 ca.org2.chaincode.yourdomain orderer1.chaincode.yourdomain peer0.org2.chaincode.yourdomain
192.168.10.12 orderer2.chaincode.yourdomain peer1.org1.chaincode.yourdomain
192.168.10.13 peer1.org2.chaincode.yourdomain
红色部分改成你自己的域名哦
/etc/init.d/network restart
7. 打包并压缩镜像
每台机器上都要下载这些镜像,因为不同的机器按照我们的规划,要部署不同的服务上去,偷懒一点就所有的都复制过去吧
[root@localhost e2e_cli]# docker save $(docker images | grep latest |awk {‘print $1‘} ) -o images
8. 传送给其他服务器(peer0.org2,peer1.org1,peer1.org2)
[root@localhost e2e_cli]# scp images root@192.168.10.11:/root/
[root@localhost e2e_cli]# scp images root@192.168.10.12:/root/
[root@localhost e2e_cli]# scp images root@192.168.10.13:/root/
在各自服务器上执行
docker load -i images
就可以加载所有镜像了,不过这个images的路径根据你自己执行的位置进行改动吧
9. 接下来,我们就要创建公私钥、证书、创世区块等
目录结构说明:
base
存放配置提炼的公有部分,有两个文件,分别为docker-compose-base.yaml和peer-base.yaml
channel-artifacts
存放生成的通道和创世纪块等文件,包括有channel.tx、genesis.block、Org1MSPanchors.tx和Org2MSPanchors.tx
crypto-config
存放生成的公私钥和证书等文件
scripts
只有一个script.sh文件,该文件是案例的运行功能的集合,运行后会自动执行全部功能,直到完成
configtx.yaml
通道配置文件
crypto-config.yaml
生成的公私钥和证书的配置文件
docker-compose-cli.yaml
Fabric网络Docker运行配置文件
download-dockerimages.sh
下载Fabric镜像执行文件
generateArtifacts.sh
生成公私钥和证书的执行文件
network_setup.sh
案例运行的入口文件
这些看懂了就好,
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # # --------------------------------------------------------------------------- # "OrdererOrgs" - Definition of organizations managing orderer nodes # --------------------------------------------------------------------------- OrdererOrgs: # --------------------------------------------------------------------------- # Orderer # --------------------------------------------------------------------------- - Name: Orderer Domain: chaincode.yourdomain CA: Country: CN Province: Zhejiang Locality: Yiwu # --------------------------------------------------------------------------- # "Specs" - See PeerOrgs below for complete description # --------------------------------------------------------------------------- Specs: - Hostname: orderer0 - Hostname: orderer1 - Hostname: orderer2 # --------------------------------------------------------------------------- # "PeerOrgs" - Definition of organizations managing peer nodes # --------------------------------------------------------------------------- PeerOrgs: # --------------------------------------------------------------------------- # Org1 # --------------------------------------------------------------------------- - Name: Org1 Domain: org1.chaincode.yourdomain EnableNodeOUs: true CA: Country: CN Province: Zhejiang Locality: Yiwu # --------------------------------------------------------------------------- # "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: 2 # --------------------------------------------------------------------------- # Org2: See "Org1" for full specification # --------------------------------------------------------------------------- - Name: Org2 Domain: org2.chaincode.yourdomain EnableNodeOUs: true CA: Country: CN Province: Zhejiang Locality: Yiwu Template: Count: 2 Users: Count: 2
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/chaincode.jzyb2b.com/msp # Policies defines the set of policies at this level of the config tree # For organization policies, their canonical path is usually # /Channel/<Application|Orderer>/<OrgName>/<PolicyName> Policies: Readers: Type: Signature Rule: "OR(‘OrdererMSP.member‘)" Writers: Type: Signature Rule: "OR(‘OrdererMSP.member‘)" Admins: Type: Signature Rule: "OR(‘OrdererMSP.admin‘)" - &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.chaincode.jzyb2b.com/msp # Policies defines the set of policies at this level of the config tree # For organization policies, their canonical path is usually # /Channel/<Application|Orderer>/<OrgName>/<PolicyName> 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: # 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.chaincode.jzyb2b.com Port: 7051 - &Org2 # DefaultOrg defines the organization which is used in the sampleconfig # of the fabric.git development environment Name: Org2MSP # ID to load the MSP definition as ID: Org2MSP MSPDir: crypto-config/peerOrganizations/org2.chaincode.jzyb2b.com/msp # Policies defines the set of policies at this level of the config tree # For organization policies, their canonical path is usually # /Channel/<Application|Orderer>/<OrgName>/<PolicyName> 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: # 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.org2.chaincode.jzyb2b.com Port: 7051 ################################################################################ # # SECTION: Capabilities # # - This section defines the capabilities of fabric network. This is a new # concept as of v1.1.0 and should not be utilized in mixed networks with # v1.0.x peers and orderers. Capabilities define features which must be # present in a fabric binary for that binary to safely participate in the # fabric network. For instance, if a new MSP type is added, newer binaries # might recognize and validate the signatures from this type, while older # binaries without this support would be unable to validate those # transactions. This could lead to different versions of the fabric binaries # having different world states. Instead, defining a capability for a channel # informs those binaries without this capability that they must cease # processing transactions until they have been upgraded. For v1.0.x if any # capabilities are defined (including a map with all capabilities turned off) # then the v1.0.x peer will deliberately crash. # ################################################################################ Capabilities: # Channel capabilities apply to both the orderers and the peers and must be # supported by both. # Set the value of the capability to true to require it. Channel: &ChannelCapabilities # V1.3 for Channel is a catchall flag for behavior which has been # determined to be desired for all orderers and peers running at the v1.3.x # level, but which would be incompatible with orderers and peers from # prior releases. # Prior to enabling V1.3 channel capabilities, ensure that all # orderers and peers on a channel are at v1.3.0 or later. V1_3: true # Orderer capabilities apply only to the orderers, and may be safely # used with prior release peers. # Set the value of the capability to true to require it. Orderer: &OrdererCapabilities # V1.1 for Orderer is a catchall flag for behavior which has been # determined to be desired for all orderers running at the v1.1.x # level, but which would be incompatible with orderers from prior releases. # Prior to enabling V1.1 orderer capabilities, ensure that all # orderers on a channel are at v1.1.0 or later. V1_1: true # Application capabilities apply only to the peer network, and may be safely # used with prior release orderers. # Set the value of the capability to true to require it. Application: &ApplicationCapabilities # V1.3 for Application enables the new non-backwards compatible # features and fixes of fabric v1.3. V1_3: true # V1.2 for Application enables the new non-backwards compatible # features and fixes of fabric v1.2 (note, this need not be set if # later version capabilities are set) V1_2: false # V1.1 for Application enables the new non-backwards compatible # features and fixes of fabric v1.1 (note, this need not be set if # later version capabilities are set). V1_1: false ################################################################################ # # 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: # Policies defines the set of policies at this level of the config tree # For Application policies, their canonical path is # /Channel/Application/<PolicyName> Policies: Readers: Type: ImplicitMeta Rule: "ANY Readers" Writers: Type: ImplicitMeta Rule: "ANY Writers" Admins: Type: ImplicitMeta Rule: "MAJORITY Admins" # Capabilities describes the application level capabilities, see the # dedicated Capabilities section elsewhere in this file for a full # description Capabilities: <<: *ApplicationCapabilities ################################################################################ # # 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.chaincode.yourdomain:7050 - orderer1.chaincode.yourdomain:7050 - orderer2.chaincode.yourdomain: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: 98 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. Edit # this list to identify the brokers of the ordering service. # NOTE: Use IP:port notation. Brokers: - kafka0:9092 - kafka1:9092 - kafka2:9092 - kafka3:9092 # Organizations is the list of orgs which are defined as participants on # the orderer side of the network Organizations: # Policies defines the set of policies at this level of the config tree # For Orderer policies, their canonical path is # /Channel/Orderer/<PolicyName> Policies: Readers: Type: ImplicitMeta Rule: "ANY Readers" Writers: Type: ImplicitMeta Rule: "ANY Writers" Admins: Type: ImplicitMeta Rule: "MAJORITY Admins" # BlockValidation specifies what signatures must be included in the block # from the orderer for the peer to validate it. BlockValidation: Type: ImplicitMeta Rule: "ANY Writers" # Capabilities describes the orderer level capabilities, see the # dedicated Capabilities section elsewhere in this file for a full # description Capabilities: <<: *OrdererCapabilities ################################################################################ # # CHANNEL # # This section defines the values to encode into a config transaction or # genesis block for channel related parameters. # ################################################################################ Channel: &ChannelDefaults # Policies defines the set of policies at this level of the config tree # For Channel policies, their canonical path is # /Channel/<PolicyName> Policies: # Who may invoke the ‘Deliver‘ API Readers: Type: ImplicitMeta Rule: "ANY Readers" # Who may invoke the ‘Broadcast‘ API Writers: Type: ImplicitMeta Rule: "ANY Writers" # By default, who may modify elements at this config level Admins: Type: ImplicitMeta Rule: "MAJORITY Admins" # Capabilities describes the channel level capabilities, see the # dedicated Capabilities section elsewhere in this file for a full # description Capabilities: <<: *ChannelCapabilities ################################################################################ # # Profile # # - Different configuration profiles may be encoded here to be specified # as parameters to the configtxgen tool # ################################################################################ Profiles: TwoOrgsOrdererGenesis: <<: *ChannelDefaults Orderer: <<: *OrdererDefaults Organizations: - *OrdererOrg Consortiums: SampleConsortium: Organizations: - *Org1 - *Org2 TwoOrgsChannel: Consortium: SampleConsortium Application: <<: *ApplicationDefaults Organizations: - *Org1 - *Org2
base/docker-compose-base.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: zookeeper: image: hyperledger/fabric-zookeeper restart: always ports: - 2181:2181 - 2888:2888 - 3888:3888 extra_hosts: - "zookeeper0:192.168.10.10" - "zookeeper1:192.168.10.11" - "zookeeper2:192.168.10.12" - "kafka0:192.168.10.10" - "kafka1:192.168.10.11" - "kafka2:192.168.10.12" - "kafka3:192.168.10.13" kafka: image: hyperledger/fabric-kafka restart: always environment: - KAFKA_MESSAGE_MAX_BYTES=103809024 # 99 * 1024 * 1024 B - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024 # 99 * 1024 * 1024 B - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false ports: - 9092:9092 extra_hosts: - "zookeeper0:192.168.10.10" - "zookeeper1:192.168.10.11" - "zookeeper2:192.168.10.12" - "kafka0:192.168.10.10" - "kafka1:192.168.10.11" - "kafka2:192.168.10.12" - "kafka3:192.168.10.13" orderer0.chaincode.yourdomain: container_name: orderer0.chaincode.yourdomain image: hyperledger/fabric-orderer environment: - ORDERER_GENERAL_LOGLEVEL=debug - 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_RETRY_LONGINTERVAL=10s - ORDERER_KAFKA_RETRY_LONGTOTAL=100s - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s - ORDERER_KAFKA_VERBOSE=true working_dir: /workspace/golang/src/github.com/hyperledger/fabric command: orderer volumes: - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ../crypto-config/ordererOrganizations/chaincode.yourdomain/orderers/orderer0.chaincode.yourdomain/msp:/var/hyperledger/orderer/msp - ../crypto-config/ordererOrganizations/chaincode.yourdomain/orderers/orderer0.chaincode.yourdomain/tls/:/var/hyperledger/orderer/tls ports: - 7050:7050 extra_hosts: - "orderer0:192.168.10.10" - "orderer1:192.168.10.11" - "orderer2:192.168.10.12" - "kafka0:192.168.10.10" - "kafka1:192.168.10.11" - "kafka2:192.168.10.12" - "kafka3:192.168.10.13" orderer1.chaincode.yourdomain: container_name: orderer1.chaincode.yourdomain image: hyperledger/fabric-orderer environment: - ORDERER_GENERAL_LOGLEVEL=debug - 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_RETRY_LONGINTERVAL=10s - ORDERER_KAFKA_RETRY_LONGTOTAL=100s - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s - ORDERER_KAFKA_VERBOSE=true working_dir: /workspace/golang/src/github.com/hyperledger/fabric command: orderer volumes: - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ../crypto-config/ordererOrganizations/chaincode.yourdomain/orderers/orderer1.chaincode.yourdomain/msp:/var/hyperledger/orderer/msp - ../crypto-config/ordererOrganizations/chaincode.yourdomain/orderers/orderer1.chaincode.yourdomain/tls/:/var/hyperledger/orderer/tls ports: - 7050:7050 extra_hosts: - "orderer0:192.168.10.10" - "orderer1:192.168.10.11" - "orderer2:192.168.10.12" - "kafka0:192.168.10.10" - "kafka1:192.168.10.11" - "kafka2:192.168.10.12" - "kafka3:192.168.10.13" orderer2.chaincode.yourdomain: container_name: orderer2.chaincode.yourdomain image: hyperledger/fabric-orderer environment: - ORDERER_GENERAL_LOGLEVEL=debug - 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_RETRY_LONGINTERVAL=10s - ORDERER_KAFKA_RETRY_LONGTOTAL=100s - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s - ORDERER_KAFKA_VERBOSE=true working_dir: /workspace/golang/src/github.com/hyperledger/fabric command: orderer volumes: - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ../crypto-config/ordererOrganizations/chaincode.yourdomain/orderers/orderer2.chaincode.yourdomain/msp:/var/hyperledger/orderer/msp - ../crypto-config/ordererOrganizations/chaincode.yourdomain/orderers/orderer2.chaincode.yourdomain/tls/:/var/hyperledger/orderer/tls ports: - 7050:7050 extra_hosts: - "orderer0:192.168.10.10" - "orderer1:192.168.10.11" - "orderer2:192.168.10.12" - "kafka0:192.168.10.10" - "kafka1:192.168.10.11" - "kafka2:192.168.10.12" - "kafka3:192.168.10.13" peer0.org1.chaincode.yourdomain: container_name: peer0.org1.chaincode.yourdomain extends: file: peer-base.yaml service: peer-base environment: - CORE_PEER_ID=peer0.org1.chaincode.yourdomain - CORE_PEER_ADDRESS=peer0.org1.chaincode.yourdomain:7051 - CORE_PEER_CHAINCODEADDRESS=peer0.org1.chaincode.yourdomain:7052 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.chaincode.yourdomain:7051 - CORE_PEER_LOCALMSPID=Org1MSP volumes: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org1.chaincode.yourdomain/peers/peer0.org1.chaincode.yourdomain/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org1.chaincode.yourdomain/peers/peer0.org1.chaincode.yourdomain/tls:/etc/hyperledger/fabric/tls ports: - 7051:7051 - 7052:7052 - 7053:7053 extra_hosts: - "orderer0.chaincode.yourdomain:192.168.10.10" - "orderer1.chaincode.yourdomain:192.168.10.11" - "orderer2.chaincode.yourdomain:192.168.10.12" peer1.org1.chaincode.yourdomain: container_name: peer1.org1.chaincode.yourdomain extends: file: peer-base.yaml service: peer-base environment: - CORE_PEER_ID=peer1.org1.chaincode.yourdomain - CORE_PEER_ADDRESS=peer1.org1.chaincode.yourdomain:7051 - CORE_PEER_CHAINCODEADDRESS=peer1.org1.chaincode.yourdomain:7052 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.chaincode.yourdomain:7051 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.chaincode.yourdomain:7051 - CORE_PEER_LOCALMSPID=Org1MSP volumes: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org1.chaincode.yourdomain/peers/peer1.org1.chaincode.yourdomain/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org1.chaincode.yourdomain/peers/peer1.org1.chaincode.yourdomain/tls:/etc/hyperledger/fabric/tls ports: - 7051:7051 - 7052:7052 - 7053:7053 extra_hosts: - "orderer0.chaincode.yourdomain:192.168.10.10" - "orderer1.chaincode.yourdomain:192.168.10.11" - "orderer2.chaincode.yourdomain:192.168.10.12" peer0.org2.chaincode.yourdomain: container_name: peer0.org2.chaincode.yourdomain extends: file: peer-base.yaml service: peer-base environment: - CORE_PEER_ID=peer0.org2.chaincode.yourdomain - CORE_PEER_ADDRESS=peer0.org2.chaincode.yourdomain:7051 - CORE_PEER_CHAINCODEADDRESS=peer0.org2.chaincode.yourdomain:7052 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.chaincode.yourdomain:7051 - CORE_PEER_LOCALMSPID=Org2MSP volumes: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org2.chaincode.yourdomain/peers/peer0.org2.chaincode.yourdomain/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org2.chaincode.yourdomain/peers/peer0.org2.chaincode.yourdomain/tls:/etc/hyperledger/fabric/tls ports: - 7051:7051 - 7052:7052 - 7053:7053 extra_hosts: - "orderer0.chaincode.yourdomain:192.168.10.10" - "orderer1.chaincode.yourdomain:192.168.10.11" - "orderer2.chaincode.yourdomain:192.168.10.12" peer1.org2.chaincode.yourdomain: container_name: peer1.org2.chaincode.yourdomain extends: file: peer-base.yaml service: peer-base environment: - CORE_PEER_ID=peer1.org2.chaincode.yourdomain - CORE_PEER_ADDRESS=peer1.org2.chaincode.yourdomain:7051 - CORE_PEER_CHAINCODEADDRESS=peer1.org2.chaincode.yourdomain:7052 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.chaincode.yourdomain:7051 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.chaincode.yourdomain:7051 - CORE_PEER_LOCALMSPID=Org2MSP volumes: - /var/run/:/host/var/run/ - ../crypto-config/peerOrganizations/org2.chaincode.yourdomain/peers/peer1.org2.chaincode.yourdomain/msp:/etc/hyperledger/fabric/msp - ../crypto-config/peerOrganizations/org2.chaincode.yourdomain/peers/peer1.org2.chaincode.yourdomain/tls:/etc/hyperledger/fabric/tls ports: - 7051:7051 - 7052:7052 - 7053:7053 extra_hosts: - "orderer0.chaincode.yourdomain:192.168.10.10" - "orderer1.chaincode.yourdomain:192.168.10.11" - "orderer2.chaincode.yourdomain:192.168.10.12"
以上这个docker-compose-base.yaml文件需要在每台服务器上的base目录下替换成同一个,否则后面执行会失败哦
重要的事情:把192.168.10.10服务器的hyperledger/fabric/examples/e2e_cli目录下channel_artifacts/*,crypto-config/*拷贝到其他三台服务器的同一个目录下
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: ca0: image: hyperledger/fabric-ca environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server - FABRIC_CA_SERVER_CA_NAME=ca-org1 - FABRIC_CA_SERVER_TLS_ENABLED=true - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.chaincode.jzyb2b.com-cert.pem - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/67ae2160f54652ddb1c0cfffe1efef2dsfsdfsdfsds5d0591084c55d37a39a21a_sk ports: - "7054:7054" command: sh -c ‘fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.chaincode.jzyb2b.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/67ae2160f54652ddb1c0cfffe1efef2fghfhfghfh0591084c55d37a39a21a_sk -b admin:adminpw -d‘ volumes: - ./crypto-config/peerOrganizations/org1.chaincode.jzyb2b.com/ca/:/etc/hyperledger/fabric-ca-server-config container_name: ca_peerOrg1
注意:你的和我的,是不一样的,别拷贝我这份,拷贝了也没有用,因为我的证书不会给你啊
接下来配置Zookeeper,因为超级账本的启动顺序是zookeeper,kafka,orderer,peer
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: zookeeper0: container_name: zookeeper0 hostname: zookeeper0 extends: file: base/docker-compose-base.yaml service: zookeeper environment: - ZOO_MY_ID=1 - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888
注意:每台机器的hostname,container_name,zoo_my_id是不一样的,别搞错了
接下来
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: kafka0: container_name: kafka0 hostname: kafka0 extends: file: base/docker-compose-base.yaml service: kafka environment: - KAFKA_BROKER_ID=1 - KAFKA_MIN_INSYNC_REPLICAS=2 - KAFKA_DEFAULT_REPLICATION_FACTOR=3 - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
注意:每台机器的hostname,container_name,kafka_broker_id是不一样的,别搞错了
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: orderer0.chaincode.yourdomain: extends: file: base/docker-compose-base.yaml service: orderer0.chaincode.yourdomain container_name: orderer0.chaincode.yourdomain
docker-compose-peer.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: peer0.org1.chaincode.yourdomain: container_name: peer0.org1.chaincode.yourdomain hostname: peer0.org1.chaincode.yourdomain extends: file: base/docker-compose-base.yaml service: peer0.org1.chaincode.yourdomain
再给每个终端建立服务Cli
CHANNEL_NAME=xinhong.test TIMEOUT=10000 docker-compose -f docker-compose-cli.yaml up -d 2>&1
注意,配置文件里的command都需要先注释掉,下一步等的zo每台机器的okeeper,kafka,orderer,peer都部署好了,然后在第一台机器上进入cli需要创建channel,其他的都只需要把创建的xinhong.test.block复制过去就进行了,然后所有peer加入channel后,再安装智能合约以及实例化
docker-compose-cli.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: # 每一台Peer的以下配置不相同 # 主要体现在 CORE_PEER_ADDRESS=peer0.org1.chaincode.yourdomain:7051 cli: container_name: cli image: hyperledger/fabric-tools tty: true environment: - GOPATH=/workspace/golang - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_LOGGING_LEVEL=DEBUG - CORE_PEER_ID=cli - CORE_PEER_ADDRESS=peer0.org1.chaincode.yourdomain:7051 - CORE_PEER_LOCALMSPID=Org1MSP - CORE_PEER_LOCALMSPTYPE=bccsp - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.chaincode.yourdomain/peers/peer0.org1.chaincode.yourdomain/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.chaincode.yourdomain/peers/peer0.org1.chaincode.yourdomain/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.chaincode.yourdomain/peers/peer0.org1.chaincode.yourdomain/tls/ca.crt - CORE_PEER_MSPCONFIGPATH=/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.chaincode.yourdomain/users/Admin@org1.chaincode.yourdomain/msp working_dir: /workspace/golang/src/github.com/hyperledger/fabric/peer #command: /bin/bash -c ‘./scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT‘ volumes: - /var/run/:/host/var/run/ - ../chaincode/go/:/workspace/golang/src/github.com/hyperledger/fabric/examples/chaincode/go - ./crypto-config:/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/ - ./scripts:/workspace/golang/src/github.com/hyperledger/fabric/peer/scripts/ - ./channel-artifacts:/workspace/golang/src/github.com/hyperledger/fabric/peer/channel-artifacts extra_hosts: - "orderer0.chaincode.yourdomain:192.168.10.10" - "orderer1.chaincode.yourdomain:192.168.10.11" - "orderer2.chaincode.yourdomain:192.168.10.12" - "peer0.org1.chaincode.yourdomain:192.168.10.10" - "peer0.org2.chaincode.yourdomain:192.168.10.11" - "peer1.org1.chaincode.yourdomain:192.168.10.12" - "peer1.org2.chaincode.yourdomain:192.168.10.13"
然后按照一样的方式把192.168.10.11,192.168.10.12,192.168.10.13都重新部署一遍
192.168.10.11:
docker-compose-ca.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: ca1: image: hyperledger/fabric-ca environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server - FABRIC_CA_SERVER_CA_NAME=ca-org2 - FABRIC_CA_SERVER_TLS_ENABLED=true - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.chaincode.jzyb2b.com-cert.pem - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/19846ce7eab8886312dceeadd4564564576aede848e158610ea2a50089_sk ports: - "8054:7054" command: sh -c ‘fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org2.chaincode.jzyb2b.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/19846ce7eab8886312dceeyjumj77cf6b9e6aede848e158610ea2a50089_sk -b admin:adminpw -d‘ volumes: - ./crypto-config/peerOrganizations/org2.chaincode.yourdomain/ca/:/etc/hyperledger/fabric-ca-server-config container_name: ca_peerOrg2
docker-compose-zookeeper.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: zookeeper1: container_name: zookeeper1 hostname: zookeeper1 extends: file: base/docker-compose-base.yaml service: zookeeper environment: - ZOO_MY_ID=2 - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888
docker-compose-kafka.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: kafka1: container_name: kafka1 hostname: kafka1 extends: file: base/docker-compose-base.yaml service: kafka environment: - KAFKA_BROKER_ID=2 - KAFKA_MIN_INSYNC_REPLICAS=2 - KAFKA_DEFAULT_REPLICATION_FACTOR=3 - KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
docker-compose-orderer.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: orderer1.chaincode.yourdomain: extends: file: base/docker-compose-base.yaml service: orderer1.chaincode.yourdomain container_name: orderer1.chaincode.yourdomain
docker-compose-peer.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: peer0.org2.chaincode.yourdomain: container_name: peer0.org2.chaincode.yourdomain hostname: peer0.org2.chaincode.yourdomain extends: file: base/docker-compose-base.yaml service: peer0.org2.chaincode.yourdomain
docker-compose-cli.yaml
# Copyright IBM Corp. All Rights Reserved. # # SPDX-License-Identifier: Apache-2.0 # version: ‘2‘ services: # 每一台Peer的以下配置不相同 # 主要体现在 CORE_PEER_ADDRESS=peer0.org2.chaincode.yourdomain:7051 cli: container_name: cli image: hyperledger/fabric-tools tty: true environment: - GOPATH=/workspace/golang - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_LOGGING_LEVEL=DEBUG - CORE_PEER_ID=cli - CORE_PEER_ADDRESS=peer0.org2.chaincode.yourdomain:7051 - CORE_PEER_LOCALMSPID=Org2MSP - CORE_PEER_LOCALMSPTYPE=bccsp - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.chaincode.yourdomain/peers/peer0.org2.chaincode.yourdomain/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.chaincode.yourdomain/peers/peer0.org2.chaincode.yourdomain/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.chaincode.yourdomain/peers/peer0.org2.chaincode.yourdomain/tls/ca.crt - CORE_PEER_MSPCONFIGPATH=/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.chaincode.yourdomain/users/Admin@org2.chaincode.yourdomain/msp working_dir: /workspace/golang/src/github.com/hyperledger/fabric/peer #command: /bin/bash -c ‘./scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT‘ volumes: - /var/run/:/host/var/run/ - ../chaincode/go/:/workspace/golang/src/github.com/hyperledger/fabric/examples/chaincode/go - ./crypto-config:/workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/ - ./scripts:/workspace/golang/src/github.com/hyperledger/fabric/peer/scripts/ - ./channel-artifacts:/workspace/golang/src/github.com/hyperledger/fabric/peer/channel-artifacts extra_hosts: - "orderer0.chaincode.yourdomain:192.168.10.10" - "orderer1.chaincode.yourdomain:192.168.10.11" - "orderer2.chaincode.yourdomain:192.168.10.12" - "peer0.org1.chaincode.yourdomain:192.168.10.10" - "peer0.org2.chaincode.yourdomain:192.168.10.11" - "peer1.org1.chaincode.yourdomain:192.168.10.12" - "peer1.org2.chaincode.yourdomain:192.168.10.13"
192.168.10.12
部署zookeeper2,kafka2,orderer2,peer1.org1,cli
192.168.10.13
部署kafka3,peer1.org2,cli
以上服务都部署完毕后,我们再来创建区块链信息
在192.168.10.10上
进入hyperledger/fabric/examples/e2e_cli目录
执行,docker exec -it cli bash
进入cli的容器
创建通道
peer channel create -o orderer0.chaincode.yourdomain:7050 -c xinhong.test -f ./channel-artifacts/channel.tx --tls --cafile /workspace/golang/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/chaincode.yourdomain/orderers/orderer0.chaincode.yourdomain/msp/tlscacerts/tlsca.chaincode.yourdomian-cert.pem >&log.txt
成功之后,把生成的xinhong.test.block拷贝到当前目录的channel-artifacts里,等待传递到其他服务器
Peer上查询a,显示100
# peer chaincode query -C xinhong.test -n mycc -c ‘{"Args":["query","a"]}‘
Hyperledger fabric 1.3版本的安装部署(原创多机多Orderer部署
标签:合约 alt general rds ast hub -- instant contain
原文地址:https://www.cnblogs.com/si812cn/p/9860391.html