-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxmrig-install.sh
164 lines (150 loc) · 3.69 KB
/
xmrig-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#/bin/bash
if [ "$(whoami)" != "xmrnode" ]; then
echo -e 'Error: This script should NOT be run as any other users but xmrnode.'
exit 1
fi
. ~/.bashrc
# perform clean up on any failed attempts
if [ -d ~/xmrig ]; then
rm -rf ~/xmrig
fi
if [ -f /usr/sbin/xmrnode.sh ]; then
sudo systemctl stop xmrnode.service
sudo systemctl disable xmrnode.service
sudo rm -f /usr/sbin/xmrnode.sh
sudo rm -f /etc/systemd/system/xmrnode.service
fi
# install build dependencies
sudo apt-get -y install git build-essential cmake automake libtool autoconf
# clone repository
cd /home/xmrnode
git clone https://github.com/xmrig/xmrig.git
# build
mkdir xmrig/build && cd xmrig/scripts
./build_deps.sh && cd ../build
cmake .. -DXMRIG_DEPS=scripts/deps
make -j$(nproc)
# move build result to user directory
mv ./xmrig ~/xmrig.bin
rm -rfd ~/xmrig
mkdir ~/xmrig
mv ~/xmrig.bin ~/xmrig/xmrig
# configure polkit (ubuntu/debian)
sudo tee /etc/polkit-1/localauthority/50-local.d/service-auth.pkla >/dev/null <<'EOF'
[Allow xmrnode to start/stop/restart services]
Identity=unix-user:xmrnode
Action=org.freedesktop.systemd1.manage-units
ResultActive=yes
EOF
# configure hugepages
NPROC=$(nproc)
sudo tee /etc/sysctl.d/10-hugepages.conf >/dev/null <<EOF
vm.nr_hugepages = ${NPROC}
EOF
sudo sysctl -w vm.nr_hugepages=`nproc`
for i in $(sudo find /sys/devices/system/node/node* -maxdepth 0 -type d);
do
MY_DEVFILE="$i/hugepages/hugepages-1048576kB/nr_hugepages"
if [ -f "$MY_DEVFILE" ]; then
echo 3 | sudo tee $MY_DEVFILE >/dev/null
fi
done
# configure memlock and nofile
MY_MEMLOCK=`bc -l <<< $(cat /proc/meminfo | grep -i MemTotal | awk '{print $2}')*0.90 | awk '{print int($1+0.5)}'`
sudo tee /etc/security/limits.d/60-memlock.conf >/dev/null <<EOF
* - memlock ${MY_MEMLOCK}
root - memlock ${MY_MEMLOCK}
EOF
sudo tee /etc/security/limits.d/60-nofile.conf >/dev/null <<EOF
* soft nofile 10000
root soft nofile 10000
* hard nofile 10000
root hard nofile 10000
EOF
# reload after changes
service procps force-reload
# install service script
sudo tee /usr/sbin/xmrnode.sh >/dev/null <<'EOF'
#!/bin/bash
MY_POOL="10.0.0.2:5555"
MY_WALLET="46Z4T9pKPPv82ixGexhGZW9rmMHzPyLnU9ozhewcp8EbC2QagMtz2BKdiqTCx9wo1AiVbEt8R6w1J4ad8W6NpDzRJCxQUMG"
pushd /home/xmrnode/xmrig
tee /home/xmrnode/xmrig/config.json >/dev/null <<CONFIGEOF
{
"autosave": true,
"background": false,
"colors": false,
"title": false,
"randomx": {
"init": -1,
"mode": "auto",
"1gb-pages": true,
"rdmsr": true,
"wrmsr": true,
"cache_qos": false,
"numa": true,
"scratchpad_prefetch_mode": 1
},
"cpu": true,
"opencl": false,
"cuda": false,
"pools": [
{
"algo": "rx/0",
"coin": null,
"url": "${MY_POOL}",
"user": "${MY_WALLET}",
"pass": "x",
"rig-id": null,
"nicehash": false,
"keepalive": true,
"enabled": true,
"tls": false,
"tls-fingerprint": null,
"daemon": false,
"socks5": null,
"self-select": null
}
],
"print-time": 60,
"health-print-time": 60,
"retries": 5,
"retry-pause": 5,
"syslog": false,
"tls": {
"enabled": false,
"protocols": null,
"cert": null,
"cert_key": null,
"ciphers": null,
"ciphersuites": null,
"dhparam": null
},
"user-agent": null,
"verbose": 0,
"watch": false,
"pause-on-battery": false
}
CONFIGEOF
./xmrig
popd
EOF
sudo chown xmrnode:xmrnode /usr/sbin/xmrnode.sh
sudo chmod u+x /usr/sbin/xmrnode.sh
# install service unit
sudo tee /etc/systemd/system/xmrnode.service >/dev/null <<'EOF'
[Unit]
Description=PawCloud XMR Mining Service
After=network.target
[Service]
Type=simple
User=xmrnode
Group=xmrnode
ExecStart=/bin/bash -c "/usr/sbin/xmrnode.sh"
TimeoutStartSec=0
[Install]
WantedBy=default.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable xmrnode.service
sudo systemctl start xmrnode.service