# 搭建RPC节点

> Solana节点昂贵，对机器性能要求非常高，请自行考虑风险！

根据[官方要求](https://docs.solanalabs.com/operations/requirements#rpc-node-recommendations)，Solana RPC节点若要开启account-index参数的话，至少需要512GB内存。

## 挂载磁盘

官方推荐机器至少3个NVMe盘，一个系统盘，一个存账户数据，一个存账本数据。

除系统盘外，每个硬盘推荐使用2T的存储空间。以下为创建项目目录和挂载磁盘的命令：

```
mkdir /root/sol
mkdir /root/sol/accounts
mkdir /root/sol/ledger
mkdir /root/sol/bin
```

```
# n + e
fdisk /dev/nvme0n1
fdisk /dev/nvme1n1

mkfs -t ext4 /dev/nvme0n1
mkfs -t ext4 /dev/nvme1n1

mount /dev/nvme0n1 /root/sol/ledger
mount /dev/nvme1n1 /root/sol/accounts

vim /etc/fstab
/dev/nvme0n1 /root/sol/ledger ext4 defaults 0 0
/dev/nvme1n1 /root/sol/accounts ext4 defaults 0 0
```

## 将cpu设置为performance模式

Solana节点对cpu主频要求较高，推荐使用高频cpu并将性能设置为performance模式。

```
apt install linux-tools-common linux-tools-$(uname -r)

cpupower frequency-info

cpupower frequency-set --governor performance

watch "grep 'cpu MHz' /proc/cpuinfo"
```

## 下载solana-cli

```
sh -c "$(curl -sSfL https://release.anza.xyz/v2.0.18/install)"
```

```
vim /root/.bashrc
export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
source /root/.bashrc

solana --version
```

## 创建验证者私钥

```
solana-keygen new -o validator-keypair.json
```

## 系统调优

1. 修改/etc/sysctl.conf

```
vim /etc/sysctl.conf
```

添加如下

```
# Increase UDP buffer sizes
net.core.rmem_default = 134217728
net.core.rmem_max = 134217728
net.core.wmem_default = 134217728
net.core.wmem_max = 134217728

# Increase memory mapped files limit
vm.max_map_count = 1000000

# Increase number of allowed open file descriptors
fs.nr_open = 1000000
```

```
sysctl -p
```

2. 修改/etc/systemd/system.conf

```
vim /etc/systemd/system.conf
```

添加如下

```
DefaultLimitNOFILE=1000000
```

```
systemctl daemon-reload
```

3. 修改/etc/security/limits.conf

```
vim /etc/security/limits.conf
```

添加如下

```
# Increase process file descriptor count limit
* - nofile 1000000
```

```
ulimit -n 1000000 # 手动设置一下，不然需要重启机器
ulimit -n
```

## 开启防火墙

```
sudo ufw allow 22
sudo ufw allow 8000:8020/tcp
sudo ufw allow 8000:8020/udp
sudo ufw allow 8899 # http 端口
sudo ufw allow 8900 # websocket 端口

sudo ufw enable
sudo ufw status
```

## 创建启动脚本和服务

```
vim /root/sol/bin/validator.sh
```

```
#!/bin/bash

exec agave-validator \
	--ledger /root/sol/ledger \
	--accounts /root/sol/accounts \
	--identity /root/validator-keypair.json \
	--known-validator 7Np41oeYqPefeNQEHSv1UDhYrehxin3NStELsSKCT4K2 \
	--known-validator GdnSyH3YtwcxFvQrVVJMm1JhTS4QVX7MFsX56uJLUfiZ \
	--known-validator DE1bawNcRJB9rVm3buyMVfr8mBEoyyu73NBovf2oXJsJ \
	--known-validator CakcnaRDHka2gXyfbEd2d3xsvkJkqsLw2akB3zsN1D2S \
	--entrypoint entrypoint.mainnet-beta.solana.com:8001 \
	--entrypoint entrypoint2.mainnet-beta.solana.com:8001 \
	--entrypoint entrypoint3.mainnet-beta.solana.com:8001 \
	--entrypoint entrypoint4.mainnet-beta.solana.com:8001 \
	--entrypoint entrypoint5.mainnet-beta.solana.com:8001 \
	--expected-genesis-hash 5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d \
	--full-rpc-api \
	--no-voting \
	--private-rpc \
	--rpc-port 8899 \
	--dynamic-port-range 8000-8020 \
	--wal-recovery-mode skip_any_corrupted_record \
	--limit-ledger-size \
	--account-index program-id \
	--account-index spl-token-mint \
	--account-index spl-token-owner \
	--enable-rpc-transaction-history \
	--log /root/solana-rpc.log
```

```
chmod +x /root/sol/bin/validator.sh
```

```
vim /etc/systemd/system/sol.service
```

添加如下

```
[Unit]
Description=Solana Validator
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=root
LimitNOFILE=1000000
LogRateLimitIntervalSec=0
Environment="PATH=/bin:/usr/bin:/root/.local/share/solana/install/active_release/bin"
ExecStart=/root/sol/bin/validator.sh

[Install]
WantedBy=multi-user.target
```

至此，可启动Solana RPC节点。

一些系统服务相关命令如下

<pre><code><strong>systemctl start sol
</strong>systemctl status sol
systemctl stop sol
systemctl restart sol
systemctl daemon-reload
</code></pre>

## 查看日志

```
tail -f /root/solana-rpc.log
journalctl -u sol -f --no-hostname -o cat
```

## 查看同步进度

```
solana catchup --our-localhost
```

## 参考

1. <https://solana.com/docs/rpc>
2. <https://docs.solanalabs.com/operations/setup-an-rpc-node>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chainbuff.gitbook.io/tutorials/solana/da-jian-ji-chu-she-shi/da-jian-rpc-jie-dian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
