# xmrig-proxy 使用教程

> 就像前面写的那样，有些时候 ISP 屏蔽了矿池，需要使用代理才能挖矿，这种情况下，使用其他代理也可以：只是加密/包装，绕过防火墙而已。但是真正的矿机代理，还有其他功能，比如减少矿池连接数：假如一个黑客…

- Source: https://acytoo.com/ladder/monero-xmrig-proxy/
- Author: acytoo
- Published: 2022-02-08
- Updated: 2022-02-17
- Language: zh-CN
- Section: ladder
- Tags: blockchain, monero, xmrig, xmrig-proxy

就像[前面](/ladder/monero-p2pool-tut)写的那样，有些时候 ISP 屏蔽了矿池，需要使用代理才能挖矿，这种情况下，使用其他代理也可以：只是加密/包装，绕过防火墙而已。但是真正的矿机代理，还有其他功能，比如减少矿池连接数：假如一个黑客，黑了全球几亿台机器，用来挖矿，如果没有代理，那么几亿台设备都连接某个矿池，首先这么多的连接，可能会被服务器当成 DDos 攻击，而且这么多的连接，矿池能不能带动也是个问题。还有，黑客也想隐藏自己有这么多矿机的事实，不想暴露。加入代理，就可以很好的解决这个问题：代理对矿机来说，就是矿池，对矿池来说，就是矿机。矿机通过代理后，对矿池不可见。同时，代理也有一定的管理功能，比如可以批量的换矿池。

<center>
<img width="900" src="/images/xmr/proxy.png">
<i>代理作为中间层，矿池看它是矿机，矿机看它是矿池</i>
</center>

xmrig-proxy 不仅能作为 Monero 的代理，还支持 Electroneum 等，详情见 [github xmrig-proxy](https://github.com/xmrig/xmrig-proxy)

但是，这个工具连个文档也没有（至少我目前没找到），官方生成配置的网站也是两年前的，不适用最新的版本，网上也没搜到最新的配置方法，只能用命令行一点点摸索着用。

--------------------------------------------
自行编译xmrig-proxy

```shell
sudo apt update && sudo apt full-upgrade -y
sudo apt install git build-essential cmake libuv1-dev uuid-dev libmicrohttpd-dev libssl-dev
git clone https://github.com/xmrig/xmrig-proxy.git
mkdir xmrig-proxy/build
cd xmrig-proxy/build
cmake ..
make -j$(nproc)
```

然后在 screen 里执行，完整的参数在后面，下面这个是我使用的参数，测试正常。```-o```是矿池地址， ```--bind```是本地绑定的地址，```--tls-bind```是绑定的 tls 域名。挖矿难度，至少设置为 hashrate 的 30 倍，一般1分钟有 1，2 个提交为好。理论上，连接 p2pool 矿池不需要在矿机上设置钱包地址，实际上单台矿机也的确如此。但是不加上 xmrig-proxy 报错（现在可能不报错了，没试）

```shell
screen -S proxy

./xmrig-proxy -o 127.0.0.1:3333 --coin monero --tls-bind p2p.acytoo.com --bind 0.0.0.0:34512 --custom-diff 55001 --custom-diff-stats -u [钱包地址]
```

下面是矿机的配置文件，矿池 url 指向了代理地址
```json
{
    "autosave": true,
    "cpu": true,
    "opencl": false,
    "cuda": false,
    "pools": [
        {
            "url": "p2p.acytoo.com:34512",
            "rig-id": "proxied-miner",
            "tls": true
        }
    ]
}
```

--------------------------------------------------------

在 Github 上找到了 xmrig-proxy 关于 tls 的[文档](https://xmrig.com/docs/proxy/tls)，原来是新版本太简单，不需要复杂的配置，全自动化了。

---------------------------------------------------------

完整的 xmrig-proxy 参数。不同版本，可能不同。
```
Usage: xmrig-proxy [OPTIONS]

Network:
  -o, --url=URL                 URL of mining server
  -a, --algo=ALGO               mining algorithm https://xmrig.com/docs/algorithms
      --coin=COIN               specify coin instead of algorithm
  -u, --user=USERNAME           username for mining server
  -p, --pass=PASSWORD           password for mining server
  -O, --userpass=U:P            username:password pair for mining server
  -x, --proxy=HOST:PORT         connect through a SOCKS5 proxy
  -k, --keepalive               send keepalived packet for prevent timeout (needs pool support)
      --rig-id=ID               rig identifier for pool-side statistics (needs pool support)
      --tls                     enable SSL/TLS support (needs pool support)
      --tls-fingerprint=HEX     pool TLS certificate fingerprint for strict certificate pinning
      --dns-ipv6                prefer IPv6 records from DNS responses
      --dns-ttl=N               N seconds (default: 30) TTL for internal DNS cache
      --daemon                  use daemon RPC instead of pool for solo mining
      --daemon-poll-interval=N  daemon poll interval in milliseconds (default: 1000)
      --self-select=URL         self-select block templates from URL
      --submit-to-origin        also submit solution back to self-select URL
  -r, --retries=N               number of times to retry before switch to backup server (default: 5)
  -R, --retry-pause=N           time to pause between retries (default: 5)
      --user-agent              set custom user-agent string for pool
      --donate-level=N          donate level, default 0%%

Options:
  -b, --bind=ADDR               bind to specified address, example "0.0.0.0:3333"
  -m, --mode=MODE               proxy mode, nicehash (default) or simple
      --custom-diff=N           override pool diff
      --custom-diff-stats       calculate stats using custom diff shares instead of pool shares
      --reuse-timeout=N         timeout in seconds for reuse pool connections in simple mode
      --no-workers              disable per worker statistics
      --access-password=P       set password to restrict connections to the proxy
      --no-algo-ext             disable "algo" protocol extension

API:
      --api-worker-id=ID        custom worker-id for API
      --api-id=ID               custom instance ID for API
      --http-host=HOST          bind host for HTTP API (default: 127.0.0.1)
      --http-port=N             bind port for HTTP API
      --http-access-token=T     access token for HTTP API
      --http-no-restricted      enable full remote access to HTTP API (only if access token set)

TLS:
      --tls-bind=ADDR           bind to specified address with enabled TLS
      --tls-gen=HOSTNAME        generate TLS certificate for specific hostname
      --tls-cert=FILE           load TLS certificate chain from a file in the PEM format
      --tls-cert-key=FILE       load TLS certificate private key from a file in the PEM format
      --tls-dhparam=FILE        load DH parameters for DHE ciphers from a file in the PEM format
      --tls-protocols=N         enable specified TLS protocols, example: "TLSv1 TLSv1.1 TLSv1.2 TLSv1.3"
      --tls-ciphers=S           set list of available ciphers (TLSv1.2 and below)
      --tls-ciphersuites=S      set list of available TLSv1.3 ciphersuites

Logging:
  -S, --syslog                  use system log for output messages
  -l, --log-file=FILE           log all output to a file
  -A  --access-log-file=FILE    log all workers access to a file
      --no-color                disable colored output
      --verbose                 verbose output

Misc:
  -c, --config=FILE             load a JSON-format configuration file
  -B, --background              run the proxy in the background
  -V, --version                 output version information and exit
  -h, --help                    display this help and exit
      --dry-run                 test configuration and exit

```
