# 比特币全节点设置

### 硬件要求

* CPU：多核处理器
* 内存：至少 8GB
* 硬盘：至少 800GB 的SSD硬盘，可容纳完整的比特币区块链。

### Bitcoin Core设置

从[Bitcoin Core官方](https://bitcoincore.org/bin/bitcoin-core-26.0/)选择合适你操作系统的bitcoin-core文件，下载并安装。本文档中的所有程序均与[bitcoin-core-26.0](https://bitcoincore.org/bin/bitcoin-core-26.0/)版本兼容。

### bitcoind配置

bitcoind通过名为`bitcoin.conf`的主配置文件进行配置。

根据操作系统的不同，配置文件应放置在对应的文件路径中：

* MacOS: `/Users/<username>/Library/Application Support/Bitcoin`
* Linux: `/home/<username>/.bitcoin`
* Windows: `C:\Users\<username>\AppData\Roaming\Bitcoin`

两台服务器都可以使用以下基本参数框架 (适用于BTC签名网络)：

```
# Accept command line and JSON-RPC commands
server=1
# Enable transaction indexing
txindex=1
# RPC server settings
rpcuser=<rpc-username>
rpcpassword=<rpc-password>
# Optional: In case of non-mainnet BTC node,
# the following two lines specify the network that your
# node will operate; for this example, utilizing signet
signet=1
[signet]
# Port your bitcoin node will listen for incoming requests;
# below port is the canonical port for signet,
# for mainnet, typically 8332 is used
rpcport=38332
# Address your bitcoin node will listen for incoming requests
rpcbind=0.0.0.0
# Optional: Needed for remote node connectivity
rpcallowip=0.0.0.0/0
```

**注意事项：**

* 建议不要在配置中硬编码RPC服务器密码 (`rpcpassword`)，而是生成其[加盐哈希](https://cloud.tencent.com/developer/article/1636075) (salted hash) 并使用`rpcauth`字段。要生成加盐哈希，可以参考[此示例](https://jlopp.github.io/bitcoin-core-rpc-auth-generator/)——但是，加盐操作应在本地执行。生成的配置值如下所示：

```
rpcauth=<rpc-password-salted-hash>
```

* 如果你要连接到比特币主网，请确保删除下方配置：

```
signet=1
[signet]
```

### 启动bitcoind

1. **启动比特币守护进程**

```
bitcoind
```

2. **验证bitcoind是否运行**

检查bitcoind运行状态：

```
bitcoin-cli getblockchaininfo
```

如果看到有关区块链的信息，表明`bitcoind`运行正常。

### 为bitcoind创建一个systemd服务 (可选)

1. **创建systemd服务定义**

运行下方命令，将`your_username`替换为你的自定义用户名：

```
cat <<EOF | sudo tee /etc/systemd/system/bitcoind.service
[Unit]
Description=Bitcoin daemon
After=network.target

[Service]
ExecStart=/usr/local/bin/bitcoind -conf=/home/your_username/.bitcoin/bitcoin.conf
ExecStop=/usr/local/bin/bitcoin-cli stop
User=your_username
Restart=always

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

2. **重新加载systemd管理器配置**

```
sudo systemctl daemon-reload
```

3. **启用开机自动启动功能**

```
sudo systemctl enable bitcoind.service
```

4. **启动服务器**

```
sudo systemctl start bitcoind.service
```

### 服务器监控

可通过[Prometheus Blackbox Exporter](https://github.com/prometheus/blackbox_exporter)轮询bitcoind服务器的可用性。

比特币特定的Prometheus指标可以通过任何开源[Prometheus bitcoind导出器](https://github.com/jvstein/bitcoin-prometheus-exporter?tab=readme-ov-file)来公开。


---

# 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://www.docszh.com/babylon-docs/user-guides/bitcoin-staking-phase1/backend-deployment/infra/bitcoind.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.
