首先,咱們在安裝前,要考慮一個問題html
Hyperledger Fabric,經過指定的節點進行背書受權,才能完成交易的存儲java
延伸開來,就是爲了實現容錯、高併發、易擴展,須要zookeeper來選擇排序引擎處理記帳的惟一性node
咱們這裏選擇kafka排序引擎並經過Kafka集羣和zookeeper集羣保證數據的一致性,實現排序功能python
同時,爲了排序服務器的穩定,採起多Orderer集羣實現容錯空間,linux
爲此,咱們採用了最基礎的配置方案:兩個組織,四個節點git
兩個CA服務器,三個Zookeeper服務器,四個Kafka服務器,3個Orderer服務器,4個Peer服務器github
你們一看到這麼多服務器,可能會嚇一跳,那咱們就把這些服務器優化一下,變成以下:golang
192.168.10.10:docker
ca.org1.chaincode.yourdomain,zookeeper0,kafka0,orderer0.chaincode.yourdomain,peer0.org1.chaincode.yourdomaincentos
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做爲背書節點,其餘的自動同步新的更新(若是是跨公司有同一個業務,也能夠指定各自公司的背書節點,防止一方對數據進行篡改)。
說了總體的框架,那麼下面咱們就來部署吧:
1、基礎資料安裝
首先個人服務器是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"]}'