Skip to content
atori.tech

3.2 XMRig

XMRig is the most widely used open-source RandomX CPU miner. Run it on the node itself, or on any computer on your LAN (desktops, laptops, spare servers), all pointed at your P2Pool stratum.

Where to mine

Mining uses 100% of the CPU cores you give it. On the node, leave cores free for monerod, or mine only on other machines. Several miners can connect to the same P2Pool.

Requirements

  • 3.1 P2Pool running, with port 3333 open to your LAN

Installation (Linux)

On the computer that will mine:

cd /tmp
VERSION=6.26.0
wget https://github.com/xmrig/xmrig/releases/download/v$VERSION/xmrig-$VERSION-linux-static-x64.tar.gz
wget https://github.com/xmrig/xmrig/releases/download/v$VERSION/SHA256SUMS
wget https://github.com/xmrig/xmrig/releases/download/v$VERSION/SHA256SUMS.sig
wget https://raw.githubusercontent.com/xmrig/xmrig/master/doc/gpg_keys/xmrig.asc

Verify

gpg --show-keys xmrig.asc

Expected fingerprint: 9AC4 CEA8 E66E 35A5 C7CD DC1B 446A 5363 8BE9 4409

gpg --import xmrig.asc
gpg --verify SHA256SUMS.sig SHA256SUMS
grep "xmrig-$VERSION-linux-static-x64.tar.gz" SHA256SUMS | sha256sum --check

Look for Good signature from "XMRig <support@xmrig.com>" and xmrig-6.26.0-linux-static-x64.tar.gz: OK.

Antivirus warnings

On Windows, antivirus tools often flag XMRig as a "coin miner" because malware bundles it. That's expected for the genuine release, which is exactly why you verify the signature instead of trusting a random download.

Install

tar -xzf xmrig-$VERSION-linux-static-x64.tar.gz
sudo install -m 0755 -o root -g root -t /usr/local/bin xmrig-$VERSION/xmrig
rm -rf /tmp/xmrig-* /tmp/SHA256SUMS* /tmp/xmrig.asc

Huge pages

RandomX is much faster (often +20–50%) with huge pages. Reserve them permanently:

echo "vm.nr_hugepages=1280" | sudo tee /etc/sysctl.d/90-hugepages.conf
sudo sysctl --system
grep HugePages_Total /proc/meminfo

1280 pages × 2 MB = 2.5 GB of RAM reserved. Make sure the machine has enough free memory.

Configuration

Create a minimal config:

sudo mkdir -p /etc/xmrig
sudo nano /etc/xmrig/config.json
{
    "autosave": false,
    "donate-level": 1,
    "cpu": {
        "enabled": true,
        "huge-pages": true,
        "max-threads-hint": 75
    },
    "pools": [
        {
            "url": "NODE_IP:3333",
            "user": "x",
            "keepalive": true,
            "tls": false
        }
    ]
}
  • url: your node's P2Pool stratum. Use 127.0.0.1:3333 when mining on the node itself.
  • user: ignored by P2Pool, because payouts go to the wallet set in P2Pool. You can put a worker name here.
  • max-threads-hint: the percentage of CPU threads to use. Lower it to keep the machine responsive.
  • donate-level: the percentage of time donated to XMRig's developers. 1 is the minimum.

Autostart on boot

sudo nano /etc/systemd/system/xmrig.service
# MoneroBox: systemd unit for XMRig
# /etc/systemd/system/xmrig.service

[Unit]
Description=XMRig Monero miner
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/xmrig --config=/etc/xmrig/config.json --no-color
Restart=on-failure
RestartSec=30
Nice=10

[Install]
WantedBy=multi-user.target

Why root?

XMRig runs as root here so it can apply MSR register tweaks, which add another 10–15% on many CPUs. If you don't want that, add User=nobody and accept the lower hashrate.

sudo systemctl daemon-reload
sudo systemctl enable --now xmrig
journalctl -fu xmrig

Validation

