centos下塔建fabric1.1.1群集开发测试环境

1.环境准备

  • 1.安装docker,docker-compose
  • 2.安装go开发环境(goland,vscode,idea....)

2.fabric群集环境规划

节点标识 hostname IP 开放端口 系统
orderer节点 orderer.bjgoodwill.com 192.168.229.136 7050,7051,7052,7053,7054 CentOS 7 x64
jhpeer节点 peer0.jhorg.bjgoodwill.com 192.168.229.136 7050,7051,7052,7053,7054 CentOS 7 x64
jhca节点 ca.jhorg.bjgoodwill.com 192.168.229.136 7050,7051,7052,7053,7054 CentOS 7 x64
cypeer节点 peer0.cyorg.bjgoodwill.com 192.168.229.135 7051,7052,7053,7054 CentOS 7 x64
cyca节点 ca.cyorg.bjgoodwill.com 192.168.229.135 7051,7052,7053,7054 CentOS 7 x64
wjwpeer节点 peer0.wjworg.bjgoodwill.com 192.168.229.137 7051,7052,7053,7054 CentOS 7 x64
wjwca节点 ca.wjworg.bjgoodwill.com 192.168.229.137 7051,7052,7053,7054 CentOS 7 x64

 

 

 

 

 

 

  

 

 

 

 

 

  • 相关hostname必须配置dns,例
  • vim /etc/hosts  或者直接配置dns服务 vi /var/named/bjgoodwill.com.zone
  • 防火墙端口开放相关设置
  • firewall-cmd --zone=public --add-port=7050/tcp --permanent
    firewall-cmd --zone=public --add-port=7051/tcp --permanent
    firewall-cmd --zone=public --add-port=7052/tcp --permanent
    firewall-cmd --zone=public --add-port=7053/tcp --permanent
    firewall-cmd --zone=public --add-port=7054/tcp --permanent

  • firewall-cmd --reload
  • fabric相关镜像下载,并修改相关镜像的tag为latest,我本机镜像下的比较全因为有生产环境(kafka模式),开发测试环境只需要用到以下几个镜像,tools,orderer,ca,peer,couchdb

