本次多机部署将orderer,peer0.org1,peer0.org2三个节点部署分别部署在一台腾讯云服务器上和两台云服务器上,部署节点如下:
注意在云服务器上部署过程中涉及的相关端口安全组的设置。
节点 | 主机名 |
orderer | VM-8-6-ubuntu |
org1 | hecs-143392 |
org2 | hcss-ecs-88c0 |
部署前的准备
参考Prerequisites — Hyperledger Fabric Docs main documentation进行Docker以及相关的环境部署,Releases · hyperledger/fabric · GitHub 下载v2.5.5的fabric, Releases · hyperledger/fabric-ca · GitHub 下载 v1.5.7 的fabric-ca
将部署fabric, fabric-ca生成的bin文件复制到 /usr/local/中
cp bin/* /usr/local/bin/
通过 vim /etc/hosts 更改每台服务器的网络设置,在该文件后添加:
82.156.214.214 orderer.example.com
124.70.74.28 peer0.org1.example.com
123.60.9.71 peer0.org2.example.com82.156.214.214 ca.orderer.example.com
124.70.74.28 ca.org1.example.com
123.60.9.71 ca.org2.example.com
生成证书(使用FabricCA)
创建项目目录
三台虚拟机项目目录皆为/home/ubuntu/hyperledger/multinodes
(很重要)
在部署生产网络的过程,我们通过部署Fabric CA来颁发用户证书文件。
编写docker-ca.yaml文件
在三台虚拟机的/home/ubuntu/hyperledger/multinodes
目录下都编写docker-ca.yaml文件用于部署环境
vim docker-ca.yaml
orderer
version: '2'
services:
ca_orderer:
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca-orderer
- FABRIC_CA_SERVER_TLS_ENABLED=true
- FABRIC_CA_SERVER_PORT=7054
- FABRIC_CA_SERVER_CSR_CN=ca-orderer
- FABRIC_CA_SERVER_CSR_HOSTS=ca.orderer.example.com
ports:
- "7054:7054"
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
volumes:
- ./fabric-ca/ordererOrg:/etc/hyperledger/fabric-ca-server
container_name: ca_orderer
extra_hosts:
- "ca.orderer.example.com:82.156.214.214"
- "ca.org1.example.com:124.70.74.28"
- "ca.org2.example.com:123.60.9.71"
org1
version: '2'
services:
ca_org1:
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca-org1
- FABRIC_CA_SERVER_TLS_ENABLED=true
- FABRIC_CA_SERVER_PORT=7054
- FABRIC_CA_SERVER_CSR_CN=ca-org1
- FABRIC_CA_SERVER_CSR_HOSTS=ca.org1.example.com
ports:
- "7054:7054"
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
volumes:
- ./fabric-ca/org1:/etc/hyperledger/fabric-ca-server
container_name: ca_org1
extra_hosts:
- "orderer.example.com:82.156.214.214"
- "ca.org1.example.com:124.70.74.28"
- "ca.org2.example.com:123.60.9.71"
org2
version: '2'
services:
ca_org2:
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca-org2
- FABRIC_CA_SERVER_TLS_ENABLED=true
- FABRIC_CA_SERVER_PORT=7054
- FABRIC_CA_SERVER_CSR_CN=ca-org2
- FABRIC_CA_SERVER_CSR_HOSTS=ca.org2.example.com
ports:
- "7054:7054"
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
volumes:
- ./fabric-ca/org2:/etc/hyperledger/fabric-ca-server
container_name: ca_org2
extra_hosts:
- "ca.orderer.example.com:82.156.214.214"
- "ca.org1.example.com:124.70.74.28"
- "ca.org2.example.com:123.60.9.71"
运行docker-ca.yaml文件
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# vim docker-ca.yaml
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# docker-compose -f docker-ca.yaml up
Creating ca_org1 ... done
root@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# vim docker-ca.yaml
root@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# docker-compose -f docker-ca.yaml up
Creating network "multinodes_default" with the default driver
Creating ca_org2 ... done
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ vim docker-ca.yaml
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ docker-compose -f docker-ca.yaml up
Creating ca_orderer ... done
root@hecs-143392:~# cd /home/ubuntu/hyperledger/multinodes/
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# ls
docker-ca.yaml fabric-ca
root@hcss-ecs-88c0:~# cd /home/ubuntu/hyperledger/multinodes/
root@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# ls
docker-ca.yaml fabric-ca
ubuntu@VM-8-6-ubuntu:~$ cd hyperledger/multinodes/
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ ls
docker-ca.yaml fabric-ca
将每台虚拟机生成的fabric-ca的文件分别都部署到其他两台虚拟机中,即fabric-ca 文件夹可以找到org1,org2,orderer这三个文件夹,在三台/home/ubuntu/hyperledger/multinodes文件夹下再创建一个organizations文件夹,并将每虚拟机上的fabric-ca文件夹移入该organizations文件夹中文件夹结构如下所示
编写在上图所示文件夹路径/home/ubuntu/hyperledger/multinodes/organizations/fabric-ca
下编写registerEnroll.sh脚本文件来生成证书
vim registerEnroll.sh
chmod u+x registerEnroll.sh
#!/bin/bash
function createOrg1 {echo
echo "Enroll the CA admin"
echo
mkdir -p organizations/peerOrganizations/org1.example.com/export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org1.example.com/
# rm -rf $FABRIC_CA_CLIENT_HOME/fabric-ca-client-config.yaml
# rm -rf $FABRIC_CA_CLIENT_HOME/mspset -x
fabric-ca-client enroll -u https://admin:adminpw@ca.org1.example.com:7054 --caname ca-org1 --tls.certfiles ${PWD}/org1/tls-cert.pem
set +xecho 'NodeOUs:
Enable: true
ClientOUIdentifier:
Certificate: cacerts/ca-org1-example-com-7054-ca-org1.pem
OrganizationalUnitIdentifier: client
PeerOUIdentifier:
Certificate: cacerts/ca-org1-example-com-7054-ca-org1.pem
OrganizationalUnitIdentifier: peer
AdminOUIdentifier:
Certificate: cacerts/ca-org1-example-com-7054-ca-org1.pem
OrganizationalUnitIdentifier: admin
OrdererOUIdentifier:
Certificate: cacerts/ca-org1-example-com-7054-ca-org1.pem
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yamlecho
echo "Register peer0"
echo
set -x
fabric-ca-client register --caname ca-org1 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/org1/tls-cert.pem
set +xecho
echo "Register user"
echo
set -x
fabric-ca-client register --caname ca-org1 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/org1/tls-cert.pem
set +xecho
echo "Register the org admin"
echo
set -x
fabric-ca-client register --caname ca-org1 --id.name org1admin --id.secret org1adminpw --id.type admin --tls.certfiles ${PWD}/org1/tls-cert.pem
set +xmkdir -p organizations/peerOrganizations/org1.example.com/peers
mkdir -p organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.comecho
echo "## Generate the peer0 msp"
echo
set -x
fabric-ca-client enroll -u https://peer0:peer0pw@ca.org1.example.com:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp --csr.hosts peer0.org1.example.com --tls.certfiles ${PWD}/org1/tls-cert.pem
set +xcp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/config.yaml
echo
echo "## Generate the peer0-tls certificates"
echo
set -x
fabric-ca-client enroll -u https://peer0:peer0pw@ca.org1.example.com:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls --enrollment.profile tls --csr.hosts peer0.org1.example.com --csr.hosts 124.70.74.28 --tls.certfiles ${PWD}/org1/tls-cert.pem
set +x
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/signcerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/keystore/* ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.keymkdir -p ${PWD}/organizations/peerOrganizations/org1.example.com/msp/tlscacerts
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/msp/tlscacerts/ca.crtmkdir -p ${PWD}/organizations/peerOrganizations/org1.example.com/tlsca
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pemmkdir -p ${PWD}/organizations/peerOrganizations/org1.example.com/ca
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/cacerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pemmkdir -p organizations/peerOrganizations/org1.example.com/users
mkdir -p organizations/peerOrganizations/org1.example.com/users/User1@org1.example.comecho
echo "## Generate the user msp"
echo
set -x
fabric-ca-client enroll -u https://user1:user1pw@ca.org1.example.com:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp --tls.certfiles ${PWD}/org1/tls-cert.pem
set +xcp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/config.yaml
mkdir -p organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com
echo
echo "## Generate the org admin msp"
echo
set -x
fabric-ca-client enroll -u https://org1admin:org1adminpw@ca.org1.example.com:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp --tls.certfiles ${PWD}/org1/tls-cert.pem
set +xcp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml
}
function createOrg2 {echo
echo "Enroll the CA admin"
echo
mkdir -p organizations/peerOrganizations/org2.example.com/export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org2.example.com/
# rm -rf $FABRIC_CA_CLIENT_HOME/fabric-ca-client-config.yaml
# rm -rf $FABRIC_CA_CLIENT_HOME/mspset -x
fabric-ca-client enroll -u https://admin:adminpw@ca.org2.example.com:7054 --caname ca-org2 --tls.certfiles ${PWD}/org2/tls-cert.pem
set +xecho 'NodeOUs:
Enable: true
ClientOUIdentifier:
Certificate: cacerts/ca-org2-example-com-7054-ca-org2.pem
OrganizationalUnitIdentifier: client
PeerOUIdentifier:
Certificate: cacerts/ca-org2-example-com-7054-ca-org2.pem
OrganizationalUnitIdentifier: peer
AdminOUIdentifier:
Certificate: cacerts/ca-org2-example-com-7054-ca-org2.pem
OrganizationalUnitIdentifier: admin
OrdererOUIdentifier:
Certificate: cacerts/ca-org2-example-com-7054-ca-org2.pem
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yamlecho
echo "Register peer0"
echo
set -x
fabric-ca-client register --caname ca-org2 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/org2/tls-cert.pem
set +xecho
echo "Register user"
echo
set -x
fabric-ca-client register --caname ca-org2 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/org2/tls-cert.pem
set +xecho
echo "Register the org admin"
echo
set -x
fabric-ca-client register --caname ca-org2 --id.name org2admin --id.secret org2adminpw --id.type admin --tls.certfiles ${PWD}/org2/tls-cert.pem
set +xmkdir -p organizations/peerOrganizations/org2.example.com/peers
mkdir -p organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.comecho
echo "## Generate the peer0 msp"
echo
set -x
fabric-ca-client enroll -u https://peer0:peer0pw@ca.org2.example.com:7054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp --csr.hosts peer0.org2.example.com --tls.certfiles ${PWD}/org2/tls-cert.pem
set +xcp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/config.yaml
echo
echo "## Generate the peer0-tls certificates"
echo
set -x
fabric-ca-client enroll -u https://peer0:peer0pw@ca.org2.example.com:7054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls --enrollment.profile tls --csr.hosts peer0.org2.example.com --csr.hosts 123.60.9.71 --tls.certfiles ${PWD}/org2/tls-cert.pem
set +x
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/signcerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/keystore/* ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.keymkdir -p ${PWD}/organizations/peerOrganizations/org2.example.com/msp/tlscacerts
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/msp/tlscacerts/ca.crtmkdir -p ${PWD}/organizations/peerOrganizations/org2.example.com/tlsca
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pemmkdir -p ${PWD}/organizations/peerOrganizations/org2.example.com/ca
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/cacerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/ca/ca.org2.example.com-cert.pemmkdir -p organizations/peerOrganizations/org2.example.com/users
mkdir -p organizations/peerOrganizations/org2.example.com/users/User1@org2.example.comecho
echo "## Generate the user msp"
echo
set -x
fabric-ca-client enroll -u https://user1:user1pw@ca.org2.example.com:7054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp --tls.certfiles ${PWD}/org2/tls-cert.pem
set +xcp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/config.yaml
mkdir -p organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com
echo
echo "## Generate the org admin msp"
echo
set -x
fabric-ca-client enroll -u https://org2admin:org2adminpw@ca.org2.example.com:7054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp --tls.certfiles ${PWD}/org2/tls-cert.pem
set +xcp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/config.yaml
}
function createOrderer {
echo
echo "Enroll the CA admin"
echo
mkdir -p organizations/ordererOrganizations/example.comexport FABRIC_CA_CLIENT_HOME=${PWD}/organizations/ordererOrganizations/example.com
# rm -rf $FABRIC_CA_CLIENT_HOME/fabric-ca-client-config.yaml
# rm -rf $FABRIC_CA_CLIENT_HOME/mspset -x
fabric-ca-client enroll -u https://admin:adminpw@ca.orderer.example.com:7054 --caname ca-orderer --tls.certfiles ${PWD}/ordererOrg/tls-cert.pem
set +xecho 'NodeOUs:
Enable: true
ClientOUIdentifier:
Certificate: cacerts/ca-orderer-example-com-7054-ca-orderer.pem
OrganizationalUnitIdentifier: client
PeerOUIdentifier:
Certificate: cacerts/ca-orderer-example-com-7054-ca-orderer.pem
OrganizationalUnitIdentifier: peer
AdminOUIdentifier:
Certificate: cacerts/ca-orderer-example-com-7054-ca-orderer.pem
OrganizationalUnitIdentifier: admin
OrdererOUIdentifier:
Certificate: cacerts/ca-orderer-example-com-7054-ca-orderer.pem
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml
echo
echo "Register orderer"
echo
set -x
fabric-ca-client register --caname ca-orderer --id.name orderer --id.secret ordererpw --id.type orderer --tls.certfiles ${PWD}/ordererOrg/tls-cert.pem
set +xecho
echo "Register the orderer admin"
echo
set -x
fabric-ca-client register --caname ca-orderer --id.name ordererAdmin --id.secret ordererAdminpw --id.type admin --tls.certfiles ${PWD}/ordererOrg/tls-cert.pem
set +xmkdir -p organizations/ordererOrganizations/example.com/orderers
mkdir -p organizations/ordererOrganizations/example.com/orderers/example.commkdir -p organizations/ordererOrganizations/example.com/orderers/orderer.example.com
echo
echo "## Generate the orderer msp"
echo
set -x
fabric-ca-client enroll -u https://orderer:ordererpw@ca.orderer.example.com:7054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp --csr.hosts orderer.example.com --csr.hosts 82.156.214.214 --tls.certfiles ${PWD}/ordererOrg/tls-cert.pemset +x
cp ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/config.yaml
echo
echo "## Generate the orderer-tls certificates"
echo
set -x
fabric-ca-client enroll -u https://orderer:ordererpw@ca.orderer.example.com:7054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls --enrollment.profile tls --csr.hosts orderer.example.com --csr.hosts 82.156.214.214 --tls.certfiles ${PWD}/ordererOrg/tls-cert.pem
set +xcp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/tlscacerts/* ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
cp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/signcerts/* ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
cp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/keystore/* ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.keymkdir -p ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts
cp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/tlscacerts/* ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
mkdir -p ${PWD}/organizations/ordererOrganizations/example.com/msp/tlscacerts
cp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/tlscacerts/* ${PWD}/organizations/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pemmkdir -p organizations/ordererOrganizations/example.com/users
mkdir -p organizations/ordererOrganizations/example.com/users/Admin@example.comecho
echo "## Generate the admin msp"
echo
set -x
fabric-ca-client enroll -u https://ordererAdmin:ordererAdminpw@ca.orderer.example.com:7054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp --tls.certfiles ${PWD}/ordererOrg/tls-cert.pem
set +xcp ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml ${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp/config.yaml
}
createOrg1
createOrg2
createOrderer
注意其中虚拟机的ip的更改
在其中一台虚拟机上运行脚本
./registerEnroll.sh
将生成文件夹复制到另外两台虚拟机上(注意/home/ubuntu/hyperledger/multinodes/organizations/fabric-ca/organizations/ordererOrganizations/example.com/msp/tlscacerts中若缺少pem文件,可以将/home/ubuntu/hyperledger/multinodes/organizations/fabric-ca/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts 中的pem文件复制到该文件夹下)
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ scp -r ./organizations/fabric-ca/organizations/ordererOrganizations root@123.60.9.71:/home/ubuntu/hyperledger/multinodes/organizations/fabric-ca/organizations/
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ scp -r ./organizations/fabric-ca/organizations/ordererOrganizations root@82.156.214.214:/home/ubuntu/hyperledger/multinodes/organizations/fabric-ca/organizations/
生成通道文件(Orderer节点的虚拟机上运行)
创世块文件的编写
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ vim configtx.yaml
---
Organizations:- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: ./organizations/fabric-ca/organizations/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: ./organizations/fabric-ca/organizations/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: ./organizations/fabric-ca/organizations/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
#Port:9051Capabilities:
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:
<<: *ApplicationCapabilitiesOrderer: &OrdererDefaults
OrdererType: solo
Addresses:
- orderer.example.com:7050EtcdRaft:
Consenters:
- Host: orderer.example.com
Port: 7050
ClientTLSCert: /home/ubuntu/hyperledger/multinodes/organizations/fabric-ca/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls//server.crt
ServerTLSCert: /home/ubuntu/hyperledger/multinodes/organizations/fabric-ca/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crtBatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 512 KBOrganizations:
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: &ChannelDefaultsPolicies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
Capabilities:
<<: *ChannelCapabilitiesProfiles:
TwoOrgsOrdererGenesis:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Capabilities:
<<: *OrdererCapabilities
Consortiums:
SampleConsortium:
Organizations:
- *Org1
- *Org2
TwoOrgsChannel:
Consortium: SampleConsortium
<<: *ChannelDefaults
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
- *Org2
Capabilities:
<<: *ApplicationCapabilities
生成创世块文件和通道文件
生成创世区块和通道文件
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ configtxgen -profile TwoOrgsOrdererGenesis -channelID fabric-channel -outputBlock ./channel-artifacts/genesis.block
2024-04-06 00:15:57.776 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2024-04-06 00:15:57.784 CST 0002 INFO [common.tools.configtxgen.localconfig] completeInitialization -> orderer type: solo
2024-04-06 00:15:57.784 CST 0003 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
2024-04-06 00:15:57.787 CST 0004 INFO [common.tools.configtxgen] doOutputBlock -> Generating genesis block
2024-04-06 00:15:57.787 CST 0005 INFO [common.tools.configtxgen] doOutputBlock -> Creating system channel genesis block
2024-04-06 00:15:57.788 CST 0006 INFO [common.tools.configtxgen] doOutputBlock -> Writing genesis blockubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2024-04-06 00:17:26.984 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2024-04-06 00:17:26.991 CST 0002 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
2024-04-06 00:17:26.991 CST 0003 INFO [common.tools.configtxgen] doOutputChannelCreateTx -> Generating new channel configtx
2024-04-06 00:17:26.995 CST 0004 INFO [common.tools.configtxgen] doOutputChannelCreateTx -> Writing new channel tx
为org1和org2定义锚节点
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2024-04-06 00:20:54.931 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2024-04-06 00:20:54.940 CST 0002 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
2024-04-06 00:20:54.940 CST 0003 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Generating anchor peer update
2024-04-06 00:20:54.943 CST 0004 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Writing anchor peer update
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2024-04-06 00:21:05.633 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2024-04-06 00:21:05.643 CST 0002 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
2024-04-06 00:21:05.643 CST 0003 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Generating anchor peer update
2024-04-06 00:21:05.647 CST 0004 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Writing anchor peer update
将生成的文件拷贝到另外两台主机上
scp -r ./channel-artifacts root@124.70.74.28:/home/ubuntu/hyperledger/multinodes/
scp -r ./channel-artifacts root@123.60.9.71:/home/ubuntu/hyperledger/multinodes/
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# ls
channel-artifacts crypto-config
root@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# ls
channel-artifacts crypto-config
docker-compose 文件的编写
orderer节点
version: '2'
services:
orderer.example.com:
container_name: orderer.example.com
image: hyperledger/fabric-orderer
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
- ./organizations/fabric-ca/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
- ./organizations/fabric-ca/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
ports:
- 7050:7050
extra_hosts:
- "orderer.example.com:82.156.214.214"
- "peer0.org1.example.com:124.70.74.28"
- "peer0.org2.example.com:123.60.9.71"
Org1节点
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:5984peer0.org1.example.com:
container_name: peer0.org1.example.com
image: hyperledger/fabric-peer
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_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp
- 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.comworking_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
volumes:
- /var/run/:/host/var/run/
- ./organizations/fabric-ca/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
- ./organizations/fabric-ca/organizations/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:82.156.214.214"
- "peer0.org1.example.com:124.70.74.28"
- "peer0.org2.example.com:123.60.9.71"
cli:
container_name: cli
image: hyperledger/fabric-tools
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
- ./organizations/fabric-ca/organizations:/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:82.156.214.214"
- "peer0.org1.example.com:124.70.74.28"
- "peer0.org2.example.com:123.60.9.71"
Org2节点
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:5984peer0.org2.example.com:
container_name: peer0.org2.example.com
image: hyperledger/fabric-peer
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_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp
- 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.comworking_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
volumes:
- /var/run/:/host/var/run/
- ./organizations/fabric-ca/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
- ./organizations/fabric-ca/organizations/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:82.156.214.214"
- "peer0.org1.example.com:124.70.74.28"
- "peer0.org2.example.com:123.60.9.71"
cli:
container_name: cli
image: hyperledger/fabric-tools
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
- ./organizations/fabric-ca/organizations:/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:82.156.214.214"
- "peer0.org1.example.com:124.70.74.28"
- "peer0.org2.example.com:123.60.9.71"
启动服务
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ docker-compose up -d
Creating network "multinodes_default" with the default driver
Creating orderer.example.com ... done
ubuntu@VM-8-6-ubuntu:~/hyperledger/multinodes$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1051ae973e0 hyperledger/fabric-orderer "orderer" 8 seconds ago Up 7 seconds 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp orderer.example.comroot@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# docker-compose up -d
Creating network "multinodes_default" with the default driver
Creating couchdb0.org2.example.com ... done
Creating cli ... done
Creating peer0.org2.example.com ... done
root@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc76998643a3 hyperledger/fabric-peer "peer node start" 12 seconds ago Up 11 seconds 0.0.0.0:7051-7053->7051-7053/tcp, :::7051-7053->7051-7053/tcp peer0.org2.example.com
e31e6502c707 couchdb:3.1 "tini -- /docker-ent…" 12 seconds ago Up 12 seconds 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp, :::5984->5984/tcp couchdb0.org2.example.com
1a1e6d13102e hyperledger/fabric-tools "/bin/bash" 12 seconds ago Up 12 seconds cliroot@hecs-143392:/home/ubuntu/hyperledger/multinodes# docker-compose up -d
Creating network "multinodes_default" with the default driver
Creating cli ... done
Creating couchdb0.org1.example.com ... done
Creating peer0.org1.example.com ... done
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a32830323b64 hyperledger/fabric-peer "peer node start" 11 seconds ago Up 9 seconds 0.0.0.0:7051-7053->7051-7053/tcp, :::7051-7053->7051-7053/tcp peer0.org1.example.com
e24652f9504b couchdb:3.1 "tini -- /docker-ent…" 11 seconds ago Up 10 seconds 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp, :::5984->5984/tcp couchdb0.org1.example.com
eac605b80437 hyperledger/fabric-tools "/bin/bash" 11 seconds ago Up 10 seconds cli
通道操作
创建通道
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# docker exec -it cli bash
root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# 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
2024-04-05 16:39:18.291 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2024-04-05 16:39:18.352 UTC 0002 INFO [cli.common] readBlock -> Received block: 0
root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# ls
channel-artifacts crypto mychannel.block
root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# exit
exit
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block ./
Successfully copied 22.5kB to /home/ubuntu/hyperledger/multinodes/./
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# scp mychannel.block root@123.60.9.71:/home/ubuntu/hyperledger/multinodes/
root@123.60.9.71's password:
Permission denied, please try again.
root@123.60.9.71's password:
mychannel.block 100% 20KB 362.3KB/s 00:00root@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# docker cp mychannel.block cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/
Successfully copied 22.5kB to cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/
加入通道
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# docker exec -it cli bash
root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b mychannel.block
2024-04-05 16:44:53.715 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2024-04-05 16:44:53.878 UTC 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channelroot@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# docker exec -it cli bash
root@1a1e6d13102e:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b mychannel.block
2024-04-05 16:45:23.574 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2024-04-05 16:45:23.726 UTC 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
更新锚节点
root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# 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
2024-04-05 16:47:02.193 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2024-04-05 16:47:02.221 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel updateroot@1a1e6d13102e:/opt/gopath/src/github.com/hyperledger/fabric/peer# 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
2024-04-05 16:47:26.539 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2024-04-05 16:47:26.663 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
安装调用智能合约
链码文件放在/home/ubuntu/hyperledger/codechain/sacc/ 中,将链码文件传入 /home/ubuntu/hyperledger/multinodes/chaincode/go,进行智能合约的安装调用,提交链码使注意链码的编号要写下载时的id
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# cp -r /home/ubuntu/hyperledger/codechain/sacc/ /home/ubuntu/hyperledger/multinodes/chaincode/go/
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# cd chaincode/go
root@hecs-143392:/home/ubuntu/hyperledger/multinodes/chaincode/go# ls
saccroot@hecs-143392:/home/ubuntu/hyperledger/multinodes/chaincode/go/sacc# ls
index.js lib node_modules package.json package-lock.json testroot@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer lifecycle chaincode package sacc.tar.gz --path /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go/sacc/ --lang node --label sacc_1
root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# ls
channel-artifacts crypto mychannel.block sacc.tar.gzroot@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# exit
exit
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/sacc.tar.gz ./
Successfully copied 103kB to /home/ubuntu/hyperledger/multinodes/./
root@hecs-143392:/home/ubuntu/hyperledger/multinodes# scp sacc.tar.gz root@123.60.9.71:/home/ubuntu/hyperledger/multinodes/
root@123.60.9.71's password:
sacc.tar.gz 100% 99KB 909.2KB/s 00:00root@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# docker cp /home/ubuntu/hyperledger/multinodes/sacc.tar.gz cli:/opt/gopath/src/github.com/hyperledger/fabric/peer
Successfully copied 103kB to cli:/opt/gopath/src/github.com/hyperledger/fabric/peerroot@hecs-143392:/home/ubuntu/hyperledger/multinodes# docker exec -it cli bash
root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer lifecycle chaincode install sacc.tar.gz
2024-04-05 17:13:30.243 UTC 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nGsacc_1:f8b85cb0fca2b1a9694c9b415fe59a913cd81b1990dcd91153f77c77fa792b08\022\006sacc_1" >
2024-04-05 17:13:30.243 UTC 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: sacc_1:f8b85cb0fca2b1a9694c9b415fe59a913cd81b1990dcd91153f77c77fa792b08root@hcss-ecs-88c0:/home/ubuntu/hyperledger/multinodes# docker exec -it cli bash
root@1a1e6d13102e:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer lifecycle chaincode install sacc.tar.gz
2024-04-05 17:14:09.082 UTC 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nGsacc_1:f8b85cb0fca2b1a9694c9b415fe59a913cd81b1990dcd91153f77c77fa792b08\022\006sacc_1" >
2024-04-05 17:14:09.083 UTC 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: sacc_1:f8b85cb0fca2b1a9694c9b415fe59a913cd81b1990dcd91153f77c77fa792b08root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer lifecycle chaincode approveformyorg --channelID mychannel --name sacc --version 1.0 --init-required --package-id sacc_1:f8b85cb0fca2b1a9694c9b415fe59a913cd81b1990dcd91153f77c77fa792b08 --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
2024-04-05 17:16:08.238 UTC 0001 INFO [cli.lifecycle.chaincode] setOrdererClient -> Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2024-04-05 17:16:10.428 UTC 0002 INFO [chaincodeCmd] ClientWait -> txid [2e15a9773e2931bb0b566d84af8c5751f4545022cbebfd0061715653320b5375] committed with status (VALID) at peer0.org1.example.com:7051root@1a1e6d13102e:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer lifecycle chaincode approveformyorg --channelID mychannel --name sacc --version 1.0 --init-required --package-id sacc_1:f8b85cb0fca2b1a9694c9b415fe59a913cd81b1990dcd91153f77c77fa792b08 --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
2024-04-05 17:16:56.145 UTC 0001 INFO [cli.lifecycle.chaincode] setOrdererClient -> Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2024-04-05 17:16:58.405 UTC 0002 INFO [chaincodeCmd] ClientWait -> txid [fba02dee09dd9c22cdca7d3a5e543f9aecd10785f8869a4ae34168aa185b8479] committed with status (VALID) at peer0.org2.example.com:7051root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# 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
}
}root@1a1e6d13102e:/opt/gopath/src/github.com/hyperledger/fabric/peer# 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
}
}root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# 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
2024-04-05 17:19:01.711 UTC 0001 INFO [chaincodeCmd] ClientWait -> txid [efad8132aee6fdd0a3067954f038dd9cd1cb41e7cedfd82dc6e588267f061351] committed with status (VALID) at peer0.org1.example.com:7051
2024-04-05 17:19:01.721 UTC 0002 INFO [chaincodeCmd] ClientWait -> txid [efad8132aee6fdd0a3067954f038dd9cd1cb41e7cedfd82dc6e588267f061351] committed with status (VALID) at peer0.org2.example.com:7051root@eac605b80437:/opt/gopath/src/github.com/hyperledger/fabric/peer# 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":["Initialize","TokenTime","some symbol","0"]}'