1. 程式人生 > 實用技巧 >hyperledger-fabric-sample-1

hyperledger-fabric-sample-1

當我跟著書上的步驟一起做時,並沒有得到書上的結果,並且會出現許多錯誤,於是我選擇跟隨hyperledger開發文件來做。

1.開始之前的準備

準備階段

2.安裝示例、二進位制和 Docker 映象

click

3.# 使用Fabric的測試網路

click

當我執行

./network.sh down

出現如下錯誤:(具體原因未知)

root@lennon-System-Product-Name:/home/lennon/桌面/fabric-samples/test-network# ./network.sh down
Stopping network
Removing network net_test
WARNING: Network net_test not found.
Removing volume net_orderer.example.com
WARNING: Volume net_orderer.example.com not found.
Removing volume net_peer0.org1.example.com
WARNING: Volume net_peer0.org1.example.com not found.
Removing volume net_peer0.org2.example.com
WARNING: Volume net_peer0.org2.example.com not found.
Removing network net_test
WARNING: Network net_test not found.
Removing volume net_peer0.org3.example.com
WARNING: Volume net_peer0.org3.example.com not found.
No containers available for deletion
No images available for deletion
Unable to find image 'busybox:latest' locally

然後執行

./network.sh up
root@lennon-System-Product-Name:/home/lennon/桌面/fabric-samples/test-network# ./network.sh up
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.3.0
DOCKER_IMAGE_VERSION=2.3.0
/home/lennon/桌面/fabric-samples/test-network/../bin/cryptogen
Generate certificates using cryptogen tool
Create Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Create Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Create Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generate CCP files for Org1 and Org2
/home/lennon/桌面/fabric-samples/test-network/../bin/configtxgen
Generating Orderer Genesis block
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2020-12-03 21:28:55.563 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-12-03 21:28:55.568 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2020-12-03 21:28:55.568 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 
2020-12-03 21:28:55.568 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/lennon/桌面/fabric-samples/test-network/configtx/configtx.yaml
2020-12-03 21:28:55.569 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2020-12-03 21:28:55.569 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Creating system channel genesis block
2020-12-03 21:28:55.570 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
+ res=0
Creating network "net_test" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating peer0.org1.example.com ... error
Creating peer0.org2.example.com ... 
Creating orderer.example.com    ... 

ERROR: for peer0.org1.example.com  Cannot create container for service peer0.org1.example.com: Conflict. The Creating peer0.org2.example.com ... error
660a1c4c5b1dbb7c70ce2acdd8f8". You have to remove (or rename) that container to be able to reuse that name.

ERROR: for peer0.org2.example.com  Cannot create container for service peer0.org2.example.com: Conflict. The container name "/peer0.org2.example.com" is already in use by container "ee52ab3c5c5fffb5363ab36ecac3f387171ae9a9f0a2ae878e846d1a10e9ad92". You have to remove (or rename) that container to be able to reuse that name.
Creating orderer.example.com    ... error

ERROR: for orderer.example.com  Cannot start service orderer.example.com: driver failed programming external connectivity on endpoint orderer.example.com (39290adbf8f4780bce68f1a8662e3397b4f12a1cfa49a9b4f49c1cbf74e8ebc2): Bind for 0.0.0.0:7050 failed: port is already allocated

ERROR: for peer0.org1.example.com  Cannot create container for service peer0.org1.example.com: Conflict. The container name "/peer0.org1.example.com" is already in use by container "325dad70284513e43be4acc8da595d946b65660a1c4c5b1dbb7c70ce2acdd8f8". You have to remove (or rename) that container to be able to reuse that name.

ERROR: for peer0.org2.example.com  Cannot create container for service peer0.org2.example.com: Conflict. The container name "/peer0.org2.example.com" is already in use by container "ee52ab3c5c5fffb5363ab36ecac3f387171ae9a9f0a2ae878e846d1a10e9ad92". You have to remove (or rename) that container to be able to reuse that name.

