Skip to content

BitXHub部署手册

Alexader edited this page Jul 7, 2020 · 2 revisions

一键脚本部署

在bitxhub项目下,提供了一键部署的脚本,适合在有项目权限的情况下进行部署。

bitxhub/scripts
├── build
├── certs
├── cluster.sh
├── config.sh
├── cross_compile.sh
├── deploy.sh
├── prepare.sh
├── quick_start
├── solo.sh
└── x.sh

进入bitxhub项目,运行下面的命令进行部署:

## -a 为服务器地址(需要有ssh登陆权限,服务器安装tmux窗口管理器)
## -n 为需要在服务器上部署的结点数量
## -r 是否需要重新编译项目,可设为true和false
## -u 服务器ssh用户名
## -p bitxhub部署相对路径
## e.g. bash deploy.sh -a 40.125.161.213 -n 4 -r false -u root -p bitxhub

bash deploy.sh [-a <bitxhub_addr>] [-n <node_num>] [-r <if_recompile>] [-u <username>] [-p <build_path>]

插件化部署(可选)

进入plugins子目录,运行下面的命令进行编译共识算法插件:

## make raft编译共识算法
make raft

编译完成后,节点会根据bitxhub.toml文件中的order配置加载不同的共识算法。

规范化部署

前言

该文档将介绍如何部署一个拥有4个节点的BitXHub集群,操作步骤会较其他系统的部署稍繁琐一些,用户需要分别登录到4台服务器(或者在一台服务器上设置不同端口上进行操作。

这里假设4台服务器的IP分别为node1node2node3node4。操作用户都是bitxhub

1.1 获取安装包

从下面的链接获取BitXHub的zip包

wget https://github.com/meshplus/bitxhub/releases/download/v1.0.0-rc1/build_linux-amd64_v1.0.0-rc1.tar.gz

运行下面的命令,将安装包传到服务器上

scp build_linux-amd64_v1.0.0-rc1.tar.gzz bitxhub@node1:~
tar xvf build_linux-amd64_v1.0.0-rc1.tar.gz

解压完成之后,会看到如下build目录

.
├── addresses
├── agency.cert
├── agency.priv
├── bitxhub
├── ca.cert
├── ca.priv
├── libwasmer.so
├── node1
   ├── README.md
   ├── api
   ├── bitxhub.toml
   ├── certs/
   ├── genesis.json
   ├── network.toml
   ├── order.toml
   ├── plugins
   └── start.sh
├── node2
   ├── README.md
   ├── api
   ├── bitxhub.toml
   ├── certs/
   ├── genesis.json
   ├── network.toml
   ├── order.toml
   ├── plugins
   └── start.sh
├── node3
   ├── README.md
   ├── api
   ├── bitxhub.toml
   ├── certs/
   ├── genesis.json
   ├── network.toml
   ├── order.toml
   ├── plugins
   └── start.sh
├── node4
   ├── README.md
   ├── api
   ├── bitxhub.toml
   ├── certs/
   ├── genesis.json
   ├── network.toml
   ├── order.toml
   ├── plugins
   └── start.sh
├── pids
├── raft.so
└── solo.so

1.2 修改配置文件

下面以node1为例介绍如何修改配置文件

修改bitxhub.toml文件

title = "BitXHub configuration file"
# 是否按照单结点模式启动BitXHub
solo = false

# BitXHub提供服务的端口,确保和系统不冲突
[port]
  grpc = 60011
  gateway = 9091
  pprof = 53121

[pprof]
  enable = true

# 网关白名单
[gateway]
    allowed_origins = ["*"]

# 日志输出相关设置
[log]
  level = "info"
  dir = "logs"
  filename = "bitxhub.log"
  report_caller = false
  [log.module]
    p2p = "info"
    consensus = "info"
    executor = "info"
    router = "info"
    api = "info"
    coreapi = "info"


[cert]
  verify = true

# BitXHub使用的共识算法,共识模块作为插件进行加载
[order]
  plugin = "plugins/raft.so"

# BitXHub启动的创世块信息
[genesis]
    addresses = [
        "0xe6f8c9cf6e38bd506fae93b73ee5e80cc8f73667",
        "0x8374bb1e41d4a4bb4ac465e74caa37d242825efc",
        "0x759801eab44c9a9bbc3e09cb7f1f85ac57298708",
        "0xf2d66e2c27e93ff083ee3999acb678a36bb349bb"
    ]

修改network.toml文件

# BitXHub结点的IP和端口信息,BitXHub结点的id具有唯一性
N = 4
id = 1

[[nodes]]
  addr = "/ip4/127.0.0.1/tcp/4001/p2p/Qma1oh5JtrV24gfP9bFrVv4miGKz7AABpfJhZ4F2Z5ngmL"
  id = 1

[[nodes]]
  addr = "/ip4/127.0.0.1/tcp/4002/p2p/QmTGbPAfCYiAYDwYytt3QQLn3fq79dzciyP9kTFYWr8Lqb"
  id = 2

[[nodes]]
  addr = "/ip4/127.0.0.1/tcp/4003/p2p/QmNxNoU52ZmSaeFS9MEUHAvusp6iqoqZRKnpoKwUvHkVdB"
  id = 3

[[nodes]]
  addr = "/ip4/127.0.0.1/tcp/4004/p2p/QmaKBzZw94uqRRr5w8n4DMzrYcJ8V9VkyVYRxBSYYvi1te"
  id = 4

修改order.toml

# 共识算法插件的配置文件

[raft]
election_tick               = 10 # ElectionTick is the number of Node.Tick invocations that must pass between elections.
heartbeat_tick              = 1 # HeartbeatTick is the number of Node.Tick invocations that must pass between heartbeats.
max_size_per_msg            = 1048576 # 1024*1024, MaxSizePerMsg limits the max size of each append message.
max_inflight_msgs           = 500 # MaxInflightMsgs limits the max number of in-flight append messages during optimistic replication phase.
check_quorum                = true # Leader steps down when quorum is not active for an electionTimeout.
pre_vote                    = true # PreVote prevents reconnected node from disturbing network.
disable_proposal_forwarding = true # This prevents blocks from being accidentally proposed by followers.
    [raft.tx_pool]
        pack_size           = 500 # How many transactions should the primary pack.
        pool_size           = 50000 # How many transactions could the txPool stores in total.
        block_tick          = "500ms" # Block packaging time period.

1.3 启动BitXHub

将bitxhub和raft.so二进制放到各自的node目录下,再执行下面的命令

cp ~/build/bitxhub ~/build/node/
cp ~/build/raft.so ~/build/node/plugins/
bash start.sh

等待BitXHub进行共识,打印出BitXHub标志后即部署成功。