LoginSignup
3
1

More than 5 years have passed since last update.

Nekoniumのマイニングプールを立ててみよう その2 Parity-nekonium編

Last updated at Posted at 2019-01-23

はじめに

以前Nekoniumのマイニングプールを立ててみようにおいて、Go-nekoniumとopen-nekonium-poolを使用してNekoniumのマイニングプールを構築しました。

今回は最新のNekoniumクライアント「Parity-nekonium」を使用してマイニングプールを構築します。

手順

サーバーの準備

ドメインの取得

ドメインが必要な場合は、ドメイン取得代行サイトで任意のドメインを取得してください。
今回は以前取得したnuko.nekonium.siteを使用します。

サーバーの用意

Linuxサーバーを立ち上げます。
今回Google Cloud Platformで、OSは「Ubuntu 18.04LTS」、インスタンスタイプは「vCPU x 1 メモリ 3.75GB n1-standard-1」を選びました。
予算との兼ね合いもありますが、ディスクは高速で多めが望ましいです。
09686c7f60463d8960fa595d3d1bfa66.png

ファイアウォールの設定

VPCネットワークのファイアウォールルールを作成し、インスタンスに紐付けます。
今回の例ではHTTP、8008、8888、28568ポートを開けておきます。
9cfe5b7919a2aad244025bc5d51138d9.png
※追記 8080は必要ありません


937e2db211135f62267946d1b10c525f.png

固定IPの設定

VPCネットワークの「外部IPアドレス」で静的IPを取得し、インスタンスに紐付けます。
6e9d39f9cc08ae0dd53a3f860c12a520.png

詳細は割愛しますが、DNS設定も済ませておきます。

サーバーの設定

インスタンスへの接続

Windowsの場合は「PuTTY」等を使用します。
GCPはWEBコンソールも使いやすいので、そちらでも構いません。

Ubuntuのアップデート

ログインができたら、まずUbuntuをアップデートします。
sudo apt update
sudo apt upgrade

build-essentialとmakeのインストール

下記コマンドを実行してbuild-essentialおよびmakeをインストールします。
sudo apt install build-essential make

rustのインストール

下記コマンドを実行してrustをインストールします。
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env

Redisのインストール

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/
sudo mkdir /etc/redis
sudo mkdir /var/redis
sudo cp utils/redis_init_script /etc/init.d/redis_6379
sudo cp redis.conf /etc/redis/6379.conf
sudo vi /etc/redis/6379.conf 6379.confを編集します。

6379.conf

<中略>

daemonize no → daemonize yes に変更

<中略>

dir ./ → dir /var/redis/6379 に変更

sudo mkdir /var/redis/6379
sudo update-rc.d redis_6379 defaults
sudo /etc/init.d/redis_6379 start

これでRedisサーバーが起動します。

redis-cliと入力して、pingと打つとPONGが表示されれば正常に稼働しています。

redis-cliを終了する場合はexitと入力します。

nginxのインストール

下記コマンドを実行してnginxをインストールします。
cd
sudo apt install nginx

nodejsとnpmのインストール

下記コマンドを実行してnodejsとnpmをインストールします。
sudo apt install nodejs npm
sudo npm install n -g
sudo n v9
sudo npm install npm -g

古いバージョンは消しておきます。
sudo apt purge -y nodejs npm

新しいバージョンにリンクを張ります。
sudo ln -sf /usr/local/bin/node /usr/bin/node
sudo ln -sf /usr/local/bin/npm /usr/bin/npm

node -v npm -vと入力すると、それぞれバージョンが確認できます。

parity-nekoniumのインストール

下記コマンドを実行してparity-nekoniumをインストールします。
cd
sudo apt install libudev-dev libssl-dev openssl git
git clone https://github.com/mike-theminer/parity-nekonium
cd parity-nekonium
echo '1.26.2' > rust-toolchain
cargo build --release

最新のrustだとビルドに失敗するのでバージョンを下げています。

parity-nekoniumの初回起動

ブロックチェーンの同期

下記コマンドを実行してブロックチェーンの同期を行います。
target/release/parity --no-warp
少し時間がかかります。(30分以上)

同期終了

最新のブロックに追いついてImported....と表示されはじめれば同期が成功したことになります。

プール用アドレスの作成

上記セッションを維持したまま、別セッションで下記コマンドを実行してプール用のNekoniumアドレスを作成します。
~/parity-nekonium/target/release/parity account new
パスワードを求められますので、入力して忘れないようにしてください。
Address: {0xd0f68fa09e8acc9eb7b2fc709f16162e3f6344ac}
のように表示されれば、プール用アドレスの作成は完了です。

マイニングプールの設定

GoLangのインストール

下記コマンドを実行してGoをインストールします。
cd
wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz
sudo tar -xvf go1.9.2.linux-amd64.tar.gz
sudo mv go /usr/local
export GOROOT=/usr/local/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
export GOPATH=$HOME/go
go version と入力してgo version go1.9.2 linux/amd64と出力されればインストール成功です。

Open Nekonium Pool のインストール

下記コマンドを実行してOpen Nekonium Poolをインストールします。
今回はparityに最適化した最新のリポジトリを使用します。