ERROR: for orderer.example.com  Cannot start service orderer.example.com: driver failed programming external connectivity on endpoint orderer.example.com (39290adbf8f4780bce68f1a8662e3397b4f12a1cfa49a9b4f49c1cbf74e8ebc2): Bind for 0.0.0.0:7050 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
CONTAINER ID        IMAGE                                    COMMAND                  CREATED             STATUS                   PORTS                                         NAMES
5f56a825884e        hyperledger/fabric-orderer:latest        "orderer"                3 seconds ago       Created                                                                orderer.example.com
bcda3c4b5799        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        23 hours ago        Up 5 hours               9443/tcp, 0.0.0.0:8051->7051/tcp              peer1.org1.example.com
97dad4c06e80        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        23 hours ago        Up 5 hours               9443/tcp, 0.0.0.0:10051->7051/tcp             peer1.org2.example.com
325dad702845        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        23 hours ago        Up 5 hours               0.0.0.0:7051->7051/tcp, 9443/tcp              peer0.org1.example.com
ee52ab3c5c5f        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        23 hours ago        Up 5 hours               9443/tcp, 0.0.0.0:9051->7051/tcp              peer0.org2.example.com
66edbe51aba7        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          23 hours ago        Up 5 hours               0.0.0.0:7050->7050/tcp, 8443/tcp              orderer0.example.com
32f11286be4e        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          23 hours ago        Up 5 hours               8443/tcp, 0.0.0.0:8050->7050/tcp              orderer1.example.com
a2a8b3f255c0        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          23 hours ago        Up 5 hours               8443/tcp, 0.0.0.0:9050->7050/tcp              orderer2.example.com
0a251475276f        yeasy/hyperledger-fabric:2.0.0           "bash -c 'cd /tmp; s…"   23 hours ago        Up 5 hours               7050-7051/tcp, 7054/tcp, 8443/tcp, 9443/tcp   fabric-cli
4ed7334f8531        hello-world                              "/hello"                 2 weeks ago         Exited (0) 2 weeks ago                                                 beautiful_heyrovsky

出現了$\color{red}{error,無法創造容器}$,好像是因為我之前跟著書上的來做docker中建立過容器,需要移出或者重新命名之前那個才行。

然後,我輸入命令

docker ps

檢視本地系統中執行的容器資訊:

CONTAINER ID        IMAGE                                    COMMAND                  CREATED             STATUS                   PORTS                                         NAMES
5f56a825884e        hyperledger/fabric-orderer:latest        "orderer"                40 seconds ago      Created                                                                orderer.example.com
bcda3c4b5799        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        23 hours ago        Up 5 hours               9443/tcp, 0.0.0.0:8051->7051/tcp              peer1.org1.example.com
97dad4c06e80        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        23 hours ago        Up 5 hours               9443/tcp, 0.0.0.0:10051->7051/tcp             peer1.org2.example.com
325dad702845        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        23 hours ago        Up 5 hours               0.0.0.0:7051->7051/tcp, 9443/tcp              peer0.org1.example.com
ee52ab3c5c5f        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        23 hours ago        Up 5 hours               9443/tcp, 0.0.0.0:9051->7051/tcp              peer0.org2.example.com
66edbe51aba7        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          23 hours ago        Up 5 hours               0.0.0.0:7050->7050/tcp, 8443/tcp              orderer0.example.com
32f11286be4e        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          23 hours ago        Up 5 hours               8443/tcp, 0.0.0.0:8050->7050/tcp              orderer1.example.com
a2a8b3f255c0        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          23 hours ago        Up 5 hours               8443/tcp, 0.0.0.0:9050->7050/tcp              orderer2.example.com
0a251475276f        yeasy/hyperledger-fabric:2.0.0           "bash -c 'cd /tmp; s…"   23 hours ago        Up 5 hours               7050-7051/tcp, 7054/tcp, 8443/tcp, 9443/tcp   fabric-cli
4ed7334f8531        hello-world                              "/hello"                 2 weeks ago         Exited (0) 2 weeks ago                                                 beautiful_heyrovsky

這說明我之前已經建立過了容器,我需要先將這些刪除掉,但是我當時並沒有這樣做,而是運行了建立通道的命令

./network.sh createChannel

然後就出現了error

