扩容Max版区块链节点(无tars管理台)

1. 脚本功能介绍

build_chain.sh脚本用于快速生成一条链中节点的配置文件,以下为用于扩容无tars版pro/max 脚本选项功能介绍:

C选项[Optional]

脚本的命令,支持 deploy ,默认为deploy:

  • deploy: 用于部署pro链。

  • expand_node: 用于扩容节点

  • expand_group: 用于扩容群组

  • expand_service: 用于扩容RPC/Gateway服务

V选项[Optional]

指定链版本(air、pro、max),默认为air。

c选项[Optional]

用于指定服务的配置文件路径,此路径须包括config.toml,默认为./BcosBuilder/max/config.toml。

o选项[Optional]

指定生成的节点产物所在的目录,默认目录为 ./expand

2、扩容RPC/Gateway service

2.1 设置RPC/Gateway服务扩容配置

使用build_chain脚本,部署一个max服务,现需要对rpc/gateway进行扩容,

其主要修改如下:

1、指定[chain] rpc_ca_cert_path、gateway_ca_cert_path中的ca路径;
2、[tars]中的tars_pkg_dir指定服务的二进制位置;
3、设置[[agency]]中的机构 name
4、设置[agency.rpc]的deploy_ip、listen_port、tars_listen_port 服务ip 和相应的端口;
5、设置[agency.gateway]的deploy_ip、listen_port、tars_listen_port服务ip 和相应的端口,同时修改peers (需要将已经部署完成的gateway的IP:port写上,其他已经部署的gateway不需要修改相应的nodes.json;

注意,tars_listen_port需要比之前部署的最后一个端口相差大于6,例如之前部署的最后一个节点的tars_listen_port=40402,那么此次的rpc中tars_listen_port最小为40408,gateway中tars_listen_port最小为40409

新RPC/Gateway服务的配置config.toml如下:

[tars]
tars_pkg_dir = "/data/task/BcosBuilder/max/binary"

[chain]
chain_id="chain0"
# the rpc-service enable sm-ssl or not, default disable sm-ssl
rpc_sm_ssl=false
# the gateway-service enable sm-ssl or not, default disable sm-ssm
gateway_sm_ssl=false
# the existed rpc service ca path, will generate new ca if not configured
rpc_ca_cert_path="/data/task/generate/rpc/chain0/ca"
# the existed gateway service ca path, will generate new ca if not configured
gateway_ca_cert_path="/data/task/generate/gateway/chain0/ca"

[[group]]
group_id="group0"
# the genesis configuration path of the group, will generate new genesis configuration if not configured
#genesis_config_path = ""
# VM type, now only support evm/wasm
vm_type="evm"
# use sm-crypto or not
sm_crypto=false
# enable auth-check or not
auth_check=false
init_auth_address="0x182ee9ac08a729b098e5b8e45b6b328c16a4f0a7"

# the genesis config
# the number of blocks generated by each leader
leader_period = 1
# the max number of transactions of a block
block_tx_count_limit = 1000
# consensus algorithm now support PBFT(consensus_type=pbft)
consensus_type = "pbft"
# transaction gas limit
gas_limit = "3000000000"
# compatible version, can be dynamically upgraded through setSystemConfig
compatibility_version="3.4.0"

[[agency]]
name = "agencyB"
failover_cluster_url = "172.30.93.111:2379"
# enable data disk encryption for rpc/gateway or not, default is false
enable_storage_security = false
# url of the key center, in format of ip:port, please refer to https://github.com/FISCO-BCOS/key-manager for details
# key_center_url =
# cipher_data_key =

    [agency.rpc]
    deploy_ip=["172.30.93.111"]
    # rpc listen ip
    listen_ip="0.0.0.0"
    # rpc listen port
    listen_port=20210
    thread_count=4
    # rpc tars server listen ip
    tars_listen_ip="0.0.0.0"
    # rpc tars server listen port
    tars_listen_port=43408

    [agency.gateway]
    deploy_ip=["172.30.93.111"]
    # gateway listen ip
    listen_ip="0.0.0.0"
    # gateway listen port
    listen_port=30310
    # gateway connected peers, should be all of the gateway peers info
    peers=["172.31.184.227:33300","172.30.93.111:30310"]
    tars_listen_port=43409

2.2 生成RPC/Gateway

# 扩容并部署RPC服务
bash build_chain.sh -C expand_service -V max -o expand_service -c ./config.toml

扩容过程中生成的RPC/Gateway服务相关的配置位于expand_service/${deploy_ip}`目录,具体如下:

$ tree expand_service/172.30.93.111
expand_service/172.30.93.111
├── gateway_30310
│   ├── BcosGatewayService
│   ├── conf
│      ├── ca.crt
│      ├── cert.cnf
│      ├── config.ini
│      ├── nodes.json
│      ├── ssl.crt
│      ├── ssl.key
│      ├── ssl.nodeid
│      ├── tars.conf
│      └── tars_proxy.ini
│   ├── start.sh
│   └── stop.sh
├── rpc_20210
│   ├── BcosRpcService
│   ├── conf
│      ├── ca.crt
│      ├── cert.cnf
│      ├── config.ini
│      ├── sdk
│         ├── ca.crt
│         ├── cert.cnf
│         ├── sdk.crt
│         ├── sdk.key
│         └── sdk.nodeid
│      ├── ssl.crt
│      ├── ssl.key
│      ├── ssl.nodeid
│      ├── tars.conf
│      └── tars_proxy.ini
│   ├── start.sh
│   └── stop.sh
├── start_all.sh
└── stop_all.sh

2.3 部署TiKV

在扩容服务去机器上部署tikv,此处为展示方便,使用TiUP playground启动TiKV节点,playground仅用于测试环境,生产环境请参考TiKV官方文档部署集群;

下载和安装tiup

$ curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

启动tikv v6.5.0

# 部署并启动tikv(这里设机器的物理ip为172.30.93.111)
$ nohup tiup playground v6.5.0 --mode tikv-slim --host=172.30.93.111 -T tikv_demo --without-monitor > ~/tikv.log 2>&1 &
# 获取tikv监听端口(tikv的默认监听端口是2379)
$ cat ~/tikv.log
tiup is checking updates for component playground ...timeout!
Starting component `playground`: /home/fisco/.tiup/components/playground/v1.9.4/tiup-playground v6.5.0 --mode tikv-slim --host=172.30.93.111 -T tikv_demo --without-monitor
Playground Bootstrapping...
Start pd instance:v6.5.0
Start tikv instance:v6.5.0
PD client endpoints: [172.30.93.111:2379]

2.4 通过控制台获取新扩容的服务信息

将生成的产物放置到对应ip机器中并启动服务,启动控制台,输入getPeers命令,控制台显示的Gateway服务节点数目由1个增加为2个。

[group0]: /apps> getPeers 
PeersInfo{
    p2pNodeID='3082010a0282010100bb4983a6136c0b1823a00a93d401899ed736c2e149ebd456052d3a2d256eae26b5bd5af6764e045f9066590f333e0f970d32de2a1f4ec134eb2429eec8f37e55584c8f69fafc3b1dc6c53576afe3575dba0cce3426fd359cbf2cae41ca127e1af607b361bf338323f2c25ec21216f7ac01e4e200ea9628905a76ce72abf0dfcdc44fb8a53710d8990823dbd88e587b2422df5be10778f5f8af88d3f824e50410767e40c4cf17f64c25fe7ef300472e305f8fd7464553739044f57350cd4eda608b8f815025c2d502ab48fd3e0f68b4ae7240ef20a14edc3e4267584c910abb7925168994818a0f1e56b7bff152180c039f45af00945b555c15facb4f8986c9870203010001',
    endPoint='0.0.0.0:33300',
    groupNodeIDInfo=[
        NodeIDInfo{
            group='group0',
            nodeIDList=[
                57b1eceaf9129b062f4845c159eff7440b01cc40c3787019bebc30d66e47aa22e73ea31028e23d325ed559258ab10021cd0b586b5e757d99f76914b2680a9d79
            ]
        }
    ],
    peers=[
        PeerInfo{
            p2pNodeID='3082010a0282010100cadd66bad17ea1764a9a08dca2659d375cd36fbc5f577d3ad1817169fa3460188713c28e8b556d25adcdc20a98f36e484e5215146b295777c65798230aced92df76609665461ab7f2b7174a757dae76e1080aa742f4395ddc45a7b3642977f6794965433bb9d04d870eca8d3f47e11f5c605a8bcfef0ac3ac864c54945e415232a147850a3ed3a240450248fcfe4ea9d0f38908039b974d53c8e40c57ccd1bb5e5f09af0c5d51cba6370c37bb8954c61a3e35eda92759553db8589cf39dd7ddff6a605b5b61034dc21cae771685c0b12cbb908f56fcba0a917a07ec5df410643d27721ac2dbe84c44e67b97fc57bc69db9778ab2f6bc9596a1e3cccdbf30a9990203010001',
            endPoint='172.30.93.111:49646',
            groupNodeIDInfo=[
                
            ]
        }
    ]
}

3、扩容node service

3.1设置区块链节点扩容配置

具体步骤如下:

1、复制部署时的config.toml,仅保留想要扩容节点的agency配置,将其他agency的配置文件删除;
2、[tars]中的tars_pkg_dir指定服务的二进制位置;
3、[group] genesis_config_path,指定已有节点的创世块配置文件路径;
4、[[agency]] 中的[agency.group]选项,修改node_name、tars_listen_port;

注意,[[agency.group.node]]中的tars_listen_port需要占用6个端口,因此本次tars_listen_port端口需要和之前部署的最后一个端口相差大于6,例如之前部署的最后一个节点的tars_listen_port=40402,那么此次的tars_listen_port最小为40408。

扩容配置config.toml如下(例如对已扩容的rpc/gateway服务扩容节点):

[tars]
tars_pkg_dir = "/data/task/BcosBuilder/max/binary"

[chain]
chain_id="chain0"
# the rpc-service enable sm-ssl or not, default disable sm-ssl
rpc_sm_ssl=false
# the gateway-service enable sm-ssl or not, default disable sm-ssm
gateway_sm_ssl=false
# the existed rpc service ca path, will generate new ca if not configured
rpc_ca_cert_path="/data/task/generate/rpc/chain0/ca"
# the existed gateway service ca path, will generate new ca if not configured
gateway_ca_cert_path="/data/task/generate/gateway/chain0/ca"

[[group]]
group_id="group0"
# the genesis configuration path of the group, will generate new genesis configuration if not configured
genesis_config_path = "/data/task/generate/172.31.184.227/group0_max_node_40402/conf/config.genesis"

# VM type, now only support evm/wasm
vm_type="evm"
# use sm-crypto or not
sm_crypto=false
# enable auth-check or not
auth_check=false
init_auth_address="0x182ee9ac08a729b098e5b8e45b6b328c16a4f0a7"

# the genesis config
# the number of blocks generated by each leader
leader_period = 1
# the max number of transactions of a block
block_tx_count_limit = 1000
# consensus algorithm now support PBFT(consensus_type=pbft)
consensus_type = "pbft"
# transaction gas limit
gas_limit = "3000000000"
# compatible version, can be dynamically upgraded through setSystemConfig
compatibility_version="3.4.0"

[[agency]]
name = "agencyB"
failover_cluster_url = "172.30.93.111:2379"
# enable data disk encryption for rpc/gateway or not, default is false
enable_storage_security = false
# url of the key center, in format of ip:port, please refer to https://github.com/FISCO-BCOS/key-manager for details
# key_center_url =
# cipher_data_key =

    [agency.rpc]
    deploy_ip=["172.30.93.111"]
    # rpc listen ip
    listen_ip="0.0.0.0"
    # rpc listen port
    listen_port=20210
    thread_count=4
    # rpc tars server listen ip
    tars_listen_ip="0.0.0.0"
    # rpc tars server listen port
    tars_listen_port=40408

    [agency.gateway]
    deploy_ip=["172.30.93.111"]
    # gateway listen ip
    listen_ip="0.0.0.0"
    # gateway listen port
    listen_port=30310
    # gateway connected peers, should be all of the gateway peers info
    peers=["172.31.184.227:33300","172.30.93.111:30310"]
    tars_listen_port=40409

    [[agency.group]]
        group_id = "group0"
        [[agency.group.node]]
        node_name =  "node0"
        # the tikv storage pd-addresses
        pd_addrs = "172.30.93.111:2379"
        key_page_size=10240
        deploy_ip = ["172.30.93.111"]
        executor_deploy_ip=["172.30.93.111"]
        monitor_listen_port =  "3901"
        # the tikv storage pd-addresses
        # monitor log path example:"/home/fisco/tars/framework/app_log/"
        monitor_log_path = ""
        # node tars server listen ip
        tars_listen_ip="0.0.0.0"
        # node tars server listen port
        tars_listen_port=40410

3.2 部署生成节点

# 扩容node service
bash build_chain.sh -C expand_node -V max -o expand_node -c ./config.toml

执行上述命令后,扩容过程中生成的产物具体如下

$ tree expand_node/172.30.93.111/
expand_node/172.30.93.111/
├── group0_executor_43410
│   ├── BcosExecutorService
│   ├── conf
│   │   ├── config.genesis
│   │   ├── config.ini
│   │   ├── tars.conf
│   │   └── tars_proxy.ini
│   ├── start.sh
│   └── stop.sh
├── group0_max_node_43410
│   ├── BcosMaxNodeService
│   ├── conf
│   │   ├── config.genesis
│   │   ├── config.ini
│   │   ├── node.nodeid
│   │   ├── node.pem
│   │   ├── tars.conf
│   │   └── tars_proxy.ini
│   ├── start.sh
│   └── stop.sh
├── start_all.sh
└── stop_all.sh

3.3 将新扩容节点加入到群组

将生成的产物放置到对应ip机器中,在启动节点前,同2.3一样也需要先开启tikv;

注解

扩容新节点时,先将节点添加为观察节点,当扩容节点的块高与链上已有节点最高块高一致时候,才可将其加入为共识节点。

步骤1:获取扩容节点的NodeID

新节点扩容成功后,可通过控制台的getGroupPeers命令查看新增的节点列表:

[group0]: /apps> getGroupPeers 
peer0: 2300e14703675333d947154d8f01bb9d9f814c23a89980872404f368b301d45be2d3acebe306fa6d5a2859fd67f6ba2515eba0b263c940a5f67977ca440f806d
f760b1ef241faa35f2cc68cdb370bfc6b27f9b94b4c79a3d24d4fee41021d87d858a486b611c8ec8213c666faf9e6eec41115cb289bb0249d233e8866f22a94a

[group0]: /apps> getSealerList 
[
    Sealer{
        nodeID='57b1eceaf9129b062f4845c159eff7440b01cc40c3787019bebc30d66e47aa22e73ea31028e23d325ed559258ab10021cd0b586b5e757d99f76914b2680a9d79',
        weight=1
    }
]

从控制台输出可看出,nodeID为16357cee953a4838d74f3d401c7bf9b5db0120fd8f45e1748ca63d4f420b3d168f66c7a118dcfd16b3ab438c7ca7d4218828709c9c99fe7f867d09c30663c8f8的节点不在群组内,使用控制台addObserver命令将其加入到观察节点如下:

步骤2: 将扩容节点加入为观察节点

[group0]: /apps> addObserver 16357cee953a4838d74f3d401c7bf9b5db0120fd8f45e1748ca63d4f420b3d168f66c7a118dcfd16b3ab438c7ca7d4218828709c9c99fe7f867d09c30663c8f8
{
    "code":0,
    "msg":"Success"
}

步骤3:扩容节点同步到最高块后,将扩容节点加入为共识节点

[group0]: /apps> addSealer 16357cee953a4838d74f3d401c7bf9b5db0120fd8f45e1748ca63d4f420b3d168f66c7a118dcfd16b3ab438c7ca7d4218828709c9c99fe7f867d09c30663c8f8 1
{
    "code":0,
    "msg":"Success"
}
[group0]: /apps> getSealerList 
[
    Sealer{
        nodeID='57b1eceaf9129b062f4845c159eff7440b01cc40c3787019bebc30d66e47aa22e73ea31028e23d325ed559258ab10021cd0b586b5e757d99f76914b2680a9d79',
        weight=1
    },
    Sealer{
        nodeID='16357cee953a4838d74f3d401c7bf9b5db0120fd8f45e1748ca63d4f420b3d168f66c7a118dcfd16b3ab438c7ca7d4218828709c9c99fe7f867d09c30663c8f8',
        weight=1
    }
]