超级账本 fabric多机部署步骤(solo)

这里将演示一个fabric orderer solo的多机部署版本。kafka版本的地址: kafka版本的部署步骤

测试环境:

  • 多机环境:1 个 ubuntu18 + 5台centos 7,其中ubuntu作为client机器.在6台机器上,修改/etc/hosts:
192.168.64.136 peer0.org1.ping40.net
192.168.64.225 peer1.org1.ping40.net
192.168.64.243 peer0.org2.ping40.net
192.168.64.249 peer1.org2.ping40.net
192.168.64.69     orderer.ping40.net 

多机环境下,要保证所有机器的时间一样。在 core.yaml, orderer.yaml配置文件要求时间相处不能超过15分钟:

authentication:
        # the acceptable difference between the current server time and the
        # client's time as specified in a client request message
        timewindow: 15m

理论上也可以使用2~5台机器进行测试

  • 单机环境:1 个 ubuntu18,/etc/hosts 修改配置:
127.0.0.1 peer0.org1.ping40.net
127.0.0.1 peer1.org1.ping40.net
127.0.0.1 peer0.org2.ping40.net
127.0.0.1 peer1.org2.ping40.net
127.0.0.1    orderer.ping40.net
  • 本测试生成的二进制程序是fabric 1.4.0版本。
commit b2ea980d57b2ff50240049b2feef69adaa44a2e3
  • 测试例子中没有启用tls,且 是一个orderer,solo模式

  • docker环境准备
    peer0.org1,peer0.org2的机器需要docker环境和二个镜像:
    hyperledger/fabric-baseos:amd64-0.4.14
    hyperledger/fabric-ccenv:latest

[root@c243 tmp]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
hyperledger/fabric-baseos   amd64-0.4.14        75f5fb1a0e0c        4 weeks ago         124MB
hyperledger/fabric-ccenv    amd64-1.3.0         953124d80237        5 weeks ago         1.38GB
hyperledger/fabric-ccenv    latest              953124d80237        5 weeks ago         1.38GB
[root@c243 tmp]# docker version
Client:
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:48:22 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:19:08 2018
  OS/Arch:          linux/amd64
  Experimental:     false

步骤1:下载脚本

在client机器上下载 https://github.com/ping40/fabric_install.git

fabric@me:~$ git clone https://github.com/ping40/fabric_install.git 
正克隆到 'fabric_install'...
remote: Enumerating objects: 20, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 20 (delta 6), reused 20 (delta 6), pack-reused 0
展开对象中: 100% (20/20), 完成.
fabric@me:~$ cd fabric_install/
fabric@me:~/fabric_install$ pwd

fabric@me:~/fabric_install$ ls -hl
总用量 96M
-rwxrwxr-x 1 fabric fabric  14K 11月 16 10:28 byfn.sh
-rwxrwxr-x 1 fabric fabric  19M 11月 16 10:28 configtxgen
-rw-rw-r-- 1 fabric fabric  12K 11月 16 10:28 configtx.yaml
-rw-rw-r-- 1 fabric fabric  28K 11月 16 10:28 core.yaml
-rw-rw-r-- 1 fabric fabric 3.9K 11月 16 10:28 crypto-config.yaml
-rwxrwxr-x 1 fabric fabric  13M 11月 16 10:28 cryptogen
-rw-rw-r-- 1 fabric fabric    3 11月 16 10:28 log.txt
-rwxrwxr-x 1 fabric fabric  28M 11月 16 10:28 orderer
-rw-rw-r-- 1 fabric fabric  14K 11月 16 10:28 orderer.yaml
-rwxrwxr-x 1 fabric fabric  36M 11月 16 10:28 peer
-rw-rw-r-- 1 fabric fabric  28K 11月 16 10:28 peer0-org1.core.yaml
-rw-rw-r-- 1 fabric fabric  28K 11月 16 10:28 peer0-org2.core.yaml
-rw-rw-r-- 1 fabric fabric  28K 11月 16 10:28 peer1-org1.core.yaml
-rw-rw-r-- 1 fabric fabric  28K 11月 16 10:28 peer1-org2.core.yaml
-rw-rw-r-- 1 fabric fabric   16 11月 16 10:28 README.md
drwxrwxr-x 3 fabric fabric 4.0K 11月 16 10:28 src