2020-12-03 21:31:32.856 CST [comm.tls] ClientHandshake -> ERRO 001 Client TLS handshake failed after 534.859µs with error: x509: certificate is valid for orderer0.example.com, orderer0, orderer0.example.com, orderer0, not orderer.example.com remoteaddress=127.0.0.1:7050
2020-12-03 21:31:33.859 CST [comm.tls] ClientHandshake -> ERRO 002 Client TLS handshake failed after 2.059853ms with error: x509: certificate is valid for orderer0.example.com, orderer0, orderer0.example.com, orderer0, not orderer.example.com remoteaddress=127.0.0.1:7050
2020-12-03 21:31:35.515 CST [comm.tls] ClientHandshake -> ERRO 003 Client TLS handshake failed after 3.180058ms with error: x509: certificate is valid for orderer0.example.com, orderer0, orderer0.example.com, orderer0, not orderer.example.com remoteaddress=127.0.0.1:7050
Error: failed to create deliver client for orderer: orderer client failed to connect to localhost:7050: failed to create new connection: context deadline exceeded
Channel creation failed
Create channel failed

然後我執行刪除之前容器的命令:

./network.sh down

出現如下提示:

Stopping network
Removing network net_test
Removing volume net_orderer.example.com
Removing volume net_peer0.org1.example.com
Removing volume net_peer0.org2.example.com
Removing network net_test
WARNING: Network net_test not found.
Removing volume net_peer0.org3.example.com
WARNING: Volume net_peer0.org3.example.com not found.
No containers available for deletion
No images available for deletion
Unable to find image 'busybox:latest' locally

提示我沒有能刪除的容器和映象。
此時我以為已經刪除掉了之前的容器,然後就嘗試建立通道

./network.sh up createChannel -c mychannel

又出現之前的錯誤

2020-12-03 21:42:15.650 CST [comm.tls] ClientHandshake -> ERRO 001 Client TLS handshake failed after 601.338µs with error: x509: certificate is valid for orderer0.example.com, orderer0, orderer0.example.com, orderer0, not orderer.example.com remoteaddress=127.0.0.1:7050
2020-12-03 21:42:16.654 CST [comm.tls] ClientHandshake -> ERRO 002 Client TLS handshake failed after 2.438379ms with error: x509: certificate is valid for orderer0.example.com, orderer0, orderer0.example.com, orderer0, not orderer.example.com remoteaddress=127.0.0.1:7050
2020-12-03 21:42:18.543 CST [comm.tls] ClientHandshake -> ERRO 003 Client TLS handshake failed after 1.941349ms with error: x509: certificate is valid for orderer0.example.com, orderer0, orderer0.example.com, orderer0, not orderer.example.com remoteaddress=127.0.0.1:7050
Error: failed to create deliver client for orderer: orderer client failed to connect to localhost:7050: failed to create new connection: context deadline exceeded
Channel creation failed
Create channel failed

這說明之前的容器還是沒有刪除掉,輸入查詢容器命令(此命令只顯示id):

docker ps -aq

輸出結果是:

bcda3c4b5799
97dad4c06e80
325dad702845
ee52ab3c5c5f
66edbe51aba7
32f11286be4e
a2a8b3f255c0
0a251475276f
4ed7334f8531

然後我又用:

./network.sh down

出現許多Not found:

Stopping network
Removing network net_test
WARNING: Network net_test not found.
Removing volume net_orderer.example.com
WARNING: Volume net_orderer.example.com not found.
Removing volume net_peer0.org1.example.com
WARNING: Volume net_peer0.org1.example.com not found.
Removing volume net_peer0.org2.example.com
WARNING: Volume net_peer0.org2.example.com not found.
Removing network net_test
WARNING: Network net_test not found.
Removing volume net_peer0.org3.example.com
WARNING: Volume net_peer0.org3.example.com not found.
No containers available for deletion
No images available for deletion
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
5f5dd3e95e9f: Pull complete 
Digest: sha256:9f1c79411e054199210b4d489ae600a061595967adb643cd923f8515ad8123d2
Status: Downloaded newer image for busybox:latest

然後查詢容器

