Banner

Chainlink v2.15.0

2026-11-19

下面按"本地开发 → Docker 快速启动 → 生产部署 → 上线测试"整理一份 Chainlink 节点安装使用教程。当前官方推荐以 Docker 镜像 为主,源码编译更适合二次开发;生产环境以 2026 年公开资料看,可参考 Chainlink v2.15.0 及官方最新 tag。

1. 环境与架构准备

Chainlink 节点依赖三样东西:

组件要求说明
操作系统Linux / macOS / WSL生产环境推荐 Linux
Docker≥ 24推荐直接跑官方镜像
PostgreSQL≥ 12,Docker 镜像最高兼容 16官方文档要求 ≥12,但 Docker 镜像内置客户端最高支持到 16.x
以太坊 RPCHTTP + WebSocket可用 Infura、Alchemy、QuickNode,也可自建 Geth/Besu

如果你只是想跑通流程,建议先用 Sepolia 测试网 + 第三方 RPC。

2. 源码编译安装

源码编译适合需要调试、改插件或参与贡献的场景:

# 安装依赖
# Go 1.23
# Node.js v20 + pnpm v10
# PostgreSQL ≥12

git clone https://github.com/smartcontractkit/chainlink.git
cd chainlink

make install
chainlink help

本地开发可以禁用 TLS:

make chainlink-dev
chainlink node start

启动后访问:

http://localhost:6688

3. Docker 快速启动

先创建数据目录:

mkdir -p ~/.chainlink
cd ~/.chainlink

生成密码文件:

openssl rand -base64 24 > .password
openssl rand -base64 24 > .api

创建 .env:

ROOT=/chainlink
LOG_LEVEL=info
ETH_CHAIN_ID=11155111
ETH_URL=wss://sepolia.infura.io/ws/v3/YOUR_KEY
DATABASE_URL=postgresql://chainlink:YOUR_PG_PASSWORD@host.docker.internal:5432/chainlink?sslmode=disable
LINK_CONTRACT_ADDRESS=0x779877A7B0D9E8603169DdbD7836e478b4624789
API_EMAIL=admin@example.com
API_PASSWORD=your-strong-api-password
SECURE_COOKIES=false
CHAINLINK_TLS_PORT=0
ALLOW_ORIGINS=*
MINIMUM_CONTRACT_PAYMENT=100000000000000000

启动 PostgreSQL:

docker run -d \
  --name chainlink-db \
  -e POSTGRES_USER=chainlink \
  -e POSTGRES_PASSWORD=YOUR_PG_PASSWORD \
  -e POSTGRES_DB=chainlink \
  -p 5432:5432 \
  postgres:16-alpine

启动节点:

docker run -d \
  -p 6688:6688 \
  -v ~/.chainlink:/chainlink \
  --env-file ~/.chainlink/.env \
  --name chainlink-node \
  smartcontract/chainlink:2.15.0 \
  chainlink node start

首次启动会要求设置 keystore 密码和 API 登录信息。

4. 生产环境要点

生产部署建议用 Docker Compose 或 Kubernetes,并注意:

  • 不要暴露 6688 端口到公网,优先用 SSH 隧道或 VPN。
  • 使用 TOML 配置 管理日志、Gas、数据库、WebServer。
  • 数据库连接不要用明文写进 docker run,可用 Docker Secrets 或环境变量文件。
  • ETH_CHAIN_ID 必须和 RPC 网络一致,否则节点可能无法启动。
  • 生产环境建议启用 TLS、限制来源 IP、使用独立 VM 运行节点。
  • 镜像可用 cosign 做签名验证。

生产 config.toml 示例片段:

[Log]
Level = "warn"

[WebServer]
Port = 6688
SecureCookies = true

[Database]
DatabaseURL = "postgresql://chainlink:${PGPASSWORD}@chainlink-db:5432/chainlink?sslmode=disable"
MaxOpenConns = 25
MaxIdleConns = 10
MigrateOnStartup = true

5. 部署 Operator 合约

节点跑起来后,还需要链上 Operator 合约 才能接收请求。

在 Remix 上部署 Operator.sol,传入:

  • link:当前网络的 LINK 代币地址
  • owner:部署者地址

Sepolia 上的 LINK 地址示例:

0x779877A7B0D9E8603169DdbD7836e478b4624789

部署后调用 setAuthorizedSenders,把 Chainlink 节点的以太坊地址加入白名单。

6. 创建 Job

在 Operator UI 中打开 Jobs → New Job,使用类似配置:

name = "Get > Uint256"
schemaVersion = 1
type = "directrequest"
evmChainID = "11155111"
contractAddress = "YOUR_OPERATOR_CONTRACT_ADDRESS"
observationSource = """
decode_log   [type="ethabidecodelog"
  abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
  data="$(jobRun.logData)"
  topics="$(jobRun.logTopics)"]
decode_cbor  [type="cborparse" data="$(decode_log.data)"]
fetch        [type="http" method=GET url="$(decode_cbor.get)" allowUnrestrictedNetworkAccess="true"]
parse        [type="jsonparse" path="$(decode_cbor.path)" data="$(fetch)"]
multiply     [type="multiply" input="$(parse)" times="$(decode_cbor.times)"]
encode_data  [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \"requestId\": $(decode_log.requestId), \"value\": $(multiply) }"]
encode_tx    [type="ethabiencode"
  abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
  data="{\"requestId\": $(decode_log.requestId), \"payment\": $(decode_log.payment), \"callbackAddress\": $(decode_log.callbackAddr), \"callbackFunctionId\": $(decode_log.callbackFunctionId), \"expiration\": $(decode_log.cancelExpiration), \"data\": $(encode_data)}"]
submit_tx    [type="ethtx" to="YOUR_OPERATOR_CONTRACT_ADDRESS" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""

注意把 YOUR_OPERATOR_CONTRACT_ADDRESS 替换成实际合约地址。

7. 用 Consumer 合约测试

部署 ATestnetConsumer.sol,向合约转入少量 Sepolia LINK,然后调用 requestEthereumPrice。

参数示例:

  • operator:Operator 合约地址
  • jobId:Job 的 externalJobID,去掉横杠

执行后在 Operator UI 的 Runs 页面查看任务是否完成。完成后调用合约的 currentPrice,如果能读到价格,说明节点已打通。

8. 常见问题

  • 节点启动失败:优先检查 ETH_URL、ETH_CHAIN_ID、DATABASE_URL。
  • 数据库连接失败:确认 PostgreSQL 版本、端口、用户名密码和 sslmode。
  • Job 不执行:检查 Operator 合约是否授权了节点地址。
  • Gas 不足:节点钱包需要少量 ETH 用于链上回写。
  • UI 打不开:确认 6688 端口是否映射、TLS 是否关闭、防火墙是否放行。

如果你要上主网,建议先把这套流程在 Sepolia 跑通,再换成对应主网参数、Operator 合约地址和 LINK 地址。

25