distributed-deploy: add LICENSE, AUTHORS, etc

Signed-off-by: zeoio <kinsleer@outlook.com>
This commit is contained in:
zeoio 2020-04-26 10:31:54 +08:00
parent 958749e76c
commit 0222eae216
4 changed files with 552 additions and 0 deletions

View file

@ -0,0 +1,8 @@
# This is the official list of distributed-deploy authors for copyright purposes.
# This project is contributed by Credit Card Center of China Guangfa Bank.
梁海山 <8404595@qq.com>
李峥 <786881767@qq.com>
何跃江 <fullbenhouse@126.com>
zeoio <kinsleer@outlook.com>

202
distributed-deploy/LICENSE Normal file
View file

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View file

@ -0,0 +1,154 @@
# 分布式部署
区块链安装部署包的主要功能分为三个部分,分别为新装、扩缩容以及修复。
新装功能主要是根据部署包的配置文件单机或分布式部署`orderer`和`peer`用户只需配置好相应的域名及ip即可实现一键部署。
扩缩容功能是针对正在运行的区块链网络,可以对网络中`orderer`和`peer`进行添加节点或减少节点。
修复功能是结合扩缩容功能实现的,对需要修复的`peer`或`orderer`节点进行先缩容后扩容的操作。
## 依赖环境
请确保运行在`Linux`环境上并安装以下的工具:
- jdk8以上版本
- Maven推荐3.6.0版本以上
- Docker推荐19.x以上
- Docker-compose推荐1.23.2以上
- Fabric 1.4.2
## 构建部署包
首先,我们需要先构建一些依赖文件。主要包括,项目的依赖包和`fabric`的二进制文件。我们先构建项目的依赖包,进入项目的根目录,然后执行下面的命令:
```shell
mvn package -DskipTests
```
生成的`jar`包位于*bcp-install-main/target/*目录中。
之后,我们进入`fabric`的代码目录,执行如下命令生成我们需要的二进制文件:
```shell
make release
```
我们将编译好的二进制文件复制到项目的*bcp-install-main/resources/generateInstallPackage/masterPackage/tools/linux*中。
*注意: 主要的二进制文件包括configtxgen, configtxlator和cryptogen*
## 开始部署
默认情况下,我们启动两个`peer`节点,和三个`orderer`节点。
### 复制主/从节点部署包到服务器中
主/从节点部署包主要位于*bcp-install-main/resources/generateInstallPackage*目录中,其中*masterPackage*为主节点部署包,*slavePackage*为从节点部署包。
我们需要将上一小节**构建部署包**中生成的`jar`文件,即`bcp-install.jar`分别复制到*masterPackage*和*slavePackage*中。
![](11)
我们将`peer0`作为主节点服务器,将*masterPackage*目录复制到`peer0`服务器上。同时我们需要将*slavePackage*目录分别复制到`peer1`, `orderer0`, `orderer1`, `orderer2`服务器中。
### 修改initconfig.properties配置
我们首先需要得到`peer0`, `peer1`, `orderer0`, `orderer1`以及`orderer2`所在服务器的**ip**和对应的**端口**。然后修改*masterPackage*目录中的initconfig.properties配置文件。
![](22)
### 执行部署安装脚本
首先执行各个从节点部署包的部署安装脚本,在从节点部署包根目录下执行脚本**start-installService-slave.sh**,脚本有一个必填启动选项“-p”表示安装目录必须填写为绝对路径我们可以使用如下的命令启动从节点部署包:
```shell
./start-installService-slave.sh -p /home/deploy/
```
![](33)
所有从节点部署包启动成功后,在`peer0`服务器上执行主节点部署包目录下的**start-installService-master.sh**脚本,这个脚本有两个必填启动选项,分别是“-m”和“-p”。“-m”表示部署操作可选值有“newInstall”和“updateNetwork”“-p”表示安装目录必须填写为绝对路径我们可以使用如下的命令启动主节点部署包:
```shell
./start-installService-master.sh -m newInstall -p /home/deploy
```
![](44)
## 扩缩容部署流程
### 修改配置文件
首先,我们在主节点部署包的根目录下修改**initconfig.propertise**配置文件。
扩容修改的规则为在需要扩容节点的角色域名配置项中**peerHostConfig**或者**ordererHostConfig**添加新节点的**域名**、**ip**、**端口**以及涉及到的其他配置项的信息。
缩容修改的规则为,在需要缩容节点的角色域名的配置项中**peerHostConfig**或者**ordererHostConfig**删除对应的配置信息。
### 运行部署包
我们使用如下的命令启动主节点安装部署包:
```shell
./start-installService-master.sh -o 1 -m updateNetwork -p /home/bcp-master
```
*注意安装路径要与“newInstall”时一致*
启动新节点的从节点安装部署包, 如果新节点配置在主节点部署包所在服务器上,则无需启动从节点部署包。我们使用如下命令运行:
```shell
./start-installService-slave.sh -o 0 -p /home/bcp-master
```
*注意安装路径要与“newInstall”时一致*
除了启动这两个节点外,扩缩容不同角色的节点还需启动不同角色所在服务器的从节点部署包,具体的启动规则如下所述:
扩缩容`orderer`
1. 需启动正在运行所有`orderer`所在服务器的从节点部署包,如果与新节点位于同一服务器无需启动从节点部署包。
2. 需启动正在运行的后台所在服务器的从节点部署包,如果与新节点位于同一服务器无需启动从节点部署包。
扩缩容`peer`
需启动正在运行的后台所在服务器的从节点部署包,如果与新节点位于同一服务器无需启动从节点部署包。
## 部署包配置文件initconfig.propertise
**initconfig.propertise**文件位于主节点安装部署包的目录中, 文件主要分为五部分的配置,分别为`fabric机构信息配置`, `orderer相关配置`, `peer相关配置`, `区块链管理平台相关配置`, `前端相关配置`
### orderer配置
ordererDomain: orderer所使用的域名。例bcplatform.com。
ordererHostConfig这一项需要填写接入区块链网络的orderer节点host配置信息和开启的访问端口。如果orderer节点有多个则需要配置多个orderer节点的host配置信息一般建议至少接入三个orderer节点。左边是域名右边是IP地址和端口。注意要与ordererDomain一致。例orderer. bcplatform.com 172.100.10.1:7050
### peer配置
peerDomainpeer所使用的域名。例bcplatform.com。
peerHostConfig这一项需要填写接入区块链网络的peer节点host配置信息和开启的访问端口。如果peer节点有多个则需要配置多个peer节点的host配置信息一般建议至少接入两个peer节点。左边是域名右边是IP地址和端口。注意要与peerDomain一致。例Peer0.orgName.bcplatform.com 172.100.10.4:7051。
metricPortConfig配置peer的交易数查询端口要与peerHostConfig配置中的host一一对应。例Peer0.orgName.bcplatform.com:9443。
### fabric机构信息配置
network: docker在创建环境时用到的网络名称
channelName: 创建的链名称
orgMSPID: 接入链网络的机构MSPID
orgName: 接入链网络的机构名
## 贡献
感谢您考虑提供源代码帮助!我们欢迎互联网上任何人的贡献,并感谢即使是最小的修复!
如果您想为项目做贡献,请分叉,修复,提交并发送请求请求,以供维护人员查看并合并到主要代码库中。
## 许可
项目源代码文件在LICENSE文件中的Apache许可证版本2.0Apache-2.0下可用。可在http://creativecommons.org/licenses/by/4.0/获得的知识共享署名4.0国际许可CC-BY-4.0)下提供**项目文档文件。

188
distributed-deploy/start.sh Executable file
View file

@ -0,0 +1,188 @@
#!/bin/bash
#
# Copyright CGB Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#
# Print the usage message
function printHelp() {
echo "Usage: "
echo " start.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-o <consensus-type>] [-i <imagetag>] [-a] [-n] [-v]"
echo " <mode> - one of 'up', 'down', 'restart', 'generate' or 'upgrade'"
echo " - 'up' - bring up the network with docker-compose up"
echo " - 'down' - clear the network with docker-compose down"
echo " - 'restart' - restart the network"
echo " - 'generate' - generate required certificates and genesis block"
echo " - 'upgrade' - upgrade the network from version 1.3.x to 1.4.0"
echo " -c <channel name> - channel name to use (defaults to \"mychannel\")"
echo " -t <timeout> - CLI timeout duration in seconds (defaults to 10)"
echo " -d <delay> - delay duration in seconds (defaults to 3)"
echo " -f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)"
echo " -s <dbtype> - the database backend to use: goleveldb (default) or couchdb"
echo " -l <language> - the chaincode language: golang (default) or node"
echo " -o <consensus-type> - the consensus-type of the ordering service: solo (default), kafka, or etcdraft"
echo " -p <path> - the data path"
echo " -i <imagetag> - the tag to be used to launch the network (defaults to \"latest\")"
echo " -a - launch certificate authorities (no certificate authorities are launched by default)"
echo " -n - do not deploy chaincode (abstore chaincode is deployed by default)"
echo " -v - verbose mode"
echo " start.sh -h (print this message)"
echo
echo "Typically, one would first generate the required certificates and "
echo "genesis block, then bring up the network. e.g.:"
echo
echo " start.sh generate -c mychannel"
echo " start.sh up -c mychannel -s couchdb"
echo " start.sh up -c mychannel -s couchdb -i 1.4.0"
echo " start.sh up -l node"
echo " start.sh down -c mychannel"
echo " start.sh upgrade -c mychannel"
echo
echo "Taking all defaults:"
echo " start.sh up"
echo " start.sh down"
}
function mvnPackage() {
mvn clean
mvn package -DskipTests
if [ $? -ne 0 ]; then
echo "Failed of mvn package..."
exit 1
fi
}
# Obtain CONTAINER_IDS and remove them
# TODO Might want to make this optional - could clear other containers
function clearContainers() {
CONTAINER_IDS=$(docker ps -a | awk '($2 ~ /dev-peer.*/) {print $1}')
if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
echo "---- No containers available for deletion ----"
else
docker rm -f $CONTAINER_IDS
fi
}
# Delete any images that were generated as a part of this setup
# specifically the following images are often left behind:
# TODO list generated image naming patterns
function removeUnwantedImages() {
DOCKER_IMAGE_IDS=$(docker images | awk '($1 ~ /dev-peer.*/) {print $3}')
if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" == " " ]; then
echo "---- No images available for deletion ----"
else
docker rmi -f $DOCKER_IMAGE_IDS
fi
}
# Generate the needed certificates, the genesis block and start the network.
function networkUp() {
# checkPrereqs
mvnPackage
# Copy the file to the specified directory
cp bcp-install-main/target/bcp-install.jar bcp-install-main/resources/generateInstallPackage/masterPackage/
# create directory if it don't exist
if [ ! -d $DATA_PATH ]; then
mkdir $DATA_PATH
fi
BASE_PATH=$(pwd)
cd $MASTER_DIR
sudo ./start-installService-master.sh -m newInstall -p $BASE_PATH/$DATA_PATH
}
# Tear down running network
function networkDown() {
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker volume prune
docker network prune
# Don't remove the generated artifacts -- note, the ledgers are always removed
if [ "$MODE" != "restart" ]; then
# Bring down the network, deleting the volumes
#Delete any ledger backups
# docker run -v $PWD:/tmp/first-network --rm hyperledger/fabric-tools:$IMAGETAG rm -Rf /tmp/first-network/ledgers-backup
#Cleanup the chaincode containers
clearContainers
#Cleanup images
removeUnwantedImages
fi
# clear java env
mvn clean
}
BASE_DIR=$(pwd)
MASTER_DIR=bcp-install-main/resources/generateInstallPackage/masterPackage
# data storage path
DATA_PATH=./mainData
MODE=$1
shift
while getopts "h?c:t:d:f:s:l:i:o:p:anv" opt; do
case "$opt" in
h | \?)
printHelp
exit 0
;;
c)
CHANNEL_NAME=$OPTARG
;;
t)
CLI_TIMEOUT=$OPTARG
;;
d)
CLI_DELAY=$OPTARG
;;
f)
COMPOSE_FILE=$OPTARG
;;
s)
IF_COUCHDB=$OPTARG
;;
l)
LANGUAGE=$OPTARG
;;
i)
IMAGETAG=$(go env GOARCH)"-"$OPTARG
;;
o)
CONSENSUS_TYPE=$OPTARG
;;
p)
DATA_PATH=$OPTARG
;;
a)
CERTIFICATE_AUTHORITIES=true
;;
n)
NO_CHAINCODE=true
;;
v)
VERBOSE=true
;;
esac
done
# Determine whether starting, stopping, restarting, generating or upgrading
if [ "$MODE" == "up" ]; then
networkUp
elif [ "$MODE" == "down" ]; then
networkDown
elif [ "$MODE" == "restart" ]; then
networkDown
networkUp
else
printHelp
exit 1
fi