clickhouse的安装和使用教程 Centos7
clickhouse-server-21.9.4.35.tgz
clickhouse-common-static-dbg-21.9.4.35.tgz
clickhouse-common-static-21.9.4.35.tgz
clickhouse-client-21.9.4.35.tgz
以上是使用的包
下载地址
通过网盘分享的文件:clickhouse.zip
链接: https://pan.baidu.com/s/1REDJUyXk_AqAJY8u-wvtxA?pwd=hh8k 提取码: hh8k
在开始安装前,建议关闭防火墙以避免端口访问问题
systemctl stop firewalld.service
systemctl disable firewalld.service
验证CPU是否支持SSE4.2指令集,这是ClickHouse高效运行的关键特性
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
创建目标目录并解压所有组件到指定位置
mkdir -p /opt/module/clickhouse/
tar -zxvf clickhouse-common-static-21.9.4.35.tgz -C /opt/module/clickhouse/
tar -zxvf clickhouse-common-static-dbg-21.9.4.35.tgz -C /opt/module/clickhouse/
tar -zxvf clickhouse-server-21.9.4.35.tgz -C /opt/module/clickhouse/
tar -zxvf clickhouse-client-21.9.4.35.tgz -C /opt/module/clickhouse/
按顺序执行每个组件的安装脚本
cd /opt/module/clickhouse/clickhouse-common-static-21.9.4.35/
./install/doinst.sh
cd ../clickhouse-common-static-dbg-21.9.4.35/
./install/doinst.sh
cd ../clickhouse-server-21.9.4.35/
./install/doinst.sh
cd ../clickhouse-client-21.9.4.35/
./install/doinst.sh
配置修改
服务器配置
编辑主配置文件以支持远程连接和自定义数据路径
vi /etc/clickhouse-server/config.xml
<listen_host>0.0.0.0</listen_host>
<tcp_port>9001</tcp_port>
修改网络监听配置
vi /etc/clickhouse-server/config.xml
<listen_host>0.0.0.0</listen_host>
<tcp_port>9001</tcp_port>
路径配置
数据存储:<path>/opt/module/clickhouse/clickhouse-server/data/</path>
临时文件:<tmp_path>/opt/module/clickhouse/clickhouse-server/tmp/</tmp_path>
日志文件:<log>/var/log/clickhouse-server/clickhouse-server.log</log>
验证目录权限
检查目录所有权和权限设置:
ls -la /opt/module/var/
ls -la /opt/module/clickhouse/
修改用户访问权限
vim /etc/clickhouse-server/users.xml
<ip>::1</ip>
<ip>本机ip</ip>
systemctl start clickhouse-server
systemctl status clickhouse-server
# 设置开机自启
systemctl enable clickhouse-server
验证启动状态
ps aux | grep clickhouse
netstat -tlnp | grep clickhouse
无密码连接:clickhouse-client
重启服务并验证
修改配置后需要重启服务使更改生效
systemctl stop clickhouse-server.service
systemctl start clickhouse-server.service
systemctl status clickhouse-server.service
使用以下命令确认ClickHouse是否在正确端口上监听连接
netstat -tulnp | grep clickhouse
如果防火墙处于开启状态,需要开放ClickHouse相关端口
firewall-cmd --add-port=9000/tcp --permanent
firewall-cmd --add-port=8123/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
如果问题仍然存在,查看ClickHouse服务器日志获取详细错误信息
tail -f /var/log/clickhouse-server/clickhouse-server.log
重新启动服务
完成权限设置后重新启动ClickHouse服务:
systemctl daemon-reload
systemctl start clickhouse-server
systemctl status clickhouse-server
服务成功启动后,验证连接:
端口链接
clickhouse-client --port 9001
ip地址连接
clickhouse-client -h ip地址
在ClickHouse客户端中执行测试命令:
sql
Copy Code
SHOW DATABASES;
SELECT version();

浙公网安备 33010602011771号