Skip to content

Ubuntu Server with XMRig Installation

BK edited this page Feb 1, 2024 · 11 revisions

Description

This guide shows you how to build XMRig from source, and have it automatically start up whenever you reboot your server.

The user being used is named miner, so throughout the instructions, amend user if yours is different ! Where you see COIN, substitute this to the coin's Ticker, e.g. xmr

Installation

Pre-requisites

These are all required before you proceed:

  1. Ubuntu Server with OpenSSH Server installed and configured for access.
  2. The COIN you are mining, e.g. xmr.
  3. Pool port, typically 100nn, nn being the last to digits unique to the pool. See our Discord for port list for guidance. e.g. 10009
  4. Your Wallet Address for the COIN.
  5. SSH client connected to the server.

Build XMRig from Source

NOTE: To leave a donation for the developers for their hard work, skip this line sed -i 's/5\;/0\;/g' xmrig/src/donate.h && sed -i 's/1\;/0\;/g' xmrig/src/donate.h

Let's build XMRig from source:

cd ~
sudo apt install git build-essential cmake libuv1-dev libssl-dev libhwloc-dev sed
git clone https://github.com/xmrig/xmrig.git
sed -i 's/5\;/0\;/g' xmrig/src/donate.h && sed -i 's/1\;/0\;/g' xmrig/src/donate.h
mkdir xmrig/build && cd xmrig/build
cmake ..
make -j$(nproc)
mkdir ~/XMRig
mv xmrig ~/XMRig/xmrig
cd ~
sudo rm xmrig -r

Enable Hugepages

This will increase your hashing performance:

Edit the file /etc/sysctl.conf using your preferred editor, use sudo to elevate your permissions, adding the following to the end of the file:

vm.nr_hugepages=1024

Download the GNTL custom config.json file

cd ~/XMRig
wget -O config.json https://raw.githubusercontent.com/The-GNTL-Project/Configs/master/XMRig_config.json

Edit the config.json file, adding Pool, Wallet and Worker name

Edit the file ~/XMRig/config.json using your preferred editor, adding for example:

"url": "pool.gntl.uk:10007",
"user": "gnt1ibrAtYtThQWQ8QdeLPWGD9ZeqnDsJ9A4d86DMC2RD7frBSE1uZmFezsbW7TXHdNHYWDWsccRo8TpE55p2HWR74ofajRWc5",
"pass": "Desktop01",

Create a Service to run XMRig

We will run our XMRig instance in a screen session, so you can attach and detach to it to monitor it. Create the file /etc/systemd/system/mining.service using your preferred editor, use sudo to elevate your permissions:

[Unit]
Description=Mining Service

[Service]
LimitMEMLOCK=infinity
Type=forking
RemainAfterExit=yes
User=miner
WorkingDirectory=/home/miner
ExecStart=/home/miner/StartMining
KillMode=none

[Install]
WantedBy=multi-user.target

Create a Startup file

This is what the service runs. We have separated this, as it's easier to add/remove additional commands, without having to modify the service file. We will run our XMRig instance in a screen session, so you can attach and detach to it to monitor it.

Create the file ~/StartMining using your preferred editor:

#!/bin/sh
screen -dmS Mine sudo /home/miner/XMRig/xmrig

Set permissions for the Service and Startup files

Let's now grant the required permissions for this to work:

sudo systemctl daemon-reload
sudo systemctl enable mining
sudo chmod 0755 ~/StartMining

Run the Miner

Simply reboot the server, which will start the miner on the next boot.

sudo reboot

Monitor Miner

A few commands to monitor the miner:

  1. Attach to the screen session using screen -r, so you can view connection, errors, hashrate, etc.
  2. De-attach from the screen session using CTRL A D, so you can leave it running in the background.