ClickHouse是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS)。
官方网站:https://clickhouse.com/
官方文档:https://clickhouse.com/docs/zh
下载地址:https://packages.clickhouse.com/rpm/stable/ #稳定版本
或者:https://packages.clickhouse.com/rpm/lts/ #长期支持版
1、关闭selinux
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
2、关闭防火墙
ClickHouse提供两个网络端口: TCP 默认9000,HTTP 默认8123,建议在内网环境下部署ClickHouse,关闭服务器防火墙。
CentOS-7.x默认使用的是firewall作为防火墙,关闭
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
systemctl mask firewalld
systemctl stop firewalld
yum remove firewalld
3、配置系统文件句柄数量
vi /etc/security/limits.d/clickhouse.conf #文件句柄数量的配置
clickhouse soft nofile 1048576
clickhouse hard nofile 1048576
:wq! #保存退出
4、安装ClickHouse
4.1、安装ClickHouse所需的依赖包
yum install -y libtool *unixODBC*
4.2、分别下载client,static,static-dbg,keeper-dbg和server五个安装包,五个包的版本要一致,这里以23.3.2.37版本为例。
clickhouse-client-23.3.2.37.x86_64.rpm
clickhouse-common-static-23.3.2.37.x86_64.rpm
clickhouse-common-static-dbg-23.3.2.37.x86_64.rpm
clickhouse-server-23.3.2.37.x86_64.rpm
clickhouse-keeper-dbg-23.3.2.37.x86_64.rpm
把下载的五个包放到一个空的文件夹下,比如:/usr/local/src 进入该目录下,执行rpm -ivh *.rpm命令安装,默认回车
rpm -ivh *.rpm #安装过程中会提示输入密码,直接回车不设置密码,密码后面我们在配置文件中设置。
4.3、目录说明
/etc/clickhouse-server:服务端的配置文件目录,包括全局配置config.xml和用户配置users.xml等
/etc/clickhouse-client:客户端配置,包括conf.d文件夹和config.xml文件
/var/lib/clickhouse:默认的数据存储目录,建议修改路径到大容量磁盘
/var/log/clickhouse-server:默认保存日志的目录,建议修改路径到大容量磁盘
4.4、新建存储目录
mkdir -p /data/server/clickhouse #数据存储目录
mkdir -p /data/server/clickhouse/log #日志存放目录
修改目录权限:
chown clickhouse:clickhouse /data/server/clickhouse -R
chown clickhouse:clickhouse /data/server/clickhouse/log -R
chmod 755 /data/server/clickhouse -R
chmod 755 /data/server/clickhouse/log -R
4.5、编辑config.xml配置文件,添加如下内容
cp /etc/clickhouse-server/config.xml /etc/clickhouse-server/config.xml.bak
vi /etc/clickhouse-server/config.xml
<timezone>Asia/Shanghai</timezone> #修改时区
<listen_host>::</listen_host> #开启外部访问
<path>/data/server/clickhouse/</path> #修改数据存放路径,默认是<path>/var/lib/clickhouse</path>
<level>none</level> #不记录日志
<!-- <log>/data/server/clickhouse/log/clickhouse-server.log</log> --> #不记录日志
<!-- <errorlog>/data/server/clickhouse/log/clickhouse-server.err.log</errorlog> --> #不记录日志
<max_open_files>1048576</max_open_files> #文件句柄数量的配置
<http_port>8123</http_port> #http默认端口
<tcp_port>9008</tcp_port> #tcp默认端口
:wq! #保存退出
4.6、设置数据库密码,默认用户名是:default
cp /etc/clickhouse-server/users.xml /etc/clickhouse-server/users.xml.bak
vi /etc/clickhouse-server/users.xml
<password>c5*rH7\*IYMk)</password>
:wq! #保存退出
#启动clickhouse
systemctl start clickhouse-server
systemctl status clickhouse-server
systemctl stop clickhouse-server
systemctl restart clickhouse-server
systemctl enable clickhouse-server
#如果启动报错,请再次检查设置权限
chown -R clickhouse:clickhouse /var/lib/clickhouse
chown -R clickhouse:clickhouse /var/log/clickhouse-server
chown -R clickhouse:clickhouse /etc/clickhouse-server
chown -R clickhouse:clickhouse /etc/clickhouse-client
chmod 755 /var/lib/clickhouse -R
chmod 755 /var/log/clickhouse-server -R
chmod 755 /etc/clickhouse-server -R
chmod 755 /etc/clickhouse-client -R
4.7、进入客户端,输入之前设置的密码
clickhouse-client --password
show databases; #查看数据库
exit; #退出控制台
4.8、查看clickhouse相关信息
#查看端口
netstat -tunlpa | grep 9000 #yum install -y net-tools
#查看日志
journalctl -xe | grep clickhouse-server
#命令行后台启动
nohup sudo -u "clickhouse" /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml &
#看看进程
lsof -i:8123
ps -ef | grep clickhouse-server
#卸载ClickHouse
rpm -qa | grep clickhouse
clickhouse-client-23.3.2.37-1.x86_64
clickhouse-keeper-dbg-23.3.2.37-1.x86_64
clickhouse-common-static-23.3.2.37-1.x86_64
clickhouse-server-23.3.2.37-1.x86_64
clickhouse-common-static-dbg-23.3.2.37-1.x86_64
#执行卸载命令
rpm -e clickhouse-client-23.3.2.37-1.x86_64
rpm -e clickhouse-keeper-dbg-23.3.2.37-1.x86_64
rpm -e clickhouse-server-23.3.2.37-1.x86_64
rpm -e clickhouse-common-static-dbg-23.3.2.37-1.x86_64
rpm -e clickhouse-common-static-23.3.2.37-1.x86_64
至此,Linux下ClickHouse单节点安装部署完成。
clickhouse-client --host=ip --port=9008 --user=default --password='密码'
ClickHouse
最新推荐文章于 2024-03-19 13:31:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)