sudo apt-get update
cd /usr/local
上传go的压缩包
sudo rz
解压压缩包
sudo tar -zxf go1.14.4.linux-amd64.tar.gz
配置环境
vim ~/.bashrc
export GOROOT=/usr/local/go
export GOPATH=/opt/gopath
export PATH=$PATH:$GOROOT/bin/:$GOPATH/bin
source ~/.bashrc
go version
下载二进制源码包
cd /www/download
wget https://nodejs.org/dist/v10.16.2/node-v10.16.2-linux-x64.tar.xz
解压并安装
sudo tar xvf node-v10.16.2-linux-x64.tar.xz -C /opt
配置环境
sudo vim /etc/profile
export NODEJS_HOME=/opt/node-v10.16.2-linux-x64
export PATH=$PATH:$NODEJS_HOME/bin
. /etc/profile
node -v
sudo apt-get install -y docker.io
修改当前用户(我使用的用户叫fish)权限
sudo usermod -aG docker fish
注销并重新登录(或关闭当前黑屏窗口重新进入),然后添加国内的Docker Hub镜像:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com"]
}
EOF
cd /etc/docker
more daemon.json
sudo systemctl daemon-reload
sudo systemctl restart docker
docker -v
Docker-compose是支持通过模板脚本批量创建Docker容器的一个组件。
sudo apt-get install -y docker-compose
docker-compose --version
git clone https://github.com/hyperledger/fabric.git
git clone https://github.com/hyperledger/fabric-sdk-go.git
git clone https://github.com/hyperledger/fabric-samples.git
sudo mkdir -p /opt/gopath/src/github.com/hyperledger/
cd /opt/gopath/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric-samples.git
切换fabric版本:
git tag
sudo git checkout -b v2.0.0
vim docker_images.sh
#!/bin/bash
docker pull hyperledger/fabric-ca:1.4.7
docker tag hyperledger/fabric-ca:1.4.7 hyperledger/fabric-ca:latest
docker pull hyperledger/fabric-tools:2.0.0
docker tag hyperledger/fabric-tools:2.0.0 hyperledger/fabric-tools:latest
docker pull hyperledger/fabric-ccenv:2.0
docker tag hyperledger/fabric-ccenv:2.0 hyperledger/fabric-ccenv:latest
docker pull hyperledger/fabric-orderer:2.0.0
docker tag hyperledger/fabric-orderer:2.0.0 hyperledger/fabric-orderer:latest
docker pull hyperledger/fabric-peer:2.0.0
docker tag hyperledger/fabric-peer:2.0.0 hyperledger/fabric-peer:latest
docker pull hyperledger/fabric-javaenv:2.0
docker tag hyperledger/fabric-javaenv:2.0 hyperledger/fabric-javaenv:latest
#docker pull hyperledger/fabric-zookeeper:0.4.15
#docker tag hyperledger/fabric-zookeeper:0.4.15 hyperledger/fabric-zookeeper:latest
#docker pull hyperledger/fabric-kafka:0.4.15
#docker tag hyperledger/fabric-kafka:0.4.15 hyperledger/fabric-kafka:latest
docker pull hyperledger/fabric-couchdb:0.4.18
docker tag hyperledger/fabric-couchdb:0.4.18 hyperledger/fabric-couchdb:latest
docker pull hyperledger/fabric-baseos:2.0
docker tag hyperledger/fabric-baseos:2.0 hyperledger/fabric-baseos:latest
执行
chmod 777 docker_images.sh
./docker_images.sh
需要一段时间。。。。
docker images
https://github.com/hyperledger/fabric/releases/tag/v2.0.0
上传configtxgen、cryptogen、configtxlator 到 /usr/local/bin目录下, 这样fabric的这些可执行程序就可以在全局范围内使用
cd /usr/local/bin
sudo chmod 777 *
到此,万事具备,只欠东风了。。。
cd /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network
sudo ./byfn.sh generate
sudo ./byfn.sh generate -c mychannel 指定通道名
Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/../bin/cryptogen
##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x
Generate CCP files for Org1 and Org2
/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/../bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
+ configtxgen -profile SampleMultiNodeEtcdRaft -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2020-07-24 13:42:33.061 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-24 13:42:33.131 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2020-07-24 13:42:33.131 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-07-24 13:42:33.132 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-07-24 13:42:33.141 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2020-07-24 13:42:33.143 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
+ res=0
+ set +x
#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2020-07-24 13:42:33.178 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-24 13:42:33.212 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-07-24 13:42:33.213 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
2020-07-24 13:42:33.217 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx
+ res=0
+ set +x
#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2020-07-24 13:42:33.253 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-24 13:42:33.298 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-07-24 13:42:33.299 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
2020-07-24 13:42:33.302 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update
+ res=0
+ set +x
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2020-07-24 13:42:33.336 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-24 13:42:33.381 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-07-24 13:42:33.382 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
2020-07-24 13:42:33.386 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update
+ res=0
+ set +x
以golang链码为例
处理链码依赖问题
换成国内代理
unset GOPROXY
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
下载依赖
cd fabric-samples/chaincode/abstore/go
GO111MODULE=on go mod vendor
启动网络
sudo ./byfn.sh up
其它启动方式:
sudo ./byfn.sh up -l javascript 指定链码为javascript
sudo ./byfn.sh up -l java 指定链码为java
sudo ./byfn.sh up -n 只启动集群不安装链码
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
LOCAL_VERSION=2.0.0
DOCKER_IMAGE_VERSION=2.0.0
Creating network "net_byfn" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_orderer2.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating volume "net_orderer5.example.com" with default driver
Creating volume "net_orderer4.example.com" with default driver
Creating volume "net_orderer3.example.com" with default driver
Creating peer1.org2.example.com
Creating orderer3.example.com
Creating orderer4.example.com
Creating peer1.org1.example.com
Creating orderer.example.com
Creating orderer5.example.com
Creating peer0.org1.example.com
Creating orderer2.example.com
Creating peer0.org2.example.com
Creating cli
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
65871784c544 hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli
7fea7594ca1e hyperledger/fabric-peer:latest "peer node start" 7 seconds ago Up 1 second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com
9d72791c4ad3 hyperledger/fabric-orderer:latest "orderer" 7 seconds ago Up 2 seconds 7050/tcp, 0.0.0.0:8050->8050/tcp orderer2.example.com
27124ebccd8c hyperledger/fabric-peer:latest "peer node start" 7 seconds ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com
ba5b2e7f7231 hyperledger/fabric-orderer:latest "orderer" 7 seconds ago Up 1 second 7050/tcp, 0.0.0.0:11050->11050/tcp orderer5.example.com
653e7123ec01 hyperledger/fabric-orderer:latest "orderer" 7 seconds ago Up 1 second 0.0.0.0:7050->7050/tcp orderer.example.com
ff579d1927a8 hyperledger/fabric-peer:latest "peer node start" 7 seconds ago Up 1 second 7051/tcp, 0.0.0.0:8051->8051/tcp peer1.org1.example.com
a0e442c45996 hyperledger/fabric-orderer:latest "orderer" 7 seconds ago Up 3 seconds 7050/tcp, 0.0.0.0:10050->10050/tcp orderer4.example.com
00849c33d598 hyperledger/fabric-orderer:latest "orderer" 7 seconds ago Up 4 seconds 7050/tcp, 0.0.0.0:9050->9050/tcp orderer3.example.com
2e47ff706668 hyperledger/fabric-peer:latest "peer node start" 7 seconds ago Up 2 seconds 7051/tcp, 0.0.0.0:10051->10051/tcp peer1.org2.example.com
Sleeping 15s to allow Raft cluster to complete booting
Vendoring Go dependencies ...
/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode/abstore/go /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network
/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network
Finished vendoring Go dependencies
____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|
Build your first network (BYFN) end-to-end test
Channel name : mychannel
Creating channel...
+ peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-07-24 06:40:15.890 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-24 06:40:15.911 UTC [cli.common] readBlock -> INFO 002 Expect block, but got status: &{NOT_FOUND}
2020-07-24 06:40:15.925 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2020-07-24 06:40:16.127 UTC [cli.common] readBlock -> INFO 004 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2020-07-24 06:40:16.130 UTC [channelCmd] InitCmdFactory -> INFO 005 Endorser and orderer connections initialized
2020-07-24 06:40:16.331 UTC [cli.common] readBlock -> INFO 006 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2020-07-24 06:40:16.334 UTC [channelCmd] InitCmdFactory -> INFO 007 Endorser and orderer connections initialized
2020-07-24 06:40:16.535 UTC [cli.common] readBlock -> INFO 008 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2020-07-24 06:40:16.537 UTC [channelCmd] InitCmdFactory -> INFO 009 Endorser and orderer connections initialized
2020-07-24 06:40:16.738 UTC [cli.common] readBlock -> INFO 00a Expect block, but got status: &{SERVICE_UNAVAILABLE}
2020-07-24 06:40:16.742 UTC [channelCmd] InitCmdFactory -> INFO 00b Endorser and orderer connections initialized
2020-07-24 06:40:16.945 UTC [cli.common] readBlock -> INFO 00c Expect block, but got status: &{SERVICE_UNAVAILABLE}
2020-07-24 06:40:16.951 UTC [channelCmd] InitCmdFactory -> INFO 00d Endorser and orderer connections initialized
2020-07-24 06:40:17.153 UTC [cli.common] readBlock -> INFO 00e Received block: 0
===================== Channel 'mychannel' created =====================
Having all peers join the channel...
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-07-24 06:40:17.231 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-24 06:40:17.262 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org1 joined channel 'mychannel' =====================
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-07-24 06:40:20.319 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-24 06:40:20.349 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org1 joined channel 'mychannel' =====================
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-07-24 06:40:23.426 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-24 06:40:23.458 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org2 joined channel 'mychannel' =====================
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-07-24 06:40:26.514 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-24 06:40:26.543 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org2 joined channel 'mychannel' =====================
Updating anchor peers for org1...
+ peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-07-24 06:40:29.600 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-24 06:40:29.615 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' =====================
Updating anchor peers for org2...
+ peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-07-24 06:40:32.694 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-24 06:40:32.704 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' =====================
+ peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/abstore/go/ --lang golang --label mycc_1
+ res=0
+ set +x
===================== Chaincode is packaged on peer0.org1 =====================
Installing chaincode on peer0.org1...
+ peer lifecycle chaincode install mycc.tar.gz
+ res=0
+ set +x
2020-07-24 06:41:00.655 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:
2020-07-24 06:41:00.655 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc_1:f5cc6d6e871262e8da9788f3d463442e51c482ec8288c13e4545741ad45d86fa
===================== Chaincode is installed on peer0.org1 =====================
Install chaincode on peer0.org2...
+ peer lifecycle chaincode install mycc.tar.gz
+ res=0
+ set +x
2020-07-24 06:41:20.078 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:
2020-07-24 06:41:20.079 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc_1:f5cc6d6e871262e8da9788f3d463442e51c482ec8288c13e4545741ad45d86fa
===================== Chaincode is installed on peer0.org2 =====================
+ peer lifecycle chaincode queryinstalled
+ res=0
+ set +x
Installed chaincodes on peer:
Package ID: mycc_1:f5cc6d6e871262e8da9788f3d463442e51c482ec8288c13e4545741ad45d86fa, Label: mycc_1
PackageID is mycc_1:f5cc6d6e871262e8da9788f3d463442e51c482ec8288c13e4545741ad45d86fa
===================== Query installed successful on peer0.org1 on channel =====================
+ peer lifecycle chaincode approveformyorg --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name mycc --version 1 --init-required --package-id mycc_1:f5cc6d6e871262e8da9788f3d463442e51c482ec8288c13e4545741ad45d86fa --sequence 1 --waitForEvent
+ set +x
2020-07-24 06:41:20.307 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2020-07-24 06:41:22.579 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [02587b63bbd191086eb97563cccfe0b80eda89c0475702d355272b993db0ddcb] committed with status (VALID) at
===================== Chaincode definition approved on peer0.org1 on channel 'mychannel' =====================
===================== Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'... =====================
Attempting to check the commit readiness of the chaincode definition on peer0.org1 ...3 secs
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1 --sequence 1 --output json --init-required
+ res=0
+ set +x
{
"approvals": {
"Org1MSP": true,
"Org2MSP": false
}
}
===================== Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel' =====================
===================== Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'... =====================
Attempting to check the commit readiness of the chaincode definition on peer0.org2 ...3 secs
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1 --sequence 1 --output json --init-required
+ res=0
+ set +x
{
"approvals": {
"Org1MSP": true,
"Org2MSP": false
}
}
===================== Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel' =====================
+ peer lifecycle chaincode approveformyorg --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name mycc --version 1 --init-required --package-id mycc_1:f5cc6d6e871262e8da9788f3d463442e51c482ec8288c13e4545741ad45d86fa --sequence 1 --waitForEvent
+ set +x
2020-07-24 06:41:28.910 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2020-07-24 06:41:31.041 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [f083aeb03bd378ca96f05e87fc8127f09648f3181eb18778c144b7d2eb0bfa6b] committed with status (VALID) at
===================== Chaincode definition approved on peer0.org2 on channel 'mychannel' =====================
===================== Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'... =====================
Attempting to check the commit readiness of the chaincode definition on peer0.org1 ...3 secs
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1 --sequence 1 --output json --init-required
+ res=0
+ set +x
{
"approvals": {
"Org1MSP": true,
"Org2MSP": true
}
}
===================== Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel' =====================
===================== Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'... =====================
Attempting to check the commit readiness of the chaincode definition on peer0.org2 ...3 secs
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1 --sequence 1 --output json --init-required
+ res=0
+ set +x
{
"approvals": {
"Org1MSP": true,
"Org2MSP": true
}
}
===================== Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel' =====================
+ peer lifecycle chaincode commit -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --version 1 --sequence 1 --init-required
2020-07-24 06:41:39.807 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [ae598c82605564488e5d610cc6071faf323ac6cccc59c16757623ee725d1818d] committed with status (VALID) at peer0.org2.example.com:9051
2020-07-24 06:41:39.878 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [ae598c82605564488e5d610cc6071faf323ac6cccc59c16757623ee725d1818d] committed with status (VALID) at peer0.org1.example.com:7051
===================== Chaincode definition committed on channel 'mychannel' =====================
===================== Querying chaincode definition on peer0.org1 on channel 'mychannel'... =====================
+ res=0
+ set +x
Attempting to Query committed status on peer0.org1 ...3 secs
+ peer lifecycle chaincode querycommitted --channelID mychannel --name mycc
+ res=0
+ set +x
Committed chaincode definition for chaincode 'mycc' on channel 'mychannel':
Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
===================== Query chaincode definition successful on peer0.org1 on channel 'mychannel' =====================
===================== Querying chaincode definition on peer0.org2 on channel 'mychannel'... =====================
Attempting to Query committed status on peer0.org2 ...3 secs
+ peer lifecycle chaincode querycommitted --channelID mychannel --name mycc
+ res=0
+ set +x
Committed chaincode definition for chaincode 'mycc' on channel 'mychannel':
Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
===================== Query chaincode definition successful on peer0.org2 on channel 'mychannel' =====================
+ peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --isInit -c '{"Args":["Init","a","100","b","100"]}'
+ res=0
+ set +x
2020-07-24 06:41:46.178 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x
100
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
Sending invoke transaction on peer0.org1 peer0.org2...
+ peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
+ res=0
+ set +x
2020-07-24 06:41:49.358 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x
90
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
Installing chaincode on peer1.org2...
+ peer lifecycle chaincode install mycc.tar.gz
+ res=0
+ set +x
2020-07-24 06:42:13.828 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:
2020-07-24 06:42:13.828 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc_1:f5cc6d6e871262e8da9788f3d463442e51c482ec8288c13e4545741ad45d86fa
===================== Chaincode is installed on peer1.org2 =====================
Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'mychannel'... =====================
Attempting to Query peer1.org2 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x
90
===================== Query successful on peer1.org2 on channel 'mychannel' =====================
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
docker ps -a
docker exec -it cli bash
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
就这样,搭建fabric2.0.0的raft共识单机版集群环境完成了。。。
sudo ./byfn.sh down
Fabric 2.0在链码操作上有很大改动,整体的流程可以分为四个步骤:打包、安装、机构审批、 链码提交。
链码打包:创建一个打包文件(tar格式),其中包含Fabric链码以及一些元数据。
peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/abstore/go/ --lang golang --label mycc_1
安装:将打包的Fabric链码文件安装在指定的peer节点上。和之前的版本一样, 只有需要接受链码调用的节点才需要安装链码。在这个节点,Fabric链码还不可用, 因为还没有提交到通道中。
peer lifecycle chaincode install mycc.tar.gz
peer lifecycle chaincode queryinstalled
机构审批是在Hyperledger Fabric 2.0中增加的步骤。在Fabric 2.0中,需要机构显式地审批链码。需要多少机构 审批则是由生命周期背书策略来决定,默认情况下设置为需要大多数机构(超过半数)。如果Fabric网络中包含两个机构,那么就需要这两个机构同时批准。在审批过程中需要排序节点的参与,因为每次审批都会生成一个新的区块,这意味着所有的peer节点都了解审批的状态。
peer lifecycle chaincode approveformyorg --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name mycc --version 1 --init-required --package-id mycc_1:f5cc6d6e871262e8da9788f3d463442e51c482ec8288c13e4545741ad45d86fa --sequence 1 --waitForEvent
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1 --sequence 1 --output json --init-required
链码提交:可以在任一peer节点上完成。该流程首先需要批准机构的背书,然后交易提交到排序服务并生成新的区块,最后所有的对等节点在账本中提交该区块。
peer lifecycle chaincode commit -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --version 1 --sequence 1 --init-required
peer lifecycle chaincode querycommitted --channelID mychannel --name mycc
在Fabric 1.4中,当链码实例化时会自动调用链码的Init方法;但在Fabric 2.0中,需要在提交链码后显式地调用Init方法。
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --isInit -c '{"Args":["Init","a","100","b","100"]}'
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'