コンテンツにスキップ

1. Ubuntu の初期設定

まず Ubuntu Server の構築手順 をおこなってください。

2. プレビューノードインストール

インストールバージョン

Node CLI GHC Cabal CNCLI
10.5.3 10.11.0.0 9.6.7 3.12.1.0 6.6.0

2-1. 依存関係インストール

パッケージ情報の更新とアップデート

sudo apt update -y && sudo apt upgrade -y

依存するパッケージをインストール

sudo apt install git jq bc tmux htop curl -y

3-1. バイナリをダウンロード

バイナリをダウンロード

mkdir -p $HOME/git/cardano-node2
cd $HOME/git/cardano-node2
wget -q https://github.com/IntersectMBO/cardano-node/releases/download/10.5.3/cardano-node-10.5.3-linux.tar.gz

解凍する

tar zxvf cardano-node-10.5.3-linux.tar.gz ./bin/cardano-node ./bin/cardano-cli

バージョン確認

$(find $HOME/git/cardano-node2 -type f -name "cardano-cli") version  
$(find $HOME/git/cardano-node2 -type f -name "cardano-node") version

cardano-cli 10.11.0.0 - linux-x86_64 - ghc-9.6
git rev 6c034ec038d8d276a3595e10e2d38643f09bd1f2

cardano-node 10.5.3 - linux-x86_64 - ghc-9.6
git rev 6c034ec038d8d276a3595e10e2d38643f09bd1f2

バイナリファイルをインストールする

sudo cp $(find $HOME/git/cardano-node2 -type f -name "cardano-cli") /usr/local/bin/cardano-cli
sudo cp $(find $HOME/git/cardano-node2 -type f -name "cardano-node") /usr/local/bin/cardano-node

インストールされたノードバージョンを確認する

cardano-cli version
cardano-node version

cardano-cli 10.11.0.0 - linux-x86_64 - ghc-9.6
git rev 6c034ec038d8d276a3595e10e2d38643f09bd1f2

cardano-node 10.5.3 - linux-x86_64 - ghc-9.6
git rev 6c034ec038d8d276a3595e10e2d38643f09bd1f2

環境変数を設定しパスを通します

echo PATH="$HOME/.local/bin:$PATH" >> $HOME/.bashrc
echo export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" >> $HOME/.bashrc
echo export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" >> $HOME/.bashrc
echo export NODE_HOME=$HOME/cnode >> $HOME/.bashrc

環境変数にネットワークを指定する

echo export NODE_CONFIG=preview >> $HOME/.bashrc
echo export NODE_NETWORK='"--testnet-magic 2"' >> $HOME/.bashrc
echo export CARDANO_NODE_NETWORK_ID=2 >> $HOME/.bashrc

.bashrcを再読み込みする

source $HOME/.bashrc

ノード構成ファイルを取得する

mkdir $NODE_HOME
cd $NODE_HOME
wget -q https://book.play.dev.cardano.org/environments/preview/byron-genesis.json -O byron-genesis.json
wget -q https://book.play.dev.cardano.org/environments/preview/topology.json -O topology.json
wget -q https://book.play.dev.cardano.org/environments/preview/shelley-genesis.json -O shelley-genesis.json
wget -q https://book.play.dev.cardano.org/environments/preview/alonzo-genesis.json -O alonzo-genesis.json
wget -q https://book.play.dev.cardano.org/environments/preview/conway-genesis.json -O conway-genesis.json
wget -q https://book.play.dev.cardano.org/environments/preview/peer-snapshot.json -O peer-snapshot.json
wget --no-use-server-timestamps -q https://book.play.dev.cardano.org/environments/preview/config.json -O ${NODE_CONFIG}-config.json
wget --no-use-server-timestamps -q https://book.play.dev.cardano.org/environments/preview/config-bp.json -O ${NODE_CONFIG}-config.json

環境変数を追加し、.bashrcファイルを再読み込みする

echo export CARDANO_NODE_SOCKET_PATH="$NODE_HOME/db/socket" >> $HOME/.bashrc
source $HOME/.bashrc

リレーノードが使用するポート番号を指定して実行する

PORT=6000

起動スクリプトファイルを作成する

cat > $NODE_HOME/startRelayNode1.sh << EOF 
#!/bin/bash
DIRECTORY=$NODE_HOME
PORT=${PORT}
HOSTADDR=0.0.0.0
TOPOLOGY=\${DIRECTORY}/topology.json
DB_PATH=\${DIRECTORY}/db
SOCKET_PATH=\${DIRECTORY}/db/socket
CONFIG=\${DIRECTORY}/${NODE_CONFIG}-config.json
/usr/local/bin/cardano-node +RTS -N --disable-delayed-os-memory-return -I0.1 -Iw300 -A16m -F1.5 -H2500M -RTS run --topology \${TOPOLOGY} --database-path \${DB_PATH} --socket-path \${SOCKET_PATH} --host-addr \${HOSTADDR} --port \${PORT} --config \${CONFIG}
EOF

BPノードが使用するポート番号を指定して実行する

PORT=XXXX

起動スクリプトファイルを作成する

cat > $NODE_HOME/startBlockProducingNode.sh << EOF 
#!/bin/bash
DIRECTORY=$NODE_HOME
PORT=${PORT}
HOSTADDR=0.0.0.0
TOPOLOGY=\${DIRECTORY}/topology.json
DB_PATH=\${DIRECTORY}/db
SOCKET_PATH=\${DIRECTORY}/db/socket
CONFIG=\${DIRECTORY}/${NODE_CONFIG}-config.json
/usr/local/bin/cardano-node +RTS -N --disable-delayed-os-memory-return -I0.1 -Iw300 -A16m -F1.5 -H2500M -RTS run --topology \${TOPOLOGY} --database-path \${DB_PATH} --socket-path \${SOCKET_PATH} --host-addr \${HOSTADDR} --port \${PORT} --config \${CONFIG}
EOF

