# XMRig 挖矿

在 Clore.ai 的 GPU 和 CPU 服务器上使用 XMRig 挖掘 Monero (XMR) 及其他加密货币。

{% hint style="info" %}
**XMRig** 是最广泛使用的开源加密货币矿工。它支持 CPU 挖矿（Monero 的 RandomX 算法）和 GPU 挖矿（KawPow、Ethash 等）。本指南涵盖在 Clore.ai 服务器上的部署。
{% endhint %}

{% hint style="warning" %}
**在开始之前**：在挖矿之前务必计算盈利性。考虑 Clore.ai 的租用成本、矿池费用和当前币价。使用挖矿盈利计算器确保您能获得正收益。
{% endhint %}

***

## 什么是 XMRig？

XMRig 是一个高性能、跨平台的 CPU 与 GPU 矿工：

| 功能             | 详细信息                                         |
| -------------- | -------------------------------------------- |
| **CPU 挖矿**     | 通过 RandomX 挖掘 Monero (XMR) — 最佳使用场景          |
| **GPU 挖矿**     | KawPow（RVN）、Ethash 变种、Octopus                |
| **算法**         | RandomX、KawPow、Ethash、Autolykos2、Octopus 及更多 |
| **Stratum V2** | 支持现代矿池协议                                     |
| **TLS 支持**     | 加密的矿池连接                                      |
| **许可**         | GPL 3.0，开源                                   |

### 为什么选择 Clore.ai 运行 XMRig？

* **高核心数 CPU**：Clore.ai 服务器通常具有 32–128 个 CPU 核心 — 非常适合 RandomX
* **现货定价**：在非高峰时段可廉价租用
* **无需硬件投入**：无需购买和维护硬件即可挖矿
* **灵活性**：可根据盈利性切换算法或币种

***

## 先检查盈利性

{% hint style="danger" %}
**在花费一分钱租赁费用之前先这样做！**

挖矿盈利性每天都在变化。开始前务必核实。
{% endhint %}

### 盈利性计算器