下面的所有操作当前目录是:/home/fabric/fabric_install。
client机器上需要安装golang

fabric@me:~/fabric_install$ go version
go version go1.11 linux/amd64

步骤2:生成msp相关文件,genesis block,channel.tx, anchor.tx

fabric@me:~/fabric_install$ ./byfn.sh generate
CURRENTDIR = /home/fabric/fabric_install

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ ./cryptogen generate --config=./crypto-config.yaml
org1.ping40.net
org2.ping40.net
+ res=0
+ set +x

##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
+ ./configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/mygenesis.block
2018-11-16 11:02:14.849 CST [common.tools.configtxgen] main -> WARN 001 Omitting the channel ID for configtxgen for output operations is deprecated.  Explicitly passing the channel ID will be required in the future, defaulting to 'testchainid'.
2018-11-16 11:02:14.849 CST [common.tools.configtxgen] main -> INFO 002 Loading configuration
2018-11-16 11:02:14.876 CST [common.tools.configtxgen] doOutputBlock -> INFO 003 Generating genesis block
2018-11-16 11:02:14.876 CST [common.tools.configtxgen] doOutputBlock -> INFO 004 Writing genesis block
+ res=0
+ set +x

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ ./configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID ping40channel
2018-11-16 11:02:14.909 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2018-11-16 11:02:14.931 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2018-11-16 11:02:14.932 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Writing new channel tx
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
+ ./configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID ping40channel -asOrg Org1MSP
2018-11-16 11:02:14.968 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2018-11-16 11:02:14.989 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-11-16 11:02:14.990 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
+ ./configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID ping40channel -asOrg Org2MSP
2018-11-16 11:02:15.023 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2018-11-16 11:02:15.045 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-11-16 11:02:15.045 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
+ res=0
+ set +x

步骤3:为orderer,peer运行准备程序,配置文件

fabric@me:~/fabric_install$ ./byfn.sh dispatch
CURRENTDIR = /home/fabric/fabric_install