git clone https://github.com/ROZ-MOFUMOFU-ME/open-nekonium-pool.git
cd open-nekonium-pool
make
cp config.example.json config.json
vi config.json 必要に応じてconfig.jsonファイルを編集します。

config.json

<中略>

 "unlocker": {
                "enabled": true,
                "poolFee": 1.0,
                "poolFeeAddress": "0xで始まるFee(手数料)を受け取るアドレス",
                "donate": true,
                "depth": 120,
                "immatureDepth": 20,
                "keepTxFees": false,
                "interval": "10m",
                "daemon": "http://127.0.0.1:8293",
                "timeout": "10s"
        },

        "payouts": {
                "enabled": true,
                "requirePeers": 5,
                "interval": "120m",
                "daemon": "http://127.0.0.1:8293",
                "timeout": "10s",
                "address": "0xで始まるプールのアドレス",
                "gas": "21000",
                "gasPrice": "30000000000",
                "autoGas": true,
                "threshold": 500000000,
                "bgsave": false
        },

<中略>

vi www/config/environment.js environment.jsファイルを編集します。

environment.js

<中略>

    APP: {
      // API host and port
      ApiUrl: '//nuko.nekonium.site/',

      // HTTP mining endpoint
      HttpHost: 'http://nuko.nekonium.site',
      HttpPort: 8888,

      // Stratum mining endpoint
      StratumHost: 'nuko.nekonium.site',
      StratumPort: 8008,

<中略>

プールの起動

設定ファイルの作成

下記コマンドでParity用設定ファイルを作成します。
vi ~/.local/share/io.parity.ethereum/config.toml

Parity Config Generator
こちらのサイトで設定ファイルを簡単に作ることができます。

config.toml
# This config should be placed in following path:
#   ~/.local/share/io.parity.ethereum/config.toml

[account]
# From: [0xd0f68fa09e8acc9eb7b2fc709f16162e3f6344ac] you'll be able to send transactions without password.
unlock = ["0xd0f68fa09e8acc9eb7b2fc709f16162e3f6344ac"]
# File at $HOME/.safe/password.file should contain passwords to unlock your accounts. One password per line.
password = ["/home/*username*/.safe/password.file"]

[network]
# Parity will listen for connections on port 28568.
port = 28568
# Parity will try to maintain connection to at least 5 peers.
min_peers = 5

[rpc]
# JSON-RPC over HTTP will be accessible on port 8293.
port = 8293

[mining]
# Account address to receive reward when block is mined.
author = "0xd0f68fa09e8acc9eb7b2fc709f16162e3f6344ac"
parity-nekoniumパスワードファイルの作成

下記コマンドでパスワードファイルを作成しておきます。

cd
mkdir .safe
vi .safe/password.file

password.file
<プール用アドレス作成時のパスワード>

parity-nekoniumの起動

仮想ターミナルなどを使用してparity-nekoniumを起動します。
tmux new -s parity-nekonium
~/parity-nekonium/target/release/parity

Open Nekonium Pool の起動

仮想ターミナルなどを使用してOpen Nekonium Poolを起動します。
cd
cd open-nekonium-pool
tmux new -s open-nekonium-pool
./build/bin/open-nekonium-pool config.json

フロントエンドの構築

下記コマンドを実行して、フロントエンドの設定をします。
cd www
sudo npm install -g ember-cli@2.9.1
sudo npm install -g bower
npm install
bower install
./build.sh

nginxの設定

defaultファイルの設定

下記コマンドを実行して、nginxの設定をします。
cd ~/
cd /etc/nginx/sites-enabled
sudo vi default defaultファイルを編集します。

upstream api {
     server 127.0.0.1:8080;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /home/*username*/open-nekonium-pool/www/dist;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ index.html =404;
        }

        location /api {
            proxy_pass http://api;
        }
}
nginxの再起動

下記コマンドを実行してnginxを再起動します。
sudo nginx -s reload

http://nuko.nekonium.site/ にアクセスして、
下記のような画面になればプール構築成功です。
10697c7a55d1639d274d0f57e097c4eb.png

※追記

open-nekonium-poolの自動起動について

systemd登録

システム再起動時にopen-nekonium-poolを自動起動させたい場合は、/etc/systemd/system 以下に下記のようなファイルを作り、スタートアップに登録して起動してください。

/etc/systemd/system/open-nekonium-pool.service
#Edit the path below and copy to /etc/systemd/system/

[Unit]
Description=Open-Nekonium-Pool

[Service]
Restart=on-failure

#Point to the location open-nekonium-pool files
WorkingDirectory=/home/*username*/open-nekonium-pool/

#Point to the location open-nekonium-pool files
ExecStart=/home/*username*/open-nekonium-pool/build/bin/open-nekonium-pool /home/*username*/open-nekonium-pool/config.json

ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

sudo systemctl daemon-reload
sudo systemctl enable open-nekonium-pool
sudo systemctl start open-nekonium-pool

ログはjournalctl -u open-nekonium-pool -fで監視することができます。

おわりに

今回は低負荷で接続が速いParity-nekoniumを利用してプールを構築してみました。
前回と同じ部分は省略していることがありますのでご了承ください。
もしプールを構築された場合は、NekoniumのDiscordチャンネルまでご一報頂けますと幸いです。

参考サイト

Parity によるスマートコントラクトの開発
Parity Config Generator

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1