创建网络
一个生产的fabric网络应该由各个组织自己保存自己的加密材料,测试环境为了演示在本地生成所有组织的加密材料。
生成加密材料
创建配置文件
创建supply-finance
文件夹,配置config/crypto-config.yaml
文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 OrdererOrgs: - Name: Orderer Domain: supply.com Specs: - Hostname: orderer PeerOrgs: - Name: gyl_core_org1 Domain: core.supply.com Template: Count: 1 Users: Count: 2 - Name: gyl_f_org1 Domain: f1.supply.com Template: Count: 1 Users: Count: 2 - Name: gyl_s_org1 Domain: s1.supply.com Template: Count: 1 Users: Count: 2 - Name: gyl_s_org2 Domain: s2.supply.com Template: Count: 1 Users: Count: 2
使用配置文件生成加密材料
使用下面的命令生成加密材料:
1 cryptogen generate --config=config/crypto-config.yaml --output="./organizations"
使用加密材料生成创世纪区块
使用下面的命令生成系统创世纪区块:
1 configtxgen -profile TestOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
输出结果:
1 2 3 4 5 6 7 8 esis.block 2020-12-24 15:41:52.702 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration 2020-12-24 15:41:52.716 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft 2020-12-24 15:41:52.716 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 2020-12-24 15:41:52.716 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /Users/apple/code/open-source/blockchain/hyperledger/supply-finance/config/configtx.yaml 2020-12-24 15:41:52.723 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block 2020-12-24 15:41:52.723 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Creating system channel genesis block 2020-12-24 15:41:52.724 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
遇到的错误信息:
1 2020-12-24 15:39:28.696 CST [common.tools.configtxgen] main -> FATA 005 Error on outputBlock: could not create bootstrapper: could not create channel group: could not create orderer group: cannot marshal metadata for orderer type etcdraft: cannot load client cert for consenter orderer.supply.com:8050: open /Users/apple/code/open-source/blockchain/hyperledger/supply-finance/cryptogen/crypto-config/ordererOrganizations/supply.com/orderers/orderer.supply.com/tls/server.crt: no such file or directory
错误原因: $FABRIC_CFG_PATH/configtx.yaml
配置的加密文件地址不正确
启动网络
各个组织的加密材料生成之后,在本地docker环境启动这些组织的peer节点。
配置docker-compose.yml文件
在supply-finance
目录下添加docker/docker-compose.yml
文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 version: '2' volumes: orderer.supply.com: peer0.core.supply.com: peer0.f1.supply.com: peer0.s1.supply.com: peer0.s2.supply.com: networks: test: services: orderer.supply.com: container_name: orderer.supply.com image: hyperledger/fabric-orderer:2.2.0 environment: - FABRIC_LOGGING_SPEC=INFO - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_LISTENPORT=8050 - ORDERER_GENERAL_GENESISMETHOD=file - ORDERER_GENERAL_BOOTSTRAPFILE=/etc/hyperledger/orderer/orderer.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/fabric/msp - ORDERER_GENERAL_LEDGERTYPE=file - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:8443 - ORDERER_GENERAL_TLS_ENABLED=true - ORDERER_GENERAL_TLS_PRIVATEKEY=/etc/hyperledger/fabric/tls/server.key - ORDERER_GENERAL_TLS_CERTIFICATE=/etc/hyperledger/fabric/tls/server.crt - ORDERER_GENERAL_TLS_ROOTCAS=[/etc/hyperledger/fabric/tls/ca.crt] - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/etc/hyperledger/fabric/tls/server.crt - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/etc/hyperledger/fabric/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/etc/hyperledger/fabric/tls/ca.crt] working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: orderer volumes: - ../system-genesis-block/genesis.block:/etc/hyperledger/orderer/orderer.genesis.block - ../organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/msp:/etc/hyperledger/fabric/msp - ../organizations/ordererOrganizations/supply.com/orderers/orderer.supply.com/tls:/etc/hyperledger/fabric/tls - orderer.supply.com:/var/hyperledger/production/orderer - ../organizations:/tmp ports: - 8050 :8050 networks: - test peer0.core.supply.com: container_name: peer0.core.supply.com image: hyperledger/fabric-peer:2.2.0 environment: - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_test - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_TLS_ENABLED=true - CORE_PEER_PROFILE_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt - CORE_PEER_ID=peer0.core.supply.com - CORE_PEER_ADDRESS=peer0.core.supply.com:8051 - CORE_PEER_LISTENADDRESS=0.0.0.0:8051 - CORE_PEER_CHAINCODEADDRESS=peer0.core.supply.com:8052 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052 - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.core.supply.com:8051 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.core.supply.com:8051 - CORE_PEER_LOCALMSPID=GylCoreOrg1MSP volumes: - /var/run/:/host/var/run/ - ../organizations/peerOrganizations/core.supply.com/peers/peer0.core.supply.com/msp:/etc/hyperledger/fabric/msp - ../organizations/peerOrganizations/core.supply.com/peers/peer0.core.supply.com/tls:/etc/hyperledger/fabric/tls - peer0.core.supply.com:/var/hyperledger/production - ../organizations:/tmp working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start ports: - 8051 :8051 networks: - test peer0.f1.supply.com: container_name: peer0.f1.supply.com image: hyperledger/fabric-peer:2.2.0 environment: - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_test - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_TLS_ENABLED=true - CORE_PEER_PROFILE_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt - CORE_PEER_ID=peer0.f1.supply.com - CORE_PEER_ADDRESS=peer0.f1.supply.com:8053 - CORE_PEER_LISTENADDRESS=0.0.0.0:8053 - CORE_PEER_CHAINCODEADDRESS=peer0.f1.supply.com:8054 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8054 - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.f1.supply.com:8053 - CORE_PEER_LOCALMSPID=GylFOrg1MSP volumes: - /var/run/:/host/var/run/ - ../organizations/peerOrganizations/f1.supply.com/peers/peer0.f1.supply.com/msp:/etc/hyperledger/fabric/msp - ../organizations/peerOrganizations/f1.supply.com/peers/peer0.f1.supply.com/tls:/etc/hyperledger/fabric/tls - peer0.f1.supply.com:/var/hyperledger/production - ../organizations:/tmp working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start ports: - 8053 :8053 networks: - test peer0.s1.supply.com: container_name: peer0.s1.supply.com image: hyperledger/fabric-peer:2.2.0 environment: - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_test - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_TLS_ENABLED=true - CORE_PEER_PROFILE_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt - CORE_PEER_ID=peer0.s1.supply.com - CORE_PEER_ADDRESS=peer0.s1.supply.com:8055 - CORE_PEER_LISTENADDRESS=0.0.0.0:8055 - CORE_PEER_CHAINCODEADDRESS=peer0.s1.supply.com:8056 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8056 - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.s1.supply.com:8055 - CORE_PEER_LOCALMSPID=GylSOrg1MSP volumes: - /var/run/:/host/var/run/ - ../organizations/peerOrganizations/s1.supply.com/peers/peer0.s1.supply.com/msp:/etc/hyperledger/fabric/msp - ../organizations/peerOrganizations/s1.supply.com/peers/peer0.s1.supply.com/tls:/etc/hyperledger/fabric/tls - peer0.s1.supply.com:/var/hyperledger/production - ../organizations:/tmp working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start ports: - 8055 :8055 networks: - test peer0.s2.supply.com: container_name: peer0.s2.supply.com image: hyperledger/fabric-peer:2.2.0 environment: - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_test - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_TLS_ENABLED=true - CORE_PEER_PROFILE_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt - CORE_PEER_ID=peer0.s2.supply.com - CORE_PEER_ADDRESS=peer0.s2.supply.com:8151 - CORE_PEER_LISTENADDRESS=0.0.0.0:8151 - CORE_PEER_CHAINCODEADDRESS=peer0.s2.supply.com:8152 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8152 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.s2.supply.com:8151 - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.s2.supply.com:8151 - CORE_PEER_LOCALMSPID=GylSOrg2MSP volumes: - /var/run/:/host/var/run/ - ../organizations/peerOrganizations/s2.supply.com/peers/peer0.s2.supply.com/msp:/etc/hyperledger/fabric/msp - ../organizations/peerOrganizations/s2.supply.com/peers/peer0.s2.supply.com/tls:/etc/hyperledger/fabric/tls - ../organizations:/tmp - peer0.s2.supply.com:/var/hyperledger/production working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start ports: - 8151 :8151 networks: - test
使用docker-compose.yml配置文件启动各组织的服务
命令如下:
1 docker-compose -f ./docker/docker-compose.yml up -d
启动之后会在docker启动下面这些容器: