# nockchian部署教程

By [huadong.eth](https://paragraph.com/@huadong) · 2025-05-20

---

安装v2rayu后
=========

恢复 Homebrew 主仓库为官方源
===================

git -C "$(brew --repo)" remote set-url origin [https://github.com/Homebrew/brew.git](https://github.com/Homebrew/brew.git)

恢复 Homebrew Core 仓库为官方源
=======================

git -C "$(brew --repo homebrew/core)" remote set-url origin [https://github.com/Homebrew/homebrew-core.git](https://github.com/Homebrew/homebrew-core.git)

恢复 Homebrew Cask 仓库为官方源（可选）
===========================

git -C "$(brew --repo homebrew/cask)" remote set-url origin [https://github.com/Homebrew/homebrew-cask.git](https://github.com/Homebrew/homebrew-cask.git)

清除 Homebrew 镜像相关环境变量（如果之前设置过）
=============================

unset HOMEBREW\_BREW\_GIT\_REMOTE

unset HOMEBREW\_CORE\_GIT\_REMOTE

unset HOMEBREW\_BOTTLE\_DOMAIN

export http\_proxy=[http://127.0.0.1:1087](http://127.0.0.1:1087);

export https\_proxy=[http://127.0.0.1:1087](http://127.0.0.1:1087);

export ALL\_PROXY=socks5://127.0.0.1:1080

git config --global http.proxy [http://127.0.0.1:](http://127.0.0.1:7890)1087

git config --global https.proxy [http://127.0.0.1:](http://127.0.0.1:7890)1087

脚本

#!/bin/bash

set -e

echo -e "\\n🍺 安装依赖工具（通过 Homebrew）..."

检查并安装 Homebrew
==============

if ! command -v brew &> /dev/null; then echo "⚠️ 未检测到 Homebrew，正在安装..." /bin/bash -c "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh](https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh))" fi

brew update brew install git curl wget jq lz4 make gcc automake autoconf tmux htop pkg-config openssl leveldb coreutils gnu-sed screen

echo -e "\\n🦀 安装 Rust..." curl --proto '=https' --tlsv1.2 -sSf [https://sh.rustup.rs](https://sh.rustup.rs) | sh -s -- -y source "$HOME/.cargo/env" rustup default stable

echo -e "\\n📁 检查 nockchain 仓库..." if \[ -d "nockchain" \]; then echo "⚠️ 已存在 nockchain 目录，是否删除重新克隆（必须选 y ）？(y/n)" read -r confirm if \[\[ "$confirm" == "y" || "$confirm" == "Y" \]\]; then rm -rf nockchain git clone [https://github.com/zorp-corp/nockchain](https://github.com/zorp-corp/nockchain) else echo "➡️ 使用已有目录 nockchain" fi else git clone [https://github.com/zorp-corp/nockchain](https://github.com/zorp-corp/nockchain) fi

cd nockchain

echo -e "\\n🔧 编译核心组件中..." make install-hoonc make build make install-nockchain-wallet make install-nockchain

echo -e "\\n✅ 配置环境变量..." ENV\_FILE="$HOME/.zprofile" echo 'export PATH="$PATH:/root/nockchain/target/release"' >> "$ENV\_FILE" echo 'export RUST\_LOG=info' >> "$ENV\_FILE" echo 'export MINIMAL\_LOG\_FORMAT=true' >> "$ENV\_FILE" source "$ENV\_FILE"

\=== 生成钱包 ===
=============

echo -e "\\n🔐 自动生成钱包助记词与主私钥..." WALLET\_CMD="./target/release/nockchain-wallet" if \[ ! -f "$WALLET\_CMD" \]; then echo "❌ 未找到钱包命令 $WALLET\_CMD" exit 1 fi

SEED\_OUTPUT=$($WALLET\_CMD keygen) echo "$SEED\_OUTPUT"

SEED\_PHRASE=$(echo "$SEED\_OUTPUT" | grep -iE "seed phrase" | sed 's/.\*: //') echo -e "\\n🧠 助记词：$SEED\_PHRASE"

echo -e "\\n🔑 从助记词派生主私钥..." MASTER\_PRIVKEY=$($WALLET\_CMD gen-master-privkey --seedphrase "$SEED\_PHRASE" | grep -i "master private key" | awk '{print $NF}') echo "主私钥：$MASTER\_PRIVKEY"

echo -e "\\n📬 获取主公钥..." MASTER\_PUBKEY=$($WALLET\_CMD gen-master-pubkey --master-privkey "$MASTER\_PRIVKEY" | grep -i "master public key" | awk '{print $NF}') echo "主公钥：$MASTER\_PUBKEY"

echo -e "\\n📄 写入 Makefile 挖矿公钥..." gsed -i "s|^export MINING\_PUBKEY :=.\*$|export MINING\_PUBKEY := $MASTER\_PUBKEY|" Makefile

\=== 可选：初始化 choo hoon 测试 ===
============================

read -p $'\\n🌀 是否执行 choo 初始化测试？这一步可能卡住界面，非必须操作。输入 y 继续：' confirm\_choo if \[\[ "$confirm\_choo" == "y" || "$confirm\_choo" == "Y" \]\]; then mkdir -p hoon assets echo "%trivial" > hoon/trivial.hoon choo --new --arbitrary hoon/trivial.hoon fi

\=== 启动指引 ===
=============

echo -e "\\n🚀 配置完成，启动命令如下："

echo -e "\\n➡️ 启动 leader 节点：" echo -e "screen -S leader\\nmake run-nockchain-leader"

echo -e "\\n➡️ 启动 follower 节点：" echo -e "screen -S follower\\nmake run-nockchain-follower"

echo -e "\\n📄 查看日志方法：" echo -e "screen -r leader # 查看 leader 日志" echo -e "screen -r follower # 查看 follower 日志" echo -e "按 Ctrl+A 再按 D 可退出 screen 会话"

echo -e "\\n🎉 部署完成，祝你挖矿愉快！"

---

*Originally published on [huadong.eth](https://paragraph.com/@huadong/nockchian)*
