見出し画像

Raspberry Pi で Astar Node 動かす②

「Raspberry Pi で Astar Node 動かす①」の続きです。

①で作成した Ubuntu ブートドライブから、OSを起動して、Astar Archive Node のセットアップし、起動をするところまで解説します。

Ubuntu の起動

外付けのSSDドライブ、電源ケーブル、HDMIケーブルを接続して、電源を通電します。

※HDMIケーブルを接続せずに起動すると、外部モニタ出力は後からできません。しかし、HDMIケーブルをつげなくてもセットアップは可能であり、トラブル時の保険として、はじめはつなげておきます。

Ubuntu へのSSHアクセス

HDMIケーブルをつけているので直接コンソールでログインしてよいのですが、今回は①の設定でWiFiの接続設定とUbuntuの一般ユーザー作成が完了しているので、自宅のWiFi環境により自動的にIPマスカレードによるIPアドレスが設定されています。

よって、SSHによりリモートアクセスが可能な状態になっているのでそれでアクセスをします。この方が何かとセットアップに都合がよいので。

自分の Windows PC 上の WSL (これも Ubuntu ですが)からSSHでログインします。(自分のWindows PCも同じWiFi上のLANにあるのでそこからアクセスが可能)


fuga@DESKTOP-VG4GHSG:~$ ssh hoge@192.168.1.1
hoge@192.168.1.1's password:
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-1024-raspi aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun May 14 21:55:15 JST 2023

  System load:  1.5361328125       Temperature:            47.2 C
  Usage of /:   0.3% of 916.64GB   Processes:              159
  Memory usage: 8%                 Users logged in:        0
  Swap usage:   0%                 IPv4 address for wlan0: 192.168.2.112

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ここからは、以下を参考に進めていきます。

アップグレードとパッケージインストール

$ sudo apt update && sudo apt upgrade
$ sudo apt install -y adduser libfontconfig1
$ sudo shutdown -r now

実施したときは、カーネルのアップデートがあったので一度再起動します。

スワップファイルの作成

SDRAMが 4GBしかないので、メモリ不足となるのを避けるために別途 swap file を 4GB 分作って設定します。(足回りがSSDなのでHDDよりは悪くない)

$ sudo fallocate -l 4g /file.swap
$ sudo chmod 600 /file.swap
$ sudo mkswap /file.swap
$ sudo swapon /file.swap

### 以下確認
$ sudo swapon -s
Filename                                Type            Size            Used            Priority
/file.swap                              file            4194300         0               -2

$ free
               total        used        free      shared  buff/cache   available
Mem:         3880036      166820     3346148        3124      367068     3546792
Swap:        4194300           0     4194300

htop コマンドでも、確認できる。

Astar Node(astar-collator)のインストール

ラズパイは、ARMで動いているのでそれ用(aarch64 アーキテクチャ)のバイナリをダウンロードしてきます。本投稿時点で バージョンは 5.4.0 です。