The first minute of the log tells you whether XMRig set itself up well. Look for lines like:

 * HUGE PAGES   supported
 * MSR          ... msr register values for "ryzen_19h" preset have been set successfully
[randomx]  use pool NODE_IP:3333
[randomx]  init dataset algo rx/0 (8 threads) seed ...
[randomx]  allocated 2336 MB (2080+256) huge pages 100% 1168/1168 +JIT
[cpu]      READY threads 8/8 (8) huge pages 100% 8/8 memory 16384 KB
[net]      new job from NODE_IP:3333 diff 300K algo rx/0 height ...
[cpu]      accepted (1/0) diff 300K (25 ms)
  • huge pages 100%: the huge pages from above work.
  • msr register values ... set successfully: the MSR tweak works (needs root).
  • accepted: P2Pool accepted your miner's work.

Then check from the node:

jq '.hashrate_15m, .connections, .shares_found' /data/p2pool/api/local/stratum

connections counts your miners, and hashrate_15m is their combined hashrate.

Windows and macOS

XMRig has releases for Windows and macOS. Download them with Tor Browser, verify them the same way, then run it with the same pools settings (xmrig.exe -o NODE_IP:3333).

Extras (optional)

Mine only when the computer is idle

On a desktop or laptop you also use, let XMRig step aside while you work. Add to config.json:

"pause-on-active": 60,
"pause-on-battery": true,
pause-on-active pauses mining while you use the keyboard or mouse, and resumes after 60 seconds of inactivity. pause-on-battery pauses whenever a laptop runs on battery.

Lower XMRig's priority

The service already runs XMRig with Nice=10. To make it yield even more to other programs, set the CPU priority in config.json (0 = idle … 5 = highest):

"cpu": { "priority": 0, ... }

Read XMRig's stats over its HTTP API

XMRig can serve its live stats as JSON. Enable it on localhost only, with an access token:

"http": {
    "enabled": true,
    "host": "127.0.0.1",
    "port": 18088,
    "access-token": "A_LONG_RANDOM_STRING",
    "restricted": true
},
curl -s -H "Authorization: Bearer A_LONG_RANDOM_STRING" http://127.0.0.1:18088/2/summary | jq '.hashrate.total'
restricted makes the API read-only.

1 GB huge pages (a few % more hashrate)

Some CPUs mine a little faster with 1 GB pages. Enable them in config.json:

"randomx": { "1gb-pages": true, ... }
When run as root on Linux, XMRig tries to reserve them itself. The start-up log shows 1GB PAGES and whether it worked. If it fails, nothing breaks: XMRig falls back to normal huge pages.

Troubleshooting

connect error: connection refused (or timed out)

XMRig can't reach P2Pool's stratum port.

  • On the node: systemctl is-active p2pool must print active, and sudo ss -tlnp | grep 3333 must show it listening on 0.0.0.0:3333.
  • The firewall must have a rule for 3333: sudo ufw status | grep 3333.
  • When mining on the node itself, use 127.0.0.1:3333 in config.json.
huge pages 0% in the log

The huge pages aren't reserved. Check with grep HugePages_Total /proc/meminfo. If it shows 0, run sudo sysctl --system again, or reboot. If it shows fewer than you set, the machine didn't have enough free memory: reboot, so memory is reserved before other programs start.

Hashrate is much lower than expected
  • Check the log for huge pages 100% and the MSR line (see Validation).
  • Lower max-threads-hint if the machine also runs monerod and P2Pool: competing for CPU slows everything down.
  • Check CPU temperature with sensors (from the lm-sensors package). A hot CPU throttles itself.

Upgrade

Repeat Installation with the new VERSION, then:

sudo systemctl restart xmrig

Uninstall

sudo systemctl disable --now xmrig
sudo rm /etc/systemd/system/xmrig.service /usr/local/bin/xmrig
sudo rm -rf /etc/xmrig
sudo rm /etc/sysctl.d/90-hugepages.conf     # frees the reserved RAM after a reboot