##########################################################
##### copy files to run-orderer, run-peer0-org1 #########
##### run-peer1-org1, run-peer0-org2,run-peer1-org2######
##########################################################
run-orderer/
run-orderer/msp/
run-orderer/msp/tlscacerts/
run-orderer/msp/tlscacerts/tlsca.ping40.net-cert.pem
run-orderer/msp/admincerts/
run-orderer/msp/admincerts/Admin@ping40.net-cert.pem
run-orderer/msp/signcerts/
run-orderer/msp/signcerts/orderer.ping40.net-cert.pem
run-orderer/msp/keystore/
run-orderer/msp/keystore/a4bd8fcb673d31141fd34016db02f86e7e4172b111382b513bce084616910b3f_sk
run-orderer/msp/cacerts/
run-orderer/msp/cacerts/ca.ping40.net-cert.pem
run-orderer/orderer.yaml
run-orderer/orderer
run-orderer/mygenesis.block
run-peer0-org1/
run-peer0-org1/msp/
run-peer0-org1/msp/tlscacerts/
run-peer0-org1/msp/tlscacerts/tlsca.org1.ping40.net-cert.pem
run-peer0-org1/msp/admincerts/
run-peer0-org1/msp/admincerts/Admin@org1.ping40.net-cert.pem
run-peer0-org1/msp/signcerts/
run-peer0-org1/msp/signcerts/peer0.org1.ping40.net-cert.pem
run-peer0-org1/msp/keystore/
run-peer0-org1/msp/keystore/e91ac45bff00c72c6c328380fedbbcbd3980b971922617fdb1c5eb00ce12998e_sk
run-peer0-org1/msp/cacerts/
run-peer0-org1/msp/cacerts/ca.org1.ping40.net-cert.pem
run-peer0-org1/msp/config.yaml
run-peer0-org1/peer
run-peer0-org1/core.yaml
run-peer1-org1/
run-peer1-org1/msp/
run-peer1-org1/msp/tlscacerts/
run-peer1-org1/msp/tlscacerts/tlsca.org1.ping40.net-cert.pem
run-peer1-org1/msp/admincerts/
run-peer1-org1/msp/admincerts/Admin@org1.ping40.net-cert.pem
run-peer1-org1/msp/signcerts/
run-peer1-org1/msp/signcerts/peer1.org1.ping40.net-cert.pem
run-peer1-org1/msp/keystore/
run-peer1-org1/msp/keystore/801cab394608c18f3103b934312db1d38de12af6583b716be46fe81862683026_sk
run-peer1-org1/msp/cacerts/
run-peer1-org1/msp/cacerts/ca.org1.ping40.net-cert.pem
run-peer1-org1/msp/config.yaml
run-peer1-org1/peer
run-peer1-org1/core.yaml
run-peer0-org2/
run-peer0-org2/msp/
run-peer0-org2/msp/tlscacerts/
run-peer0-org2/msp/tlscacerts/tlsca.org2.ping40.net-cert.pem
run-peer0-org2/msp/admincerts/
run-peer0-org2/msp/admincerts/Admin@org2.ping40.net-cert.pem
run-peer0-org2/msp/signcerts/
run-peer0-org2/msp/signcerts/peer0.org2.ping40.net-cert.pem
run-peer0-org2/msp/keystore/
run-peer0-org2/msp/keystore/60b8537a807cb75558a489f7370f8fb1a77c6a722bad7bc1ecf672c3c4e03df5_sk
run-peer0-org2/msp/cacerts/
run-peer0-org2/msp/cacerts/ca.org2.ping40.net-cert.pem
run-peer0-org2/msp/config.yaml
run-peer0-org2/peer
run-peer0-org2/core.yaml
run-peer1-org2/
run-peer1-org2/msp/
run-peer1-org2/msp/tlscacerts/
run-peer1-org2/msp/tlscacerts/tlsca.org2.ping40.net-cert.pem
run-peer1-org2/msp/admincerts/
run-peer1-org2/msp/admincerts/Admin@org2.ping40.net-cert.pem
run-peer1-org2/msp/signcerts/
run-peer1-org2/msp/signcerts/peer1.org2.ping40.net-cert.pem
run-peer1-org2/msp/keystore/
run-peer1-org2/msp/keystore/2e3473ee76be82329d62b975467d23aebe23baa99c1d5ff4025ae0ab632695da_sk
run-peer1-org2/msp/cacerts/
run-peer1-org2/msp/cacerts/ca.org2.ping40.net-cert.pem
run-peer1-org2/msp/config.yaml
run-peer1-org2/peer
run-peer1-org2/core.yaml

一:多机环境下程序分发

fabric@me:~/fabric_install$ cd multimachine/
fabric@me:~/fabric_install/multimachine$ ll
总用量 58444
drwxrwxr-x  2 fabric fabric     4096 11月 16 11:05 ./
drwxrwxr-x 12 fabric fabric     4096 11月 16 11:05 ../
-rw-rw-r--  1 fabric fabric  9749482 11月 16 11:05 run-orderer.tar.gz  -->这个文件复制到orderer的机器上
-rw-rw-r--  1 fabric fabric 12521375 11月 16 11:05 run-peer0-org1.tar.gz -->这个文件复制到peer0-org1的机器上
-rw-rw-r--  1 fabric fabric 12521356 11月 16 11:05 run-peer0-org2.tar.gz
-rw-rw-r--  1 fabric fabric 12521335 11月 16 11:05 run-peer1-org1.tar.gz
-rw-rw-r--  1 fabric fabric 12520864 11月 16 11:05 run-peer1-org2.tar.gz

步骤4: 启动orderer,peer程序

一:多机环境下

启动orderer

[root@c69 run-orderer]# ls -lh
总用量 28M
drwxr-xr-x 7 1001 1001  85 11月 16 11:05 msp
-rw-r--r-- 1 1001 1001 13K 11月 16 11:05 mygenesis.block
-rwxrwxr-x 1 1001 1001 28M 11月 16 11:05 orderer
-rw-rw-r-- 1 1001 1001 14K 11月 16 11:05 orderer.yaml
[root@c69 run-orderer]# 
[root@c69 run-orderer]# ./orderer start
......
5e38af704638328bfac205bd953153359bcb9d949daf4b6aa771cc8eac7e47b9 and orderer type solo
2018-11-16 11:29:01.247 CST [orderer.common.server] Start -> INFO 005 Starting orderer:
 Version: 1.4.0
 Commit SHA: b2ea980d5
 Go version: go1.11
 OS/Arch: linux/amd64