$ wget $(curl -s https://api.github.com/repos/AstarNetwork/Astar/releases/latest | grep "tag_name" | awk '{print "https://github.com/AstarNetwork/Astar/releases/download/" substr($2, 2, length($2)-3) "/astar-collator-v" substr($2, 3, length($2)-4) "-ubuntu-aarch64.tar.gz"}') && tar -xvf astar-collator*.tar.gz
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.109.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 56632845 (54M) [application/octet-stream]
Saving to: ‘astar-collator-v5.4.0-ubuntu-aarch64.tar.gz’

astar-collator-v5.4.0-ubuntu-aarch64.t 100%[==========================================================================>]  54.01M  9.39MB/s    in 6.6s

2023-05-13 15:54:27 (8.20 MB/s) - ‘astar-collator-v5.4.0-ubuntu-aarch64.tar.gz’ saved [56632845/56632845]

Astar Archvie Node の構築と起動

$ sudo useradd --no-create-home --shell /usr/sbin/nologin astar
$ sudo mv ./astar-collator /usr/local/bin
$ sudo chmod +x /usr/local/bin/astar-collator
$ sudo mkdir /var/lib/astar && sudo chown astar:astar /var/lib/astar

astar-collator の サービス設定

astar-collator をsystemdで起動するため専用のUnit定義ファイルを作成します。

ファイル:
 /etc/systemd/system/astar.service
変更部分:
 --name でノード名を指定(ここでは”HOGE_RasPi")

[Unit]
Description=Astar Archive node

[Service]
User=astar
Group=astar

ExecStart=/usr/local/bin/astar-collator \
--pruning archive \
--rpc-cors all \
--name HOGE_RasPi \
--chain astar \
--base-path /var/lib/astar \
--rpc-external \
--ws-external \
--rpc-methods Safe \
--rpc-max-request-size 1 \
--rpc-max-response-size 1 \
--telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \

Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

astar-collator サービスの有効化と起動

$ sudo systemctl enable astar.service
$ sudo systemctl start astar.service

起動および同期確認

起動直後は以下のようなログが出力されます。

May 14 22:48:26 hogehost systemd[1]: Started Astar Archive node.
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 Astar Collator
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 ✌️  version 5.4.0-6256fbda03a
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 ❤️  by Stake Technologies <devops@stake.co.jp>, 2019-2023
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 📋 Chain specification: Astar
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 🏷  Node name:  HOGE_RasPi
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 👤 Role: FULL
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 💾 Database: RocksDb at /var/lib/astar/chains/astar/db/full
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 ⛓  Native runtime: astar-58 (astar-0.tx2.au1)
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 Parachain id: Id(2006)
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 Parachain Account: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 Parachain genesis state: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
May 14 22:48:26 hogehost astar-collator[2858]: 2023-05-14 22:48:26 Is collating: no
May 14 22:48:30 hogehost astar-collator[2858]: 2023-05-14 22:48:30 [Parachain] 🔨 Initializing Genesis block/state (state: 0xc945…4da9, header-hash: 0x9eb7…29c6)
May 14 22:48:38 hogehost astar-collator[2858]: 2023-05-14 22:48:38 [Relaychain] 🔨 Initializing Genesis block/state (state: 0x29d0…4e17, header-hash: 0x91b1…90c3)
May 14 22:48:38 hogehost astar-collator[2858]: 2023-05-14 22:48:38 [Relaychain] 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 👶 Creating empty BABE epoch changes on what appears to be first startup.
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 🏷  Local node iden tity is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 💻 Operating system: linux
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 💻 CPU architecture: aarch64
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 💻 Target environment: gnu
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 💻 Memory: 3789MB
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 💻 Kernel: 5.15.0-1028-raspi
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 💻 Linux distribution: Ubuntu 22.04.2 LTS
May 14 22:48:41 hogehost  astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 💻 Virtual machine: no
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 📦 Highest known block at #0
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] 〽️ Prometheus exporter started at 127.0.0.1:9616
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] Running JSON-RPC HTTP server: addr=127.0.0.1:9934, allowed origins=["http://localhost:*", "http://127.0.0.1:*", "https://localhost:*", "https://127.0.0.1:*", "https://polkadot.js.org"]
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] Running JSON-RPC WS server: addr=127.0.0.1:9945, allowed origins=["http://localhost:*", "http://127.0.0.1:*", "https://localhost:*", "https://127.0.0.1:*", "https://polkadot.js.org"]
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Relaychain] Starting with an empty approval vote DB.
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 🏷  Local node ident ity is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 💻 Operating system: linux
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 💻 CPU architecture: aarch64
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 💻 Target environment: gnu
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 💻 Memory: 3789MB
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 💻 Kernel: 5.15.0-1028-raspi
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 💻 Linux distribution: Ubuntu 22.04.2 LTS
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 💻 Virtual machine: no
May 14 22:48:41 hogehost astar-collator[2858]: 2023-05-14 22:48:41 [Parachain] 📦 Highest known block at #0
:
:
:

少ししてから同期が始まります。

May 14 22:37:28 hogehost astar-collator[1378]: 2023-05-14 22:37:28 [Parachain] ⚙️  Syncing, target=#3566062 (7 peers), best: #459 (0xbbe9…8a44), finalized #0 (0x9eb7…29c6), ⬇ 1.0MiB/s ⬆ 7.1kiB/s
May 14 22:37:29 hogehost astar-collator[1378]: 2023-05-14 22:37:29 [Parachain] assembling new collators for new session 3 at #600
May 14 22:37:31 hogehost astar-collator[1378]: 2023-05-14 22:37:31 [Parachain] assembling new collators for new session 4 at #900
May 14 22:37:33 hogehost astar-collator[1378]: 2023-05-14 22:37:33 [Relaychain] ⚙️  Syncing 142.4 bps, target=#15518907 (40 peers), best: #1262 (0x8a4a…a718), finalized #1024 (0x25a1…88da), ⬇ 75.3kiB/s ⬆ 20.1kiB/s
May 14 22:37:33 hogehost astar-collator[1378]: 2023-05-14 22:37:33 [Parachain] ⚙️  Syncing 132.5 bps, target=#3566062 (16 peers), best: #1122 (0x3480…292d), finalized #0 (0x9eb7…29c6), ⬇ 581.5kiB/s ⬆ 6.9kiB/s
May 14 22:37:33 hogehost astar-collator[1378]: 2023-05-14 22:37:33 [Parachain] assembling new collators for new session 5 at #1200
May 14 22:37:36 hogehost astar-collator[1378]: 2023-05-14 22:37:36 [Parachain] assembling new collators for new session 6 at #1500
May 14 22:37:38 hogehost astar-collator[1378]: 2023-05-14 22:37:38 [Relaychain] ⚙️  Syncing 128.1 bps, target=#15518907 (40 peers), best: #1904 (0x8757…0fde), finalized #1536 (0x0029…1bfd), ⬇ 104.2kiB/s ⬆ 21.7kiB/s
May 14 22:37:38 hogehost astar-collator[1378]: 2023-05-14 22:37:38 [Parachain] ⚙️  Syncing 132.0 bps, target=#3566062 (18 peers), best: #1783 (0xbef0…1908), finalized #0 (0x9eb7…29c6), ⬇ 539.4kiB/s ⬆ 2.9kiB/s
May 14 22:37:38 hogehost astar-collator[1378]: 2023-05-14 22:37:38 [Parachain] assembling new collators for new session 7 at #1800

ノードのログの確認は journalctl コマンドか、syslog で可能です。

$ journalctl -f -u astar.service -n 100

ブロックが最新状態まで同期が完了するまではだいたい計算して、数日かかりそうなので、いったんこのままにして完了まで待ちます。

Reference


この記事が気に入ったらサポートをしてみませんか?