# 高可用节点的部署方案

这个方案的主要目的在于防止由于单个节点故障导致整体无法服务,由于节点程序可能可以运行,但是存在不同步的情况,因而单纯使用 nginx 服务无法做到自动选择良好的节点。本方案中是在 nginx 和节点程序之间引入新的代理程序来解决问题,代理程序会自动的在多个节点中监控高度重量变化,每次请求只会选择正常的节点。另一个安全之处在于节点这里可以选择不同的实现,这样万一某个实现出了问题也可以有其他实现的节点顶上去。

# 部署节点

节点授权这里建议连接 venus-auth 进行授权,不然节点出问题 token 会发生变化。

venus:

#build
git clone https://github.com/filecoin-project/venus.git
git checkout <RELEASE TAG>
make
#run
./venus daemon --network <network-type> --auth-url <venus-auth url> --auth-token <venus-auth token>

lotus:

#build
git clone https://github.com/ipfs-force-community/lotus.git
git checkout <RELEASE TAG>
make <network-type>
#run
./lotus daemon --auth-url <venus-auth url> --auth-token <venus-auth token>

# 部署 chain-co

#build
git clone https://github.com/ipfs-force-community/sophon-co.git
git checkout <RELEASE TAG>
make
#run
./sophon-co  run -listen 0.0.0.0:<port> --auth <venus-auth-token:venus-auth-url> --node <token:rpc-url> --node<token:rpc-url>

# 部署代理 (可选)

代理可以有多种选择,包括 nginx,slb 等负载均衡方案,但是注意的是需要支持长链接以及自定义 header 头。这里以 nginx 为例子 安装:https://www.nginx.com/resources/wiki/start/topics/tutorials/install 配置文件参考:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

worker_rlimit_nofile 655350;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 655350;
}

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
 
    upstream websocket {
        server <endpoint>;
    }
 
    server {
        listen 34530;
      #  listen 34531 ssl; #https

      #  server_name <server name>;       

      #  access_log  /root/proxy.access.log;
      #  error_log   /root/proxy.error.log;

      #  ssl_certificate  <ssl>;
      #  ssl_certificate_key <key>;
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        location / {
            proxy_pass http://websocket;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header Authorization $http_authorization;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        }
   }
}

# 注意事项

  1. 因为节点之间数据还是分离的,所以无法提供完全一致的接口访问,特别是在头部区块的处理上。
  2. 如果部署 lotus,需要使用定制后的版本,因为 venus 有一些特有的接口。
  3. 如果存在问题,请提 issue。