Fabric 1.4.6部署方案
配置CentOS的系统
查看Linux 发行版
cat /etc/*-release
修改为多用户状态
执行:
systemctl set-default multi-user.target
设置yum源并升级系统
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum update
在 CentOS 7.× 上启用 ELRepo 仓库,运行:
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
仓库启用后,使用下面的命令列出可用的系统内核相关包:
yum --disablerepo="*" --enablerepo=“elrepo-kernel” list available
安装最新的主线稳定内核:
yum --enablerepo=elrepo-kernel install kernel-ml
设置启动顺序
grub2-set-default “Linux (5.5.3-1.el7.elrepo.x86_64) 7 (Core)”
grub2-set-default “Linux (5.6.7-1.el7.elrepo.x86_64) 7 (Core)”
grub2-set-default “Linux (3.10.0-1062.9.1.el7.x86_64)”
grub2-editenv list
reboot
创建用户组和用户
/usr/sbin/groupadd fabric
/usr/sbin/groupadd dba
/usr/sbin/useradd -m -g fabric -G dba fabric
passwd fabric
允许fabric用户su –
编辑:
vi /etc/sudoers
添加
fabric ALL=(ALL) NOPASSWD: /bin/su
fabric用户互认
解决Bad owner or permissions on /home/fabric/.ssh/config
chmod 600 /home/fabric/.ssh/config
sshUserSetup.sh
$ ./sshUserSetup.sh -user fabric -hosts “10.11.2.34 10.11.2.35 10.11.2.36 10.11.2.37” -advanced -noPromptPassphrase
修改每台机器的/etc/hosts
10.11.2.34
10.11.2.35
10.11.2.36
10.11.2.37
linux 系统参数调整和网络参数调整
echo “kernel.shmmni = 4096” >> /etc/sysctl.conf
echo “kernel.sem = 250 32000 100 128” >> /etc/sysctl.conf
echo “fs.file-max = 65536” >> /etc/sysctl.conf
echo “net.ipv4.ip_local_port_range = 1024 65000” >> /etc/sysctl.conf
echo “net.core.rmem_default = 262144” >> /etc/sysctl.conf
echo “net.core.rmem_max = 262144” >> /etc/sysctl.conf
echo “net.core.wmem_default = 262144” >> /etc/sysctl.conf
echo “net.core.wmem_max = 262144” >>/etc/sysctl.conf
echo “net.bridge.bridge-nf-call-ip6tables=1” >>/etc/sysctl.conf
echo “net.bridge.bridge-nf-call-iptables=1” >>/etc/sysctl.conf
echo “net.bridge.bridge-nf-call-arptables=1” >>/etc/sysctl.conf
echo “net.ipv4.ip_forward=1” >>/etc/sysctl.conf
生效
sysctl -p
展示
sysctl -a
安装NODEJS
wget https://nodejs.org/download/release/v8.9.4/node-v8.9.4-linux-x64.tar.gz
下载后解压:
tar -zxf node-v8.9.4-linux-x64.tar.gz
安装目录/opt/
sudo mv node-v8.9.4-linux-x64 /opt
安装npm和node:
ln -s /opt/node-v8.9.4-linux-x64/bin/node /usr/local/bin/node
ln -s /opt/node-v8.9.4-linux-x64/bin/npm /usr/local/bin/npm
安装golang
下载的软件包
wget -c https://studygolang.com/dl/golang/go1.13.7.linux-amd64.tar.gz
wget -c https://studygolang.com/dl/golang/go1.14.2.linux-amd64.tar.gz
解压到指定目录
tar -C /opt/ -xzf go*.linux-amd64.tar.gz
配置环境变量
修改~/.bash_profile
export GOROOT=/opt/go
export GOPATH=~/go
export GOARCH=amd64
export GOOS=linux
export GOBIN= G O P A T H / b i n e x p o r t P A T H = GOPATH/bin export PATH= GOPATH/binexportPATH=PATH: G O R O O T / b i n : GOROOT/bin: GOROOT/bin:GOBIN:./
export LANG=zh_CN.UTF-8
环境变量生效
source ~/.bash_profile
安装goimports
$ mkdir -p $GOPATH/src/golang.org/x
$ cd $GOPATH/src/golang.org/x
$ git clone https://github.com/golang/tools.git
$ go get golang.org/x/tools/cmd/goimports
$ go get -u github.com/client9/misspell/cmd/misspell
go get -u github.com/golang/dep/cmd/dep
go get github.com/axw/gocov/gocov
go get github.com/vektra/mockery/cmd/mockery
安装docker
yum install libtool-ltdl
yum install libcgroup*
yum install container-selinux
yum install pigz
yum install glibc*
扩展yum功能
yum install -y yum-utils
添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
自动选择最快yum仓库源
yum makecache fast
查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
安装docker
yum install -y docker-ce
docker version
Docker version 19.03.5, build 633a0ea
启动docker
systemctl status docker.service
systemctl start docker.service
systemctl enable docker
开发环境下:解决错误dial unix /var/run/docker.sock: connect: permission denied
- 将当前用户加入到docker组中
sudo gpasswd -a fabric docker
- 将当前用户切换到docker组中
$ newgrp docker
另有临时方法:docker服务重启, 需要重新设置一次cd /var/run
sudo chmod 666 docker.sock
安装docker compose
curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-uname -s
-uname -m
-o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
sha256sum /usr/local/bin/docker-compose
常用LINUX命令
查看linux 端口信息
lsof -i
netstat -ano
netstat -tunlp
清理证书文件
linux 下用find命令查找文件,rm命令删除文件。
删除指定目录下指定文件
find ./. -name *.tx | xargs rm -rf
find ./. -name genesisblock | xargs rm -rf
find ./. -name *.block | xargs rm -rf
删除指定名称的文件或文件夹:
find -type d | grep channel-artifacts$ | xargs rm -r
rm -rf /var/hyperledger/production
同步时间
ntpdate -u ntp.api.bz
编译安装hyperledger fabric
下载fabric源代码
在下列网址下载最新的主线版本的zip文件
https://github.com/hyperledger/fabric
$ wget -c https://github.com/hyperledger/fabric/archive/master.zip
$ mkdir -p ~/go/src/github.com/hyperledger/
$ unzip -d ~/go/src/github.com/hyperledger/master.zip
进入工作目录
$ cd ~/go/src/github.com/hyperledger/
$ ln -s fabric-master fabric
编译fabric
hyperledger fabric工程概况
Go项目的Makefile文件的部分注释
- all (default) - builds all targets and runs all non-integration tests/checks
- checks - runs all non-integration tests/checks
- desk-check - runs linters and verify to test changed packages
- configtxgen - builds a native configtxgen binary
- configtxlator - builds a native configtxlator binary
- cryptogen - builds a native cryptogen binary
- idemixgen - builds a native idemixgen binary
- peer - builds a native fabric peer binary
- orderer - builds a native fabric orderer binary
- release - builds release packages for the host platform
- release-all - builds release packages for all target platforms
- publish-images - publishes release docker images to nexus3 or docker hub.
- unit-test - runs the go-test based unit tests
- verify - runs unit tests for only the changed package tree
- profile - runs unit tests for all packages in coverprofile mode (slow)
- gotools - installs go tools like golint
- linter - runs all code checks
- check-deps - check for vendored dependencies that are no longer used
- license - checks go source files for Apache license header
- native - ensures all native binaries are available
- docker[-clean] - ensures all docker images are available[/cleaned]
- docker-list - generates a list of docker images that ‘make docker’ produces
- peer-docker[-clean] - ensures the peer container is available[/cleaned]
- orderer-docker[-clean] - ensures the orderer container is available[/cleaned]
- tools-docker[-clean] - ensures the tools container is available[/cleaned]
- protos - generate all protobuf artifacts based on .proto files
- clean - cleans the build area
- clean-all - superset of ‘clean’ that also removes persistent state
- dist-clean - clean release packages for all target platforms
- unit-test-clean - cleans unit test state (particularly from docker)
- basic-checks - performs basic checks like license, spelling, trailing spaces and linter
- docker-thirdparty - pulls thirdparty images (kafka,zookeeper,couchdb)
- docker-tag-latest - re-tags the images made by ‘make docker’ with the :latest tag
- docker-tag-stable - re-tags the images made by ‘make docker’ with the :stable tag
- help-docs - generate the command reference docs
$ cd fabric
$ make all
编译完成后
在build/bin文件夹里会出现如下可执行文件
configtxgen configtxlator cryptogen discover idemixgen orderer peer
查看文件版本:
[fabric@localhost bin]$ ./peer version
peer:
Version: 2.0.0
Commit SHA:
Go version: go1.13.7
OS/Arch: linux/amd64
Chaincode:
Base Docker Namespace: hyperledger
Base Docker Label: org.hyperledger.fabric
Docker Namespace: hyperledger
[fabric@localhost bin]$ ./orderer version
orderer:
Version: 2.0.0
Commit SHA:
Go version: go1.13.7
OS/Arch: linux/amd64
体验Hyperledger Fabric1.4.6的first-network
git clone https://github.com/hyperledger/fabric-samples
byfn.sh generate
[fabric@localhost first-network]$ ./byfn.sh generate
Generating certs and genesis block for channel ‘mychannel’ with CLI timeout of ‘10’ seconds and CLI delay of ‘3’ seconds
Continue? [Y/n] y
proceeding …
/home/fabric/github.com/hyperledger/fabric-samples/bin/cryptogen
##########################################################
Generate certificates using cryptogen tool
##########################################################
- cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com - res=0
- set +x
/home/fabric/github.com/hyperledger/fabric-samples/bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
CONSENSUS_TYPE=solo
- ‘[’ solo == solo ‘]’
- configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2020-04-28 19:42:52.822 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-04-28 19:42:52.861 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2020-04-28 19:42:52.861 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /home/fabric/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-04-28 19:42:52.905 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2020-04-28 19:42:52.906 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /home/fabric/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-04-28 19:42:52.907 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2020-04-28 19:42:52.907 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block - res=0
- set +x
#################################################################
Generating channel configuration transaction ‘channel.tx’
#################################################################
- configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2020-04-28 19:42:52.946 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-04-28 19:42:52.985 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/fabric/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-04-28 19:42:53.026 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-04-28 19:42:53.026 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/fabric/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-04-28 19:42:53.026 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2020-04-28 19:42:53.028 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx - res=0
- set +x
#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
- configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2020-04-28 19:42:53.073 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-04-28 19:42:53.111 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/fabric/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-04-28 19:42:53.154 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-04-28 19:42:53.154 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/fabric/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-04-28 19:42:53.154 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2020-04-28 19:42:53.154 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update - res=0
- set +x
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
- configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2020-04-28 19:42:53.194 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-04-28 19:42:53.232 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/fabric/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-04-28 19:42:53.273 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-04-28 19:42:53.273 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/fabric/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2020-04-28 19:42:53.273 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2020-04-28 19:42:53.274 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update - res=0
- set +x
byfn.sh up
[fabric@localhost first-network]$ ./byfn.sh up
Starting for channel ‘mychannel’ with CLI timeout of ‘10’ seconds and CLI delay of ‘3’ seconds
Continue? [Y/n] y
proceeding …
LOCAL_VERSION=1.4.0
DOCKER_IMAGE_VERSION=1.4.6
=================== WARNING ===================
Local fabric binaries and docker images are
out of sync. This may cause problems.
===============================================
Starting peer0.org1.example.com …
peer1.org1.example.com is up-to-date
peer0.org2.example.com is up-to-date
Starting peer0.org1.example.com … done
Starting orderer.example.com … done
Creating cli … done
/ | | | / \ | _ \ | |
_ \ | | / _ \ | |) | | |
) | | | / ___ \ | _ < | |
|/ || // _\ || _\ |_|
Build your first network (BYFN) end-to-end test
Channel name : mychannel
Creating channel…
- 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/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
- res=0
- set +x
2020-04-28 08:04:29.062 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-04-28 08:04:29.109 UTC [cli.common] readBlock -> INFO 002 Received block: 0
===================== Channel ‘mychannel’ created =====================
Having all peers join the channel…
-
peer channel join -b mychannel.block
-
res=0
-
set +x
2020-04-28 08:04:29.186 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-04-28 08:04:29.289 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org1 joined channel ‘mychannel’ ===================== -
peer channel join -b mychannel.block
-
res=0
-
set +x
2020-04-28 08:04:32.369 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-04-28 08:04:32.480 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org1 joined channel ‘mychannel’ ===================== -
peer channel join -b mychannel.block
-
res=0
-
set +x
2020-04-28 08:04:35.563 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-04-28 08:04:35.683 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org2 joined channel ‘mychannel’ ===================== -
peer channel join -b mychannel.block
-
res=0
-
set +x
2020-04-28 08:04:38.757 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-04-28 08:04:38.937 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org2 joined channel ‘mychannel’ =====================
Updating anchor peers for org1…
- peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --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
- res=0
- set +x
2020-04-28 08:04:42.020 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-04-28 08:04:42.038 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org ‘Org1MSP’ on channel ‘mychannel’ =====================
Updating anchor peers for org2…
- peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --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
- res=0
- set +x
2020-04-28 08:04:45.116 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-04-28 08:04:45.133 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org ‘Org2MSP’ on channel ‘mychannel’ =====================
Installing chaincode on peer0.org1…
- peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
- res=0
- set +x
2020-04-28 08:04:48.217 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-04-28 08:04:48.217 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-04-28 08:04:48.510 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:“OK” >
===================== Chaincode is installed on peer0.org1 =====================
Install chaincode on peer0.org2…
- peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
- res=0
- set +x
2020-04-28 08:04:48.588 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-04-28 08:04:48.588 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-04-28 08:04:48.899 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:“OK” >
===================== Chaincode is installed on peer0.org2 =====================
Instantiating chaincode on peer0.org2…
- peer chaincode instantiate -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 mycc -l golang -v 1.0 -c ‘{“Args”:[“init”,“a”,“100”,“b”,“200”]}’ -P ‘AND (’’‘Org1MSP.peer’’’,’’‘Org2MSP.peer’’’)’
- res=0
- set +x
2020-04-28 08:04:48.984 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-04-28 08:04:48.984 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
===================== Chaincode is instantiated on peer0.org2 on channel ‘mychannel’ =====================
Querying chaincode on peer0.org1…
===================== Querying on peer0.org1 on channel ‘mychannel’… =====================
Attempting to Query peer0.org1 …3 secs
- peer chaincode query -C mychannel -n mycc -c ‘{“Args”:[“query”,“a”]}’
- res=0
- set +x
100
===================== Query successful on peer0.org1 on channel ‘mychannel’ =====================
Sending invoke transaction on peer0.org1 peer0.org2…
- 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 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”]}’
- res=0
- set +x
2020-04-28 08:05:14.851 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel ‘mychannel’ =====================
Installing chaincode on peer1.org2…
- peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
- res=0
- set +x
2020-04-28 08:05:14.932 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-04-28 08:05:14.932 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-04-28 08:05:15.211 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:“OK” >
===================== Chaincode is installed on peer1.org2 =====================
Querying chaincode on peer1.org2…
===========