赞
踩
参考(内容有错误,已修改): 区块链——Hyperledger Fabric2.2多机搭建及区块链浏览器
前提: order---10.10.10.65,org1---10.10.10.64,org2---10.10.10.53
三台服务器都要设置
vim /etc/hosts
- root@order:~# apt-get update
- root@order:~# apt-get -y install apt-transport-https ca-certificates curl software-properties-common
- root@order:~# curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
- root@order:~# add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
- root@order:~# apt-get -y update
- root@order:~# apt-get -y install docker-ce
- root@order:~# service docker start
- root@order:~# systemctl enable docker
- root@order:~# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- root@order:~# chmod +x /usr/local/bin/docker-compose
- root@order:~# docker-compose -v
- docker-compose version 1.29.2, build 5becea4c
- root@order:~# wget https://golang.google.cn/dl/go1.16.8.linux-amd64.tar.gz
- root@order:~# tar zxf go1.16.8.linux-amd64.tar.gz
- root@order:~# mv go /usr/local/
- root@order:~# vim /etc/profile
- export GOPATH=~/Go
- export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
- export GO111MODULE=on
- export GOPROXY=https://goproxy.cn
- root@order:~# source /etc/profile
- root@order:~# go version
- go version go1.16.8 linux/amd64
克隆项目fabric和fabric-samples
git clone https://gitee.com/hyperledger/fabric.git
git clone https://github.com/hyperledger/fabric-samples.git
cp fabric-samples/bin/* /usr/local/bin/
vim /etc/profile
export PATH=/home/bering/project/golandProjects/fabric/scripts/fabric-samples/bin:$PATH
source /etc/profile
- root@order:~# mkdir hyperledger/multinodes/
- root@order:~# cd hyperledger/multinodes/
- root@order:~/hyperledger/multinodes# cryptogen showtemplate > crypto-config.yaml
- root@order:~/hyperledger/multinodes# vim crypto-config.yaml
- OrdererOrgs:
-
- - Name: Orderer
- Domain: example.com
- EnableNodeOUs: true
-
- Specs:
- - Hostname: orderer
- PeerOrgs:
-
- - Name: org1
- Domain: org1.example.com
- EnableNodeOUs: true
- Template:
- Count: 1
- Users:
- Count: 1
-
- - Name: org2
- Domain: org2.example.com
- EnableNodeOUs: true
- Template:
- Count: 1
- Users:
- Count: 1
- root@order:~/hyperledger/multinodes# cryptogen generate --config=crypto-config.yaml
- org1.example.com
- org2.example.com
- root@order:~/hyperledger/multinodes# scp -r ./crypto-config root@10.10.10.64:/home/bering/project/hyperledger/multinodes/
- root@order:~/hyperledger/multinodes# scp -r ./crypto-config root@10.10.10.53:/home/bering/project/hyperledger/multinodes/
- root@order:~/hyperledger/multinodes# vim configtx.yaml
- ---
- Organizations:
-
- - &OrdererOrg
-
- Name: OrdererOrg
- ID: OrdererMSP
- MSPDir: ./crypto-config/ordererOrganizations/example.com/msp
- Policies:
- Readers:
- Type: Signature
- Rule: "OR('OrdererMSP.member')"
- Writers:
- Type: Signature
- Rule: "OR('OrdererMSP.member')"
- Admins:
- Type: Signature
- Rule: "OR('OrdererMSP.admin')"
- OrdererEndpoints:
- - orderer.example.com:7050
-
- - &Org1
-
- Name: Org1MSP
- ID: Org1MSP
- MSPDir: ./crypto-config/peerOrganizations/org1.example.com/msp
- Policies:
- Readers:
- Type: Signature
- Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
- Writers:
- Type: Signature
- Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
- Admins:
- Type: Signature
- Rule: "OR('Org1MSP.admin')"
- Endorsement:
- Type: Signature
- Rule: "OR('Org1MSP.peer')"
- AnchorPeers:
- - Host: peer0.org1.example.com
- Port: 7051
-
- - &Org2
-
- Name: Org2MSP
- ID: Org2MSP
- MSPDir: ./crypto-config/peerOrganizations/org2.example.com/msp
- Policies:
- Readers:
- Type: Signature
- Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
- Writers:
- Type: Signature
- Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
- Admins:
- Type: Signature
- Rule: "OR('Org2MSP.admin')"
- Endorsement:
- Type: Signature
- Rule: "OR('Org2MSP.peer')"
-
- AnchorPeers:
- - Host: peer0.org2.example.com
- Port: 7051
-
-
- 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: solo
-
- Addresses:
- - orderer.example.com:7050
-
- EtcdRaft:
- Consenters:
- - Host: orderer.example.com
- Port: 7050
- ClientTLSCert: ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
- ServerTLSCert: ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
-
- BatchTimeout: 2s
- 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:
- Type: ImplicitMeta
- Rule: "ANY Writers"
-
-
- Channel: &ChannelDefaults
-
- Policies:
-
- Readers:
- Type: ImplicitMeta
- Rule: "ANY Readers"
- Writers:
- Type: ImplicitMeta
- Rule: "ANY Writers"
- Admins:
- Type: ImplicitMeta
- Rule: "MAJORITY Admins"
-
-
- Capabilities:
- <<: *ChannelCapabilities
-
- Profiles:
-
- TwoOrgsOrdererGenesis:
- <<: *ChannelDefaults
- Orderer:
- <<: *OrdererDefaults
- Organizations:
- - *OrdererOrg
- Capabilities:
- <<: *OrdererCapabilities
- Consortiums:
- SampleConsortium:
- Organizations:
- - *Org1
- - *Org2
- TwoOrgsChannel:
- Consortium: SampleConsortium
- <<: *ChannelDefaults
- Application:
- <<: *ApplicationDefaults
- Organizations:
- - *Org1
- - *Org2
- Capabilities:
- <<: *ApplicationCapabilities
- root@order:~/hyperledger/multinodes# configtxgen -profile TwoOrgsOrdererGenesis -channelID fabric-channel -outputBlock ./channel-artifacts/genesis.block
- 2021-11-04 10:40:27.919 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
- 2021-11-04 10:40:27.925 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
- 2021-11-04 10:40:27.925 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: configtx.yaml
- 2021-11-04 10:40:27.927 CST [common.tools.configtxgen] doOutputBlock -> INFO 004 Generating genesis block
- 2021-11-04 10:40:27.927 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Creating system channel genesis block
- 2021-11-04 10:40:27.927 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
- root@order:~/hyperledger/multinodes# configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
- 2021-11-04 10:40:31.528 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
- 2021-11-04 10:40:31.533 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
- 2021-11-04 10:40:31.533 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
- 2021-11-04 10:40:31.535 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx
- root@order:~/hyperledger/multinodes# configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
- 2021-11-04 10:40:35.494 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
- 2021-11-04 10:40:35.499 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
- 2021-11-04 10:40:35.499 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
- 2021-11-04 10:40:35.500 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update
- root@order:~/hyperledger/multinodes# configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
- 2021-11-04 10:40:38.888 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
- 2021-11-04 10:40:38.893 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
- 2021-11-04 10:40:38.893 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
- 2021-11-04 10:40:38.894 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update
- root@order:~/hyperledger/multinodes# scp -r ./channel-artifacts root@10.10.10.64:/home/bering/projec/hyperledger/multinodes/
- root@order:~/hyperledger/multinodes# scp -r ./channel-artifacts root@10.10.10.53:/home/bering/projec/hyperledger/multinodes/
- root@order:~/hyperledger/multinodes# vim docker-compose.yaml
- version: '2'
-
- services:
- orderer.example.com:
- container_name: orderer.example.com
- image: hyperledger/fabric-orderer:2.2
- environment:
- - FABRIC_LOGGING_SPEC=INFO
- - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- - ORDERER_GENERAL_LISTENPORT=7050
- - ORDERER_GENERAL_GENESISMETHOD=file
- - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
- - 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_KAFKA_TOPIC_REPLICATIONFACTOR=1
- - ORDERER_KAFKA_VERBOSE=true
- - 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/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
- - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
- ports:
- - 7050:7050
- extra_hosts:
- - "orderer.example.com:10.10.10.65"
- - "peer0.org1.example.com:10.10.10.64"
- - "peer0.org2.example.com:10.10.10.53"
- root@org1:~/hyperledger/multinodes# vim docker-compose.yaml
- version: '2'
-
- services:
- couchdb0.org1.example.com:
- container_name: couchdb0.org1.example.com
- image: couchdb:3.1
- environment:
- - COUCHDB_USER=admin
- - COUCHDB_PASSWORD=adminpw
- ports:
- - 5984:5984
-
- peer0.org1.example.com:
- container_name: peer0.org1.example.com
- image: hyperledger/fabric-peer:2.2
- environment:
- - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- - CORE_PEER_ID=peer0.org1.example.com
- - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
- - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
- - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
- - CORE_PEER_LOCALMSPID=Org1MSP
- - 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_CHAINCODE_EXECUTETIMEOUT=300s
- - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
- - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0.org1.example.com:5984
- - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin
- - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=adminpw
- depends_on:
- - couchdb0.org1.example.com
-
- working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
- command: peer node start
- volumes:
- - /var/run/:/host/var/run/
- - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
- - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
- ports:
- - 7051:7051
- - 7052:7052
- - 7053:7053
- extra_hosts:
- - "orderer.example.com:10.10.10.65"
- - "peer0.org1.example.com:10.10.10.64"
- - "peer0.org2.example.com:10.10.10.53"
- cli:
- container_name: cli
- image: hyperledger/fabric-tools:2.2
- tty: true
- stdin_open: true
- environment:
- - GOPATH=/opt/gopath
- - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- - FABRIC_LOGGING_SPEC=INFO
- - CORE_PEER_ID=cli
- - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- - CORE_PEER_LOCALMSPID=Org1MSP
- - CORE_PEER_TLS_ENABLED=true
- - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
- - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
- - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
- - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
- working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
- command: /bin/bash
- volumes:
- - /var/run/:/host/var/run/
- - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/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:
- - "orderer.example.com:10.10.10.65"
- - "peer0.org1.example.com:10.10.10.64"
- - "peer0.org2.example.com:10.10.10.53"
- root@org2:~/hyperledger/multinodes# vim docker-compose.yaml
- version: '2'
-
- services:
- couchdb0.org2.example.com:
- container_name: couchdb0.org2.example.com
- image: couchdb:3.1
- environment:
- - COUCHDB_USER=admin
- - COUCHDB_PASSWORD=adminpw
- ports:
- - 5984:5984
-
- peer0.org2.example.com:
- container_name: peer0.org2.example.com
- image: hyperledger/fabric-peer:2.2
- environment:
- - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- - CORE_PEER_ID=peer0.org2.example.com
- - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- - CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:7052
- - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:7051
- - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
- - CORE_PEER_LOCALMSPID=Org2MSP
- - 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_CHAINCODE_EXECUTETIMEOUT=300s
- - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
- - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0.org2.example.com:5984
- - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin
- - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=adminpw
- depends_on:
- - couchdb0.org2.example.com
-
- working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
- command: peer node start
- volumes:
- - /var/run/:/host/var/run/
- - ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
- - ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
- ports:
- - 7051:7051
- - 7052:7052
- - 7053:7053
- extra_hosts:
- - "orderer.example.com:10.10.10.65"
- - "peer0.org1.example.com:10.10.10.64"
- - "peer0.org2.example.com:10.10.10.53"
- cli:
- container_name: cli
- image: hyperledger/fabric-tools:2.2
- tty: true
- stdin_open: true
- environment:
- - GOPATH=/opt/gopath
- - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- - FABRIC_LOGGING_SPEC=INFO
- - CORE_PEER_ID=cli
- - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
- - CORE_PEER_LOCALMSPID=Org2MSP
- - CORE_PEER_TLS_ENABLED=true
- - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
- - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
- - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
- - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
- working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
- command: /bin/bash
- volumes:
- - /var/run/:/host/var/run/
- - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/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:
- - "orderer.example.com:10.10.10.65"
- - "peer0.org1.example.com:10.10.10.64"
- - "peer0.org2.example.com:10.10.10.53"
4、启动
order,org1,org2分别执行
- root@order:~/hyperledger/multinodes# docker-compose up -d
- Creating network "multinodes_default" with the default driver
- Creating orderer.example.com ... done
- root@org1:~/hyperledger/multinodes# docker-compose up -d
- Creating network "multinodes_default" with the default driver
- Creating couchdb0.org1.example.com ... done
- Creating cli ... done
- Creating peer0.org1.example.com ... done
- root@org2:~/hyperledger/multinodes# docker-compose up -d
- Creating network "multinodes_default" with the default driver
- Creating cli ... done
- Creating couchdb0.org2.example.com ... done
- Creating peer0.org2.example.com ... done
org1执行
- root@org1:~/hyperledger/multinodes# docker exec -it cli bash
- bash-5.1# 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/msp/tlscacerts/tlsca.example.com-cert.pem
- 2021-11-04 05:35:20.209 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
- 2021-11-04 05:35:20.243 UTC [cli.common] readBlock -> INFO 002 Received block: 0
- bash-5.1# ls
- channel-artifacts crypto mychannel.block
- bash-5.1# exit
将通道文件 mychannel.block 拷贝到宿主机及其他节点的容器网址
org1执行
- root@org1:~/hyperledger/multinodes# docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block ./
- root@org1:~/hyperledger/multinodes# scp mychannel.block root@10.10.10.53:/home/bering/project/hyperledger/multinodes/
org2执行
root@org2:~/hyperledger/multinodes# docker cp mychannel.block cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/
org1执行
- root@org1:~/hyperledger/multinodes# docker exec -it cli bash
- bash-5.1# peer channel join -b mychannel.block
- 2021-11-04 05:39:36.166 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
- 2021-11-04 05:39:36.292 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
org2执行
- root@org2:~/hyperledger/multinodes# docker exec -it cli bash
- bash-5.1# peer channel join -b mychannel.block
- 2021-11-04 05:39:29.125 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
- 2021-11-04 05:39:29.237 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
org1执行
- bash-5.1# peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
- 2021-11-04 05:39:59.758 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
- 2021-11-04 05:39:59.770 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
org2执行
- bash-5.1# peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
- 2021-11-04 05:40:14.723 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
- 2021-11-04 05:40:14.740 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
order执行
创建目录chaincode/go
/home/bering/project/golandProjects/hyperledger/multinodes/ 下创建 chaincode/go
把/home/bering/project/golandProjects/fabric-samples/chaincode 下的sacc目录移动到 chaincode/go下
org1执行
/home/bering/project/hyperledger/multinodes/ 下创建 chaincode/go
复制sacc到go目录下
org2执行
/home/bering/project/hyperledger/multinodes/ 下创建 chaincode/go
复制sacc到go目录下
org1执行
- root@org1:~/hyperledger/multinodes# docker exec -it cli bash
- bash-5.1# cd /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go/sacc
- bash-5.1# ls
- go.mod go.sum sacc.go sacc_test.go vendor
- bash-5.1# go env -w GOPROXY=https://goproxy.cn,direct
- bash-5.1# go env -w GO111MODULE=auto
- bash-5.1# go mod init
- go: /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go/sacc/go.mod already exists
- bash-5.1# go mod vendor
- go: downloading github.com/hyperledger/fabric-chaincode-go v0.0.0-20190823162523-04390e015b85
- go: downloading github.com/hyperledger/fabric-protos-go v0.0.0-20190821214336-621b908d5022
- go: downloading github.com/golang/protobuf v1.3.2
- go: downloading google.golang.org/grpc v1.23.0
- go: downloading golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
- go: downloading google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55
- go: downloading golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a
- go: downloading golang.org/x/text v0.3.2
org2执行
- root@org2:~/hyperledger/multinodes# docker exec -it cli bash
- bash-5.1# cd /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go/sacc
- bash-5.1# ls
- go.mod go.sum sacc.go sacc_test.go vendor
- bash-5.1# go env -w GOPROXY=https://goproxy.cn,direct
- bash-5.1# go env -w GO111MODULE=auto
- bash-5.1# go mod init
- go: /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go/sacc/go.mod already exists
- bash-5.1# go mod vendor
- go: downloading github.com/hyperledger/fabric-chaincode-go v0.0.0-20190823162523-04390e015b85
- go: downloading github.com/hyperledger/fabric-protos-go v0.0.0-20190821214336-621b908d5022
- go: downloading github.com/golang/protobuf v1.3.2
- go: downloading google.golang.org/grpc v1.23.0
- go: downloading golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
- go: downloading google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55
- go: downloading golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a
- go: downloading golang.org/x/text v0.3.2
仅仅org1执行
- bash-5.1# cd /opt/gopath/src/github.com/hyperledger/fabric/peer
- bash-5.1# peer lifecycle chaincode package sacc.tar.gz \
- --path github.com/hyperledger/fabric-cluster/chaincode/go/sacc/ \
- --label sacc_1
- bash-5.1# ls
- channel-artifacts crypto mychannel.block sacc.tar.gz
org1执行
- root@org1:~/hyperledger/multinodes# docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/sacc.tar.gz ./
- root@org1:~/hyperledger/multinodes# scp sacc.tar.gz root@10.10.10.53:/home/bering/project/hyperledger/multinodes
org2执行
root@org2:~/hyperledger/multinodes# docker cp /home/bering/project/hyperledger/multinodes/sacc.tar.gz cli:/opt/gopath/src/github.com/hyperledger/fabric/peer
org1执行
- root@org1:~/hyperledger/multinodes# docker exec -it cli bash
- bash-5.1# peer lifecycle chaincode install sacc.tar.gz
- 2021-11-04 05:44:44.537 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nGsacc_1:2791ff83074c654ab40b864ba03f6bb2710439d720adc883c26438212de8d259\022\006sacc_1" >
- 2021-11-04 05:44:44.537 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: sacc_1:2791ff83074c654ab40b864ba03f6bb2710439d720adc883c26438212de8d259
org2执行
- root@org2:~/hyperledger/multinodes# docker exec -it cli bash
- bash-5.1# peer lifecycle chaincode install sacc.tar.gz
- 2021-11-04 05:44:36.627 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nGsacc_1:2791ff83074c654ab40b864ba03f6bb2710439d720adc883c26438212de8d259\022\006sacc_1" >
- 2021-11-04 05:44:36.627 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: sacc_1:2791ff83074c654ab40b864ba03f6bb2710439d720adc883c26438212de8d259
org1执行
- bash-5.1# peer lifecycle chaincode approveformyorg --channelID mychannel --name sacc --version 1.0 --init-required --package-id sacc_1:2791ff83074c654ab40b864ba03f6bb2710439d720adc883c26438212de8d259 --sequence 1 --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
- 2021-11-04 05:45:51.128 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
- 2021-11-04 05:45:53.260 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [c2bebc9d5dbbe4b342facd9ae558dec6cc142f373bbf5a08fbf0953e06c2dce4] committed with status (VALID) at peer0.org1.example.com:7051
org2执行
- bash-5.1# peer lifecycle chaincode approveformyorg --channelID mychannel --name sacc --version 1.0 --init-required --package-id sacc_1:2791ff83074c654ab40b864ba03f6bb2710439d720adc883c26438212de8d259 --sequence 1 --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
- 2021-11-04 05:45:46.313 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
- 2021-11-04 05:45:48.447 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [456f2a9b88c235812d679e5a8b79fd2476f0843f51dcb273b239102f649a2c76] committed with status (VALID) at peer0.org2.example.com:7051
org1执行
- bash-5.1# peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name sacc --version 1.0 --init-required --sequence 1 --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 --output json
- {
- "approvals": {
- "Org1MSP": true,
- "Org2MSP": true
- }
- }
org2执行
- bash-5.1# peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name sacc --version 1.0 --init-required --sequence 1 --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 --output json
- {
- "approvals": {
- "Org1MSP": true,
- "Org2MSP": true
- }
- }
仅仅org1执行
- bash-5.1# peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name sacc --version 1.0 --sequence 1 --init-required --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 --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:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
- 2021-11-04 05:46:43.990 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [ac1b9887ed54dda567f54417216b6ac34255fcdccad14ffa8dd4eeb4b78fe781] committed with status (VALID) at peer0.org1.example.com:7051
- 2021-11-04 05:46:44.025 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [ac1b9887ed54dda567f54417216b6ac34255fcdccad14ffa8dd4eeb4b78fe781] committed with status (VALID) at peer0.org2.example.com:7051
仅仅org1执行
- bash-5.1# peer chaincode invoke -o orderer.example.com:7050 --isInit --ordererTLSHostnameOverride orderer.example.com --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 sacc --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:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["a","bb"]}'
- 2021-11-04 05:46:55.388 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
org1和org2都可执行
- bash-5.1# peer chaincode query -C mychannel -n sacc -c '{"Args":["query","a"]}'
- bb
org1和org2都可执行
- bash-5.1# 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 sacc --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:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["set","a","cc"]}'
- 2021-11-04 05:47:25.219 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 payload:"cc"
- bash-5.1# peer chaincode query -C mychannel -n sacc -c '{"Args":["query","a"]}'
- cc
order上执行
- root@order:~/hyperledger/multinodes# mkdir explorer
- root@order:~/hyperledger/multinodes# cd explorer/
- root@order:~/hyperledger/multinodes/explorer# wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/config.json
- root@order:~/hyperledger/multinodes/explorer# wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/connection-profile/test-network.json -P connection-profile
- root@order:~/hyperledger/multinodes/explorer# wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/docker-compose.yaml
- root@order:~/hyperledger/multinodes/explorer# cd ..
- root@order:~/hyperledger/multinodes# cd crypto-config
- root@order:~/hyperledger/multinodes/crypto-config#ls
- ordererOrganizations peerOrganizations
- root@order:~/hyperledger/multinodes/crypto-config#cd ..
- root@order:~/hyperledger/multinodes# cp -r crypto-config explorer/organizations
- root@order:~/hyperledger/multinodes# cd explorer/
- root@order:~/hyperledger/multinodes/explorer# ls organizations/
- ordererOrganizations peerOrganizations
order上执行
- root@order:~/hyperledger/multinodes/explorer# cd connection-profile/
- root@order:~/hyperledger/multinodes/explorer/connection-profile# mv test-network.json org1-network.json
- root@order:~/hyperledger/multinodes/explorer/connection-profile# vim org1-network.json
- root@order:~/hyperledger/multinodes/explorer/connection-profile# sed -i "s/test-network/org1-network/g" org1-network.json
- root@order:~/hyperledger/multinodes/explorer/connection-profile# vim org1-network.json
- {
- "name": "org1-network",
- "version": "1.0.0",
- "client": {
- "tlsEnable": true,
- "adminCredential": {
- "id": "exploreradmin",
- "password": "exploreradminpw"
- },
- "enableAuthentication": true,
- "organization": "Org1MSP",
- "connection": {
- "timeout": {
- "peer": {
- "endorser": "1200"
- },
- "orderer": "1200"
- }
- }
- },
- "channels": {
- "mychannel": {
- "peers": {
- "peer0.org1.example.com": {}
- }
- }
- },
- "organizations": {
- "Org1MSP": {
- "mspid": "Org1MSP",
- "adminPrivateKey": {
- "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk"
- },
- "peers": ["peer0.org1.example.com"],
- "signedCert": {
- "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem"
- }
- }
- },
- "peers": {
- "peer0.org1.example.com": {
- "tlsCACerts": {
- "path": "/tmp/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
- },
- "url": "grpcs://peer0.org1.example.com:7051"
- }
- }
- }
- root@order:~/hyperledger/multinodes/explorer/connection-profile# cp org1-network.json org2-network.json
- root@order:~/hyperledger/multinodes/explorer/connection-profile# sed -i "s/org1/org2/g" org2-network.json
- root@order:~/hyperledger/multinodes/explorer/connection-profile# sed -i "s/Org1/Org2/g" org2-network.json
- root@order:~/hyperledger/multinodes/explorer/connection-profile# sed -i "s/7051/7051/g" org2-network.json
- root@order:~/hyperledger/multinodes/explorer/connection-profile# vim org2-network.json
- {
- "name": "org2-network",
- "version": "1.0.0",
- "client": {
- "tlsEnable": true,
- "adminCredential": {
- "id": "exploreradmin",
- "password": "exploreradminpw"
- },
- "enableAuthentication": true,
- "organization": "Org2MSP",
- "connection": {
- "timeout": {
- "peer": {
- "endorser": "1200"
- },
- "orderer": "1200"
- }
- }
- },
- "channels": {
- "mychannel": {
- "peers": {
- "peer0.org2.example.com": {}
- }
- }
- },
- "organizations": {
- "Org2MSP": {
- "mspid": "Org2MSP",
- "adminPrivateKey": {
- "path": "/tmp/crypto/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/priv_sk"
- },
- "peers": ["peer0.org2.example.com"],
- "signedCert": {
- "path": "/tmp/crypto/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/User1@org2.example.com-cert.pem"
- }
- }
- },
- "peers": {
- "peer0.org2.example.com": {
- "tlsCACerts": {
- "path": "/tmp/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
- },
- "url": "grpcs://peer0.org2.example.com:7051"
- }
- }
- }
- root@order:~/hyperledger/multinodes/explorer/connection-profile# cd ..
- root@order:~/hyperledger/multinodes/explorer# vim config.json
- {
- "network-configs": {
- "org1-network": {
- "name": "org1-network",
- "profile": "./connection-profile/org1-network.json"
- },
- "org2-network": {
- "name": "org2-network",
- "profile": "./connection-profile/org2-network.json"
- }
- },
- "license": "Apache-2.0"
- }
order上执行
- root@order:~/hyperledger/multinodes/explorer# vim docker-compose.yaml
- # SPDX-License-Identifier: Apache-2.0
- version: '2.1'
-
- volumes:
- pgdata:
- walletstore:
-
- networks:
- mynetwork.com:
- external:
- name: twonodes_test
-
- services:
-
- explorerdb.mynetwork.com:
- image: hyperledger/explorer-db:latest
- container_name: explorerdb.mynetwork.com
- hostname: explorerdb.mynetwork.com
- environment:
- - DATABASE_DATABASE=fabricexplorer
- - DATABASE_USERNAME=hppoc
- - DATABASE_PASSWORD=password
- healthcheck:
- test: "pg_isready -h localhost -p 5432 -q -U postgres"
- interval: 30s
- timeout: 10s
- retries: 5
- volumes:
- - pgdata:/var/lib/postgresql/data
- networks:
- - mynetwork.com
-
- explorer.mynetwork.com:
- image: hyperledger/explorer:latest
- container_name: explorer.mynetwork.com
- hostname: explorer.mynetwork.com
- environment:
- - DATABASE_HOST=explorerdb.mynetwork.com
- - DATABASE_DATABASE=fabricexplorer
- - DATABASE_USERNAME=hppoc
- - DATABASE_PASSWD=password
- - LOG_LEVEL_APP=debug
- - LOG_LEVEL_DB=debug
- - LOG_LEVEL_CONSOLE=debug
- - LOG_CONSOLE_STDOUT=true
- - DISCOVERY_AS_LOCALHOST=false
- volumes:
- - ./config.json:/opt/explorer/app/platform/fabric/config.json
- - ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile
- - ./organizations:/tmp/crypto
- - walletstore:/opt/explorer/wallet
- ports:
- - 8080:8080
- depends_on:
- explorerdb.mynetwork.com:
- condition: service_healthy
- networks:
- - mynetwork.com
- extra_hosts:
- - "orderer.example.com:10.10.10.65"
- - "peer0.org1.example.com:10.10.10.64"
- - "peer0.org2.example.com:10.10.10.53"
- root@order:~/hyperledger/multinodes/explorer# docker-compose up -d
- Creating network "explorer_default" with the default driver
- Creating volume "explorer_pgdata" with default driver
- Creating volume "explorer_walletstore" with default driver
- Creating explorerdb.mynetwork.com ... done
- Creating explorer.mynetwork.com ... done
- root@order:~/hyperledger/multinodes/explorer# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- d21e179e2060 hyperledger/explorer:latest "docker-entrypoint.s…" 6 seconds ago Up 5 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp explorer.mynetwork.com
- 831395f70c85 hyperledger/explorer-db:latest "docker-entrypoint.s…" 37 seconds ago Up 36 seconds (healthy) 5432/tcp explorerdb.mynetwork.com
- 69ab158d8d67 dev-peer0.org1.example.com-sacc_1-2791ff83074c654ab40b864ba03f6bb2710439d720adc883c26438212de8d259-8784c8728adbd8a126fe5163d5cae63d43ee9085043dddaa179d6f74edaf2d12 "chaincode -peer.add…" 18 minutes ago Up 18 minutes dev-peer0.org1.example.com-sacc_1-2791ff83074c654ab40b864ba03f6bb2710439d720adc883c26438212de8d259
- 84e8e0d3fe09 hyperledger/fabric-peer:2.3 "peer node start" 48 minutes ago Up 18 minutes 0.0.0.0:7051-7053->7051-7053/tcp, :::7051-7053->7051-7053/tcp peer0.org1.example.com
- 57cfe35e69a6 hyperledger/fabric-tools:2.2 "/bin/bash" 49 minutes ago Up 18 minutes cli
- 421b25e99adf couchdb:3.1 "tini -- /docker-ent…" 49 minutes ago Up 18 minutes 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp, :::5984->5984/tcp couchdb0.org1.example.com
2021-07-08T08:08:14.461Z - error: [DiscoveryService]: send[mychannel] - Channel:mychannel received discovery error:access denied
explorer.mynetwork.com | [2021-07-08T08:08:14.461] [ERROR] FabricClient - Error: DiscoveryService: mychannel error: access denied
explorer.mynetwork.com | at DiscoveryService.send (/opt/explorer/node_modules/fabric-common/lib/DiscoveryService.js:363:11)
explorer.mynetwork.com | at processTicksAndRejections (internal/process/task_queues.js:97:5)
explorer.mynetwork.com | at async NetworkImpl._initializeInternalChannel (/opt/explorer/node_modules/fabric-network/lib/network.js:279:13)
explorer.mynetwork.com | at async NetworkImpl._initialize (/opt/explorer/node_modules/fabric-network/lib/network.js:231:9)
explorer.mynetwork.com | at async Gateway.getNetwork (/opt/explorer/node_modules/fabric-network/lib/gateway.js:330:9)
解决1:
接入被拒绝了,明显是鉴权问题
排查
既然是explorer报的鉴权问题,那fabric这边应该会有日志打印,docker logs peer0.org1.example.com查看org1.peer0的日志(因为explorer这边鉴权用的就是org1的身份信息),果然其中有错,蓝色的一片INFO日志中赫然几条黄色的WARN在列:
- 2021-07-08 07:34:53.173 UTC [policies] SignatureSetToValidIdentities -> WARN 048 invalid identity: certificate subject=CN=org1admin,OU=admin,O=Hyperledger,ST=North Carolina,C=US serialnumber=406667895762504197446585402379494299487974961868 error="the supplied identity is not valid: x509: certificate signed by unknown authority (possibly because of \"x509: ECDSA verification failure\" while trying to verify candidate authority certificate \"ca.org1.example.com\")"
- 2021-07-08 07:34:53.185 UTC [policies] SignatureSetToValidIdentities -> WARN 049 invalid identity: certificate subject=CN=org1admin,OU=admin,O=Hyperledger,ST=North Carolina,C=US serialnumber=406667895762504197446585402379494299487974961868 error="the supplied identity is not valid: x509: certificate signed by unknown authority (possibly because of \"x509: ECDSA verification failure\" while trying to verify candidate authority certificate \"ca.org1.example.com\")"
- 2021-07-08 07:34:53.185 UTC [discovery] processQuery -> WARN 04a got query for channel mychannel from 172.21.0.10:54952 but it isn't eligible: implicit policy evaluation failed - 0 sub-policies were satisfied, but this policy requires 1 of the 'Writers' sub-policies to be satisfied
- 2021-07-08 07:34:53.185 UTC [discovery] processQuery -> WARN 04b got query for channel mychannel from 172.21.0.10:54952 but it isn't eligible: implicit policy evaluation failed - 0 sub-policies were satisfied, but this policy requires 1 of the 'Writers' sub-policies to be satisfied
通过日志信息可以知晓,确实是证书验证失败了,无论失败的原因为何,目前的基本猜想还是explorer所用证书与fabric本身生成的证书不一致。因为启动过两次第二次启动时没有清除第一次的证书。
马上执行docker volume ls查看,果然是有wallet残留:
- local explorer_pgdata
- local explorer_walletstore
清除volume
$ docker-compose down -v
执行命令删除残留的volume:
- docker volume rm explorer_pgdata
- docker volume rm explorer_walletstore
重新启动一切恢复正常。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。