cd /opt/gopath/src
mkdir meat
cd meat
mkdir multiple-deployment
cd /opt/gopath/src/github.com/hyperledger/fabric/scripts
cp -r fabric-samples/bin /opt/gopath/src/meat
2、添加环境变量
vim ~/.bashrc
将以下内容复制到bashrc文件中,
export PATH=$PATH:/opt/gopath/src/meat/bin
export FABRIC_CFG_PATH=/opt/gopath/src/meat/multiple-deployment
更新环境变量
source ~/.bashrc
3、域名ip映射
设置Fabric服务的地址映射
vim /etc/hosts
把以下内容填充至hosts文件中,IP需要按实际情况更改
ip | 名称 |
---|---|
106.xxx.xxx.xxx | breedingorderer.meat.com |
107.xxx.xxx.xxx | slaughterorderer.meat.com |
108x.xxx.xxx | salesorderer.meat.com |
106.xxx.xxx.xxx | peer0.breeding.meat.com |
106.xxx.xxx.xxx | peer1.breeding.meat.com |
107.xxx.xxx.xxx | peer0.slaughter.meat.com |
107.xxx.xxx | peer1.slaughter.meat.com |
108.xxx.xxx | peer0.sales.meat.com |
108.xxx.xxx | peer1.sales.meat.com |
重启
shutdown -r now
云服务器须在控制台开放Fabric服务所需的端口,6060、7050、7051、7052、7053、7054、8051、8052、8053、3000、8443、9443、10443、9090、5984
三、 准备chaincodecd /opt/gopath/src/meat/multiple-deployment
mkdir chaincode
mkdir chaincode/Sales/go
将chaincode复制到相关的文件夹中
cd chaincode/Sales/go
go env -w GOPROXY=https://goproxy.io,direct
go env -w GO111MODULE=on
go mod init BreedingContract
go mod vendor
四、 编写相关配置文件
在 服务器1 的multiple-deployment文件夹下新建crypto-config.yaml文件和configtx.yaml文件(证书密钥和交易配置文件),用于生产证书、密钥、创世区块等文件,注:服务器2、3不用建这两个文件
cd /opt/gopath/src/meat/multiple-deployment
touch crypto-config.yaml
touch configtx.yaml
1、crypto-config.yaml(用于生产证书、密钥)文件
将以下内容写进crypto-config.yaml文件中
OrdererOrgs:
- Name: Orderer
Domain: meat.com
Specs:
- Hostname: breedingorderer
- Hostname: slaughterorderer
- Hostname: salesorderer
PeerOrgs:
- Name: Breeding
Domain: breeding.meat.com
EnableNodeOUs: true
Template:
Count: 2 #生成证书的数量
Users:
Count: 1 #生成用户证书个数
- Name: Slaughter
Domain: slaughter.meat.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1
- Name: Sales
Domain: sales.meat.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1
- Name: Transport
Domain: transport.meat.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1
2、configtx.yaml(通道配置)文件
将以下内容写进configtx.yaml文件中-
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: crypto-config/ordererOrganizations/meat.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Writers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Admins:
Type: Signature
Rule: "OR('OrdererMSP.admin')"
- &Breeding
Name: BreedingMSP
ID: BreedingMSP
MSPDir: crypto-config/peerOrganizations/breeding.meat.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('BreedingMSP.admin', 'BreedingMSP.peer', 'BreedingMSP.client')"
Writers:
Type: Signature
Rule: "OR('BreedingMSP.admin', 'BreedingMSP.client')"
Admins:
Type: Signature
Rule: "OR('BreedingMSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('BreedingMSP.peer')"
AnchorPeers:
- Host: peer0.breeding.meat.com
Port: 7051
- &Slaughter
Name: SlaughterMSP
ID: SlaughterMSP
MSPDir: crypto-config/peerOrganizations/slaughter.meat.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('SlaughterMSP.admin', 'SlaughterMSP.peer', 'SlaughterMSP.client')"
Writers:
Type: Signature
Rule: "OR('SlaughterMSP.admin', 'SlaughterMSP.client')"
Admins:
Type: Signature
Rule: "OR('SlaughterMSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('SlaughterMSP.peer')"
AnchorPeers:
- Host: peer0.slaughter.meat.com
Port: 7151
- &Sales
Name: SalesMSP
ID: SalesMSP
MSPDir: crypto-config/peerOrganizations/sales.meat.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('SalesMSP.admin', 'SalesMSP.peer', 'SalesMSP.client')"
Writers:
Type: Signature
Rule: "OR('SalesMSP.admin', 'SalesMSP.client')"
Admins:
Type: Signature
Rule: "OR('SalesMSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('SalesMSP.peer')"
AnchorPeers:
- Host: peer0.sales.meat.com
Port: 7251
- &Transport
Name: TransportMSP
ID: TransportMSP
MSPDir: crypto-config/peerOrganizations/transport.meat.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('TransportMSP.admin', 'TransportMSP.peer', 'TransportMSP.client')"
Writers:
Type: Signature
Rule: "OR('TransportMSP.admin', 'TransportMSP.client')"
Admins:
Type: Signature
Rule: "OR('TransportMSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('TransportMSP.peer')"
AnchorPeers:
- Host: peer0.transport.meat.com
Port: 7351
Capabilities:
Channel: &ChannelCapabilities
V2_0: true
Orderer: &OrdererCapabilities
V2_0: true
Application: &ApplicationCapabilities
V2_0: true
Application: &ApplicationDefaults
Organizations:
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
LifecycleEndorsement:
Type: ImplicitMeta
Rule: "MAJORITY Endorsement"
Endorsement:
Type: ImplicitMeta
Rule: "MAJORITY Endorsement"
Capabilities:
<<: *ApplicationCapabilities
Orderer: &OrdererDefaults
OrdererType: etcdraft
Addresses: # orderer 集群节点
- breedingorderer.meat.com:7050
- slaughterorderer.meat.com:7150
- salesorderer.meat.com:7250
# 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:
MaxMessageCount: 10
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 512 KB
Organizations:
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"
Channel: &ChannelDefaults
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:
<<: *ChannelCapabilities
Profiles:
FourOrgsChannel:
Consortium: SampleConsortium
<<: *ChannelDefaults
Application:
<<: *ApplicationDefaults
Organizations:
- *Breeding
- *Slaughter
- *Sales
- *Transport
Capabilities:
<<: *ApplicationCapabilities
SampleMultiNodeEtcdRaft:
<<: *ChannelDefaults
Capabilities:
<<: *ChannelCapabilities
Orderer:
<<: *OrdererDefaults
OrdererType: etcdraft
EtcdRaft:
Consenters:
- Host: breedingorderer.meat.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/tls/server.crt
- Host: slaughterorderer.meat.com
Port: 7150
ClientTLSCert: crypto-config/ordererOrganizations/meat.com/orderers/slaughterorderer.meat.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/meat.com/orderers/slaughterorderer.meat.com/tls/server.crt
- Host: salesorderer.meat.com
Port: 7250
ClientTLSCert: crypto-config/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/tls/server.crt
Addresses:
- breedingorderer.meat.com:7050
- slaughterorderer.meat.com:7150
- salesorderer.meat.com:7250
Organizations:
- *OrdererOrg
Capabilities:
<<: *OrdererCapabilities
Application:
<<: *ApplicationDefaults
Organizations:
- <<: *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Breeding
- *Slaughter
- *Sales
- *Transport
五、 生成配置文件
生成证书、密钥、创世区块、各组织的交易配置文件等
生成证书配置
cryptogen generate --config=./crypto-config.yaml
生成创世区块
configtxgen -profile SampleMultiNodeEtcdRaft -channelID meatdeploy -outputBlock ./channel-artifacts/genesis.block
生成通道配置
configtxgen -profile FourOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID meat
定义各个组织的锚节点
configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/BreedingMSPanchors.tx -channelID meat -asOrg BreedingMSP
configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/SlaughterMSPanchors.tx -channelID meat -asOrg SlaughterMSP
configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/SalesMSPanchors.tx -channelID meat -asOrg SalesMSP
configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/TransportMSPanchors.tx -channelID meat -asOrg TransportMSP
若部署在不同服务器生成的文件需要拷贝至其他服务器相应目录中
六、 编写docker-compose-up.yaml文件touch docker-compose-breeding-up.yaml
编写Fabric启动的yaml文件,这里只展现其中一个组织,其他两个组织的Fabric启动代码照葫芦画瓢即可
version: '2'
services:
couchdb:
container_name: couchdb
image: hyperledger/fabric-couchdb
# Populate the COUCHDB_USER and COUCHDB_PASSWORD to set an admin user and password
# for CouchDB. This will prevent CouchDB from operating in an "Admin Party" mode.
environment:
- COUCHDB_USER=adonis
- COUCHDB_PASSWORD=111
# Comment/Uncomment the port mapping if you want to hide/expose the CouchDB service,
# for example map it to utilize Fauxton User Interface in dev environments.
ports:
- "5984:5984"
ca.breeding.meat.com:
container_name: ca.breeding.meat.com
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.breeding.meat.com
- FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.breeding.meat.com-cert.pem
- FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/priv_sk
- FABRIC_CA_SERVER_TLS_ENABLED=true
- FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-tls/tlsca.breeding.meat.com-cert.pem
- FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-tls/priv_sk
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/ca
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
volumes:
- ./crypto-config/peerOrganizations/breeding.meat.com/ca/:/etc/hyperledger/fabric-ca-server-config
- ./crypto-config/peerOrganizations/breeding.meat.com/tlsca/:/etc/hyperledger/fabric-ca-server-tls
ports:
- "7054:7054"
ca.slaughter.meat.com:
container_name: ca.slaughter.meat.com
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.slaughter.meat.com
- FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.slaughter.meat.com-cert.pem
- FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/priv_sk
- FABRIC_CA_SERVER_TLS_ENABLED=true
- FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-tls/tlsca.slaughter.meat.com-cert.pem
- FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-tls/priv_sk
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/ca
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
volumes:
- ./crypto-config/peerOrganizations/slaughter.meat.com/ca/:/etc/hyperledger/fabric-ca-server-config
- ./crypto-config/peerOrganizations/slaughter.meat.com/tlsca/:/etc/hyperledger/fabric-ca-server-tls
ports:
- "7154:7054"
ca.sales.meat.com:
container_name: ca.sales.meat.com
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.sales.meat.com
- FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.sales.meat.com-cert.pem
- FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/priv_sk
- FABRIC_CA_SERVER_TLS_ENABLED=true
- FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-tls/tlsca.sales.meat.com-cert.pem
- FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-tls/priv_sk
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/ca
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
volumes:
- ./crypto-config/peerOrganizations/sales.meat.com/ca/:/etc/hyperledger/fabric-ca-server-config
- ./crypto-config/peerOrganizations/sales.meat.com/tlsca/:/etc/hyperledger/fabric-ca-server-tls
ports:
- "7254:7054"
ca.transport.meat.com:
container_name: ca.transport.meat.com
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.transport.meat.com
- FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.transport.meat.com-cert.pem
- FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/priv_sk
- FABRIC_CA_SERVER_TLS_ENABLED=true
- FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-tls/tlsca.transport.meat.com-cert.pem
- FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-tls/priv_sk
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/ca
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
volumes:
- ./crypto-config/peerOrganizations/transport.meat.com/ca/:/etc/hyperledger/fabric-ca-server-config
- ./crypto-config/peerOrganizations/transport.meat.com/tlsca/:/etc/hyperledger/fabric-ca-server-tls
ports:
- "7354:7054"
breeding.meat.com:
container_name: breeding.meat.com
image: hyperledger/fabric-orderer:2.3.1
environment:
- FABRIC_LOGGING_SPEC=DEBUG
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_BOOTSTRAPMETHOD=file
- ORDERER_GENERAL_BOOTSTRAPFILE=/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_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ./crypto-config/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/msp:/var/hyperledger/orderer/msp
- ./crypto-config/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/tls/:/var/hyperledger/orderer/tls
ports:
- 7050:7050
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
slaughter.meat.com:
container_name: slaughter.meat.com
image: hyperledger/fabric-orderer:2.3.1
environment:
- FABRIC_LOGGING_SPEC=DEBUG
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_BOOTSTRAPMETHOD=file
- ORDERER_GENERAL_BOOTSTRAPFILE=/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_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ./crypto-config/ordererOrganizations/meat.com/orderers/slaughterorderer.meat.com/msp:/var/hyperledger/orderer/msp
- ./crypto-config/ordererOrganizations/meat.com/orderers/slaughterorderer.meat.com/tls/:/var/hyperledger/orderer/tls
ports:
- 7150:7050
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
sales.meat.com:
container_name: sales.meat.com
image: hyperledger/fabric-orderer:2.3.1
environment:
- FABRIC_LOGGING_SPEC=DEBUG
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_BOOTSTRAPMETHOD=file
- ORDERER_GENERAL_BOOTSTRAPFILE=/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_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ./crypto-config/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/msp:/var/hyperledger/orderer/msp
- ./crypto-config/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/tls/:/var/hyperledger/orderer/tls
ports:
- 7250:7050
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
peer0.breeding.meat.com:
container_name: peer0.breeding.meat.com
image: hyperledger/fabric-peer:2.3.1
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=multiple-deployment_default
- CORE_PEER_ID=peer0.breeding.meat.com
- CORE_PEER_ADDRESS=peer0.breeding.meat.com:7051
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- CORE_PEER_CHAINCODEADDRESS=peer0.breeding.meat.com:7052
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.breeding.meat.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.breeding.meat.com:7051
- CORE_PEER_LOCALMSPID=BreedingMSP
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- 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_LEDGER_STATE_STATEDATABASE=CouchDB
- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=adonis
- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=123
# Allow more time for chaincode container to build on install.
- CORE_CHAINCODE_EXECUTETIMEOUT=300s
- CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:9443
- CORE_METRICS_PROVIDER=prometheus
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
volumes:
- /var/run/:/host/var/run/
- ./crypto-config/peerOrganizations/breeding.meat.com/peers/peer0.breeding.meat.com/msp:/etc/hyperledger/fabric/msp
- ./crypto-config/peerOrganizations/breeding.meat.com/peers/peer0.breeding.meat.com/tls:/etc/hyperledger/fabric/tls
ports:
- 7051:7051
- 7052:7052
- 7053:7053
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
depends_on:
- couchdb
peer0.slaughter.meat.com:
container_name: peer0.slaughter.meat.com
image: hyperledger/fabric-peer:2.3.1
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=multiple-deployment_default
- CORE_PEER_ID=peer0.slaughter.meat.com
- CORE_PEER_ADDRESS=peer0.slaughter.meat.com:7051
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- CORE_PEER_CHAINCODEADDRESS=peer0.slaughter.meat.com:7052
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.slaughter.meat.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.slaughter.meat.com:7051
- CORE_PEER_LOCALMSPID=SlaughterMSP
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- 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_LEDGER_STATE_STATEDATABASE=CouchDB
- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=adonis
- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=123
# Allow more time for chaincode container to build on install.
- CORE_CHAINCODE_EXECUTETIMEOUT=300s
- CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:9443
- CORE_METRICS_PROVIDER=prometheus
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
volumes:
- /var/run/:/host/var/run/
- ./crypto-config/peerOrganizations/slaughter.meat.com/peers/peer0.slaughter.meat.com/msp:/etc/hyperledger/fabric/msp
- ./crypto-config/peerOrganizations/slaughter.meat.com/peers/peer0.slaughter.meat.com/tls:/etc/hyperledger/fabric/tls
ports:
- 7151:7051
- 7152:7052
- 7153:7053
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
depends_on:
- couchdb
peer0.sales.meat.com:
container_name: peer0.sales.meat.com
image: hyperledger/fabric-peer:2.3.1
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=multiple-deployment_default
- CORE_PEER_ID=peer0.sales.meat.com
- CORE_PEER_ADDRESS=peer0.sales.meat.com:7051
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- CORE_PEER_CHAINCODEADDRESS=peer0.sales.meat.com:7052
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.sales.meat.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.sales.meat.com:7051
- CORE_PEER_LOCALMSPID=SalesMSP
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- 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_LEDGER_STATE_STATEDATABASE=CouchDB
- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=adonis
- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=123
# Allow more time for chaincode container to build on install.
- CORE_CHAINCODE_EXECUTETIMEOUT=300s
- CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:9443
- CORE_METRICS_PROVIDER=prometheus
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
volumes:
- /var/run/:/host/var/run/
- ./crypto-config/peerOrganizations/sales.meat.com/peers/peer0.sales.meat.com/msp:/etc/hyperledger/fabric/msp
- ./crypto-config/peerOrganizations/sales.meat.com/peers/peer0.sales.meat.com/tls:/etc/hyperledger/fabric/tls
ports:
- 7251:7051
- 7252:7052
- 7253:7053
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
depends_on:
- couchdb
peer0.transport.meat.com:
container_name: peer0.transport.meat.com
image: hyperledger/fabric-peer:2.3.1
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=multiple-deployment_default
- CORE_PEER_ID=peer0.transport.meat.com
- CORE_PEER_ADDRESS=peer0.transport.meat.com:7051
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- CORE_PEER_CHAINCODEADDRESS=peer0.transport.meat.com:7052
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.transport.meat.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.transport.meat.com:7051
- CORE_PEER_LOCALMSPID=TransportMSP
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- 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_LEDGER_STATE_STATEDATABASE=CouchDB
- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=adonis
- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=123
# Allow more time for chaincode container to build on install.
- CORE_CHAINCODE_EXECUTETIMEOUT=300s
- CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:9443
- CORE_METRICS_PROVIDER=prometheus
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
volumes:
- /var/run/:/host/var/run/
- ./crypto-config/peerOrganizations/transport.meat.com/peers/peer0.transport.meat.com/msp:/etc/hyperledger/fabric/msp
- ./crypto-config/peerOrganizations/transport.meat.com/peers/peer0.transport.meat.com/tls:/etc/hyperledger/fabric/tls
ports:
- 7351:7051
- 7352:7052
- 7353:7053
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
depends_on:
- couchdb
breedingcli1:
container_name: breedingcli1
image: hyperledger/fabric-tools:2.3.1
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
#- FABRIC_LOGGING_SPEC=DEBUG
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_ID=breedingcli1
- CORE_PEER_ADDRESS=peer0.breeding.meat.com:7051
- CORE_PEER_LOCALMSPID=BreedingMSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/breeding.meat.com/peers/peer0.breeding.meat.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/breeding.meat.com/peers/peer0.breeding.meat.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/breeding.meat.com/peers/peer0.breeding.meat.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/breeding.meat.com/users/Admin@breeding.meat.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./chaincode/CommonContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/CommonContract/go
- ./chaincode/BreedingContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/BreedingContract/go
- ./chaincode/SlaughterContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/SlaughterContract/go
- ./chaincode/SalesContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/SalesContract/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
- "peer0.breeding.meat.com:***.***.***.***"
- "peer0.slaughter.meat.com:***.***.***.***"
- "peer0.sales.meat.com:***.***.***.***"
- "peer0.transport.meat.com:***.***.***.***"
slaughtercli1:
container_name: slaughtercli1
image: hyperledger/fabric-tools:2.3.1
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
#- FABRIC_LOGGING_SPEC=DEBUG
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_ID=slaughtercli1
- CORE_PEER_ADDRESS=peer0.slaughter.meat.com:7151
- CORE_PEER_LOCALMSPID=SlaughterMSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/slaughter.meat.com/peers/peer0.slaughter.meat.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/slaughter.meat.com/peers/peer0.slaughter.meat.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/slaughter.meat.com/peers/peer0.slaughter.meat.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/slaughter.meat.com/users/Admin@slaughter.meat.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./chaincode/CommonContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/CommonContract/go
- ./chaincode/BreedingContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/BreedingContract/go
- ./chaincode/SlaughterContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/SlaughterContract/go
- ./chaincode/SalesContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/SalesContract/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
- "peer0.breeding.meat.com:***.***.***.***"
- "peer0.slaughter.meat.com:***.***.***.***"
- "peer0.sales.meat.com:***.***.***.***"
- "peer0.transport.meat.com:***.***.***.***"
salescli1:
container_name: salescli1
image: hyperledger/fabric-tools:2.3.1
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
#- FABRIC_LOGGING_SPEC=DEBUG
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_ID=salescli1
- CORE_PEER_ADDRESS=peer0.sales.meat.com:7251
- CORE_PEER_LOCALMSPID=SalesMSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/sales.meat.com/peers/peer0.sales.meat.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/sales.meat.com/peers/peer0.sales.meat.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/sales.meat.com/peers/peer0.sales.meat.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/sales.meat.com/users/Admin@sales.meat.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./chaincode/CommonContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/CommonContract/go
- ./chaincode/BreedingContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/BreedingContract/go
- ./chaincode/SlaughterContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/SlaughterContract/go
- ./chaincode/SalesContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/SalesContract/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
- "peer0.breeding.meat.com:***.***.***.***"
- "peer0.slaughter.meat.com:***.***.***.***"
- "peer0.sales.meat.com:***.***.***.***"
- "peer0.transport.meat.com:***.***.***.***"
transportcli1:
container_name: transportcli1
image: hyperledger/fabric-tools:2.3.1
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
#- FABRIC_LOGGING_SPEC=DEBUG
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_ID=salescli1
- CORE_PEER_ADDRESS=peer0.transport.meat.com:7351
- CORE_PEER_LOCALMSPID=TransportMSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/transport.meat.com/peers/peer0.transport.meat.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/transport.meat.com/peers/peer0.transport.meat.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/transport.meat.com/peers/peer0.transport.meat.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/transport.meat.com/users/Admin@transport.meat.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./chaincode/CommonContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/CommonContract/go
- ./chaincode/BreedingContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/BreedingContract/go
- ./chaincode/SlaughterContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/SlaughterContract/go
- ./chaincode/SalesContract/go/:/opt/gopath/src/meat/multiple-deployment/chaincode/SalesContract/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
extra_hosts:
- "breedingorderer.meat.com:***.***.***.***"
- "slaughterorderer.meat.com:***.***.***.***"
- "salesorderer.meat.com:***.***.***.***"
- "peer0.breeding.meat.com:***.***.***.***"
- "peer0.slaughter.meat.com:***.***.***.***"
- "peer0.sales.meat.com:***.***.***.***"
- "peer0.transport.meat.com:***.***.***.***"
七、 使用couch db
通过http://***.***.***.***:5984/_utils查看区块链数据
新建索引META-INF\statedb\couchdb\indexes\indexSales.json以支持couch db的富查询
{
"index":{
"fields":["docType","salesCompanyId", "salesSpecies"]
},
"ddoc":"indexSalesDoc",
"name":"indexSales",
"type":"json"
}
八、 启动网络
1、启动Fabric网络
docker-compose -f docker-compose-up.yaml up -d
#查看某个容器日志
docker logs -f breeding.meat.com
2、创建通道与更新养殖组织锚节点
docker exec -it breedingcli1 bash
peer channel create -o breedingorderer.meat.com:7050 -c meat -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
peer channel join -b meat.block
peer channel update -o breedingorderer.meat.com:7050 -c meat -f ./channel-artifacts/BreedingMSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
退出breedingcli1容器,将区块文件meat.block从容器中拷贝出来,拷贝至slaughtercli1容器中,使slaughterpeer0也加入区块中
exit
docker cp breedingcli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/meat.block ./
docker cp meat.block slaughtercli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/
docker exec -it slaughtercli1 bash
peer channel join -b meat.block
peer channel update -o breedingorderer.meat.com:7050 -c meat -f ./channel-artifacts/SlaughterMSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/slaughterorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
退出slaughtercli1容器,将区块文件meat.block从容器中拷贝出来,拷贝至salescli1容器中,使salespeer0也加入区块中
exit
docker cp meat.block salescli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/
docker exec -it salescli1 bash
peer channel join -b meat.block
peer channel update -o breedingorderer.meat.com:7050 -c meat -f ./channel-artifacts/SalesMSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
退出salescli1容器,将区块文件meat.block从容器中拷贝出来,拷贝至transportcli1容器中,使transportpeer0也加入区块中
exit
docker cp meat.block transportcli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/
docker exec -it transportcli1 bash
peer channel join -b meat.block
peer channel update -o breedingorderer.meat.com:7050 -c meat -f ./channel-artifacts/TransportMSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
若在不同服务器则将meat.block拷贝至其他服务器
九、 部署chaincode 1、各个对应节点打包并安装链码exit
docker exec -it breedingcli1 bash
peer lifecycle chaincode package BreedingContract.tar.gz --path meat/multiple-deployment/chaincode/BreedingContract/go --lang golang --label BreedingContract_1
peer lifecycle chaincode install BreedingContract.tar.gz
exit
docker cp breedingcli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/BreedingContract.tar.gz ./
docker cp BreedingContract.tar.gz slaughtercli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/
docker exec -it slaughtercli1 bash
peer lifecycle chaincode install BreedingContract.tar.gz
exit
docker cp BreedingContract.tar.gz salescli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/
docker exec -it salescli1 bash
peer lifecycle chaincode install BreedingContract.tar.gz
exit
docker cp BreedingContract.tar.gz transportcli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/
docker exec -it transportcli1 bash
peer lifecycle chaincode install BreedingContract.tar.gz
2、各个锚节点同意提交链码
可以用下面命令查找peer上的package ID
peer lifecycle chaincode queryinstalled
同意public(id为上文安装时所生成的id)
exit
docker exec -it breedingcli1 bash
peer lifecycle chaincode approveformyorg --channelID meat --name BreedingContract --version 1.0 --package-id BreedingContract_1:8e9316e27f5a06b80e65ddc79256029af09f12dc2dc7f2dd71bd323bca8b2826 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
exit
docker exec -it slaughtercli1 bash
peer lifecycle chaincode approveformyorg --channelID meat --name BreedingContract --version 1.0 --package-id BreedingContract_1:8e9316e27f5a06b80e65ddc79256029af09f12dc2dc7f2dd71bd323bca8b2826 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/slaughterorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
exit
docker exec -it salescli1 bash
peer lifecycle chaincode approveformyorg --channelID meat --name BreedingContract --version 1.0 --package-id BreedingContract_1:8e9316e27f5a06b80e65ddc79256029af09f12dc2dc7f2dd71bd323bca8b2826 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
exit
docker exec -it transportcli1 bash
peer lifecycle chaincode approveformyorg --channelID meat --name BreedingContract --version 1.0 --package-id BreedingContract_1:8e9316e27f5a06b80e65ddc79256029af09f12dc2dc7f2dd71bd323bca8b2826 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
3、任意节点查看链码状态是否就绪
peer lifecycle chaincode checkcommitreadiness --channelID meat --name BreedingContract --version 1.0 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem --output json
4、任一节点提交链码
peer lifecycle chaincode commit -o breedingorderer.meat.com:7050 --channelID meat --name BreedingContract --version 1.0 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem --peerAddresses peer0.breeding.meat.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/breeding.meat.com/peers/peer0.breeding.meat.com/tls/ca.crt --peerAddresses peer0.slaughter.meat.com:7151 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/slaughter.meat.com/peers/peer0.slaughter.meat.com/tls/ca.crt --peerAddresses peer0.sales.meat.com:7251 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/sales.meat.com/peers/peer0.sales.meat.com/tls/ca.crt --peerAddresses peer0.transport.meat.com:7351 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/transport.meat.com/peers/peer0.transport.meat.com/tls/ca.crt
可以使用peer lifecycle chaincode querycommitted来确认链码定义是否已经被提交到通道上。
peer lifecycle chaincode querycommitted --channelID meat --name BreedingContract --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem
5、与链码进行交互
peer chaincode query -C meat -n BreedingContract -c '{"Args":["QueryMeatsBySpecies","牛肉"]}'
peer chaincode query -C meat -n Sales -c '{"Args":["QueryMeatByRange","",""]}'
peer chaincode query -C meat -n Sales -c '{"Args":["QueryMeatsByOwner","123"]}'
peer chaincode query -C meat -n Sales -c '{"Args":["GetMeatHistory","123"]}'
peer chaincode invoke -o breedingorderer.meat.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/msp/tlscacerts/tlsca.meat.com-cert.pem -C meat -n BreedingContract --peerAddresses peer0.breeding.meat.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/breeding.meat.com/peers/peer0.breeding.meat.com/tls/ca.crt --peerAddresses peer0.slaughter.meat.com:7151 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/slaughter.meat.com/peers/peer0.slaughter.meat.com/tls/ca.crt --peerAddresses peer0.sales.meat.com:7251 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/sales.meat.com/peers/peer0.sales.meat.com/tls/ca.crt --peerAddresses peer0.transport.meat.com:7351 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/transport.meat.com/peers/peer0.transport.meat.com/tls/ca.crt -c '{"Args":["CreatSalesStock","456","456","456","456","456","456"]}'
6、升级链码
新的链码版本,新的sequence(递增一位)。执行1-5步骤即可
十、 与java SDK交互 1、 添加pom<dependency>
<groupId>org.hyperledger.fabricgroupId>
<artifactId>fabric-gateway-javaartifactId>
<version>2.2.1version>
dependency>
2、配置静态资源,包括证书密钥和连接文件
将服务器1生成的crypto-config复制到SpringBoot项目的resources目录下,并在该目录下新建名为connection.json的连接文件
将以下内容复制到connection.json文件中(IP地址记得修改)
{
"name": "meat",
"version": "1.0.0",
"client": {
"organization": "Agridepart",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
},
"orderer": "300"
}
}
},
"channels": {
"meat": {
"orderers": [
"breedingorderer.meat.com",
"slaughterorderer.meat.com",
"salesorderer.meat.com"
],
"peers": {
"peer0.breeding.meat.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"ledgerQuery": true,
"eventSource": true
},
"peer0.slaughter.meat.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"ledgerQuery": true,
"eventSource": true
},
"peer0.sales.meat.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"ledgerQuery": true,
"eventSource": true
}
}
}
},
"organizations": {
"Agridepart": {
"mspid": "AgridepartMSP",
"peers": [
"peer0.breeding.meat.com"
],
"certificateAuthorities": [
"ca.breeding.meat.com"
],
"adminPrivateKeyPEM": {
"path": "src/main/resources/crypto-config/peerOrganizations/breeding.meat.com/users/Admin@breeding.meat.com/msp/keystore/priv_sk"
},
"signedCertPEM": {
"path": "src/main/resources/crypto-config/peerOrganizations/breeding.meat.com/users/Admin@breeding.meat.com/msp/signcerts/Admin@breeding.meat.com-cert.pem"
}
},
"Agrimacowner": {
"mspid": "AgrimacownerMSP",
"peers": [
"peer0.slaughter.meat.com"
],
"certificateAuthorities": [
"ca.slaughter.meat.com"
],
"adminPrivateKeyPEM": {
"path": "src/main/resources/crypto-config/peerOrganizations/slaughter.meat.com/users/Admin@slaughter.meat.com/msp/keystore/priv_sk"
},
"signedCertPEM": {
"path": "src/main/resources/crypto-config/peerOrganizations/slaughter.meat.com/users/Admin@slaughter.meat.com/msp/signcerts/Admin@slaughter.meat.com-cert.pem"
}
},
"Financedepart": {
"mspid": "FinancedepartMSP",
"peers": [
"peer0.sales.meat.com"
],
"certificateAuthorities": [
"ca.sales.meat.com"
],
"adminPrivateKeyPEM": {
"path": "src/main/resources/crypto-config/peerOrganizations/sales.meat.com/users/Admin@sales.meat.com/msp/keystore/priv_sk"
},
"signedCertPEM": {
"path": "src/main/resources/crypto-config/peerOrganizations/sales.meat.com/users/Admin@sales.meat.com/msp/signcerts/Admin@sales.meat.com-cert.pem"
}
}
},
"orderers": {
"breedingorderer.meat.com": {
"url": "grpcs://106.xxx.xxx.xxx:7050",
"mspid": "OrdererMSP",
"grpcOptions": {
"ssl-target-name-override": "breedingorderer.meat.com",
"hostnameOverride": "breedingorderer.meat.com"
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/orderers/breedingorderer.meat.com/tls/ca.crt"
},
"adminPrivateKeyPEM": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/users/Admin@meat.com/msp/keystore/priv_sk"
},
"signedCertPEM": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/users/Admin@meat.com/msp/signcerts/Admin@meat.com-cert.pem"
}
},
"slaughterorderer.meat.com": {
"url": "grpcs://120.xxx.xxx.xxx:7050",
"mspid": "OrdererMSP",
"grpcOptions": {
"ssl-target-name-override": "slaughterorderer.meat.com",
"hostnameOverride": "slaughterorderer.meat.com"
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/orderers/slaughterorderer.meat.com/tls/ca.crt"
},
"adminPrivateKeyPEM": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/users/Admin@meat.com/msp/keystore/priv_sk"
},
"signedCertPEM": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/users/Admin@meat.com/msp/signcerts/Admin@meat.com-cert.pem"
}
},
"salesorderer.meat.com": {
"url": "grpcs://42.xxx.xxx.xxx:7050",
"mspid": "OrdererMSP",
"grpcOptions": {
"ssl-target-name-override": "salesorderer.meat.com",
"hostnameOverride": "slaughterorderer.meat.com"
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/orderers/salesorderer.meat.com/tls/ca.crt"
},
"adminPrivateKeyPEM": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/users/Admin@meat.com/msp/keystore/priv_sk"
},
"signedCertPEM": {
"path": "src/main/resources/crypto-config/ordererOrganizations/meat.com/users/Admin@meat.com/msp/signcerts/Admin@meat.com-cert.pem"
}
}
},
"peers": {
"peer0.breeding.meat.com": {
"url": "grpcs://106.xxx.xxx.xxx:7051",
"grpcOptions": {
"ssl-target-name-override": "peer0.breeding.meat.com",
"hostnameOverride": "peer0.breeding.meat.com",
"request-timeout": 120001
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/peerOrganizations/breeding.meat.com/peers/peer0.breeding.meat.com/tls/ca.crt"
}
},
"peer0.slaughter.meat.com": {
"url": "grpcs://120.xxx.xxx.xxx:7051",
"grpcOptions": {
"ssl-target-name-override": "peer0.slaughter.meat.com",
"hostnameOverride": "peer0.slaughter.meat.com",
"request-timeout": 120001
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/peerOrganizations/slaughter.meat.com/peers/peer0.slaughter.meat.com/tls/ca.crt"
}
},
"peer0.sales.meat.com": {
"url": "grpcs://42.xxx.xxx.xxx:7051",
"grpcOptions": {
"ssl-target-name-override": "peer0.sales.meat.com",
"hostnameOverride": "peer0.sales.meat.com",
"request-timeout": 120001
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/peerOrganizations/sales.meat.com/peers/peer0.sales.meat.com/tls/ca.crt"
}
}
},
"certificateAuthorities": {
"ca.breeding.meat.com": {
"url": "https://106.xxx.xxx.xxx:7054",
"httpOptions": {
"verify": true
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/peerOrganizations/breeding.meat.com/ca/ca.breeding.meat.com-cert.pem"
},
"registrar": [
{
"enrollId": "admin",
"enrollSecret": "adminpw"
}
]
},
"ca.slaughter.meat.com": {
"url": "https://120.xxx.xxx.xxx:7054",
"httpOptions": {
"verify": true
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/peerOrganizations/slaughter.meat.com/ca/ca.slaughter.meat.com-cert.pem"
},
"registrar": [
{
"enrollId": "admin",
"enrollSecret": "adminpw"
}
]
},
"ca.sales.meat.com": {
"url": "https://42.xxx.xxx.xxx:7054",
"httpOptions": {
"verify": true
},
"tlsCACerts": {
"path": "src/main/resources/crypto-config/peerOrganizations/sales.meat.com/ca/ca.sales.meat.com-cert.pem"
},
"registrar": [
{
"enrollId": "admin",
"enrollSecret": "adminpw"
}
]
}
}
}
3、官方demo
package com.scau.meat.hyperledger;
import lombok.extern.slf4j.Slf4j;
import org.hyperledger.fabric.gateway.*;
import org.hyperledger.fabric.gateway.impl.GatewayImpl;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.InvalidKeyException;
import java.security.PrivateKey;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@Slf4j
Sales class fabricdemo {
private Gateway gateway;
private Network network;
private static final Path NETWORK_CONFIG_PATH = Paths.get("src", "main", "resources", "connection.json");
private static final Path credentialPath = Paths.get("src", "main","resources", "crypto-config",
"peerOrganizations", "breeding.meat.com", "users", "User1@breeding.meat.com", "msp");
Sales static void main(String[] args) {
X509Certificate certificate = null;
PrivateKey privateKey = null;
Gateway gateway = null;
try {
//使用breeding中的user1初始化一个网关wallet账户用于连接网络
Wallet wallet = Wallets.newInMemoryWallet();
Path certificatePath = credentialPath.resolve(Paths.get("signcerts", "User1@breeding.meat.com-cert.pem"));
certificate = readX509Certificate(certificatePath);
Path privateKeyPath = credentialPath.resolve(Paths.get("keystore", "priv_sk"));
privateKey = getPrivateKey(privateKeyPath);
wallet.put("user",Identities.newX509Identity("AgridepartMSP",certificate,privateKey));
//根据connection.json 获取Fabric网络连接对象
GatewayImpl.Builder builder = (GatewayImpl.Builder) Gateway.createBuilder();
builder.identity(wallet, "user").networkConfig(NETWORK_CONFIG_PATH);
//连接网关
gateway = builder.connect();
//获取amops通道
Network network = gateway.getNetwork("meat");
//获取合约对象
Contract contract = network.getContract("Sales");
//查询合约对象evaluateTransaction
byte[] queryCulSubsidyResultBefore = contract.evaluateTransaction("QueryCulSubsidyByKey","0");
System.out.println("查询key=0结果:"+new String(queryCulSubsidyResultBefore, StandardCharsets.UTF_8));
//创建补贴记录
byte[] createCarResult = contract.createTransaction("CreateSubsidy")
.submit("10","325","1","yujialing","3000","2020-12-07","23.165767499024923","113.35528715035957","10");
System.out.println("创建交易的结果"+new String(createCarResult, StandardCharsets.UTF_8));
//查询合约对象evaluateTransaction
byte[] queryCulSubsidyResultAfter = contract.evaluateTransaction("QueryCulSubsidyByKey","10");
System.out.println("查询key=10结果:"+new String(queryCulSubsidyResultAfter, StandardCharsets.UTF_8));
} catch (Exception e) {
e.printStackTrace();
}
}
private static X509Certificate readX509Certificate(final Path certificatePath) throws IOException, CertificateException {
try (Reader certificateReader = Files.newBufferedReader(certificatePath, StandardCharsets.UTF_8)) {
return Identities.readX509Certificate(certificateReader);
}
}
private static PrivateKey getPrivateKey(final Path privateKeyPath) throws IOException, InvalidKeyException {
try (Reader privateKeyReader = Files.newBufferedReader(privateKeyPath, StandardCharsets.UTF_8)) {
return Identities.readPrivateKey(privateKeyReader);
}
}
}
十一、 结束
1、关闭网络
docker-compose -f docker-compose-up.yaml down
2、清一下docker
docker stop $(docker ps -aq)
docker rm $(docker ps -qa)
若docker占有磁盘空间过多可删除/var/lib/docker/volumes中的内容
十二、 参考文档:CouchDB:https://hyperledger-fabric.readthedocs.io/en/latest/couchdb_tutorial.html#cdb-enable-couch
Java SDK API:https://sdkjavadocs.github.io/
https://hyperledger.github.io/fabric-gateway-java/release-2.2/
SDK教程:https://hyperledger-fabric.readthedocs.io/en/release-2.2/write_first_app.html
https://hyperledger-fabric.readthedocs.io/en/release-2.2/developapps/application.html
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)