3.准备fabric1.1.1版本的平台特定二进制文件在线的很难下载的下来

  • 离线下载网址https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/
  • 准备configtx.yaml(创世区块及频道认证文件配置文件)crypto-config.yaml(组织机构和证书相关配置文件)配置文件本项目中使用fabric1.0源码中的版本(solo模式),fabric1.1默认共识是kafka
  • crypto-config.yaml文件内容如下
  •  1 # Copyright IBM Corp. All Rights Reserved.
     2 #
     3 # SPDX-License-Identifier: Apache-2.0
     4 #
     5 
     6 # ---------------------------------------------------------------------------
     7 # "OrdererOrgs" - Definition of organizations managing orderer nodes
     8 # ---------------------------------------------------------------------------
     9 OrdererOrgs:
    10   # ---------------------------------------------------------------------------
    11   # Orderer
    12   # ---------------------------------------------------------------------------
    13   - Name: Orderer
    14     Domain: bjgoodwill.com
    15     # ---------------------------------------------------------------------------
    16     # "Specs" - See PeerOrgs below for complete description
    17     # ---------------------------------------------------------------------------
    18     Specs:
    19       - Hostname: orderer
    20 # ---------------------------------------------------------------------------
    21 # "PeerOrgs" - Definition of organizations managing peer nodes
    22 # ---------------------------------------------------------------------------
    23 PeerOrgs:
    24   # ---------------------------------------------------------------------------
    25   # Org1
    26   # ---------------------------------------------------------------------------
    27   - Name: JHOrg
    28     Domain: jhorg.bjgoodwill.com
    29     # ---------------------------------------------------------------------------
    30     # "Specs"
    31     # ---------------------------------------------------------------------------
    32     # Uncomment this section to enable the explicit definition of hosts in your
    33     # configuration.  Most users will want to use Template, below
    34     #
    35     # Specs is an array of Spec entries.  Each Spec entry consists of two fields:
    36     #   - Hostname:   (Required) The desired hostname, sans the domain.
    37     #   - CommonName: (Optional) Specifies the template or explicit override for
    38     #                 the CN.  By default, this is the template:
    39     #
    40     #                              "{{.Hostname}}.{{.Domain}}"
    41     #
    42     #                 which obtains its values from the Spec.Hostname and
    43     #                 Org.Domain, respectively.
    44     # ---------------------------------------------------------------------------
    45     # Specs:
    46     #   - Hostname: foo # implicitly "foo.org1.example.com"
    47     #     CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above
    48     #   - Hostname: bar
    49     #   - Hostname: baz
    50     # ---------------------------------------------------------------------------
    51     # "Template"
    52     # ---------------------------------------------------------------------------
    53     # Allows for the definition of 1 or more hosts that are created sequentially
    54     # from a template. By default, this looks like "peer%d" from 0 to Count-1.
    55     # You may override the number of nodes (Count), the starting index (Start)
    56     # or the template used to construct the name (Hostname).
    57     #
    58     # Note: Template and Specs are not mutually exclusive.  You may define both
    59     # sections and the aggregate nodes will be created for you.  Take care with
    60     # name collisions
    61     # ---------------------------------------------------------------------------
    62     Template:
    63       Count: 4
    64       # Start: 5
    65       # Hostname: {{.Prefix}}{{.Index}} # default
    66     # ---------------------------------------------------------------------------
    67     # "Users"
    68     # ---------------------------------------------------------------------------
    69     # Count: The number of user accounts _in addition_ to Admin
    70     # ---------------------------------------------------------------------------
    71     Users:
    72       Count: 2
    73   # ---------------------------------------------------------------------------
    74   # Org2: See "Org1" for full specification
    75   # ---------------------------------------------------------------------------
    76   - Name: CYOrg
    77     Domain: cyorg.bjgoodwill.com
    78     Template:
    79       Count: 2
    80     Users:
    81       Count: 1
    82    # ---------------------------------------------------------------------------
    83   # Org2: See "Org1" for full specification
    84   # ---------------------------------------------------------------------------
    85   - Name: WJWOrg
    86     Domain: wjworg.bjgoodwill.com
    87     Template:
    88       Count: 2
    89     Users:
    90       Count: 1
    View Code
  • configtx.yaml文件内容如下
  •   1 # Copyright IBM Corp. All Rights Reserved.
      2 #
      3 # SPDX-License-Identifier: Apache-2.0
      4 #
      5 
      6 ---
      7 ################################################################################
      8 #
      9 #   Profile
     10 #
     11 #   - Different configuration profiles may be encoded here to be specified
     12 #   as parameters to the configtxgen tool
     13 #
     14 ################################################################################
     15 Profiles:
     16 
     17     TwoOrgsOrdererGenesis:
     18         Orderer:
     19             <<: *OrdererDefaults
     20             Organizations:
     21                 - *PrescriptionOrdererOrg
     22         Consortiums:
     23             SampleConsortium:
     24                 Organizations:
     25                     - *JHOrg
     26                     - *CYOrg
     27                     - *WJWOrg
     28     TwoOrgsChannel:
     29         Consortium: SampleConsortium
     30         Application:
     31             <<: *ApplicationDefaults
     32             Organizations:
     33                     - *JHOrg
     34                     - *CYOrg
     35                     - *WJWOrg
     36 
     37 ################################################################################
     38 #
     39 #   Section: Organizations
     40 #
     41 #   - This section defines the different organizational identities which will
     42 #   be referenced later in the configuration.
     43 #
     44 ################################################################################
     45 Organizations:
     46 
     47     # SampleOrg defines an MSP using the sampleconfig.  It should never be used
     48     # in production but may be used as a template for other definitions
     49     - &PrescriptionOrdererOrg
     50         # DefaultOrg defines the organization which is used in the sampleconfig
     51         # of the fabric.git development environment
     52         Name: PrescriptionOrdererOrg
     53 
     54         # ID to load the MSP definition as
     55         ID: PrescriptionOrdererMSP
     56 
     57         # MSPDir is the filesystem path which contains the MSP configuration
     58         MSPDir: crypto-config/ordererOrganizations/bjgoodwill.com/msp
     59 
     60     - &JHOrg
     61         # DefaultOrg defines the organization which is used in the sampleconfig
     62         # of the fabric.git development environment
     63         Name: JHOrgMSP
     64 
     65         # ID to load the MSP definition as
     66         ID: JHOrgMSP
     67 
     68         MSPDir: crypto-config/peerOrganizations/jhorg.bjgoodwill.com/msp
     69 
     70         AnchorPeers:
     71             # AnchorPeers defines the location of peers which can be used
     72             # for cross org gossip communication.  Note, this value is only
     73             # encoded in the genesis block in the Application section context
     74             - Host: peer0.jhorg.bjgoodwill.com
     75               Port: 7051
     76 
     77     - &CYOrg
     78         # DefaultOrg defines the organization which is used in the sampleconfig
     79         # of the fabric.git development environment
     80         Name: CYOrgMSP
     81 
     82         # ID to load the MSP definition as
     83         ID: CYOrgMSP
     84 
     85         MSPDir: crypto-config/peerOrganizations/cyorg.bjgoodwill.com/msp
     86 
     87         AnchorPeers:
     88             # AnchorPeers defines the location of peers which can be used
     89             # for cross org gossip communication.  Note, this value is only
     90             # encoded in the genesis block in the Application section context
     91             - Host: peer0.cyorg.bjgoodwill.com
     92               Port: 7051
     93 
     94     - &WJWOrg
     95         # DefaultOrg defines the organization which is used in the sampleconfig
     96         # of the fabric.git development environment
     97         Name: WJWOrgMSP
     98 
     99         # ID to load the MSP definition as
    100         ID: WJWOrgMSP
    101 
    102         MSPDir: crypto-config/peerOrganizations/wjworg.bjgoodwill.com/msp
    103 
    104         AnchorPeers:
    105             # AnchorPeers defines the location of peers which can be used
    106             # for cross org gossip communication.  Note, this value is only
    107             # encoded in the genesis block in the Application section context
    108             - Host: peer0.wjworg.bjgoodwill.com
    109               Port: 7051
    110 
    111 ################################################################################
    112 #
    113 #   SECTION: Orderer
    114 #
    115 #   - This section defines the values to encode into a config transaction or
    116 #   genesis block for orderer related parameters
    117 #
    118 ################################################################################
    119 Orderer: &OrdererDefaults
    120 
    121     # Orderer Type: The orderer implementation to start
    122     # Available types are "solo" and "kafka"
    123     OrdererType: solo
    124 
    125     Addresses:
    126         - orderer.bjgoodwill.com:7050
    127 
    128     # Batch Timeout: The amount of time to wait before creating a batch
    129     BatchTimeout: 2s
    130 
    131     # Batch Size: Controls the number of messages batched into a block
    132     BatchSize:
    133 
    134         # Max Message Count: The maximum number of messages to permit in a batch
    135         MaxMessageCount: 10
    136 
    137         # Absolute Max Bytes: The absolute maximum number of bytes allowed for
    138         # the serialized messages in a batch.
    139         AbsoluteMaxBytes: 32 MB
    140 
    141         # Preferred Max Bytes: The preferred maximum number of bytes allowed for
    142         # the serialized messages in a batch. A message larger than the preferred
    143         # max bytes will result in a batch larger than preferred max bytes.
    144         PreferredMaxBytes: 512 KB
    145 
    146     Kafka:
    147         # Brokers: A list of Kafka brokers to which the orderer connects
    148         # NOTE: Use IP:port notation
    149         Brokers:
    150             - 127.0.0.1:9092
    151 
    152     # Organizations is the list of orgs which are defined as participants on
    153     # the orderer side of the network
    154     Organizations:
    155 
    156 ################################################################################
    157 #
    158 #   SECTION: Application
    159 #
    160 #   - This section defines the values to encode into a config transaction or
    161 #   genesis block for application related parameters
    162 #
    163 ################################################################################
    164 Application: &ApplicationDefaults
    165 
    166     # Organizations is the list of orgs which are defined as participants on
    167     # the application side of the network
    168     Organizations:
    View Code

     

  • 配置文件每一项的具体作用这里就不细说了

