推荐用官方仓库一键安装,核心三步:配源、装包、启服务;生产环境需调优配置和权限限制,系统支持ubuntu 22.04/24.04、centos 7/8、rocky/almalinux 8+,禁用老旧内核。

Linux 服务器上部署 ClickHouse,推荐用官方仓库一键安装,省去编译和依赖管理的麻烦。核心就三步:配源、装包、启服务。生产环境注意调优配置和权限限制,否则容易卡顿或连不上。
系统与硬件准备
ClickHouse 对 Linux 发行版兼容性好,Ubuntu 22.04/24.04、CentOS 7/8、Rocky/AlmaLinux 8+ 均可。不建议在老旧内核(
- 测试环境:2 核 CPU + 4GB 内存 + 20GB 磁盘(SSD 更佳)
- 生产环境:8 核起 + 32GB 起内存,磁盘空间按日增数据量 × 90 天预估,并预留 30% 空闲
- 提前关闭 SELinux(CentOS/RHEL 必做):
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config,重启生效 - 调高文件描述符限制(避免连接数不足):
在/etc/security/limits.conf末尾添加:* soft nofile 65536* hard nofile 65536* soft nproc 131072* hard nproc 131072
安装方式选型与执行
根据系统类型选择对应命令,全程无需下载 RPM/DEB 文件,自动拉取最新稳定版(当前为 24.12+)。
-
Ubuntu/Debian(APT):
sudo apt-get updatesudo apt-get install -y apt-transport-https ca-certificates dirmngrsudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.listsudo apt-get update && sudo apt-get install -y clickhouse-server clickhouse-client -
CentOS/RHEL/Rocky(YUM/DNF):
sudo yum install -y yum-utilssudo rpm --import https://repo.clickhouse.com/CLICKHOUSE-KEY.GPGsudo yum-config-manager --add-repo https://repo.clickhouse.com/rpm/clickhouse.reposudo yum install -y clickhouse-server clickhouse-client
安装过程会提示设置 default 用户密码 —— 强烈建议设一个,否则默认无密码,存在安全风险。
启动与基础验证
服务安装后不会自动启动,需手动操作并确认状态。
- 启动服务:
sudo systemctl start clickhouse-server - 设为开机自启:
sudo systemctl enable clickhouse-server - 检查运行状态:
sudo systemctl status clickhouse-server(看到active (running)即成功) - 本地连接测试:
clickhouse-client(若设了密码则加--password) - 简单验证语句:
SELECT version(), now(), uptime() FORMAT Vertical
如报错“Connection refused”,先确认服务是否真在运行;如提示“Can't connect to localhost:9000”,检查 /etc/clickhouse-server/config.xml 中 <listen_host></listen_host> 是否为 0.0.0.0(默认是 localhost,远程连不上)。
关键配置调优建议
开箱即用能跑,但要稳定高效,这几个配置项建议检查并修改(改完需重启服务):
-
监听地址:编辑
/etc/clickhouse-server/config.xml,把<listen_host>localhost</listen_host>改成<listen_host>0.0.0.0</listen_host>(如需远程访问) -
最大内存使用:在
users.xml的defaultprofile 下,调整:<max_memory_usage>26843545600</max_memory_usage>(例如设为 26GB) -
线程数上限:在
config.xml中搜索max_threads,设为 CPU 核心数 × 1.5(如 8 核 → 12) -
时区统一:在
config.xml中设置:<timezone>UTC</timezone>(避免跨时区时间字段解析错误)
改完记得执行:sudo systemctl restart clickhouse-server











