FISCO BCOS 联盟链Max搭建

忘是亡心i 2024-03-24 12:34 110阅读 0赞

FISCO BCOS Max版本

版本说明

为了能够支撑海量交易上链场景,v3.0.0推出了Max版本FISCO BCOS,Max版本FISCO BCOS旨在提供海量存储服务、高性能可扩展的执行模块、高可用的故障恢复机制。 Max版FISCO BCOS节点采用分布式存储TiKV,执行模块独立成服务,存储和执行均可横向扩展,且支持自动化主备恢复。

  • Max版本FISCO BCOS使用 BcosBuilder/max 工具进行建链和扩容等相关操作,该工具的介绍请参考 BcosBuilder
  • FISCO BCOS 3.x基于tars进行微服务构建和管理,搭建Max版本FISCO BCOS之前,需先安装tars服务,本章介绍了docker版本tars服务的搭建流程,若需要了解更多tars部署、构建相关的信息,请参考 这里
  • 本章基于Docker搭建tars服务,请确保拥有 root 权限
  • 搭建Max版本FISCO BCOS需先部署TiKV集群,TiKV集群的部署请参考 这里

1.Ubuntu20.04环境搭建

注意:

按照 FISCO BCOS Pro版本 搭建的环境,安装基础的依赖包和BcosBuilder工具,搭建完Tars服务即可。

1.1 搭建Tars服务

略过

1.2 搭建TiUP单机

1.通过执行以下命令安装 TiUP

  1. $ curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
  2. # 1.设置 TiUP 环境变量、重新声明全局环境变量:
  3. $ source .bashrc
  4. # 2.确认是否安装了 TiUP:
  5. $ tiup
  6. # 3.将 TiUP 游乐场组件更新到最新版本:
  7. $ tiup update --self && tiup update playground
  8. # 4.显示 TiUP 版本:
  9. $ tiup -v
  10. # 5.版本 >= 1.5.2:
  11. $ tiup playground --mode tikv-slim
  12. # 6.版本 < 1.5.2:
  13. $ tiup playground
  14. # 7.host是本机的ip地址
  15. $ nohup tiup playground v5.4.0 --mode tikv-slim --host=192.168.0.138 -T tikv_demo --without-monitor > ~/tikv.log 2>&1 &
  16. # 8.获取tikv监听端口(tikv的默认监听端口是2379)
  17. $ cat ~/tikv.log
  18. tiup is checking updates for component playground ...timeout!
  19. Starting component `playground`: /home/fisco/.tiup/components/playground/v1.9.4/tiup-playground v5.4.0 --mode tikv-slim --host=172.25.0.3 -T tikv_demo --without-monitor
  20. Playground Bootstrapping...
  21. Start pd instance:v5.4.0
  22. Start tikv instance:v5.4.0
  23. PD client endpoints: [172.25.0.3:2379]

1.3 单机部署TiKV集群

此处是扩展,可以不做

1.下载官方二进制包

  1. # 下载官方的压缩包
  2. $ wget https://download.pingcap.org/tidb-latest-linux-amd64.tar.gz
  3. $ wget http://download.pingcap.org/tidb-latest-linux-amd64.sha256
  4. # 检查sha256的加密
  5. $ sha256sum -c tidb-latest-linux-amd64.sha256
  6. # 解压安装包
  7. $ tar -xzf tidb-latest-linux-amd64.tar.gz
  8. $ cd tidb-latest-linux-amd64

2.启动 PD

  1. $ ./bin/pd-server --name=pd1 \
  2. --data-dir=pd1 \
  3. --client-urls="http://127.0.0.1:2379" \
  4. --peer-urls="http://127.0.0.1:2380" \
  5. --initial-cluster="pd1=http://127.0.0.1:2380" \
  6. --log-file=pd1.log

3.启动TiKV