4.生成相关证书与组织机构,生成创世区块频道验证文件

  • 本机的fabric路径为 /work/go/src/github.com/hyperledger/fabric
  • 在fabric当前目录新建一个bjgoodwill的目录 用来放相关文件
  • [root@orderer ~]# mkdir bjgoodwill
  • [root@orderer ~]# cd bjgoodwill
  • 把fabric1.1版本的平台特定二进制文件bin目录放到bjgoodwill目录下,目录结构如下
  • [root@orderer ~]# ./bin/cryptogen generate --config=./crypto-config.yaml  //生成证书与组织机构
  • 提示exe没有执行权限
  • [root@orderer ~]# chmod +x cryptogen
  • [root@orderer ~]# ./bin/cryptogen generate --config=./crypto-config.yaml
  • 设置FABRIC_CFG_PATH环境变量
  • [root@orderer ~]# export  FABRIC_CFG_PATH =$PWD
  • [root@orderer ~]# echo $PWD
  • 根据configtx.yaml生成创世区块和频道验证文件
  • 创建创世工块输出文件夹
  • [root@orderer ~]# mkdir channel-artifacts
  • [root@orderer ~]# ./bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
  • TwoOrgsOrdererGenesis为configtx.yaml文件Profiles->TwoOrgsOrdererGenesis节点名称

  •  生成频道验证文件 prescription.tx文件,生成该文件会指定channelID,该项特别重要,后边很多步骤都会用到,大家可以把该项写到环境变量里

  • [root@orderer ~]# ./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/prescription.tx -channelID prescriptionchannel
  • TwoOrgsChannel为configtx.yaml文件Profiles->TwoOrgsChannel节点名称
  • 我们可以修改一下这两个节点名称再来生成创世区块和频道验证文件
  • 如上图所示,我们把TwoOrgsOrdererGenesis ,TwoOrgsChannel,分别改成了PrescriptionThreeOrgsOrdererGenesis,PrescriptionThreeOrgsChannel,我们再运行一下上边两条命令
  • [root@orderer ~]# ./bin/configtxgen -profile PrescriptionThreeOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis1.block
  • [root@orderer ~]# ./bin/configtxgen -profile PrescriptionThreeOrgsChannel -outputCreateChannelTx ./channel-artifacts/prescription1.tx -channelID prescriptionchannel1