2018-11-16 11:29:01.247 CST [orderer.common.server] Start -> INFO 006 Beginning to serve requests

启动4个peer节点

ll
总用量 36124
-rw-rw-r-- 1 1001 1001    28267 11月 16 11:05 core.yaml
drwxr-xr-x 7 1001 1001      103 11月 16 11:05 msp
-rwxrwxr-x 1 1001 1001 36961288 11月 16 11:05 peer
[root@c249 run-peer1-org2]# pwd
/root/run-peer1-org2
[root@c249 run-peer1-org2]# ./peer node start
2018-11-16 11:33:47.335 CST [nodeCmd] serve -> INFO 001 Starting peer:
 Version: 1.4.0
 Commit SHA: b2ea980d5
 Go version: go1.11
 OS/Arch: linux/amd64
 Chaincode:
  Base Image Version: 0.4.14
  Base Docker Namespace: hyperledger
  Base Docker Label: org.hyperledger.fabric
  Docker Namespace: hyperledger
2018-11-16 11:33:47.336 CST [ledgermgmt] initialize -> INFO 002 Initializing ledger mgmt
.....

二:单机环境环境下

drwxrwxr-x  3 fabric fabric     4096 11月 16 11:05 run-orderer/
drwxrwxr-x  3 fabric fabric     4096 11月 16 11:05 run-peer0-org1/
drwxrwxr-x  3 fabric fabric     4096 11月 16 11:05 run-peer0-org2/
drwxrwxr-x  3 fabric fabric     4096 11月 16 11:05 run-peer1-org1/
drwxrwxr-x  3 fabric fabric     4096 11月 16 11:05 run-peer1-org2/

请到上面5个目录下,启动对应的服务

步骤5: 创建通道

步骤5.1: 创建通道

fabric@me:~/fabric_install$ ./byfn.sh createChannel
CURRENTDIR = /home/fabric/fabric_install
00 setGlobals 0, 1
02 setGlobals 0, 1
CORE_PEER_ADDRESS: peer0.org1.ping40.net:51100 
CORE_PEER_LOCALMSPID: Org1MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org1MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org1.ping40.net:51100
+ ./peer channel create -o orderer.ping40.net:51000 -c ping40channel -f ./channel-artifacts/channel.tx --logging-level=debug
+ res=0
+ set +x
2018-11-16 11:41:55.284 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:41:55.298 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:41:55.300 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-11-16 11:41:55.421 CST [cli.common] readBlock -> INFO 004 Received block: 0
===================== Channel 'ping40channel' created ===================== 

步骤5.2: peer节点加入通道

