| 知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
Tools 在生成創世區塊的時候我們就曾經使用,你可以沿用之前的 tools 節點,或者創建一個 cli 節點,這個節點主要是用於管理區塊鏈集群,例如合約部署,調試等等。
docker pull hyperledger/fabric-tools:x86_64-1.1.0 docker tag hyperledger/fabric-tools:x86_64-1.1.0 hyperledger/fabric-tools
version: '3'
networks:
basic:
services:
cli:
container_name: cli
image: hyperledger/fabric-tools
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
- CORE_CHAINCODE_KEEPALIVE=10
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./chaincode/:/opt/gopath/src/github.com/
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ~/netkiller:/root/netkiller
networks:
- basic
#depends_on:
# - orderer.example.com
# - peer0.org1.example.com
# - couchdb
extra_hosts:
- "ca.example.com:172.16.0.20"
- "orderer.example.com:172.16.0.21"
- "peer0.org1.example.com:172.16.0.22"
- "couchdb.example.com:172.16.0.25"
[root@localhost netkiller]# docker-compose -f docker-compose-cli.yaml up -d
後面合約的部署將在 cli 節點上進行
這裡我們需要幾個命令(configtxgen configtxlator cryptogen),官方的安裝方式:
curl -sSL https://goo.gl/byy2Qj | bash -s 1.1.0
無論如何我都安裝不成功,可能是(https://goo.gl/byy2Qj)被天朝給牆了。不過我發現 fabric-tools 裡面有這個工具。
![]() | 提示 |
|---|---|
|
經過翻牆發現 https://goo.gl/byy2Qj 地址是 301 到下面地址: https://raw.githubusercontent.com/hyperledger/fabric/v1.1.0/scripts/bootstrap.sh |
[root@localhost ~]# mkdir netkiller
[root@localhost ~]# cd netkiller/
[root@localhost netkiller]# mkdir -p {chaincode,crypto-config,config,artifacts}
創建證書
OrdererOrgs:
- Name: Orderer
Domain: example.com
Specs:
- Hostname: orderer
PeerOrgs:
- Name: Org1
Domain: org1.example.com
Template:
Count: 1
Users:
Count: 1
---
Profiles:
OneOrgOrdererGenesis:
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org1
OneOrgChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: crypto-config/ordererOrganizations/example.com/msp
- &Org1
Name: Org1MSP
ID: Org1MSP
MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
AnchorPeers:
- Host: peer0.org1.example.com
Port: 7051
Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
- orderer.example.com:7050
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 512 KB
Kafka:
Brokers:
- 127.0.0.1:9092
Organizations:
Application: &ApplicationDefaults
Organizations:
命令
cryptogen generate --config=./crypto-config.yaml
演示
root@8f467a88de99:~/netkiller# cryptogen generate --config=./crypto-config.yaml org1.example.com root@8f467a88de99:~/netkiller# ls -1 crypto-config ordererOrganizations peerOrganizations
root@8f467a88de99:~/netkiller# export FABRIC_CFG_PATH=$PWD root@8f467a88de99:~/netkiller# configtxgen -profile OneOrgOrdererGenesis -outputBlock ./config/genesis.block 2018-02-08 08:35:30.121 UTC [common/configtx/tool] main -> INFO 001 Loading configuration 2018-02-08 08:35:30.236 UTC [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block 2018-02-08 08:35:30.238 UTC [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block
命令
CHANNEL_NAME=mychannel configtxgen -profile OneOrgChannel -outputCreateChannelTx ./config/channel.tx -channelID $CHANNEL_NAME
操作演示
root@8f467a88de99:~/netkiller# CHANNEL_NAME=mychannel root@8f467a88de99:~/netkiller# configtxgen -profile OneOrgChannel -outputCreateChannelTx ./config/channel.tx -channelID $CHANNEL_NAME 2018-02-08 08:41:08.010 UTC [common/configtx/tool] main -> INFO 001 Loading configuration 2018-02-08 08:41:08.020 UTC [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx 2018-02-08 08:41:08.020 UTC [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx
命令
CHANNEL_NAME=mychannel configtxgen -profile OneOrgChannel -outputAnchorPeersUpdate ./config/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
操作演示
root@8f467a88de99:~/netkiller# CHANNEL_NAME=mychannel root@8f467a88de99:~/netkiller# configtxgen -profile OneOrgChannel -outputAnchorPeersUpdate ./config/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP 2018-02-08 08:46:19.162 UTC [common/configtx/tool] main -> INFO 001 Loading configuration 2018-02-08 08:46:19.176 UTC [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update 2018-02-08 08:46:19.177 UTC [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
至此所有需要生成的配置檔案全部生成完畢。
[root@localhost netkiller]# tree -L 4 crypto-config
crypto-config
|-- ordererOrganizations
| `-- example.com
| |-- ca
| | |-- ca.example.com-cert.pem
| | `-- de9204448c9c8e2a72d092f53e8ff069e12dea62001b7b8b9a83ae240d80ed57_sk
| |-- msp
| | |-- admincerts
| | |-- cacerts
| | `-- tlscacerts
| |-- orderers
| | `-- orderer.example.com
| |-- tlsca
| | |-- c0b4dd42bd396d68f468aa07dae8ce944ab2d9832b2593cfafb27e53c69ec5e2_sk
| | `-- tlsca.example.com-cert.pem
| `-- users
| `-- Admin@example.com
`-- peerOrganizations
`-- org1.example.com
|-- ca
| |-- 74023bd84cc5e6957f9bc30b3ebcd6c5b7507016721702a014dd640df265b61a_sk
| `-- ca.org1.example.com-cert.pem
|-- msp
| |-- admincerts
| |-- cacerts
| `-- tlscacerts
|-- peers
| `-- peer0.org1.example.com
|-- tlsca
| |-- 71bb82530580707aa20fa5955beab202f266aa4da4b435bef20741ce5e64abb9_sk
| `-- tlsca.org1.example.com-cert.pem
`-- users
|-- Admin@org1.example.com
`-- User1@org1.example.com
25 directories, 8 files
將config和crypto-config檔案加複製到ca,orderer,peer,cli等節點上去。