要启动 3 个 TiKV 实例,请打开一个新的终端选项卡或窗口,进入tidb-latest-linux-amd64目录,然后使用以下命令启动实例:

  1. $ ./bin/tikv-server --pd-endpoints="127.0.0.1:2379" \
  2. --addr="127.0.0.1:20160" \
  3. --data-dir=tikv1 \
  4. --log-file=tikv1.log
  5. $ ./bin/tikv-server --pd-endpoints="127.0.0.1:2379" \
  6. --addr="127.0.0.1:20161" \
  7. --data-dir=tikv2 \
  8. --log-file=tikv2.log
  9. $ ./bin/tikv-server --pd-endpoints="127.0.0.1:2379" \
  10. --addr="127.0.0.1:20162" \
  11. --data-dir=tikv3 \
  12. --log-file=tikv3.log

可以使用pd-ctl工具验证 PD 和 TiKV 是否部署成功:

  1. $ ./bin/pd-ctl store -d -u http://127.0.0.1:2379

1.4 部署Max版本区块链系统

Max版本FISCO BCOS包括RPC服务、Gateway服务、区块链节点服务BcosMaxNodeService以及区块链执行服务BcosExecutorService:

  • RPC服务:负责接收客户端请求,并将请求转发到节点进行处理, RPC服务可横向扩展,一个RPC服务可接入多个区块链节点服务;
  • Gateway服务:负责跨机构区块链节点之间的网络通信,Gateway服务横向可扩展,一个Gateway服务可接入多个区块链节点服务;
  • 区块链节点服务BcosMaxNodeService:负责提供区块链调度相关的服务,包括区块打包、共识、执行调度、提交调度等,节点服务通过接入到RPC服务和Gateway服务获取网络通信功能;
  • 区块链执行服务BcosExecutorService:负责区块执行,可横向扩展、动态扩容。

1.下载二进制安装包,然后解压安装依赖,配置配置文件直接启动。

  1. $ curl -#LO https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/releases/v3.0.0/BcosBuilder.tgz && tar -xvf BcosBuilder.tgz
  2. # 1.安装构建工具依赖包
  3. $ cd BcosBuilder && pip3 install -r requirements.txt
  4. # 2.运行build_chain.py脚本下载二进制,二进制包默认下载到binary目录
  5. $ python3 build_chain.py download_binary -t cdn
  6. # 3.从conf目录拷贝配置
  7. cp conf/config-deploy-example.toml conf/config.toml

2.当前的配置文件如下

需要将2379端口的原来的IP地址修改为本机的IP地址。

  1. [tars]
  2. tars_url = "http://127.0.0.1:3000"
  3. tars_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJhZG1pbiIsImlhdCI6MTY2MjI5OTE2MywiZXhwIjoxNzM1NjUyNzYzfQ.p4NtwV9rJx2NIPJ3B93nuuwSB5psnHg9nJBNL0bjmjY"
  4. tars_pkg_dir = "binary/"
  5. [chain]
  6. chain_id="chain0"
  7. # the rpc-service enable sm-ssl or not, default disable sm-ssl
  8. rpc_sm_ssl=false
  9. # the gateway-service enable sm-ssl or not, default disable sm-ssm
  10. gateway_sm_ssl=false
  11. # the existed rpc service ca path, will generate new ca if not configured
  12. #rpc_ca_cert_path=""
  13. # the existed gateway service ca path, will generate new ca if not configured
  14. #gateway_ca_cert_path=""
  15. [[group]]
  16. group_id="group0"
  17. # the genesis configuration path of the group, will generate new genesis configuration if not configured
  18. # genesis_config_path = ""
  19. # VM type, now only support evm/wasm
  20. vm_type="evm"
  21. # use sm-crypto or not
  22. sm_crypto=false
  23. # enable auth-check or not
  24. auth_check=false
  25. init_auth_address=""
  26. # the genesis config
  27. # the number of blocks generated by each leader
  28. leader_period = 1
  29. # the max number of transactions of a block
  30. block_tx_count_limit = 1000
  31. # consensus algorithm now support PBFT(consensus_type=pbft)
  32. consensus_type = "pbft"
  33. # transaction gas limit
  34. gas_limit = "3000000000"
  35. # compatible version, can be dynamically upgraded through setSystemConfig
  36. # the default is 3.0.0-rc4
  37. compatibility_version="3.0.0"
  38. [[agency]]
  39. name = "agencyA"
  40. # 修改一下这里的IP地址
  41. failover_cluster_url = "192.168.0.138:2379"
  42. # enable data disk encryption for rpc/gateway or not, default is false
  43. enable_storage_security = false
  44. # url of the key center, in format of ip:port, please refer to https://github.com/FISCO-BCOS/key-manager for details
  45. # key_center_url =
  46. # cipher_data_key =
  47. [agency.rpc]
  48. deploy_ip=["172.25.0.3"]
  49. listen_ip="0.0.0.0"
  50. listen_port=20200
  51. thread_count=4
  52. [agency.gateway]
  53. deploy_ip=["172.25.0.3"]
  54. listen_ip="0.0.0.0"
  55. listen_port=30300
  56. peers=["172.25.0.3:30300"]
  57. [[agency.group]]
  58. group_id = "group0"
  59. [[agency.group.node]]
  60. node_name = "node0"
  61. # 修改一下这里的IP地址
  62. pd_addrs="192.168.0.138:2379"
  63. key_page_size=10240
  64. deploy_ip = ["172.25.0.3"]
  65. executor_deploy_ip=["172.25.0.3"]
  66. monitor_listen_port = "3901"
  67. # the tikv storage pd-addresses
  68. # monitor log path example:"/home/fisco/tars/framework/app_log/"
  69. monitor_log_path = ""

