IF
IndexFlowing
/ Docs
🌐 English Docs GitHub ↗

安装与设置

本文介绍自托管 IndexFlow 的系统要求、源码构建、容器化运行和数据库初始化。


系统要求

IndexFlow 旨在保持轻量并高效利用资源。

最低硬件要求

  • CPU:1 个 vCPU(x86_64 或 aarch64)
  • RAM:512 MB(编译期间建议 1 GB)
  • 磁盘:500 MB 可用空间(取决于数据库大小和跟踪 URL 数量)

支持的操作系统

  • Linux:Ubuntu 20.04+、Debian 11+、Alpine Linux 3.18+、RHEL/Rocky Linux 8+
  • macOS:12+(Apple Silicon 与 Intel)
  • Windows:Windows 10/11 或 Windows Server 2019+(原生或通过 WSL2)

方法 1:从源码构建(Linux/macOS 推荐)

1. 安装依赖

确保已安装 Rust 编译器、Cargo、OpenSSL 和 SQLite 开发库:

Ubuntu / Debian

sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev sqlite3 libsqlite3-dev git
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"

Alpine Linux

apk add --no-cache build-base pkgconfig openssl-dev sqlite-dev git curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"

macOS

xcode-select --install
brew install openssl sqlite git

2. 克隆仓库

git clone https://github.com/IndexFlowing/IndexFlow-core.git
cd IndexFlow-core

3. 编译二进制文件

构建优化后的发布二进制文件:

cargo build --release

编译后的二进制文件位于:

target/release/indexflow-core

也可以将其安装到系统路径:

sudo cp target/release/indexflow-core /usr/local/bin/

方法 2:Docker 部署

无需在本地安装 Rust 工具链,即可在容器中运行 IndexFlow。

1. Dockerfile

在工作目录中创建 Dockerfile:

# Build stage
FROM rust:1.75-bookworm AS builder
WORKDIR /app
COPY . .
RUN cargo build --release

# Runtime stage
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    libssl3 \
    libsqlite3-0 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY --from=builder /app/target/release/indexflow-core /app/indexflow-core
COPY --from=builder /app/migrations /app/migrations

# Create directory for persistent SQLite storage
RUN mkdir -p /data

ENV SERVER_HOST=0.0.0.0
ENV SERVER_PORT=8080
ENV DATABASE_URL=sqlite:/data/indexflow.db?mode=rwc
ENV RUST_LOG=indexflow_core=info,tower_http=info

EXPOSE 8080
VOLUME ["/data"]

CMD ["/app/indexflow-core"]

2. 构建并运行

# Build the Docker image
docker build -t indexflow:latest .

# Run the container with persistent volume
docker run -d \
  --name indexflow \
  -p 8080:8080 \
  -v $(pwd)/data:/data \
  -e JWT_SECRET="your-secure-jwt-secret-key-at-least-32-chars" \
  -e DRY_RUN="false" \
  indexflow:latest

数据库初始化与自动迁移

IndexFlow 使用 SQLite 作为内置主数据库,无需安装外部 PostgreSQL 或 MySQL 实例。

自动执行迁移

indexflow-core 启动时,会通过 sqlx::migrate!("./migrations") 自动执行内置 SQL 迁移:

  1. 001_init.sql:建立核心表(site_config、urls、admin_users、submission_logs、health_checks)。
  2. 002_multi_site.sql:升级 schema 以支持多租户(sites 表和 site_id 外键)。
  3. 003_bing_inspection.sql:添加 Bing Webmaster 检查字段(bing_index_status、bing_coverage_state)。
  4. 004_sitemap_synced_at.sql:添加抓取跟踪时间戳。
  5. 005_seo_warnings.sql:添加 Schema.org 类型、AI bot 阻断和 OpenGraph 审计字段。
  6. 006_discovery_source.sql:跟踪 URL 发现来源(sitemap 与 gsc_orphan)。
  7. 007_custom_user_agent.sql:添加 Cloudflare WAF 绕过 token 支持。
  8. 008_indexing_watchlist.sql:实现 URL 监控 watchlist 和 index_status_history。

SQLite WAL 模式

IndexFlow 启动时将 SQLite 配置为 **预写式日志(WAL)**模式:

PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA busy_timeout = 5000;

这样后台 worker 写入审计和提交日志时仍可并发读取,且不会锁定数据库。


验证安装

通过 HTTP 检查服务器健康状态:

curl -s http://localhost:8080/health | json_pp

预期输出:

{
  "db": "sqlite-wal",
  "service": "indexflow-core",
  "status": "healthy"
}