---
# System prepended metadata

title: 矿池代理部署方案

---

# 矿池代理部署方案

### 矿池延时

本地ping矿池
eth-sg.flexpool.io		73ms
asia1.ethermine.org		226ms
aspac1-eth.hiveon.net	315ms  有丢包

香港azure机房ping矿池
eth-sg.flexpool.io		34ms
asia1.ethermine.org 		2.5ms
aspac1-eth.hiveon.net 	34ms

香港rackspace机房ping矿池
eth-sg.flexpool.io		31ms
asia1.ethermine.org 		1.9ms
aspac1-eth.hiveon.net 	30-40ms

### 代理方案
![](https://i.imgur.com/aeIU6ck.png)
1. cheny在多个香港机房创建多台机器，用作代理服务器，代理服务器部署haproxy或nginx实现到矿池的TCP反向代理

2. 每个代理服务器监听5555/5556/5557端口，分别转发到三个矿池的SSL挖矿端口
5555 》asia1.ethermine.org:5555
5556 》eth-sg.flexpool.io:5555
5557 》aspac1-eth.hiveon.net:24443

3. 每台矿机的hiveos(ubuntu)系统上，均安装Haproxy，实现负载均衡和代理IP故障自动切换，Haproxy监听127.0.0.1:5554，后端对应cheny提供的来自多个香港机房的反向代理IP

4. 矿机上haproxy配置示例

    frontend hiveon
        mode tcp
        bind :5554
        default_backend hiveon_backend

    backend hiveon_backend
        mode tcp
        server hk1 119.9.77.185:5557 weight 1 check inter 1s rise 2 fall 2
        server hk2 119.9.77.29:5557 weight 1 check inter 1s rise 2 fall 2
        server hk3 23.92.32.46:5557 weight 1 check inter 1s rise 2 fall 2

5. 以上面的配置为例，NBminer只需连接127.0.0.1:5554即可，Haproxy会在
    119.9.77.185:5557
    119.9.77.29:5557
    23.92.32.46:5557
    三个反向代理中随机选择一个创建连接，如果出现网络故障，Haproxy会自动切换到另外一个代理IP
    
6. 修改矿机的HOSTS文件，比如 asia1.ethermine.org 到 127.0.0.1
配置矿机NBminer连接矿池asia1.ethermine.org:5554即可

7. 批量安装
初期使用python脚本在矿场局域网内执行，自动批量连接矿机的ssh端口，借助ssh协议和sftp协议给所有矿机批量安装和配置haproxy