3.然后用你最快的速度部署Rpc服务、Gateway服务、Node服务。

  1. $ cd BcosBuilder/max
  2. $ python3 build_chain.py chain -o deploy -t rpc
  3. $ python3 build_chain.py chain -o deploy -t gateway
  4. $ python3 build_chain.py chain -o deploy -t node

1.5 配置控制台

1.记得安装Java的jdk环境。然后配置控制台的证书

  1. $ sudo apt install -y default-jdk
  2. $ cd ~/fisco && curl -#LO https://gitee.com/FISCO-BCOS/console/raw/master/tools/download_console.sh && bash download_console.sh
  3. # 1.最新版本控制台使用如下命令拷贝配置文件
  4. cp -n console/conf/config-example.toml console/conf/config.toml
  5. # 2.可通过命令 find . -name sdk找到所有SDK证书路径
  6. cp -r ~/fisco/BcosBuilder/max/generated/rpc/chain0/agencyABcosRpcService/172.25.0.3/sdk/* console/conf/

2.启动控制台

  1. $ cd ~/fisco/console && bash start.sh
  2. =============================================================================================
  3. Welcome to FISCO BCOS console(3.0.0)!
  4. Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
  5. ________ ______ ______ ______ ______ _______ ______ ______ ______
  6. | | \/ \ / \ / \ | \ / \ / \ / \
  7. | $$$$$$$$\$$$$$| $$$$$$| $$$$$$| $$$$$$\ | $$$$$$$| $$$$$$| $$$$$$| $$$$$$\
  8. | $$__ | $$ | $$___\$| $$ \$| $$ | $$ | $$__/ $| $$ \$| $$ | $| $$___\$$
  9. | $$ \ | $$ \$$ \| $$ | $$ | $$ | $$ $| $$ | $$ | $$\$$ \
  10. | $$$$$ | $$ _\$$$$$$| $$ __| $$ | $$ | $$$$$$$| $$ __| $$ | $$_\$$$$$$\
  11. | $$ _| $$_| \__| $| $$__/ | $$__/ $$ | $$__/ $| $$__/ | $$__/ $| \__| $$
  12. | $$ | $$ \\$$ $$\$$ $$\$$ $$ | $$ $$\$$ $$\$$ $$\$$ $$
  13. \$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$
  14. =============================================================================================
  15. [group0]: />

访问验证:

image-20220904225355456

发表评论

表情:
评论列表 (有 0 条评论,110人围观)

还没有评论,来说两句吧...

相关阅读

    相关 FISCO BCOS流量控制实现

    作者:陈宇杰|FISCO BCOS 核心开发者 引言 区块链系统作为分布式系统,面对大数据量突发请求场景,暴涨的请求容易引起区块链服务或接口不可用,严重时可能导致整个区