如何搭建Solana全节点?非验证/投票节点,仅本地获取区块链数据
搭建Solana全节点(非验证/投票节点)
本文针对本地获取区块链数据的需求,介绍搭建Solana全节点(不参与验证或投票)的完整步骤。
一、系统前置要求
- 硬件:推荐至少2TB SSD(主网账本约1.5-2TB)、16GB以上内存、4核及以上CPU,稳定的网络带宽(同步阶段需较高带宽)
- 系统:Ubuntu 20.04+/CentOS 8+ 或 macOS 12+
二、安装Solana CLI
- 下载指定版本的安装脚本(以v1.18.17为例,兼容性较好):
sh -c "$(curl -sSfL https://release.solana.com/v1.18.17/install)" - 配置环境变量(临时生效,若需永久生效可添加到
~/.bashrc或~/.zshrc):export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH" - 验证安装:
solana --version
三、配置全节点数据目录与快照同步
直接同步整个区块链账本耗时极长,推荐从官方快照快速启动:
- 创建数据存储目录:
mkdir -p ~/solana-full-node/data - 下载主网最新快照(测试网可替换
--url为https://api.testnet.solana.com):solana-ledger-tool download-snapshot --url https://api.mainnet-beta.solana.com ~/solana-full-node/data
四、启动全节点
执行以下命令启动非验证/投票的全节点,开启完整RPC API:
solana-validator \ --ledger ~/solana-full-node/data \ --rpc-port 8899 \ --entrypoint entrypoint.mainnet-beta.solana.com:8001 \ --no-voting \ --full-rpc-api \ --limit-ledger-size
参数说明:
--ledger:指定账本数据存储路径--rpc-port:本地RPC服务端口(默认8899)--entrypoint:Solana主网入口节点(测试网替换为entrypoint.testnet.solana.com:8001)--no-voting:明确节点不参与投票与验证,仅同步数据--full-rpc-api:开启所有RPC接口,满足数据查询需求--limit-ledger-size:自动清理旧账本数据,防止磁盘溢出
五、验证节点运行状态
- 检查集群版本匹配:
solana cluster-version --url http://localhost:8899 - 查看同步进度:
当输出显示solana catchup --url http://localhost:8899Catchup complete即同步完成。 - 测试RPC调用:
正常情况下会返回包含curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"getLatestBlockhash"}'result字段的JSON数据。
六、日常维护
设置开机自启(Linux)
创建systemd服务文件/etc/systemd/system/solana-full-node.service:
[Unit] Description=Solana Full Node After=network.target [Service] User=your_username ExecStart=/home/your_username/.local/share/solana/install/active_release/bin/solana-validator --ledger ~/solana-full-node/data --rpc-port 8899 --entrypoint entrypoint.mainnet-beta.solana.com:8001 --no-voting --full-rpc-api --limit-ledger-size Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
替换your_username为实际用户名,然后执行:
sudo systemctl daemon-reload && sudo systemctl enable --now solana-full-node.service
查看节点日志
journalctl -u solana-full-node.service -f
注意事项
- 定期检查磁盘空间,主网全节点需预留至少2TB可用空间
- 同步过程中保持网络稳定,断开后节点会自动续连
- 若需切换测试网,只需替换启动命令中的
entrypoint与快照下载的--url地址
内容的提问来源于stack exchange,提问作者Shahbaz Ali
相关产品推荐
相关产品推荐

