内网离线部署 Chat2DB:本地化架构拆解、Docker 三步落地与版本对比实战
【免费下载链接】Chat2DBChat2DB is a free, cross-platform, local-first database client and SQL workspace for developers, DBAs, analysts, and data teams. Connect to 40+ databases, manage data, edit and run SQL, and use your own AI model to generate, explain, and optimize queries. Available on desktop, web, Docker, and CLI, with MCP support.项目地址: https://gitcode.com/GitHub_Trending/ch/Chat2DB
合规审计要求数据不出域、内网又连不上任何云服务时,数据库管理工具往往只能被搁置。Chat2DB Community 是一款免费、本地优先的数据库客户端与 SQL 工作空间,完全运行在你自己的机器上,支持连接 40+ 种数据库,并可接入你自己的 AI 模型完成 SQL 生成、解释与优化。下面从架构原理、动手部署、版本对比三个角度展开。
离线架构拆解:Chat2DB 本地化重构的三个落点
如果你要评估这套工具能否直接放进断网环境,关键就是看它把"网络依赖"都挪到了哪里。⚙️ 从仓库源码看,有三个落点值得你顺着路径验证:
服务本身以离线模式启动。后端是 Spring Boot 嵌入式容器服务,Dockerfile 的启动参数里显式带了
-Dchat2db.network.status=OFFLINE与-Dchat2db.gui=false,即不开桌面窗口、不尝试访问外网;运行时依赖由 Maven 统一解压到本地 lib 目录,通过loader.path加载,启动后不需要再拉取任何远程资源。凭据本地加密落盘。每个安装实例使用独立密钥,数据源密码和 AI 模型 API Key 用AES-256-GCM加密保存。密钥由 init-community-encryption-key.sh 一次性生成,写入
~/.config/chat2db-community/encryption.key。前端工作台状态(如保存的 DDL)则通过 IndexedDB 持久化,表结构定义见 table.ts。AI 能力指向你自己的模型。SQL 生成与解释走前端配置的模型(请求层实现见 ai.ts),编辑器补全则依赖 IntelliSense 目录中针对 MySQL、Oracle、PostgreSQL 等 7 类方言的本地规则文件。也就是说,内网环境里把模型地址指向自建 LLM 服务,AI 链路就完整闭合了。
架构看明白了,部署本身反而简单。
动手落地:Docker 三行命令完成离线部署 🚀
这一步只分三个动作:初始化密钥、启动容器、打开浏览器。
首次部署前,克隆仓库并初始化加密密钥(重复执行会复用同一把合法密钥):
git clone https://gitcode.com/GitHub_Trending/ch/Chat2DB.git cd Chat2DB ./script/security/init-community-encryption-key.sh启动容器,端口绑定 127.0.0.1,同时挂载数据目录和只读的密钥文件:
docker run --detach \ --name chat2db-community \ --restart unless-stopped \ --publish 127.0.0.1:10825:10825 \ --volume "$HOME/.chat2db-community-docker:/root/.chat2db-community" \ --env CHAT2DB_COMMUNITY_ENCRYPTION_KEY_FILE=/run/secrets/chat2db-community-encryption.key \ --volume "$HOME/.config/chat2db-community/encryption.key:/run/secrets/chat2db-community-encryption.key:ro" \ chat2db/chat2db:latest也可以用仓库自带的 docker-compose.yml 一条命令拉起:
docker compose --file docker/docker-compose.yml up --detach然后浏览器访问http://localhost:10825即可。注意 Community 是单用户应用,HTTP 服务必须绑定 127.0.0.1,不要暴露给不可信网络;升级时重建容器,但encryption.key必须保留,否则已保存的密码和 API Key 无法解密。
需要定制的企业可以走源码编译。环境要求 Temurin 17、Node.js 18.17+、Maven 3.8+。先编译后端可执行包:
mvn -B clean package -Dmaven.test.skip=true -Dchat2db.finalName=chat2db-community \ -f chat2db-community-server/pom.xml -pl chat2db-community-start -am再以 WEB 模式启动(完整参数可对照 README_CN.md):
java -Dloader.path=chat2db-community-server/chat2db-community-start/target/lib \ -Dchat2db.gui=false -Dchat2db.runtime.mode=community -Dchat2db.mode=WEB \ -Dchat2db.network.status=OFFLINE \ -Dchat2db.community.encryption-key-file="$HOME/.config/chat2db-community/encryption.key" \ -Dserver.address=127.0.0.1 -Dserver.port=10825 \ -Dspring.profiles.active=dev \ -jar chat2db-community-server/chat2db-community-start/target/chat2db-community.jar前端本地开发调试则是标准的 Yarn 流程:
cd chat2db-community-client yarn install --frozen-lockfile yarn run start:community:hot部署跑通之后,下一步通常是拿它和商业化版本做取舍。
版本横向对比:社区版与商业版的能力边界
作为技术决策者,你最关心的其实是两件事:本地版已经包含了什么,商业版又多了什么。
| 能力项 | 社区版 · 桌面模式 | 社区版 · Docker/Web | 商业版 Pro/Enterprise |
|---|---|---|---|
| 40+ 数据库连接与 SQL 工作空间 | ✅ | ✅ | ✅ |
| 元数据浏览、DDL/DML 管理 | ✅ | ✅ | ✅ |
| 数据导入导出、Dashboard 图表 | ✅ | ✅ | ✅ |
| AI 助手(接入自己的模型) | ✅ | ✅ | ✅ |
| 官方 AI 服务 | ❌ | ❌ | ✅ |
| 账号体系与云端存储 | ❌ | ❌ | ✅ |
| 多设备同步 | ❌ | ❌ | ✅ |
| 团队协作与治理能力 | ❌ | ❌ | ✅ |
可以往前看的是两个演进方向:后端已引入 Spring AI 的 MCP Server 组件,前端也有独立的 McpSetting 设置模块,说明对接MCP(Model Context Protocol,让大模型调用外部工具的标准协议)工具链正在路线上;同时 chat2db-community-plugins 目录按数据库划分插件模块,目前已覆盖 MySQL、Oracle、ClickHouse、Redis 等 30+ 驱动,后续数据库的扩展计划沿这个结构推进。对这两个目录的持续跟踪,基本就能摸清社区的迭代方向。
回到开头痛点:数据不能出域、云服务够不着时,本地优先架构不是妥协,而是唯一路径。Chat2DB Community 把 40+ 数据库的完整本地工作空间和自有 AI 模型能力做到了免费可自部署,按本文步骤,几条命令就能进生产内网。仓库地址:https://gitcode.com/GitHub_Trending/ch/Chat2DB
【免费下载链接】Chat2DBChat2DB is a free, cross-platform, local-first database client and SQL workspace for developers, DBAs, analysts, and data teams. Connect to 40+ databases, manage data, edit and run SQL, and use your own AI model to generate, explain, and optimize queries. Available on desktop, web, Docker, and CLI, with MCP support.项目地址: https://gitcode.com/GitHub_Trending/ch/Chat2DB
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考