fabric@me:~/fabric_install$ ./byfn.sh joinChannel  
CURRENTDIR = /home/fabric/fabric_install
00 setGlobals 0, 1
02 setGlobals 0, 1
CORE_PEER_ADDRESS: peer0.org1.ping40.net:51100 
CORE_PEER_LOCALMSPID: Org1MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org1MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org1.ping40.net:51100
+ ./peer channel join -b ping40channel.block --logging-level=debug
+ res=0
+ set +x
2018-11-16 11:42:47.689 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:42:47.705 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:42:47.707 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-11-16 11:42:47.984 CST [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
===================== peer0-org1.ping40.net success to join channel ===================== 

00 setGlobals 1, 1
02 setGlobals 1, 1
CORE_PEER_ADDRESS: peer1.org1.ping40.net:51110 
CORE_PEER_LOCALMSPID: Org1MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org1MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
+ CORE_PEER_ADDRESS=peer1.org1.ping40.net:51110
+ ./peer channel join -b ping40channel.block --logging-level=debug
+ res=0
+ set +x
2018-11-16 11:42:48.034 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:42:48.049 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:42:48.051 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-11-16 11:42:48.369 CST [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
===================== peer1-org1.ping40.net success to join channel ===================== 

00 setGlobals 0, 2
CORE_PEER_ADDRESS: peer0.org2.ping40.net:51200 
CORE_PEER_LOCALMSPID: Org2MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org2MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org2.ping40.net:51200
+ ./peer channel join -b ping40channel.block --logging-level=debug
+ res=0
+ set +x
2018-11-16 11:42:48.420 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:42:48.436 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:42:48.437 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-11-16 11:42:48.683 CST [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
===================== peer0-org2.ping40.net success to join channel ===================== 

00 setGlobals 1, 2
CORE_PEER_ADDRESS: peer1.org2.ping40.net:51210 
CORE_PEER_LOCALMSPID: Org2MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org2MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
+ CORE_PEER_ADDRESS=peer1.org2.ping40.net:51210
+ ./peer channel join -b ping40channel.block --logging-level=debug
+ res=0
+ set +x
2018-11-16 11:42:48.738 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:42:48.752 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:42:48.753 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-11-16 11:42:49.058 CST [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
===================== peer1-org2.ping40.net success to join channel ===================== 

步骤5.3: 更新锚节点

fabric@me:~/fabric_install$ ./byfn.sh updateAnchor
CURRENTDIR = /home/fabric/fabric_install
00 setGlobals 0, 1
02 setGlobals 0, 1
CORE_PEER_ADDRESS: peer0.org1.ping40.net:51100 
CORE_PEER_LOCALMSPID: Org1MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org1MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org1.ping40.net:51100
+ ./peer channel update -o orderer.ping40.net:51000 -c ping40channel -f channel-artifacts/Org1MSPanchors.tx --logging-level=debug
+ res=0
+ set +x
2018-11-16 11:48:18.368 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:48:18.385 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:48:18.386 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-11-16 11:48:18.410 CST [channelCmd] update -> INFO 004 Successfully submitted channel update
===================== peer0-org1.ping40.net success to updateAnchor ===================== 

00 setGlobals 0, 2
CORE_PEER_ADDRESS: peer0.org2.ping40.net:51200 
CORE_PEER_LOCALMSPID: Org2MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org2MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org2.ping40.net:51200
+ ./peer channel update -o orderer.ping40.net:51000 -c ping40channel -f channel-artifacts/Org2MSPanchors.tx --logging-level=debug
+ res=0
+ set +x
2018-11-16 11:48:18.459 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:48:18.474 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 11:48:18.475 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-11-16 11:48:18.487 CST [channelCmd] update -> INFO 004 Successfully submitted channel update
===================== peer0-org2.ping40.net success to updateAnchor ===================== 

步骤6: Chaincode的部署和调用

步骤6.1: 部署Chaincode代码

fabric@me:~/fabric_install$ ./byfn.sh installChaincode
CURRENTDIR = /home/fabric/fabric_install
00 setGlobals 0, 1
02 setGlobals 0, 1
CORE_PEER_ADDRESS: peer0.org1.ping40.net:51100 
CORE_PEER_LOCALMSPID: Org1MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
environment variables: begin
environment variables: end
+ GOPATH=/home/fabric/fabric_install
+ CORE_PEER_LOCALMSPID=Org1MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org1.ping40.net:51100
+ ./peer chaincode install -n chaincodeName -v 3.1 -p chaincode/ --logging-level=debug
+ res=0
+ set +x
2018-11-16 12:05:53.642 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 12:05:53.657 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 12:05:53.664 CST [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-11-16 12:05:53.664 CST [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-11-16 12:05:54.028 CST [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" > 
===================== peer0-org1.ping40.net success to installChaincode ===================== 

00 setGlobals 0, 2
CORE_PEER_ADDRESS: peer0.org2.ping40.net:51200 
CORE_PEER_LOCALMSPID: Org2MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
environment variables: begin
environment variables: end
+ GOPATH=/home/fabric/fabric_install
+ CORE_PEER_LOCALMSPID=Org2MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org2.ping40.net:51200
+ ./peer chaincode install -n chaincodeName -v 3.1 -p chaincode/ --logging-level=debug
+ res=0
+ set +x
2018-11-16 12:05:54.076 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 12:05:54.090 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 12:05:54.094 CST [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-11-16 12:05:54.094 CST [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-11-16 12:05:54.292 CST [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" > 
===================== peer0-org2.ping40.net success to installChaincode ===================== 

如果client机器没有 golang环境,会有如下错误

Error: error getting chaincode code chaincodeName: <go, [env]>: failed with error: "exec: not started"

步骤6.2: 实例化Chaincode代码

fabric@me:~/fabric_install$ ./byfn.sh instantiateChaincode
CURRENTDIR = /home/fabric/fabric_install
00 setGlobals 0, 2
CORE_PEER_ADDRESS: peer0.org2.ping40.net:51200 
CORE_PEER_LOCALMSPID: Org2MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org2MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org2.ping40.net:51200
+ ./peer chaincode instantiate -o orderer.ping40.net:51000 -C ping40channel -n chaincodeName -v 3.1 -c '{"Args":["init","a","100","b","200"]}' -P 'OR ('\''Org1MSP.member'\'', '\''Org2MSP.member'\'')' --logging-level=debug
+ res=0
+ set +x
2018-11-16 13:48:16.484 CST [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 13:48:16.498 CST [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
2018-11-16 13:48:16.502 CST [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-11-16 13:48:16.502 CST [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
===================== peer0-org2.ping40.net success to instantiateChaincode ===================== 

步骤6.3: 通过Chaincode写入数据

fabric@me:~/fabric_install$ ./byfn.sh invokeChaincode
CURRENTDIR = /home/fabric/fabric_install
00 setGlobals 0, 1
02 setGlobals 0, 1
CORE_PEER_ADDRESS: peer0.org1.ping40.net:51100 
CORE_PEER_LOCALMSPID: Org1MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org1MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org1.ping40.net:51100
+ ./peer chaincode invoke -o orderer.ping40.net:51000 -C ping40channel -n chaincodeName -c '{"Args":["invoke","a","b","10"]}'
+ res=0
+ set +x
2018-11-16 13:54:08.347 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 
===================== Invoke transaction successful on  on channel 'ping40channel' ===================== 

00 setGlobals 0, 2
CORE_PEER_ADDRESS: peer0.org2.ping40.net:51200 
CORE_PEER_LOCALMSPID: Org2MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org2MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org2.ping40.net:51200
+ ./peer chaincode invoke -o orderer.ping40.net:51000 -C ping40channel -n chaincodeName -c '{"Args":["invoke","a","b","10"]}'
+ res=0
+ set +x
2018-11-16 13:54:08.423 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 
===================== Invoke transaction successful on  on channel 'ping40channel' ===================== 

几乎同时触发二个transaction,其中一个会失败的

步骤6.4: 通过Chaincode查询数据

fabric@me:~/fabric_install$ ./byfn.sh queryChaincode 
CURRENTDIR = /home/fabric/fabric_install
00 setGlobals 0, 1
02 setGlobals 0, 1
CORE_PEER_ADDRESS: peer0.org1.ping40.net:51100 
CORE_PEER_LOCALMSPID: Org1MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org1MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org1.ping40.net/users/Admin@org1.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org1.ping40.net:51100
+ ./peer chaincode query -C ping40channel -n chaincodeName -c '{"Args":["query","a"]}'
+ res=0
+ set +x

90
========= Query successful on peer0.org1 on channel 'ping40channel' ===================== 
00 setGlobals 0, 2
CORE_PEER_ADDRESS: peer0.org2.ping40.net:51200 
CORE_PEER_LOCALMSPID: Org2MSP
CORE_PEER_MSPCONFIGPATH: /home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
environment variables: begin
environment variables: end
+ CORE_PEER_LOCALMSPID=Org2MSP
+ CORE_PEER_MSPCONFIGPATH=/home/fabric/fabric_install/crypto-config/peerOrganizations/org2.ping40.net/users/Admin@org2.ping40.net/msp
+ CORE_PEER_ADDRESS=peer0.org2.ping40.net:51200
+ ./peer chaincode query -C ping40channel -n chaincodeName -c '{"Args":["query","a"]}'
+ res=0
+ set +x

90
========= Query successful on peer0.org2 on channel 'ping40channel' ===================== 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,590评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,808评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,151评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,779评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,773评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,656评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,022评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,678评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,038评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,756评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,411评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,005评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,973评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,053评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,495评论 2 343

推荐阅读更多精彩内容