※本内容は技術的な観点のみとし、マイニングの収益性などの部分には触れません。
2021年05月18日現在、仮想通貨は急激な上昇から、下落に転じ、イーロン・マスクの言動で一喜一憂するような状況ですが、マイニング掘削に関する記事を検索しても、なかなかこれと言った記事が見当たらなかったので、執筆してみます。
今回はマイニングプールを利用します。
あらかじめ自分のEthereumウォレットを用意しておいてください。
また、2021年05月18日現在、Ethereum の DAG (Directed Acyclic Graph) は4GBを超えていますので、GPUメモリが4GB以下の環境ではそもそもマイニングができません。あしからず。
今回は検証のため下記のような環境で構築します。
Ubuntu 20.04 LTS
NVIDIA Tesla V100
nsfminer 1.3.13-14+commit.5488267c https://github.com/no-fee-ethereum-mining/nsfminer
$ uname -a
Linux gpu-mining 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
$ lspci | grep -i nvidia
00:04.0 3D controller: NVIDIA Corporation GV100GL [Tesla V100 PCIe 32GB] (rev a1)
$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 465.19.01 Fri Mar 19 07:44:41 UTC 2021
GCC version: gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0
$ nsfminer -V
nsfminer 1.3.13-14+commit.5488267c (No stinkin' fees edition)
Copyright 2021 Jean M. Cyr, Licensed under the terms
of the GNU General Public License Version 3
https://github.com/no-fee-ethereum-mining/nsfminer
Build: linux/release/gnu
3rd Party: GCC 9.3.0, CUDA 11.3, Boost 1.76.0
3rd Party: OpenSSL 1.1.1j 16 Feb 2021
Running as user: root
#準備
##CUDAインストール
NVIDIA CUDA Installation Guide for Linux に従って入れます
https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
今回はパッケージで入れたいと思いますので、
2. Pre-installation Actions
3. Package Manager Installation
7. Post-installation Actions
こちらを進めれば良いです。
# Kernel Headerなど必要なものを入れる
sudo apt-get -y install software-properties-common linux-headers-$(uname -r)
# aptプライオリティpinファイルをDL
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
# aptプライオリティpinファイルをaptのフォルダに移動
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
# GPGキーをインポート
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
リポジトリを登録
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
# リポジトリ更新
sudo apt-get update
# CUDAインストール
sudo apt-get -y install cuda
# パスを通す
echo 'export PATH=/usr/local/cuda-11.6/bin${PATH:+:${PATH}}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
source ~/.bashrc
インストールが完了したら再起動し、 nvidia-smi にてドライバインストールも含め完了しているか確認しましょう。
$ nvidia-smi
Tue May 18 21:36:49 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 465.19.01 Driver Version: 465.19.01 CUDA Version: 11.3 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA Tesla V1... On | 00000000:00:04.0 Off | 0 |
| N/A 32C P0 7W / 250W | 1MiB / 32510MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
##nsfminerインストール
Building from source
https://github.com/no-fee-ethereum-mining/nsfminer/blob/master/docs/BUILD.md
こちら基づいてインストールします。
# 必要パッケージをインストール
sudo apt-get update -qq && sudo apt-get -y install autoconf automake build-essential cmake git-core libssl-dev
# githubからnsfminerをclone
git clone https://github.com/no-fee-ethereum-mining/nsfminer
# nsfminerディレクトリに移動
$ cd nsfminer
# 再帰的に git submodule update
$ git submodule update --init --recursive
# build作業用ディレクトリに移動
$ mkdir build
$ cd build
# CUDA有効にしてcmake
$ cmake .. -DETHASHCUDA=ON -DETHASHCL=OFF
# ビルド
$ cmake --build .
# インストール
$ sudo make install
これで nsfminer がインストールされます。
$ which nsfminer
/usr/local/bin/nsfminer
#採掘
マイニングプールを使ってマイニングをします。
Pool Examples for ETH
https://github.com/no-fee-ethereum-mining/nsfminer/blob/master/docs/POOL_EXAMPLES_ETH.md
上記にコマンドリファレンスやマイニングプールごとのサンプルもあります。
https://ethermine.org/
ethermine.orgの例だと
ethermine.org
Non-SSL connection:
-P stratum1+tcp://ETH_WALLET.WORKERNAME@asia1.ethermine.org:4444
-P stratum1+tcp://ETH_WALLET.WORKERNAME@eu1.ethermine.org:4444
-P stratum1+tcp://ETH_WALLET.WORKERNAME@us1.ethermine.org:4444
-P stratum1+tcp://ETH_WALLET.WORKERNAME@us2.ethermine.org:4444
SSL connection:
-P stratum1+ssl://ETH_WALLET.WORKERNAME@asia1.ethermine.org:5555
-P stratum1+ssl://ETH_WALLET.WORKERNAME@eu1.ethermine.org:5555
-P stratum1+ssl://ETH_WALLET.WORKERNAME@us1.ethermine.org:5555
-P stratum1+ssl://ETH_WALLET.WORKERNAME@us2.ethermine.org:5555
と記載があるので、Non-SSLのasia1で掘りたい場合
nsfminer --report-hashrate -U -P stratum1+tcp://0xで始まる自分のETH_WALLET.ethermineで表示させたいWORKERNAME@asia1.ethermine.org:4444
みたいな感じになります。
※ --report-hashrate はethermine.org みたいなマイニングソフトからハッシュレートをマイニングプールに通知する場合必要なオプションです。実際には無くても掘れ、マイニングプールでの表示の問題だけです。
22:28:16 miner 1:51 A74 87.25 Mh - cu0 87.25
22:28:21 miner 1:51 A74 87.24 Mh - cu0 87.24
22:29:04 miner **Accepted 95 ms. asia1.ethermine.org:4444
こんな感じでハッシュレートが表示されたりAccepted表示が出てれば問題ありません。
#Systemdのserviceにする
サーバの意図せぬ再起動に対応するため、systemdのサービスにします。
# log出力先を作成
sudo mkdir /var/log/nsfminer/
sudo touch /var/log/nsfminer/nsfminer.log
sudo touch /var/log/nsfminer/nsfminer_error.log
# nsfminer.service を作る (内容は別途記載)
sudo vi /etc/systemd/system/nsfminer.service
# nsfminer.service 有効化
sudo systemctl enable nsfminer.service
# nsfminer.service 起動
sudo systemctl start nsfminer.service
# nsfminer.service ステータス確認
sudo systemctl status nsfminer.service
/etc/systemd/system/nsfminer.service の中身
※必ずExecStartから始まる行の ETH_WALLET を自分のものへ、 WORKERNAME を適当なものに書き換えてください。
[Unit]
Description=nsfminer
After=network-online.target
[Service]
User=ubuntu
Group=ubuntu
TimeoutStopSec=90
WorkingDirectory=/home/ubuntu/
ExecStart=nsfminer --report-hashrate -U -P stratum1+tcp://0xで始まる自分のETH_WALLET.ethermineで表示させたいWORKERNAME@asia1.ethermine.org:4444
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
StandardOutput=append:/var/log/nsfminer/nsfminer.log
StandardError=append:/var/log/nsfminer/nsfminer_error.log
[Install]
WantedBy=multi-user.target
問題なく実行できているか
systemctl status nsfminer.serviceで確認しましょう。
$ sudo systemctl status nsfminer.service
● nsfminer.service - nsfminer
Loaded: loaded (/etc/systemd/system/nsfminer.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-05-18 22:43:34 JST; 7min ago
Main PID: 1261 (miner)
Tasks: 6 (limit: 67446)
Memory: 120.3M
CGroup: /system.slice/nsfminer.service
└─1261 /usr/local/bin/nsfminer --report-hashrate -U -P stratum1+tcp://0x---------.workername@a>
May 18 19:13:34 gpu-mining systemd[1]: Started nsfminer.
lines 1-10/10 (END)
Active: active (running) が確認できれば問題ありません。
ちなみに StandardOutput=append: でログを吐き出す方法は systemd 240 以降の環境が必要です。
Ubuntu20.04は対応しています。
$ systemd --version
systemd 245 (245.4-4ubuntu3.6)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid
あとは、マイニングプールのWebページで自分のwalletアドレスを入れたりすると採掘状況が確認できます。