起動スクリプトに実行権限を付与し、ブロックチェーンとの同期を開始する

cd $NODE_HOME
chmod +x startRelayNode1.sh
./startRelayNode1.sh
cd $NODE_HOME
chmod +x startBlockProducingNode.sh
./startBlockProducingNode.sh

サービスユニットファイルを作成する

cat > $NODE_HOME/cardano-node.service << EOF 
# The Cardano node service (part of systemd)
# file: /etc/systemd/system/cardano-node.service 

[Unit]
Description     = Cardano node service
Wants           = network-online.target
After           = network-online.target 

[Service]
User            = ${USER}
Type            = simple
WorkingDirectory= ${NODE_HOME}
ExecStart       = /bin/bash -c '${NODE_HOME}/startRelayNode1.sh'
KillSignal=SIGINT
RestartKillSignal=SIGINT
TimeoutStopSec=300
LimitNOFILE=32768
Restart=always
RestartSec=5
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=cardano-node

[Install]
WantedBy    = multi-user.target
EOF
cat > $NODE_HOME/cardano-node.service << EOF 
# The Cardano node service (part of systemd)
# file: /etc/systemd/system/cardano-node.service 

[Unit]
Description     = Cardano node service
Wants           = network-online.target
After           = network-online.target 

[Service]
User            = ${USER}
Type            = simple
WorkingDirectory= ${NODE_HOME}
ExecStart       = /bin/bash -c '${NODE_HOME}/startBlockProducingNode.sh'
KillSignal=SIGINT
RestartKillSignal=SIGINT
TimeoutStopSec=300
LimitNOFILE=32768
Restart=always
RestartSec=5
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=cardano-node

[Install]
WantedBy    = multi-user.target
EOF

systemdにユニットファイルをコピーする

sudo cp $NODE_HOME/cardano-node.service /etc/systemd/system/cardano-node.service
権限を付与する
sudo chmod 644 /etc/systemd/system/cardano-node.service

OS起動時にサービスの自動起動を有効にする

sudo systemctl daemon-reload
sudo systemctl enable cardano-node
sudo systemctl start cardano-node

ログを確認する

journalctl --unit=cardano-node --follow
sudo systemctl stop cardano-node

Mithrilによる同期

mithril-clientをダウンロード

curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/input-output-hk/mithril/refs/heads/main/mithril-install.sh | sh -s -- -c mithril-client -d latest -p $HOME/git/

mithril-clientをインストール

sudo mv $HOME/git/mithril-client /usr/local/bin/mithril-client

バージョン確認

mithril-client -V

環境変数を設定

export AGGREGATOR_ENDPOINT=https://aggregator.testing-preview.api.mithril.network/aggregator
export GENESIS_VERIFICATION_KEY=$(curl -fsSL https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-preview/genesis.vkey)
export ANCILLARY_VERIFICATION_KEY=$(curl -fsSL https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-preview/ancillary.vkey)

既存DBフォルダを削除

rm -rf $NODE_HOME/db

最新スナップショットのダウンロード

mithril-client cardano-db download \
  --backend v2 \
  --run-mode testing-preview \
  --download-dir "$NODE_HOME" \
  --include-ancillary \
  latest

cardano-node を起動する

sudo systemctl start cardano-node

journalctl でログを確認する

journalctl --unit cardano-node -f

Guild LiveView

glive のインストール

mkdir $NODE_HOME/scripts
cd $NODE_HOME/scripts
sudo apt install bc tcptraceroute -y
curl -s -o gLiveView.sh https://raw.githubusercontent.com/cardano-community/guild-operators/master/scripts/cnode-helper-scripts/gLiveView.sh
curl -s -o env https://raw.githubusercontent.com/cardano-community/guild-operators/master/scripts/cnode-helper-scripts/env
chmod 755 gLiveView.sh
PORT=`grep "PORT=" $NODE_HOME/startRelayNode1.sh`
b_PORT=${PORT#"PORT="}
echo "リレーポートは${b_PORT}です"
PORT=`grep "PORT=" $NODE_HOME/startBlockProducingNode.sh`
b_PORT=${PORT#"PORT="}
echo "BPポートは${b_PORT}です"
sed -i $NODE_HOME/scripts/env \
    -e '1,73s!#CNODE_HOME="/opt/cardano/cnode"!CNODE_HOME=${NODE_HOME}!' \
    -e '1,73s!#CNODE_PORT=6000!CNODE_PORT='${b_PORT}'!' \
    -e '1,73s!#UPDATE_CHECK="Y"!UPDATE_CHECK="N"!' \
    -e '1,73s!#CONFIG="${CNODE_HOME}/files/config.json"!CONFIG="${CNODE_HOME}/'${NODE_CONFIG}'-config.json"!' \
    -e '1,73s!#SOCKET="${CNODE_HOME}/sockets/node.socket"!SOCKET="${CNODE_HOME}/db/socket"!' \
    -e '1,73s!#PROM_HOST=127.0.0.1!PROM_HOST=127.0.0.1!' \
    -e '1,73s!#PROM_PORT=12798!PROM_PORT=12798!'
echo alias glive="'cd $NODE_HOME/scripts; ./gLiveView.sh'" >> $HOME/.bashrc
source $HOME/.bashrc

glive でノードの起動状態を確認する

glive