5.部署orderer.bjgoodwill.com节点和peer0.jhorg.bjgoodwill.com节点

  • 准备docker-orderer.yaml和docker-peer0-jhorg.yaml配置文件
  • docker-orderer.yaml文件内容如下
  •  1 version: '2'
     2 
     3 services:
     4 
     5   orderer.bjgoodwill.com:
     6     container_name: orderer.bjgoodwill.com
     7     image: hyperledger/fabric-orderer
     8     environment:
     9       - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=bjgoodwill_default
    10       # - ORDERER_GENERAL_LOGLEVEL=error
    11       - ORDERER_GENERAL_LOGLEVEL=debug
    12       - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
    13       - ORDERER_GENERAL_LISTENPORT=7050
    14       #- ORDERER_GENERAL_GENESISPROFILE=AntiMothOrdererGenesis
    15       - ORDERER_GENERAL_GENESISMETHOD=file
    16       - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
    17       - ORDERER_GENERAL_LOCALMSPID=PrescriptionOrdererMSP
    18       - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
    19       #- ORDERER_GENERAL_LEDGERTYPE=ram
    20       #- ORDERER_GENERAL_LEDGERTYPE=file
    21       # enabled TLS
    22       - ORDERER_GENERAL_TLS_ENABLED=false
    23       - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
    24       - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
    25       - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
    26     working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    27     command: orderer
    28     volumes:
    29     - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
    30     - ./crypto-config/ordererOrganizations/bjgoodwill.com/orderers/orderer.bjgoodwill.com/msp:/var/hyperledger/orderer/msp
    31     - ./crypto-config/ordererOrganizations/bjgoodwill.com/orderers/orderer.bjgoodwill.com/tls/:/var/hyperledger/orderer/tls
    32     networks:
    33       default:
    34         aliases:
    35           - bjgoodwill
    36     ports:
    37       - 7050:7050
    View Code
  • docker-peer0-jhorg.yaml配置文件内容如下
  •   1 version: '2'
      2 
      3 services:
      4 
      5   couchdb:
      6     container_name: couchdb
      7     image: hyperledger/fabric-couchdb
      8     # Comment/Uncomment the port mapping if you want to hide/expose the CouchDB service,
      9     # for example map it to utilize Fauxton User Interface in dev environments.
     10     ports:
     11       - "5984:5984"
     12 
     13   ca:
     14     container_name: jhca
     15     image: hyperledger/fabric-ca
     16     environment:
     17       - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
     18       - FABRIC_CA_SERVER_CA_NAME=ca
     19       - FABRIC_CA_SERVER_TLS_ENABLED=false
     20       - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.jhorg.bjgoodwill.com-cert.pem
     21       - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/5c596b700e9da00130d086a3254d6596c47512766f430aae4dcbdadcb8f7e28a_sk
     22     ports:
     23       - "7054:7054"
     24     command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.jhorg.bjgoodwill.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/5c596b700e9da00130d086a3254d6596c47512766f430aae4dcbdadcb8f7e28a_sk -b admin:adminpw -d'
     25     volumes:
     26       - ./crypto-config/peerOrganizations/jhorg.bjgoodwill.com/ca/:/etc/hyperledger/fabric-ca-server-config
     27 
     28   peer0.jhorg.bjgoodwill.com:
     29     container_name: peer0.jhorg.bjgoodwill.com
     30     image: hyperledger/fabric-peer
     31     environment:
     32       - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
     33       - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
     34 
     35       - CORE_PEER_ID=peer0.jhorg.bjgoodwill.com
     36       - CORE_PEER_NETWORKID=bjgoodwill
     37       - CORE_PEER_ADDRESS=peer0.jhorg.bjgoodwill.com:7051
     38       - CORE_PEER_CHAINCODELISTENADDRESS=peer0.jhorg.bjgoodwill.com:7052
     39       - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.jhorg.bjgoodwill.com:7051
     40       - CORE_PEER_LOCALMSPID=JHOrgMSP
     41 
     42       - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
     43       # the following setting starts chaincode containers on the same
     44       # bridge network as the peers
     45       # https://docs.docker.com/compose/networking/
     46       - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=bjgoodwill
     47       # - CORE_LOGGING_LEVEL=ERROR
     48       - CORE_LOGGING_LEVEL=INFO
     49       - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=bjgoodwill_default
     50       - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
     51       - CORE_PEER_GOSSIP_USELEADERELECTION=true
     52       - CORE_PEER_GOSSIP_ORGLEADER=false
     53       - CORE_PEER_PROFILE_ENABLED=false
     54       - CORE_PEER_TLS_ENABLED=false
     55       - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
     56       - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
     57       - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
     58     volumes:
     59         - /var/run/:/host/var/run/
     60         - ./crypto-config/peerOrganizations/jhorg.bjgoodwill.com/peers/peer0.jhorg.bjgoodwill.com/msp:/etc/hyperledger/fabric/msp
     61         - ./crypto-config/peerOrganizations/jhorg.bjgoodwill.com/peers/peer0.jhorg.bjgoodwill.com/tls:/etc/hyperledger/fabric/tls
     62     working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
     63     command: peer node start
     64     ports:
     65       - 7051:7051
     66       - 7052:7052
     67       - 7053:7053
     68     depends_on:
     69       - couchdb
     70     networks:
     71       default:
     72         aliases:
     73           - bjgoodwill
     74     extra_hosts:
     75      - "orderer.bjgoodwill.com:192.168.229.136"
     76 
     77   cli:
     78     container_name: cli
     79     image: hyperledger/fabric-tools
     80     tty: true
     81     environment:
     82       - GOPATH=/opt/gopath
     83       - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
     84       # - CORE_LOGGING_LEVEL=ERROR
     85       - CORE_LOGGING_LEVEL=DEBUG
     86       - CORE_PEER_ID=cli
     87       - CORE_PEER_ADDRESS=peer0.jhorg.bjgoodwill.com:7051
     88       - CORE_PEER_LOCALMSPID=JHOrgMSP
     89       - CORE_PEER_TLS_ENABLED=false
     90       - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/jhorg.bjgoodwill.com/peers/peer0.jhorg.bjgoodwill.com/tls/server.crt
     91       - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/jhorg.bjgoodwill.com/peers/peer0.jhorg.bjgoodwill.com/tls/server.key
     92       - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/jhorg.bjgoodwill.com/peers/peer0.jhorg.bjgoodwill.com/tls/ca.crt
     93       - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/jhorg.bjgoodwill.com/users/Admin@jhorg.bjgoodwill.com/msp
     94     working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
     95     volumes:
     96         - /var/run/:/host/var/run/
     97         - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/bjgoodwill/chaincode/go
     98         - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
     99         - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    100     depends_on:
    101       - peer0.jhorg.bjgoodwill.com
    102     extra_hosts:
    103      -  "orderer.bjgoodwill.com:192.168.229.136"
    104      -  "peer0.jhorg.bjgoodwill.com:192.168.229.136"
    View Code
  • docker-peer0-jhorg.yaml文件的- FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/5c596b700e9da00130d086a3254d6596c47512766f430aae4dcbdadcb8f7e28a_sk该项内容在我们生成的相关组织证书的ca文件夹下

  • [root@orderer ~]#docker-compose -f docker-orderer.yaml up -d
  • 如果orderer容器没有启起来或有相关错误
  • [root@orderer ~]# docker logs -t -f --tail 50 orderer.bjgoodwill.com查看详细的错误信息,百分之九十的错都是配置或证书路径,或网络引起
  • 我这里由于没有错能看到详细的启动信息
  • [root@orderer ~]# docker-compose -f docker-peer0-jhorg.yaml up -d
  • 我们这里得到了一个错误,意思是couchdb容器名已使用,我们先删掉它
  • [root@orderer ~]# docker rm couchdb
  • 删掉cli couchdb容器以后我们启动成功了,我们看一下peer0.jhorg.bjgoodwill.com节点的相关日志
  • [root@orderer ~]# docker exec -it cli bash  //进入客户端
  • root@后边807b9cd828d2为cli容器的container ID
  • 创建channel
  • [root@orderer ~]# peer channel create -o orderer.bjgoodwill.com:7050 -c prescriptionchannel -t 50 -f ./channel-artifacts/prescription.tx
  • ls命令我们可以看到在cli容器运行的当前目录下生成了一个prescriptionchannel.block文件cyprescriptionchannel.block是别的频道文件,这个文件很重要,别的节点加入该频道都需要用到该文件,我们把它从容器目录拷到bjgoodwill/channel-artifacts/目录下,这里需要用到container id,
  • [root@orderer ~]# docker cp 49473348f37a:/opt/gopath/src/github.com/hyperledger/fabric/peer/prescriptionchannel.block /work/go/src/github.com/hyperledger/fabric/bjgoodwill/channel-artifacts/
  • 如果由于机子重启或者节点重启该文件丢失了,我们可以执行以下的命令 peer channel fetch config
  • [root@orderer ~]# peer channel fetch config -c prescriptionchannel -o orderer.bjgoodwill.com:7050
  • 返回orderer网络可用的最新频道配置块。这只能是一个配置事务,该命令会生成一个代_config.block文件,我们能用该文件加入频道,至于fetch的其他命令,newset,oldset,block number大家自己去看吧官网都有介绍.
  • [root@orderer ~]# peer channel join -b prescriptionchannel_config.block //我们这里直接用了刚才生成的_config.block文件
  • [root@orderer ~]# peer chaincode install -n prescriptionchannel -p github.com/hyperledger/fabric/bjgoodwill/chaincode/go/chaincode_example02 -v 1.0  //安装智能合约
  • 在bjgoodill目录下新建chaincode/go目录,把fabric/examples/e2e_cli/examples/chaincode/go/example02拷过去
  • [root@orderer ~]# peer chaincode instantiate -o orderer.bjgoodwill.com:7050 -C prescriptionchannel -n prescriptionchannel -c '{"Args":["init","A","10","B","10"]}' -P "OR ('CYOrgMSP.member')" -v 1.0  //实例化智能合约中通过-P加入了背书方案,指定了仅有CYOrg的成员才具备背书能力,别的节点都只能query
  • 我这里由于已经实例化过了所以报了这个错,当智能合约实例化成功以后,我们就可以执行,query,invoke相关操作了,具体如下
  • [root@orderer ~]# peer chaincode query -C prescriptionchannel -n prescriptionchannel -c '{"Args":["query":"A"]}' //peer0.jhorg.bjoogdwill.com 执行query
  • [root@orderer ~]# peer chaincode invoke -C prescriptionchannel -n prescriptionchannel -c'{"Args":["invoke","B","A","2"]}' //peer0.jhorg.bjoogdwill.com 执行invoke ,执行失败,不会做任何操作,因为我们指定的背书方案是CYOrg
  • [root@orderer ~]# peer chaincode query -C prescriptionchannel -n prescriptionchannel -c '{"Args":["query":"A"]}' //我们在执行一边query 操作
  • 值没有改变,依然是5
  • 我们在peer0.cyorg.bjgoodwill.com节点执行一下invoke操作
  • [root@orderer ~]# peer chaincode invoke -C prescriptionchannel -n prescriptionchannel -c'{"Args":["invoke","B","A","3"]}' //peer0.cyorg.bjoogdwill.com 执行invoke
  • [root@orderer ~]# peer chaincode query -C prescriptionchannel -n prescriptionchannel -c '{"Args":["query":"A"]}' //我们在执行一边query 操作,peer0.cyorg.bjgoodwill.com
  • 我们查询A的质,已经修改成了8
  • peer0.cyorg.bjgoodwill.com,peer0.wjworg.bjgoodwill.com这两节点就不一一讲了,下边附上这两节点的配置文件
  • docker-peer0-cyorg.yaml文件内容
  •   1 version: '2'
      2 
      3 services:
      4 
      5   couchdb:
      6     container_name: couchdb
      7     image: hyperledger/fabric-couchdb
      8     # Comment/Uncomment the port mapping if you want to hide/expose the CouchDB service,
      9     # for example map it to utilize Fauxton User Interface in dev environments.
     10     ports:
     11       - "5984:5984"
     12 
     13   ca:
     14     container_name: cyca
     15     image: hyperledger/fabric-ca
     16     environment:
     17       - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
     18       - FABRIC_CA_SERVER_CA_NAME=ca
     19       - FABRIC_CA_SERVER_TLS_ENABLED=false
     20       - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.cyorg.bjgoodwill.com-cert.pem
     21       - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/704e1a49f58b74107bcc3d60eb6481517ab5fea409f2609751c9c7fb8ae5ea51_sk
     22     ports:
     23       - "7054:7054"
     24     command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.cyorg.bjgoodwill.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/704e1a49f58b74107bcc3d60eb6481517ab5fea409f2609751c9c7fb8ae5ea51_sk -b admin:adminpw -d'
     25     volumes:
     26       - ./crypto-config/peerOrganizations/cyorg.bjgoodwill.com/ca/:/etc/hyperledger/fabric-ca-server-config
     27 
     28   peer0.cyorg.bjgoodwill.com:
     29     container_name: peer0.cyorg.bjgoodwill.com
     30     image: hyperledger/fabric-peer
     31     environment:
     32       - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
     33       - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
     34 
     35       - CORE_PEER_ID=peer0.cyorg.bjgoodwill.com
     36       - CORE_PEER_NETWORKID=bjgoodwill
     37       - CORE_PEER_ADDRESS=peer0.cyorg.bjgoodwill.com:7051
     38       - CORE_PEER_CHAINCODELISTENADDRESS=peer0.cyorg.bjgoodwill.com:7052
     39       - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.cyorg.bjgoodwill.com:7051
     40       - CORE_PEER_LOCALMSPID=CYOrgMSP
     41 
     42       - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
     43       # the following setting starts chaincode containers on the same
     44       # bridge network as the peers
     45       # https://docs.docker.com/compose/networking/
     46       - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=bjgoodwill
     47       # - CORE_LOGGING_LEVEL=ERROR
     48       - CORE_LOGGING_LEVEL=INFO
     49       - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=bjgoodwill_default
     50       - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
     51       - CORE_PEER_GOSSIP_USELEADERELECTION=true
     52       - CORE_PEER_GOSSIP_ORGLEADER=false
     53       - CORE_PEER_PROFILE_ENABLED=false
     54       - CORE_PEER_TLS_ENABLED=false
     55       - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
     56       - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
     57       - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
     58     volumes:
     59         - /var/run/:/host/var/run/
     60         - ./crypto-config/peerOrganizations/cyorg.bjgoodwill.com/peers/peer0.cyorg.bjgoodwill.com/msp:/etc/hyperledger/fabric/msp
     61         - ./crypto-config/peerOrganizations/cyorg.bjgoodwill.com/peers/peer0.cyorg.bjgoodwill.com/tls:/etc/hyperledger/fabric/tls
     62     working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
     63     command: peer node start
     64     ports:
     65       - 7051:7051
     66       - 7052:7052
     67       - 7053:7053
     68     depends_on:
     69       - couchdb
     70     networks:
     71       default:
     72         aliases:
     73           - bjgoodwill
     74     extra_hosts:
     75      - "orderer.bjgoodwill.com:192.168.229.136"
     76 
     77   cli:
     78     container_name: cli
     79     image: hyperledger/fabric-tools
     80     tty: true
     81     environment:
     82       - GOPATH=/opt/gopath
     83       - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
     84       # - CORE_LOGGING_LEVEL=ERROR
     85       - CORE_LOGGING_LEVEL=DEBUG
     86       - CORE_PEER_ID=cli
     87       - CORE_PEER_ADDRESS=peer0.cyorg.bjgoodwill.com:7051
     88       - CORE_PEER_LOCALMSPID=CYOrgMSP
     89       - CORE_PEER_TLS_ENABLED=false
     90       - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/cyorg.bjgoodwill.com/peers/peer0.cyorg.bjgoodwill.com/tls/server.crt
     91       - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/cyorg.bjgoodwill.com/peers/peer0.cyorg.bjgoodwill.com/tls/server.key
     92       - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/cyorg.bjgoodwill.com/peers/peer0.cyorg.bjgoodwill.com/tls/ca.crt
     93       - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/cyorg.bjgoodwill.com/users/Admin@cyorg.bjgoodwill.com/msp
     94     working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
     95     volumes:
     96         - /var/run/:/host/var/run/
     97         - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/bjgoodwill/chaincode/go
     98         - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
     99         - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    100     depends_on:
    101       - peer0.cyorg.bjgoodwill.com
    102     extra_hosts:
    103      -  "orderer.bjgoodwill.com:192.168.229.136"
    104      -  "peer0.cyorg.bjgoodwill.com:192.168.229.135"
    View Code
  • docker-peer0-wjworg.yaml文件内容
  •   1 version: '2'
      2 
      3 services:
      4 
      5   couchdb:
      6     container_name: couchdb
      7     image: hyperledger/fabric-couchdb
      8     # Comment/Uncomment the port mapping if you want to hide/expose the CouchDB service,
      9     # for example map it to utilize Fauxton User Interface in dev environments.
     10     ports:
     11       - "5984:5984"
     12 
     13   ca:
     14     container_name: wjwca
     15     image: hyperledger/fabric-ca
     16     environment:
     17       - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
     18       - FABRIC_CA_SERVER_CA_NAME=ca
     19       - FABRIC_CA_SERVER_TLS_ENABLED=false
     20       - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.wjworg.bjgoodwill.com-cert.pem
     21       - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/f0f25e1a4e10111e7a551004c275ce00a9f17d553e2eaf4d5d1b7cccef6fb5d5_sk
     22     ports:
     23       - "7054:7054"
     24     command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.wjworg.bjgoodwill.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/f0f25e1a4e10111e7a551004c275ce00a9f17d553e2eaf4d5d1b7cccef6fb5d5_sk -b admin:adminpw -d'
     25     volumes:
     26       - ./crypto-config/peerOrganizations/wjworg.bjgoodwill.com/ca/:/etc/hyperledger/fabric-ca-server-config
     27 
     28   peer0.wjworg.bjgoodwill.com:
     29     container_name: peer0.wjworg.bjgoodwill.com
     30     image: hyperledger/fabric-peer
     31     environment:
     32       - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
     33       - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
     34 
     35       - CORE_PEER_ID=peer0.wjworg.bjgoodwill.com
     36       - CORE_PEER_NETWORKID=bjgoodwill
     37       - CORE_PEER_ADDRESS=peer0.wjworg.bjgoodwill.com:7051
     38       - CORE_PEER_CHAINCODELISTENADDRESS=peer0.wjworg.bjgoodwill.com:7052
     39       - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.wjworg.bjgoodwill.com:7051
     40       - CORE_PEER_LOCALMSPID=WJWOrgMSP
     41 
     42       - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
     43       # the following setting starts chaincode containers on the same
     44       # bridge network as the peers
     45       # https://docs.docker.com/compose/networking/
     46       - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=bjgoodwill
     47       # - CORE_LOGGING_LEVEL=ERROR
     48       - CORE_LOGGING_LEVEL=INFO
     49       - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=bjgoodwill_default
     50       - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
     51       - CORE_PEER_GOSSIP_USELEADERELECTION=true
     52       - CORE_PEER_GOSSIP_ORGLEADER=false
     53       - CORE_PEER_PROFILE_ENABLED=false
     54       - CORE_PEER_TLS_ENABLED=false
     55       - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
     56       - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
     57       - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
     58     volumes:
     59         - /var/run/:/host/var/run/
     60         - ./crypto-config/peerOrganizations/wjworg.bjgoodwill.com/peers/peer0.wjworg.bjgoodwill.com/msp:/etc/hyperledger/fabric/msp
     61         - ./crypto-config/peerOrganizations/wjworg.bjgoodwill.com/peers/peer0.wjworg.bjgoodwill.com/tls:/etc/hyperledger/fabric/tls
     62     working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
     63     command: peer node start
     64     ports:
     65       - 7051:7051
     66       - 7052:7052
     67       - 7053:7053
     68     depends_on:
     69       - couchdb
     70     networks:
     71       default:
     72         aliases:
     73           - bjgoodwill
     74     extra_hosts:
     75      - "orderer.bjgoodwill.com:192.168.229.136"
     76 
     77   cli:
     78     container_name: cli
     79     image: hyperledger/fabric-tools
     80     tty: true
     81     environment:
     82       - GOPATH=/opt/gopath
     83       - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
     84       # - CORE_LOGGING_LEVEL=ERROR
     85       - CORE_LOGGING_LEVEL=DEBUG
     86       - CORE_PEER_ID=cli
     87       - CORE_PEER_ADDRESS=peer0.wjworg.bjgoodwill.com:7051
     88       - CORE_PEER_LOCALMSPID=WJWOrgMSP
     89       - CORE_PEER_TLS_ENABLED=false
     90       - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/wjworg.bjgoodwill.com/peers/peer0.wjworg.bjgoodwill.com/tls/server.crt
     91       - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/wjworg.bjgoodwill.com/peers/peer0.wjworg.bjgoodwill.com/tls/server.key
     92       - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/wjworg.bjgoodwill.com/peers/peer0.wjworg.bjgoodwill.com/tls/ca.crt
     93       - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/wjworg.bjgoodwill.com/users/Admin@wjworg.bjgoodwill.com/msp
     94     working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
     95     volumes:
     96         - /var/run/:/host/var/run/
     97         - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/bjgoodwill/chaincode/go
     98         - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
     99         - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    100     depends_on:
    101       - peer0.wjworg.bjgoodwill.com
    102     extra_hosts:
    103      -  "orderer.bjgoodwill.com:192.168.229.136"
    104      -  "peer0.wjworg.bjgoodwill.com:192.168.229.137"
    View Code

此文是原创,欢迎大家指正,交流,^_^^_^

posted @ 2018-09-07 14:53  一直行走的小兵  阅读(592)  评论(0编辑  收藏  举报