In this tutorial, I'll outline how to mine Monero using p2pool. Monero mining uses the RandomX algorithm and is CPU bound to prevent ASICs from centralizing the network.
As with almost all other cryptocurrencies, Monero is best mined in pools. Most pools are centralized, meaning one entity controls the operation of the pool. This is an issue, because if the pool gains at least 51% of the total hashing power of the network, the network's security can be compromised. To prevent this, p2pool was written.
p2pool is a open source Monero mining pool that provides the best rewards and helps prevent centralization of mining power. The pool is decentralized and is not controlled by any one entity.
Before you begin, it is important to know that due to the peer to peer nature of p2pool, all nodes connect to each other via forwarded ports and your IP will be visible by the network. There is currently no way to hide your IP, except maybe via VPN which is beyond the scope of this tutorial. This tutorial explains how to set one up.
Before you begin mining, you must first find a node to source block data from. This node must have zmq enabled for p2pool to function.
I recommend running your own node to reduce strain on the network and to increase your own privacy. You can follow this tutorial to set one up. If you cannot run a Monero node for some reason, pick the fastest node from the list here and write down the hostname, RPC_Port, and ZMQ_Port.
When using p2pool, you must run your own p2pool node to which the xmrig mining clients will connect.
To start, install p2pool from the GitHub downloads page:
~/Downloads
❯ wget "https://github.com/SChernykh/p2pool/releases/download/v4.0/p2pool-v4.0-linux-x64.tar.gz"
~/Downloads
❯ tar -xf p2pool-v4.0-linux-x64.tar.gz
~/Downloads
❯ mv p2pool-v4.0-linux-x64/ p2pool/
~/Downloads
❯ cd p2pool/
~/Downloads/p2pool
❯ realpath p2pool
/home/mcneb10/Downloads/p2pool/p2pool
You can also compile from source using the p2pool_source.tar.xz
tarball
Next, make a systemd service for p2pool:
~
❯ sudo vim /etc/systemd/system/p2pool.service
~
❯ cat /etc/systemd/system/p2pool.service
[Unit]
Description=p2pool
After=network.target
Wants=network.target
[Service]
ExecStart=/home/mcneb10/Downloads/p2pool/p2pool --wallet x --host 127.0.0.1 --rpc-port 18081 --zmq-port 18084 --stratum 0.0.0.0:3333 --mini
Restart=on-failure
RestartSec=10s
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
You'll need to make various changes to this config for your specific configuration:
ExecStart
to the path outputted by realpath
on your machine.
x
in --wallet x
with your own wallet address
--host
option and the ports after the --zmq-port
and --rpc-port
options to the hostname and ports specific to the Monero node you run (or the one wrote down earlier if you are using another node).
--stratum
option sets the address and port p2pool will bind to for accepting stratum connections. These stratum connections are for p2pool to communicate with the computers you will be mining on.0.0.0.0
to a different address.--mini
option if you are running a larger scale mining operation (around 100kH/s or higher)
You can then enable the service with:
~
❯ sudo systemctl enable --now p2pool
~
❯ sudo systemctl status p2pool
● p2pool.service - p2pool
Loaded: loaded (/etc/systemd/system/p2pool.service; enabled; preset: enabled)
Active: active (running) since Wed 2024-08-14 16:38:58 UTC; 2min 54s
...
Now that the p2pool node is set up, you can start mining!
The you can find the xmrig binaries on the releases page. Follow these steps to install:
~/Downloads
❯ wget "https://github.com/xmrig/xmrig/releases/download/v6.21.3/xmrig-6.21.3-linux-static-x64.tar.gz"
~/Downloads
❯ tar -xf xmrig-6.21.3-linux-static-x64.tar.gz
~/Downloads
❯ mv xmrig-6.21.3/ xmrig/
~/Downloads
❯ cd xmrig/
~/Downloads/xmrig
❯ realpath xmrig
/home/mcneb10/Downloads/xmrig/xmrig
Please note that the source code and precompiled xmrig binaries will donate 1% of your hashrate to the developer. You can change the code to prevent this or block the developer's server as it can compromise your privacy. The donation can be blocked by amending your hosts file like so:
~
❯ sudo vim /etc/hosts
~
❯ cat /etc/hosts
...
# Block xmrig donation
0.0.0.0 donate.v2.xmrig.com donate.ssl.xmrig.com
Be careful mining in apartments, dorms, shared living spaces, public spaces, etc. as many have explicit policies against mining that may result in your punishment.
With that out of the way, we can setup a systemd service like so:
~
❯ sudo vim /etc/systemd/system/xmrig.service
~
❯ cat /etc/systemd/system/xmrig.service
[Unit]
Description=xmrig
After=network.target
Wants=network.target
[Service]
ExecStart=/home/mcneb10/Downloads/xmrig/xmrig -o 127.0.0.1:3333 -k
Restart=on-failure
RestartSec=10s
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Again, you'll have to make some changes to the service config for your configuration:
ExecStart
to the path outputted by the realpath
command127.0.0.1:3333
with the hostname:port of your p2pool stratum server we just set up relative to your mining rigSome optimization info:
--cpu-no-yield
to the command line.
-t N
, where N is the number of threads.
I don't recommend changing this, as xmrig will chose the optimal settings for you.
Cutting down threads will reduce cpu + power usage.
You can then enable the service with:
~
❯ sudo systemctl enable --now xmrig
~
❯ sudo systemctl status xmrig
● xmrig.service - xmrig
Loaded: loaded (/etc/systemd/system/xmrig.service; enabled; preset: enabled)
Active: active (running) since Wed 2024-08-14 16:38:58 UTC; 2min 54s
...
Repeat the process for all of your mining rigs.
Make sure to periodically check for updates on p2pool, as there may be breaking changes that affect mining profitability and security.
To update the binaries for either p2pool or xmrig, simply download them and overwrite the old version. You can use commands in the installation instructions to overwrite the old one. The systemd services should continue to work fine.
--mini
option the site is at p2pool observer (onion).