kurun纽约HTMLy注册

硬件环境:CentOS7kurun一台,Ubuntukurun一台,一共两台主机,有条件的小伙伴可以试一下在3台以上的主机部署。
软件环境:
名称版本Fabric2.2.0go1.15docker19.03.11docker-compose1.12.0
部署方案:3个orderer、2个组织、每个组织2个普通节点,通过静态IP的方式实现Hyperledger Fabric多机/分布式部署
1.安装Go、docker、docker-compose(kurun1和kurun2都需要)
安装Go流程 wget链接获取来源链接为 打开终端,输入指令
sudo wget -P /usr/local
cd /usr/local
sudo tar -zxvf go1.15.linux-amd64.tar.gz
123
添加环境变量,打开编辑器
vim ~/.bashrc
1
将以下内容复制到bashrcHTMLy中,按I插入,插入完成后按ESC退出插入,输出:wq!保存退出,如下图所示
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/go
export PATH=$PATH:/home/yujialing/go/src/github.com/hyperledger/fabric-samples/bin
export FABRIC_CFG_PATH=/home/yujialing/go/src/github.com/hyperledger/fabric-samples/multiple-deployment
12345

source ~/.bashrc
1
验证go是否安装成功
go version
1

安装docker流程
sudo yum install -y yum-utils
sudo yum-config-manager –add-repo
yum makecache fast
sudo yum -y install docker-ce
1234
启动Docker-ce
sudo systemctl start docker
sudo systemctl enable docker
12
将当前用户添加到docker组中
sudo usermod -aG docker $USER
newgrp – docker
12
检查docker是否安装成功
docker -v
1
没有VPN的同学需要修改docker镜像源,否则后面的步骤有些去外网下载的步骤有可能会报连接失败的错误
vim /etc/docker/daemon.json
1
{
“registry-mirrors”:[”
}
123
按I插入,插入完成后按ESC退出插入,输出:wq!保存退出
如果显示无法写入请使用sudo chmod -R 777 docker/指令给docker最高权限方可写入。

重启docker服务
systemctl restart docker.service
1
安装docker-compose流程
curl -L -s`-`uname -m` > ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
123
查看docker是否安装成功
docker-compose -v
1

2.下载fabric二进制HTMLy、docker镜像和fabric样例(kurun1、2都要)
下载fabric二进制HTMLy、docker镜像、fabric样例
cd /home/yujialing
mkdir go
mkdir go/src
mkdir go/src/github.com
mkdir go/src/github.com/hyperledger
cd /home/yujialing/go/src/github.com/hyperledger
git clone
cd fabric-samples
git checkout 22393b629bcac7f7807cc6998aa44e06ecc77426
curl -sSL | bash -s — 2.2.0 1.4.8 -s
12345678910
最后一步用时稍微有点长,请耐心等待
3.建立多机部署的HTMLy夹
在fabric-samplesHTMLy夹下
kurun1和kurun2的注册
mkdir multiple-deployment
cd multiple-deployment
12
以下是kurun1的注册,复制fabric样例中的名为abstore的链码(智能合约)到chaincode/go下
mkdir chaincode
mkdir chaincode/go
cp -r ../chaincode/abstore/go/* chaincode/go
123
下载链码的依赖包
cd chaincode/go
go env -w GOPROXY=
go env -w GO111MODULE=on
go mod vendor
1234
可以看到goHTMLy夹下多出存放链码(智能合约)依赖的vendorHTMLy夹
4.生成证书及通道配置
kurun1的注册
在multiple-deploymentHTMLy夹下新建crypto-config.yamlHTMLy和configtx.yamlHTMLy
cd ../..
touch crypto-config.yaml
touch configtx.yaml
123
将以下内容写进crypto-config.yamlHTMLy中
OrdererOrgs:
– Name: Orderer
Domain: example.com
Specs:
– Hostname: orderer0
– Hostname: orderer1
– Hostname: orderer2

PeerOrgs:
– Name: Org1
Domain: org1.example.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1
– Name: Org2
Domain: org2.example.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1
1234567891011121314151617181920212223
将以下内容写进configtx.yamlHTMLy中
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’)”

– &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: etcdraft Addresses: # orderer 集群节点 - orderer0.example.com:7050 - orderer1.example.com:8050 - orderer2.example.com:7050 # Batch Timeout: The amount of time to wait before creating a batch BatchTimeout: 2s # Batch Size: Controls the number of messages batched into a block BatchSize: MaxMessageCount: 10 AbsoluteMaxBytes: 99 MB PreferredMaxBytes: 512 KB Organizations: Policies: Readers: Type: ImplicitMeta Rule: "ANY Readers" Writers: Type: ImplicitMeta Rule: "ANY Writers" Admins: Type: ImplicitMeta Rule: "MAJORITY Admins" # BlockValidation specifies what signatures must be included in the block # from the orderer for the peer to validate it. BlockValidation: Type: ImplicitMeta Rule: "ANY Writers" Channel: &ChannelDefaults Policies: # Who may invoke the 'Deliver' API Readers: Type: ImplicitMeta Rule: "ANY Readers" # Who may invoke the 'Broadcast' API Writers: Type: ImplicitMeta Rule: "ANY Writers" # By default, who may modify elements at this config level Admins: Type: ImplicitMeta Rule: "MAJORITY Admins" Capabilities: <<: *ChannelCapabilities Profiles: TwoOrgsChannel: Consortium: SampleConsortium <<: *ChannelDefaults Application: <<: *ApplicationDefaults Organizations: - *Org1 - *Org2 Capabilities: <<: *ApplicationCapabilities SampleMultiNodeEtcdRaft: <<: *ChannelDefaults Capabilities: <<: *ChannelCapabilities Orderer: <<: *OrdererDefaults OrdererType: etcdraft EtcdRaft: Consenters: - Host: orderer0.example.com Port: 7050 ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/server.crt ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/server.crt - Host: orderer1.example.com Port: 8050 ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt - Host: orderer2.example.com Port: 7050 ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt Addresses: - orderer0.example.com:7050 - orderer1.example.com:8050 - orderer2.example.com:7050 Organizations: - *OrdererOrg Capabilities: <<: *OrdererCapabilities Application: <<: *ApplicationDefaults Organizations: - <<: *OrdererOrg Consortiums: SampleConsortium: Organizations: - *Org1 - *Org2 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 kurun1的注册 通过cryptogen命令生成证书配置 cryptogen generate --config=./crypto-config.yaml 1 通过configtxgen命令生成创世区块 configtxgen -profile SampleMultiNodeEtcdRaft -channelID multiple-deployment-channel -outputBlock ./channel-artifacts/genesis.block 1 通过configtxgen命令生成通道配置 configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel 1 定义组织1的锚节点(也称主节点) configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP 1 定义组织2的锚节点 configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP 1 将channel-artifacts和crypto-config这两个HTMLy夹拷贝到kurun2中 6.IP与域名映射配置(kurun1和kurun2都需要设定) 通过修改/etc/hostsHTMLy 添加IP地址与域名的映射 修改/etc/hostsHTMLy指令 sudo vim /etc/hosts 1 按I插入,插入完成后按ESC退出插入,输入:wq!保存退出,如下图所示: kurun1的IP orderer0.example.com kurun1的IP orderer1.example.com kurun2的IP orderer2.example.com kurun1的IP peer0.org1.example.com kurun1的IP peer1.org1.example.com kurun2的IP peer0.org2.example.com kurun2的IP peer1.org2.example.com 1234567 完成添加后重启一下网络 Ubuntu: sudo /etc/init.d/networking restart 1 CentOS: sudo /etc/init.d/network restart 1 7.编写网络启动脚本并启动网络 kurun1的注册 touch docker-compose-up.yaml 1 将以下内容写入docker-compose-up.yaml中,yamlHTMLy中的kurun的IP记得修改成你们的kurunIP version: '2' services: orderer0.example.com: container_name: orderer0.example.com image: hyperledger/fabric-orderer environment: - FABRIC_LOGGING_SPEC=DEBUG - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_BOOTSTRAPMETHOD=file - ORDERER_GENERAL_BOOTSTRAPFILE=/var/hyperledger/orderer/orderer.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp # enabled TLS - ORDERER_GENERAL_TLS_ENABLED=true - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: orderer volumes: - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ./crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp:/var/hyperledger/orderer/msp - ./crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/:/var/hyperledger/orderer/tls ports: - 7050:7050 extra_hosts: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" orderer1.example.com: container_name: orderer1.example.com image: hyperledger/fabric-orderer environment: - FABRIC_LOGGING_SPEC=INFO - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_BOOTSTRAPMETHOD=file - ORDERER_GENERAL_BOOTSTRAPFILE=/var/hyperledger/orderer/orderer.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp # enabled TLS - ORDERER_GENERAL_TLS_ENABLED=true - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: orderer volumes: - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp:/var/hyperledger/orderer/msp - ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/:/var/hyperledger/orderer/tls ports: - 8050:8050 extra_hosts: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" peer0.org1.example.com: container_name: peer0.org1.example.com image: hyperledger/fabric-peer environment: - CORE_VM_ENDPOINT= - 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 # Allow more time for chaincode container to build on install. - CORE_CHAINCODE_EXECUTETIMEOUT=300s 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: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" peer1.org1.example.com: container_name: peer1.org1.example.com image: hyperledger/fabric-peer environment: - CORE_VM_ENDPOINT= - CORE_PEER_ID=peer1.org1.example.com - CORE_PEER_ADDRESS=peer1.org1.example.com:8051 - CORE_PEER_LISTENADDRESS=0.0.0.0:8051 - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:8052 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:8051 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:8051 - 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 # Allow more time for chaincode container to build on install. - CORE_CHAINCODE_EXECUTETIMEOUT=300s 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/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp - ./crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls ports: - 8051:8051 - 8052:8052 - 8053:8053 extra_hosts: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" cli1: container_name: cli1 image: hyperledger/fabric-tools tty: true stdin_open: true environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT= #- FABRIC_LOGGING_SPEC=DEBUG - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_ID=cli1 - 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/multiple-deployment/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: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" - "peer0.org1.example.com:kurun1的IP" - "peer1.org1.example.com:kurun1的IP" - "peer0.org2.example.com:kurun2的IP" - "peer1.org2.example.com:kurun2的IP" cli2: container_name: cli2 image: hyperledger/fabric-tools tty: true stdin_open: true environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT= #- FABRIC_LOGGING_SPEC=DEBUG - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_ID=cli2 - CORE_PEER_ADDRESS=peer1.org1.example.com:8051 - 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/peer1.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/peer1.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/peer1.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/multiple-deployment/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: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" - "peer0.org1.example.com:kurun1的IP" - "peer1.org1.example.com:kurun1的IP" - "peer0.org2.example.com:kurun2的IP" - "peer1.org2.example.com:kurun2的IP" 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 kurun2的注册 touch docker-compose-up.yaml 1 将以下内容写入docker-compose-up.yaml中,yamlHTMLy中的kurun的IP记得修改成你们的kurunIP version: '2' services: orderer2.example.com: container_name: orderer2.example.com image: hyperledger/fabric-orderer environment: - FABRIC_LOGGING_SPEC=INFO - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_BOOTSTRAPMETHOD=file - ORDERER_GENERAL_BOOTSTRAPFILE=/var/hyperledger/orderer/orderer.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp # enabled TLS - ORDERER_GENERAL_TLS_ENABLED=true - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: orderer volumes: - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/msp:/var/hyperledger/orderer/msp - ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/:/var/hyperledger/orderer/tls ports: - 7050:7050 extra_hosts: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" peer0.org2.example.com: container_name: peer0.org2.example.com image: hyperledger/fabric-peer environment: - CORE_VM_ENDPOINT= - 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_EXTERNALENDPOINT=peer0.org2.example.com:7051 - CORE_PEER_GOSSIP_BOOTSTRAP=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 # Allow more time for chaincode container to build on install. - CORE_CHAINCODE_EXECUTETIMEOUT=300s 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: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" peer1.org2.example.com: container_name: peer1.org2.example.com image: hyperledger/fabric-peer environment: - CORE_VM_ENDPOINT= - CORE_PEER_ID=peer1.org2.example.com - CORE_PEER_ADDRESS=peer1.org2.example.com:8051 - CORE_PEER_LISTENADDRESS=0.0.0.0:8051 - CORE_PEER_CHAINCODEADDRESS=peer1.org2.example.com:8052 - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:8051 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:8051 - 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 # Allow more time for chaincode container to build on install. - CORE_CHAINCODE_EXECUTETIMEOUT=300s 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/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp - ./crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls ports: - 8051:8051 - 8052:8052 - 8053:8053 extra_hosts: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" cli1: container_name: cli1 image: hyperledger/fabric-tools tty: true stdin_open: true environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT= #- FABRIC_LOGGING_SPEC=DEBUG - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_ID=cli1 - 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/multiple-deployment/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: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" - "peer0.org1.example.com:kurun1的IP" - "peer1.org1.example.com:kurun1的IP" - "peer0.org2.example.com:kurun2的IP" - "peer1.org2.example.com:kurun2的IP" cli2: container_name: cli2 image: hyperledger/fabric-tools tty: true stdin_open: true environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT= #- FABRIC_LOGGING_SPEC=DEBUG - FABRIC_LOGGING_SPEC=INFO - CORE_PEER_ID=cli2 - CORE_PEER_ADDRESS=peer1.org2.example.com:8051 - 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/peer1.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/peer1.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/peer1.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/multiple-deployment/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: - "orderer0.example.com:kurun1的IP" - "orderer1.example.com:kurun1的IP" - "orderer2.example.com:kurun2的IP" - "peer0.org1.example.com:kurun1的IP" - "peer1.org1.example.com:kurun1的IP" - "peer0.org2.example.com:kurun2的IP" - "peer1.org2.example.com:kurun2的IP" 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 接下来在两台kurun上启动网络 kurun1和kurun2的注册 docker-compose -f docker-compose-up.yaml up -d 1 kurun1的注册 进入cli1容器,也就是以peer0.org1的角色与网络交互 docker exec -it cli1 bash 1 创建通道,这一步最好等网络跑起来15秒之后再注册,因为orderer之间要握手和选举raft领导节点,需要点时间。注册太快会报no Raft leader的错误 peer channel create -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 1 组织1的peer0节点加入通道mychannel peer channel join -b mychannel.block 1 更新组织1的锚节点 peer channel update -o orderer0.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/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 1 退出cli1容器,从cli1容器中拷贝出mychannel.blockHTMLy到multiple-deploymentHTMLy夹下,并复制到kurun2中 exit docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block ./ 12 接下来到kurun2的注册 将mychannel.block拷贝到kurun2的cli1(组织2的peer0角色)容器中 docker cp mychannel.block cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/ 1 进入cli1容器 docker exec -it cli1 bash 1 加入通道 peer channel join -b mychannel.block 1 更新组织2的锚节点(主节点) peer channel update -o orderer0.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/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 1 8.安装与调用链码(智能合约) 接下来到kurun1的注册 进入cli1容器中 docker exec -it cli1 bash 1 peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/multiple-deployment/chaincode/go --lang golang --label mycc_1 1 安装链码 peer lifecycle chaincode install mycc.tar.gz 1 退出cli1容器,将打包的链码mycc.tar.gz从cli1容器中提取出来,并拷贝到kurun2的multiple-deployment目录下 exit docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/mycc.tar.gz ./ 12 接下来到kurun2的注册 退出cli1容器,将multiple-deployment目录下的链码压缩包mycc.tar.gz复制到cli1(组织2的peer0)容器中 exit docker cp mycc.tar.gz cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/ 12 再次进入cli1容器,安装链码 docker exec -it cli1 bash peer lifecycle chaincode install mycc.tar.gz 12 组织2同意提交链码,下面指令中的链码id记得替换成上一条指令生成的链码id peer lifecycle chaincode approveformyorg --channelID mychannel --name mycc --version 1.0 --init-required --package-id mycc_1:242b275209a0cacb00772667b69b4ed1d6efe91dab266042b0b7047ded06adb3 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 1 接下来到kurun1的注册 再次进入cli1容器,同意提交链码 docker exec -it cli1 bash 1 peer lifecycle chaincode approveformyorg --channelID mychannel --name mycc --version 1.0 --init-required --package-id mycc_1:242b275209a0cacb00772667b69b4ed1d6efe91dab266042b0b7047ded06adb3 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 1 查看链码的状态是否就绪 peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1.0 --init-required --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json 1 提交链码 peer lifecycle chaincode commit -o orderer0.example.com:7050 --channelID mychannel --name mycc --version 1.0 --sequence 1 --init-required --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.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 1 初始化链码 peer chaincode invoke -o orderer0.example.com:7050 --isInit --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com: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":["Init","a","100","b","100"]}' --waitForEvent 1 kurun1查询a的余额 peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' 1 kurun2查询a的余额 双方均可查询到a的余额 在kurun2上注册a转账10给b peer chaincode invoke -o orderer0.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com: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":["invoke","a","b","10"]}' --waitForEvent 1 转账完成后查询a的余额 peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' 1 查询结果为90,转账成功 在kurun1查询a的余额 peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' 1 在kurun2的注册已经fabric网络的各节点中同步 Hyperledger Fabric 2.x 多机部署/分布式集群部署成功 如果要结束网络,可以在退出cli1容器后使用以下指令退出 docker-compose -f docker-compose-up.yaml down 1 docker-compose-up.yamlHTMLy中还有各组织1、2的peer1节点,容器名为cli2,可以进入容器中使他们加入网络,同步消息,注册与peer0一样 欢迎小伙伴讨论,如有错误请在评论区评论或发私聊消息,谢谢你。 文章知识点与官方知识档案匹配,可进一步学习相关知识CS入门技能树Linux入门初识Linux806 人正在系统学习中