docker ps
CONTAINER ID        IMAGE                                    COMMAND                  CREATED             STATUS              PORTS                                         NAMES
bcda3c4b5799        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        24 hours ago        Up 6 hours          9443/tcp, 0.0.0.0:8051->7051/tcp              peer1.org1.example.com
97dad4c06e80        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        24 hours ago        Up 6 hours          9443/tcp, 0.0.0.0:10051->7051/tcp             peer1.org2.example.com
325dad702845        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        24 hours ago        Up 6 hours          0.0.0.0:7051->7051/tcp, 9443/tcp              peer0.org1.example.com
ee52ab3c5c5f        yeasy/hyperledger-fabric-peer:2.0.0      "peer node start"        24 hours ago        Up 6 hours          9443/tcp, 0.0.0.0:9051->7051/tcp              peer0.org2.example.com
66edbe51aba7        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          24 hours ago        Up 6 hours          0.0.0.0:7050->7050/tcp, 8443/tcp              orderer0.example.com
32f11286be4e        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          24 hours ago        Up 6 hours          8443/tcp, 0.0.0.0:8050->7050/tcp              orderer1.example.com
a2a8b3f255c0        yeasy/hyperledger-fabric-orderer:2.0.0   "orderer start"          24 hours ago        Up 6 hours          8443/tcp, 0.0.0.0:9050->7050/tcp              orderer2.example.com
0a251475276f        yeasy/hyperledger-fabric:2.0.0           "bash -c 'cd /tmp; s…"   24 hours ago        Up 6 hours          7050-7051/tcp, 7054/tcp, 8443/tcp, 9443/tcp   fabric-cli

發現還是有容器,沒有刪除掉
最後使用

docker system prune

終於刪除掉了

root@lennon-System-Product-Name:/home/lennon/桌面/fabric-samples/test-network# docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
bcda3c4b5799162f3ad9de3ca48f2098738f1a609ae2f6d110c0b5b6adb9bd63
97dad4c06e800c9b1024a31f7357c8a218879f97d2983b24a50d67c980da5732
325dad70284513e43be4acc8da595d946b65660a1c4c5b1dbb7c70ce2acdd8f8
ee52ab3c5c5fffb5363ab36ecac3f387171ae9a9f0a2ae878e846d1a10e9ad92
66edbe51aba7836bb799a878db7c0c8d787e9e260dab9001efb1e6a8084fe18a
32f11286be4ee7985fb94f29da8ddc992345c2678c0ce840ce1309bc4c35b022
a2a8b3f255c023e6e05087274791da1d8f212e591992ab3ec3c18df79d9ec882
0a251475276fc5822547cff6e209bf1d91124664511ada4619299e1a05e2ac94

Deleted Networks:
hlf_net

Total reclaimed space: 16.68MB

這時再輸入,發現之前的容器都刪除掉了。

docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

此時,啟動

./network.sh up
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.3.0
DOCKER_IMAGE_VERSION=2.3.0
/home/lennon/桌面/fabric-samples/test-network/../bin/cryptogen
Generate certificates using cryptogen tool
Create Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Create Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Create Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generate CCP files for Org1 and Org2
/home/lennon/桌面/fabric-samples/test-network/../bin/configtxgen
Generating Orderer Genesis block
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2020-12-04 09:36:04.459 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-12-04 09:36:04.464 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2020-12-04 09:36:04.464 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 
2020-12-04 09:36:04.464 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/lennon/桌面/fabric-samples/test-network/configtx/configtx.yaml
2020-12-04 09:36:04.465 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2020-12-04 09:36:04.465 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Creating system channel genesis block
2020-12-04 09:36:04.465 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
+ res=0
Creating network "net_test" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating peer0.org2.example.com ... done
Creating orderer.example.com    ... done
Creating peer0.org1.example.com ... done
CONTAINER ID        IMAGE                               COMMAND             CREATED             STATUS                  PORTS                              NAMES
25c8d2b542c9        hyperledger/fabric-peer:latest      "peer node start"   5 seconds ago       Up Less than a second   0.0.0.0:7051->7051/tcp             peer0.org1.example.com
92e942e2db16        hyperledger/fabric-orderer:latest   "orderer"           5 seconds ago       Up Less than a second   0.0.0.0:7050->7050/tcp             orderer.example.com
80d5ca18b4f6        hyperledger/fabric-peer:latest      "peer node start"   5 seconds ago       Up 1 second             7051/tcp, 0.0.0.0:9051->9051/tcp   peer0.org2.example.com