* [minerstat.com/calc](https://minerstat.com/calc) — 多算法
* [whattomine.com](https://whattomine.com) — 综合性
* [xmrig.com/docs/algorithms](https://xmrig.com/docs/algorithms) — 算力参考

### 快速计算

```
每日利润 =（每日奖励美元）-（每日租用成本）

示例（Monero，32 核服务器）：
- 算力：约 32,000 H/s（每核约 1,000 H/s）
- 每日 XMR 奖励：约 0.001–0.003 XMR/天
- XMR 价格（示例）：$160
- 每日收入：$0.16–0.48
- 服务器租用（32 核，约 $0.20/小时）：$4.80/天

结果：负收益。高核心服务器通常不适合单独挖矿获利。

更好的方法：寻找租金低于每日奖励的廉价高核心数服务器
```

{% hint style="success" %}
**什么时候有意义**：当你找到 64+ 核且每小时 $0.05–0.10 的服务器，或以低现货价租到用于 GPU 挖矿的 GPU 服务器时。始终先计算！
{% endhint %}

***

## 先决条件

| 要求          | 详细信息                             |
| ----------- | -------------------------------- |
| Clore.ai 账户 | 拥有 CLORE 余额                      |
| 矿池账户        | 在 supportXMR.com、MoneroOcean 等创建 |
| Monero 钱包   | 在 getmonero.org 下载（用于 XMR 挖矿）    |
| SSH 访问      | 端口 22                            |

### 创建 Monero 钱包

```bash
# 选项 1：CLI 钱包
wget https://downloads.getmonero.org/cli/linux64
tar xzf monero-linux-x64-*.tar.bz2
./monero-x86_64-linux-gnu-v*/monero-wallet-cli --generate-new-wallet mywallet

# 选项 2：GUI 钱包（本地机器）
# 从下载： https://www.getmonero.org/downloads/
```

保存你的钱包地址 — 它看起来像：

```
43xxxx...长字符串...xxxx
```

***

## 第 1 步：租用服务器

### 用于 CPU 挖矿（Monero/RandomX）

1. 前往 [clore.ai](https://clore.ai) → **市场**
2. 筛选条件 **CPU 核心数**：建议 32+ 核
3. 寻找具有高 CPU 线程数的服务器
4. 端口 **22** 已足够
5. 下单租用服务器

### 用于 GPU 挖矿（KawPow、Octopus）

1. 筛选条件 **GPU**：RTX 3080+、RTX 4090 可获得最佳性能
2. 所需端口： **22** 仅
3. 仅限 NVIDIA GPU 用于 CUDA 挖矿

{% hint style="info" %}
**Clore.ai 上的 CPU 与 GPU**：Clore.ai 主要是一个 GPU 市场。对于 Monero（RandomX），专用 CPU 服务器可能更便宜。对于 GPU 可挖的币种，NVIDIA 服务器提供更好性能。
{% endhint %}

***

## 第 2 步：通过 Docker 部署 XMRig

### 自定义 Dockerfile

创建一个 `Dockerfile` 在服务器上：

```dockerfile
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

# 安装依赖项
RUN apt-get update && apt-get install -y \
    wget \
    libssl-dev \
    libhwloc-dev \
    libuv1-dev \
    build-essential \
    cmake \
    git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /opt/xmrig

# 下载 XMRig 发布版
RUN wget https://github.com/xmrig/xmrig/releases/download/v6.21.3/xmrig-6.21.3-linux-static-x64.tar.gz \
    && tar xzf xmrig-*.tar.gz \
    && mv xmrig-*/xmrig . \
    && rm -rf xmrig-*.tar.gz xmrig-*/

# 创建配置目录
RUN mkdir -p /etc/xmrig

ENTRYPOINT ["/opt/xmrig/xmrig"]
```

### 构建镜像

```bash
docker build -t xmrig-miner .
```

### 运行 CPU 挖矿（Monero）

```bash
docker run -d \
  --name xmrig-cpu \
  --restart unless-stopped \
  --privileged \
  xmrig-miner \
  -o pool.supportxmr.com:443 \
  -u YOUR_MONERO_WALLET_ADDRESS \
  -p worker1 \
  -k \
  --tls \
  --cpu-max-threads-hint=100 \
  --log-file=/var/log/xmrig.log
```

### 运行 GPU 挖矿（KawPow - Ravencoin）

```bash
docker run -d \
  --name xmrig-gpu \
  --restart unless-stopped \
  --gpus all \
  xmrig-miner \
  -a kawpow \
  -o rvn.2miners.com:6060 \
  -u YOUR_RVN_WALLET.worker1 \
  --log-file=/var/log/xmrig.log
```

***

## 第 3 步：配置文件方法

使用配置文件比命令行参数更整洁。

### 创建 `config.json`

```json
{
    "autosave": true,
    "background": false,
    "colors": true,
    "title": true,
    "api": {
        "id": null,
        "worker-id": "clore-worker-1",
        "port": 9090,
        "access-token": null,
        "restricted": true
    },
    "http": {
        "enabled": true,
        "host": "0.0.0.0",
        "port": 9090,
        "access-token": null,
        "restricted": true
    },
    "randomx": {
        "init": -1,
        "init-avx2": -1,
        "mode": "auto",
        "1gb-pages": false,
        "rdmsr": true,
        "wrmsr": true,
        "cache_qos": false,
        "numa": true,
        "scratchpad_prefetch_mode": 1
    },
    "cpu": {
        "enabled": true,
        "huge-pages": true,
        "huge-pages-jit": false,
        "hw-aes": null,
        "priority": null,
        "memory-pool": false,
        "yield": true,
        "max-threads-hint": 100,
        "asm": true,
        "argon2-impl": null,
        "astrobwt-max-size": 550,
        "astrobwt-avx2": false
    },
    "opencl": {
        "enabled": false,
        "cache": true,
        "loader": null,
        "platform": "AMD"
    },
    "cuda": {
        "enabled": true,
        "loader": null,
        "nvml": true
    },
    "log-file": null,
    "donate-level": 1,
    "donate-over-proxy": 1,
    "pools": [
        {
            "algo": null,
            "coin": "XMR",
            "url": "pool.supportxmr.com:443",
            "user": "YOUR_MONERO_WALLET_ADDRESS",
            "pass": "worker1",
            "rig-id": null,
            "nicehash": false,
            "keepalive": true,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
    ],
    "print-time": 60,
    "health-print-time": 60,
    "dmi": true,
    "retries": 5,
    "retry-pause": 5,
    "syslog": false,
    "tls": {
        "enabled": false,
        "protocols": null,
        "cert": null,
        "cert_key": null,
        "ciphers": null,
        "ciphersuites": null,
        "dhparam": null
    },
    "dns": {
        "ipv6": false,
        "ttl": 30
    },
    "user-agent": null,
    "verbose": 0,
    "watch": true
}
```

将 `YOUR_MONERO_WALLET_ADDRESS` 替换为你的实际钱包地址。

### 使用配置文件运行

```bash
docker run -d \
  --name xmrig \
  --restart unless-stopped \
  --privileged \
  -v $(pwd)/config.json:/etc/xmrig/config.json \
  xmrig-miner \
  --config=/etc/xmrig/config.json
```

***

## 第 4 步：启用大页（性能提升）

RandomX 在 1GB 大页下受益显著。在主机上启用：

```bash
# 启用大页（以 root 身份在 Clore.ai 服务器上运行）
echo 1 > /proc/sys/vm/nr_hugepages

# 对于 1GB 大页（如果 CPU 支持）
mkdir -p /mnt/hugepages-1g
mount -t hugetlbfs -o pagesize=1G none /mnt/hugepages-1g
echo 4 > /proc/sys/vm/nr_hugepages

# 使其持久化
echo "vm.nr_hugepages = 128" >> /etc/sysctl.conf
sysctl -p
```

{% hint style="info" %}
**性能影响**：在某些 CPU 上，大页可将 Monero 算力提高 20–50%。如果你能访问主机系统，值得启用。
{% endhint %}

***

## 第 5 步：监控挖矿

### 检查容器状态

```bash
# 查看实时日志
docker logs xmrig -f

# 通过 API 检查统计
curl http://localhost:9090/2/summary | python3 -m json.tool
```

### 示例日志输出

```
[2024-03-01 10:15:23.456]  miner    speed 10s/60s/15m 31.2k 31.4k 31.1k H/s max 32.1k H/s
[2024-03-01 10:15:30.123]  net      accepted (1/0) diff 200001 (123 ms)
[2024-03-01 10:16:00.789]  miner    speed 10s/60s/15m 31.5k 31.3k 31.2k H/s max 32.1k H/s
```

### 要关注的关键指标

| 指标      | 含义           |
| ------- | ------------ |
| H/s（算力） | 挖矿速度 — 值越高越好 |
| 已接受的份额  | 提交到矿池的有效工作   |
| 被拒绝的份额  | 无效工作 — 应接近 0 |
| 延迟      | 矿池连接速度       |

### 矿池仪表板

在你所用矿池的网站上检查你的进度：

* **SupportXMR**: `https://supportxmr.com/#/dashboard?wallet=YOUR_ADDRESS`
* **MoneroOcean**: `https://moneroocean.stream/#/dashboard?wallet=YOUR_ADDRESS`
* **2Miners**: `https://xmr.2miners.com/account/YOUR_ADDRESS`

***

## 流行的矿池

### Monero (XMR) 矿池

| 矿池          | URL                         | 费用   | 最低支付      |
| ----------- | --------------------------- | ---- | --------- |
| SupportXMR  | pool.supportxmr.com:443     | 0.6% | 0.1 XMR   |
| MoneroOcean | gulf.moneroocean.stream:443 | 0%   | 0.003 XMR |
| XMRig 矿池    | pool.xmrig.com:443          | 1%   | 0.01 XMR  |
| MineXMR     | pool.minexmr.com:4444       | 1%   | 0.004 XMR |

### 支持 GPU 挖矿的币种

| 币种                     | 算法         | 矿池示例                 |
| ---------------------- | ---------- | -------------------- |
| Ravencoin (RVN)        | KawPow     | rvn.2miners.com:6060 |
| Ergo (ERG)             | Autolykos2 | erg.2miners.com:8888 |
| Conflux (CFX)          | Octopus    | cfx.2miners.com:4040 |
| Ethereum Classic (ETC) | Etchash    | etc.2miners.com:1010 |

{% hint style="info" %}
**MoneroOcean 有其特殊之处**：它会根据任意时刻的盈利情况自动切换你的矿工到最有利可图的算法，同时仍以 XMR 支付。非常适合最大化收益。
{% endhint %}

***

## MoneroOcean：自动盈利切换

MoneroOcean 会自动挖掘最有利的算法：

```bash
docker run -d \
  --name xmrig-mo \
  --restart unless-stopped \
  --privileged \
  xmrig-miner \
  --algo=rx/0 \
  -o gulf.moneroocean.stream:443 \
  -u YOUR_MONERO_WALLET \
  -p "YOUR_WORKER:PERFORMANCE_FEE" \
  --tls \
  --cpu-max-threads-hint=95
```

***

## 优化建议

### CPU 优化

```bash
# 使用所有 CPU 线程
--cpu-max-threads-hint=100

# 设置 CPU 优先级（0=最低，5=最高）
--cpu-priority=3

# 禁用 yield（不要与其他进程共享 CPU）
--no-yield

# 启用 AVX2 以加速 RandomX
#（如果 CPU 支持则自动启用）
```

### GPU 优化（CUDA）

```json
"cuda": {
    "enabled": true,
    "loader": null,
    "nvml": true,
    "devices": [
        {
            "index": 0,
            "threads": 512,
            "blocks": 0,
            "bfactor": 0,
            "bsleep": 0,
            "affinity": -1
        }
    ]
}
```

### 双挖（CPU + GPU）

```json
"cpu": {
    "enabled": true,
    "max-threads-hint": 100
},
"cuda": {
    "enabled": true,
    "nvml": true
}
```

***

## 安全注意事项

{% hint style="warning" %}
**挖矿安全检查清单：**

* 尽可能不要以 root 身份运行矿工
* 不要将 XMRig 的 API 端口（9090）公开暴露
* 使用与矿池的 TLS 连接（`--tls` 标志）
* 保持 XMRig 更新以修补漏洞
* 监控异常的 CPU/GPU 使用峰值
  {% endhint %}

### 保护 API 端点

```json
"api": {
    "port": 9090,
    "access-token": "your-secret-token-here",
    "restricted": true
}
```

```bash
# 使用令牌访问
curl -H "Authorization: Bearer your-secret-token-here" \
     http://localhost:9090/2/summary
```

***

## 自动化盈利监控脚本

```bash
#!/bin/bash
# monitor-mining.sh

WALLET="YOUR_WALLET_ADDRESS"
RENTAL_COST_PER_HOUR=0.50  # 你在 Clore.ai 的美元成本

while true; do
  # 获取当前算力
  HASHRATE=$(curl -s http://localhost:9090/2/summary | \
             python3 -c "import sys,json; d=json.load(sys.stdin); print(d['hashrate']['total'][0])")
  
  echo "$(date): Hashrate: ${HASHRATE} H/s"
  echo "$(date): 小时成本: \$${RENTAL_COST_PER_HOUR}"
  
  # 检查已接受的份额
  ACCEPTED=$(curl -s http://localhost:9090/2/summary | \
             python3 -c "import sys,json; d=json.load(sys.stdin); print(d['results']['shares_good'])")
  echo "$(date): 已接受的份额: ${ACCEPTED}"
  
  sleep 300  # 每 5 分钟检查一次
done
```

***

## 故障排除

### 算力低

```bash
# 检查容器内的 CPU 分配
docker exec xmrig cat /proc/cpuinfo | grep processor | wc -l

# 确保已启用大页
cat /proc/sys/vm/nr_hugepages

# 检查是否存在热节流
watch -n1 "sensors 2>/dev/null | grep temp || cat /sys/class/thermal/thermal_zone*/temp"
```

### 连接问题

```bash
# 测试矿池连通性
curl -k telnet://pool.supportxmr.com:443

# 如果被阻止，使用替代矿池
# 试试： xmr.pool.minergate.com:443
```

### CUDA 错误

```bash
# 验证容器中的 GPU 访问
docker exec xmrig-gpu nvidia-smi

# 如果缺失，请在 docker run 时添加 --gpus all
docker stop xmrig-gpu
docker rm xmrig-gpu
# 使用 --gpus all 重新运行
```

### 容器不断重启

```bash
# 检查退出代码
docker inspect xmrig --format='{{.State.ExitCode}}'

# 查看详细日志
docker logs xmrig --since 5m

# 常见原因：
# - 无效的钱包地址
# - 矿池连接失败
# - 配置文件语法错误
```

***

## 法律与道德说明

{% hint style="info" %}
**重要注意事项：**

1. **检查 Clore.ai 使用条款**：确保在你租用的服务器上允许挖矿
2. **税务合规**：挖矿所得的加密货币在你的司法辖区可能被视为应税收入
3. **盈利性**：云端挖矿通常不盈利 — 先做你的计算
4. **网络效应**：挖矿有助于区块链安全（正面贡献）
   {% endhint %}

***

## 快速参考

### 命令行参数

| 参数                         | 描述                 |
| -------------------------- | ------------------ |
| `-o URL`                   | 矿池地址               |
| `-u ADDRESS`               | 钱包地址               |
| `-p WORKER`                | 工作名                |
| `-a ALGO`                  | 算法（Monero 使用 rx/0） |
| `--tls`                    | 启用 TLS 加密          |
| `-k`                       | 保持连接（Keepalive）    |
| `--cpu-max-threads-hint=N` | 使用 N% 的 CPU 线程     |
| `--donate-level=0`         | 禁用开发者捐赠            |

### 算法参考

| 算法         | 币种              | 最佳硬件         |
| ---------- | --------------- | ------------ |
| rx/0       | Monero (XMR)    | CPU（RandomX） |
| kawpow     | Ravencoin (RVN) | GPU          |
| autolykos2 | Ergo (ERG)      | GPU          |
| 章鱼         | Conflux (CFX)   | GPU          |
| etchash    | 以太经典            | GPU          |

***

## 有用的链接

* [XMRig GitHub](https://github.com/xmrig/xmrig)
* [XMRig 文档](https://xmrig.com/docs)
* [WhatToMine 计算器](https://whattomine.com)
* [MoneroOcean 矿池](https://moneroocean.stream)
* [SupportXMR 矿池](https://supportxmr.com)
* [Clore.ai 市场](https://clore.ai)

***

## 总结

| 步骤 | 操作                            |
| -- | ----------------------------- |
| 1  | 首先计算盈利能力                      |
| 2  | 在 getmonero.org 创建门罗钱包        |
| 3  | 在一个矿池注册                       |
| 4  | 租用服务器（XMR 使用 CPU 内核，其他使用 GPU） |
| 5  | 构建 XMRig Docker 镜像            |
| 6  | 在 config.json 中配置钱包和矿池        |
| 7  | 启用大页以提升 20-50% 算力             |
| 8  | 开始挖矿并通过矿池仪表盘监控                |

Clore.ai 上的 XMRig 可按需提供高性能挖矿硬件。策略性使用——在价格高且租用成本低时挖矿。始终先算清账。⛏️

***

## Clore.ai 的 GPU 建议

| 在 Clore.ai 上的预估费用 | 开发/测试          | RTX 3090（24GB） |
| ----------------- | -------------- | -------------- |
| 入门级挖矿             | RTX 3080（10GB） | 约 $0.08/显卡/小时  |
| 优化挖矿              | 生产             | RTX 4090（24GB） |
| 高性能挖矿             | 大规模            | A100 80GB      |

> GPU 服务器上。浏览可用 GPU 并按小时租用 — 无需承诺，提供完整的 root 访问权限。 [Clore.ai](https://clore.ai/marketplace) GPU 服务器。浏览可用 GPU 并按小时租用 — 无需承诺，提供完整的 root 访问权限。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/jia-mi-huo-bi-yu-wa-kuang/xmrig.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
