ClickHouse单机安装

一、安装前准备

1.1、CentOS7 打开文件数限制

在 /etc/security/limits.conf 这个文件的末尾加入一下内容:

 sudo vim /etc/security/limits.conf

* soft nofile 65536 
* hard nofile 65536 
* soft nproc 131072 
* hard nproc 131072

在 /etc/security/limits.d/20-nproc.conf 这个文件的末尾加入一下内容:

# x0-xxx.conf 文件因操作系统不同
sudo vim /etc/security/limits.d/20-nproc.conf

* soft nofile 65536 
* hard nofile 65536 
* soft nproc 131072 
* hard nproc 131072

CentOS7 取消 SELINUX

vim /etc/selinux/config

SELINUX=disabled

重启服务器之后生效,用 ulimit -n 或者 ulimit -a 查看设置结果

ulimit -n

1.2、关闭防火墙

# 查看防火墙状态
systemctl status firewalld.service 
# 停止防火墙
systemctl stop firewalld.service 
# 启动防火墙
systemctl start firewalld.service

1.3、安装依赖

yum install -y libtool
yum install -y *unixODBC*

二、安装

ClickHouse的安装可以使用 yum在线安装,也可以使用 rpm 离线安装的方式!具体信息见官网文档:官网地址

2.1、准备操作

需要验证当前服务器的CPU是否支持SSE 4.2指令集,因为向量化执行需要用到这项特性

grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

2.1、安装操作

依次执行如下命令:

yum install yum-utils -y
rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/clickhouse.repo
yum install clickhouse-server clickhouse-client -y

如果您没法链接互联网,则也可以使用 rpm 的方式来进行离线安装:需要下载的安装包有:下载地址

clickhouse-server-20.5.4.40-2.noarch.rpm
clickhouse-common-static-20.5.4.40-2.x86_64.rpm
clickhouse-client-20.5.4.40-2.noarch.rpm

三、核心配置文件路径

3.1、配置文件路径

/etc/clickhouse-server:服务端的配置文件目录,包括全局配置config.xml和用户配置users.xml等。

/etc/clickhouse-server/config.xml

3.2、日志文件路径

/var/log/clickhouse-server:默认日志保存目录,通常会修改路径配置将日志保存到大容量磁盘挂载的路径

/var/log/clickhouse-server/

3.3、建表信息路径

/var/lib/clickhouse:默认数据存储目录,通常会修改默认路径配置,将数据保存到大容量磁盘挂载路径

# 刚开始安装是没有 metadata 目录的
/var/lib/clickhouse/metadata/

3.4、表数据路径

# 刚开始安装是没有 data 目录的
/var/lib/clickhouse/data/

3.5、可执行文件

可执行文件都在

/usr/bin

3.5.1、clickhouse

主程序的可执行文件

3.5.2、clickhouse-client

一个指向ClickHouse可执行文件的软链接,供客户端连接使用

3.5.3、clickhouse-server

一个指向ClickHouse可执行文件的软链接,供服务端启动使用

3.5.4、clickhouse-compressor

内置提供的压缩工具,可用于数据的正压反解

四、启动

4.1、前台启动

clickhouse-server --config-file=/etc/clickhouse-server/config.xml

第一次启动会报以下错误:

[root@hadoop102 ~]# clickhouse-server --config-file=/etc/clickhouse-server/config.xml
Processing configuration file '/etc/clickhouse-server/config.xml'.
Logging trace to /var/log/clickhouse-server/clickhouse-server.log
Logging errors to /var/log/clickhouse-server/clickhouse-server.err.log
Logging trace to console
2021.03.20 17:06:10.261154 [ 2490 ] {} <Information> SentryWriter: Sending crash reports is disabled
2021.03.20 17:06:10.264596 [ 2490 ] {} <Trace> Pipe: Pipe capacity is 1.00 MiB
2021.03.20 17:06:10.307780 [ 2490 ] {} <Information> : Starting ClickHouse 21.3.3.14 with revision 54448, build id: 7C39F44C9AD4D3BA36D74775616894F60A552276, PID 2490
2021.03.20 17:06:10.307885 [ 2490 ] {} <Information> Application: starting up
2021.03.20 17:06:10.493835 [ 2490 ] {} <Information> Application: Calculated checksum of the binary: 11A63B17AD9F07EA53F49019A0B82E36, integrity check passed.
2021.03.20 17:06:10.494001 [ 2490 ] {} <Trace> Application: Will do mlock to prevent executable memory from being paged out. It may take a few seconds.
2021.03.20 17:06:10.512014 [ 2490 ] {} <Trace> Application: The memory map of clickhouse executable has been mlock'ed, total 180.98 MiB
2021.03.20 17:06:10.512639 [ 2490 ] {} <Error> Application: DB::Exception: Effective user of the process (root) does not match the owner of the data (clickhouse). Run under 'sudo -u clickhouse'.
2021.03.20 17:06:10.512692 [ 2490 ] {} <Information> Application: shutting down
2021.03.20 17:06:10.512702 [ 2490 ] {} <Debug> Application: Uninitializing subsystem: Logging Subsystem
2021.03.20 17:06:10.513687 [ 2491 ] {} <Trace> BaseDaemon: Received signal -2
2021.03.20 17:06:10.513801 [ 2491 ] {} <Information> BaseDaemon: Stop SignalListener thread

主要原因是:启动 clickhouse 默认用户是 clickhouse 但是当前用户是root

解决方案:
第一种:创建一个用户组为 clickhouse 使用clickhouse用启动
第二种(推荐):

cd /var/lib/ 
chown -R root:root clickhouse

再次重新启动:

clickhouse-server --config-file=/etc/clickhouse-server/config.xml

4.2、后台启动

nohup clickhouse-server --config-file=/etc/clickhouse-server/config.xml 1>~/logs/clickhouse_std.log 2>~/logs/clickhouse_err.log &

4.3、检查

# 查看进程
ps -aux | grep clickhouse
# 查看端口
netstat -nltp | grep clickhouse

在这里插入图片描述

五、启动客户端

具体命令:

clickhouse-client

默认的用户是default

[root@hadoop102 ~]# clickhouse-client 
ClickHouse client version 21.3.3.14 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.3.3 revision 54447.

六、测试

6.1、查看所有数据库

show databases;

6.2、创建数据库

 create database clickhouse1;

6.3、切换数据库

use clickhouse1;

6.4、创建表

create table test01 (id Int8,name String) engine=TinyLog;

6.5、查询表列表

show tables;

6.6、插入数据

insert into test01 values (1,'clickhouse'),(2,'flink');

6.7、查询数据

select id,name from test01;

6.8、统计查询

select count(*) from test01;

6.9、退出客户端

quit

七、停止

直接 kill -9 进程id(粗暴)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_41311979

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值