9. 基于现有节点新增一条链(普通证书模式)
9.1. 使用脚本部署四节点单链(普通证书模式)
9.1.1. 证书生成
进入
chainmaker-go/scripts
目录,执行prepare.sh
脚本生成单链4节点集群配置,存于路径chainmaker-go/build
中
# 进入脚本目录
$ cd ../scripts
# 查看脚本帮助
$ ./prepare.sh -h
Usage:
prepare.sh node_cnt(1/4/7/10/13/16) chain_cnt(1-4) p2p_port(default:11301) rpc_port(default:12301)
eg1: prepare.sh 4 1
eg2: prepare.sh 4 1 11301 12301
# 生成单链4节点集群的证书和配置
$ ./prepare.sh 4 1
begin check params...
begin generate certs, cnt: 4
input consensus type (0-SOLO,1-TBFT(default),3-HOTSTUFF,4-RAFT,5-DPOS):
input log level (DEBUG|INFO(default)|WARN|ERROR):
enable docker vm (YES|NO(default))
begin generate node1 config...
begin generate node2 config...
begin generate node3 config...
begin generate node4 config...
9.1.2. 编译和安装包制作
生成证书(
prepare.sh
脚本)后执行build_release.sh
脚本,将编译chainmaker-go
模块,并打包生成安装,存于路径chainmaker-go/build/release
中
$ ./build_release.sh
$ tree ../build/release/
../build/release/
├── chainmaker-v2.0.0-wx-org1.chainmaker.org-20210406194833-x86_64.tar.gz
├── chainmaker-v2.0.0-wx-org2.chainmaker.org-20210406194833-x86_64.tar.gz
├── chainmaker-v2.0.0-wx-org3.chainmaker.org-20210406194833-x86_64.tar.gz
├── chainmaker-v2.0.0-wx-org4.chainmaker.org-20210406194833-x86_64.tar.gz
└── crypto-config-20210406194833.tar.gz
9.1.3. 启动节点集群
执行
cluster_quick_start.sh
脚本,会解压各个安装包,调用bin
目录中的start.sh
脚本,启动chainmaker
节点
$ ./cluster_quick_start.sh normal
9.2. 修改节点配置文件 chainmaker.yml
修改所有节点
build/release/chainmaker-v2.3.0_alpha-wx-orgN.chainmaker.org/config/wx-orgN.chainmaker.org
中的chainmaker.yml
, 如:build/release/chainmaker-v2.3.0_alpha-wx-org1.chainmaker.org/config/wx-org1.chainmaker.org/chainmaker.yml
。将chainmaker.yml
中:
blockchain:
# chain id and its genesis block file path.
- chainId: chain1
genesis: ../config/wx-org1.chainmaker.org/chainconfig/bc1.yml
# - chainId: chain2
# genesis: ../config/{org_path2}/chainconfig/bc2.yml
修改为
blockchain:
# chain id and its genesis block file path.
- chainId: chain1
genesis: ../config/wx-org1.chainmaker.org/chainconfig/bc1.yml
- chainId: chain2
genesis: ../config/wx-org1.chainmaker.org/chainconfig/bc2.yml
9.3. 创建新链的创世块配置文件 bc2.yml
复制所有节点
build/release/chainmaker-v2.3.0_alpha-wx-orgN.chainmaker.org/config/wx-orgN.chainmaker.org/chainconfig
中的bc1.yml
为bc2.yml
, 如:build/release/chainmaker-v2.3.0_alpha-wx-org1.chainmaker.org/config/wx-org1.chainmaker.org/chainconfig/bc2.yml
$ tree ./config
./config
└── wx-org1.chainmaker.org
├── certs
│ ├── ca
│ │ ├── wx-org1.chainmaker.org
│ │ │ └── ca.crt
│ │ ├── wx-org2.chainmaker.org
│ │ │ └── ca.crt
│ │ ├── wx-org3.chainmaker.org
│ │ │ └── ca.crt
│ │ ├── wx-org4.chainmaker.org
│ │ │ └── ca.crt
│ │ ├── wx-org5.chainmaker.org
│ │ │ └── ca.crt
│ │ ├── wx-org6.chainmaker.org
│ │ │ └── ca.crt
│ │ └── wx-org7.chainmaker.org
│ │ └── ca.crt
│ ├── node
│ │ ├── common1
│ │ │ ├── common1.nodeid
│ │ │ ├── common1.sign.crt
│ │ │ ├── common1.sign.key
│ │ │ ├── common1.tls.crt
│ │ │ └── common1.tls.key
│ │ └── consensus1
│ │ ├── consensus1.nodeid
│ │ ├── consensus1.sign.crt
│ │ ├── consensus1.sign.key
│ │ ├── consensus1.tls.crt
│ │ └── consensus1.tls.key
│ └── user
│ ├── admin1
│ │ ├── admin1.sign.crt
│ │ ├── admin1.sign.key
│ │ ├── admin1.tls.crt
│ │ └── admin1.tls.key
│ ├── client1
│ │ ├── client1.addr
│ │ ├── client1.sign.crt
│ │ ├── client1.sign.key
│ │ ├── client1.tls.crt
│ │ └── client1.tls.key
│ └── light1
│ ├── light1.sign.crt
│ ├── light1.sign.key
│ ├── light1.tls.crt
│ └── light1.tls.key
├── chainconfig
│ ├── bc1.yml
│ └── bc2.yml # 新增第二条链配置
├── chainmaker.yml
└── log.yml
修改所有节点
release/chainmaker-v2.3.0_alpha-wx-orgN.chainmaker.org/config/wx-org1.chainmaker.org/chainconfig
的bc2.yml
# chain id
chain_id: chain1
将chain_id
修改为定义好的新链的id
eg:
# chain id
chain_id: chain2
9.4. 使用cmc命令动态启动新增链
需要连接到各个节点,动态加载每个节点中的新增链配置
./cmc client blockchains checknew --sdk-conf-path=./testdata/sdk_config.yml
9.5. 新增链链配置验证
修改
cmc/testdata/sdk_config.yml
# 链ID
chain_id: "chain1"
将chain_id
修改为新增链id
eg:
# 链ID
chain_id: "chain2"
使用cmc命令查询新增链链配置
./cmc client chainconfig query \
--sdk-conf-path=./testdata/sdk_config.yml