ClickHouse是一个面向联机分析处理(OLAP)的开源的面向列式存储的DBMS,简称CK, 与Hadoop, Spark相比,ClickHouse很轻量级,由俄罗斯第一大搜索引擎Yandex于2016年6月发布, 开发语言为C++。下面将详细介绍centos环境下的ClickHouse安装与使用。
操作系统版本:Centos 7.3
ClickHouse RMP包下载地址:http://repo.red-soft.biz/repos/clickhouse/stable/el7/
安装前需要修改一些centos系统配置。
需要验证当前服务器的CPU是否支持SSE 4.2指令集,因为向量化执行需要用到这项特性,检查命令如下:
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
如果支持则会显示 SSE 4.2 supported。
在/etc/security/limits.conf、/etc/security/limits.d/90-nproc.conf这2个文件的末尾加入一下内容:
vim /etc/security/limits.conf
在文件末尾添加:
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
vim /etc/security/limits.d/90-nproc.conf
在文件末尾添加:
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
重启服务器之后生效,用ulimit -n 或者ulimit -a查看设置结果。
修改/etc/selinux/config中的SELINUX=disabled后重启.
vim /etc/selinux/config
SELINUX=disabled
关闭防火墙,两种方式:
方式一:暂时关闭关闭防火墙:
systemctl stop firewalld.service
systemctl disable firewalld.service
方式二:关闭防火墙
service iptables stop
service ip6tables stop
注:
在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理 ;如果想要使用 service iptables start/stop 命令,需要下载 iptables-services。在 Centos 7 下下载 iptables-services 时,需要执行以下命令:
systemctl stop firewalld --关闭防火墙
systemctl mask firewalld
yum install iptables-services --安装iptables-services
systemctl enable iptables --设置开机启动
service iptables save --保存
1.6 安装ClickHouse相关依赖
yum install -y libtool
yum install -y *unixODBC*
mkdir -p /opt/software/clickhouse/
cd /opt/software/clickhouse/
wget -nd -r -l1 -A.rpm --no-parent http://repo.red-soft.biz/repos/clickhouse/stable/el7/
ClickHouse PRM包共五个文件:
clickhouse-client-1.1.54236-4.el7.x86_64.rpm -- clickhouse客户端
clickhouse-server-1.1.54236-4.el7.x86_64.rpm -- clickhouse服务端
clickhouse-compressor-1.1.54236-4.el7.x86_64.rpm --内置提供的压缩工具,可用于数据的正压反解。
clickhouse-server-common-1.1.54236-4.el7.x86_64.rpm
clickhouse-debuginfo-1.1.54236-4.el7.x86_64.rpm
方式一:单个安装:
rpm -ivh clickhouse-client-1.1.54236-4.el7.x86_64.rpm
rpm -ivh clickhouse-server-1.1.54236-4.el7.x86_64.rpm
rpm -ivh clickhouse-compressor-1.1.54236-4.el7.x86_64.rpm
rpm -ivh clickhouse-server-common-1.1.54236-4.el7.x86_64.rpm
rpm -ivh clickhouse-debuginfo-1.1.54236-4.el7.x86_64.rpm
方式二:批量安装:
rpm -ivh *.rpm
rpm安装后,会在服务器上生成如下几个文件:
# 默认配置文件位置
root@localhost.localdomain:/ # ls /etc/clickhouse-server
config.xml users.xml
# 上述文件定义了默认数据目录,临时目录位置,日志目录
/var/lib/clickhouse
/var/lib/clickhouse/tmp/
/var/log/clickhouse-server
# 默认启动脚本,注意,这个名字虽然叫server,其实是个shell脚本
/etc/rc.d/init.d/clickhouse-server
root@localhost.localdomain:/ # file /etc/rc.d/init.d/clickhouse-server
/etc/rc.d/init.d/clickhouse-server: POSIX shell script, ASCII text executable, with very long lines
# 最大文件打开数
root@localhost.localdomain:/ # cat /etc/security/limits.d/clickhouse.conf
clickhouse soft nofile 262144
clickhouse hard nofile 262144
# 默认crontab目录(没啥用)
/etc/cron.d/clickhouse-server
# 剩下就是/usr/bin下的二进制文件,但其实都是软链接到了clickhouse这个二进制文件
root@localhost.localdomain:/usr/bin # ll | grep click -i
-rwxr-xr-x 1 root root 63M Sep 20 16:58 clickhouse
lrwxrwxrwx 1 root root 10 Dec 11 17:14 clickhouse-client -> clickhouse
-rwxr-xr-x 1 root root 3.3M Sep 20 16:58 clickhouse-compressor
lrwxrwxrwx 1 root root 10 Dec 11 17:14 clickhouse-server -> clickhouse
ClickHouse需要进行一些权限配置,配置文件存放在/etc/clickhouse-server
。该目录下有四个配置文件:
重点关注config.xml 和 users.xml,其中:
config.xml 端口配置、本地机器名配置、内存设置等
users.xml 权限、配额设置
users.xml配置参考如下:
<?xml version="1.0"?>
<yandex>
<profiles>
<!-- 读写用户设置 -->
<default>
<max_memory_usage>10000000000</max_memory_usage>
<use_uncompressed_cache>0</use_uncompressed_cache>
<load_balancing>random</load_balancing>
</default>
<!-- 只写用户设置 -->
<readonly>
<max_memory_usage>10000000000</max_memory_usage>
<use_uncompressed_cache>0</use_uncompressed_cache>
<load_balancing>random</load_balancing>
<readonly>1</readonly>
</readonly>
</profiles>
<!-- 配额 -->
<quotas>
<!-- Name of quota. -->
<default>
<interval>
<duration>3600</duration>
<queries>0</queries>
<errors>0</errors>
<result_rows>0</result_rows>
<read_rows>0</read_rows>
<execution_time>0</execution_time>
</interval>
</default>
</quotas>
<users>
<!-- 读写用户 -->
<default>
<password_sha256_hex>967f3bf355dddfabfca1c9f5cab39352b2ec1cd0b05f9e1e6b8f629705fe7d6e</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</default>
<!-- 只读用户 -->
<ck>
<password_sha256_hex>967f3bf355dddfabfca1c9f5cab39352b2ec1cd0b05f9e1e6b8f629705fe7d6e</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>readonly</profile>
<quota>default</quota>
</ck>
</users>
</yandex>
[root@hadoop102 ~]# vim /etc/clickhouse-server/config.xml
<listen_host>::</listen_host>
<!-- <listen_host>::1</listen_host> -->
<!-- <listen_host>127.0.0.1</listen_host> -->
[root@hadoop103 ~]# vim /etc/clickhouse-server/config.xml
<listen_host>::</listen_host>
<!-- <listen_host>::1</listen_host> -->
<!-- <listen_host>127.0.0.1</listen_host> -->
[root@hadoop104 ~]# vim /etc/clickhouse-server/config.xml
<listen_host>::</listen_host>
<!-- <listen_host>::1</listen_host> -->
<!-- <listen_host>127.0.0.1</listen_host> -->
[root@hadoop102 ~]# vim /etc/metrika.xml
添加如下内容:
<yandex>
<clickhouse_remote_servers>
<perftest_3shards_1replicas>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>hadoop102</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<internal_replication>true</internal_replication>
<host>hadoop103</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>hadoop104</host>
<port>9000</port>
</replica>
</shard>
</perftest_3shards_1replicas>
</clickhouse_remote_servers>
<zookeeper-servers>
<node index="1">
<host>hadoop102</host>
<port>2181</port>
</node>
<node index="2">
<host>hadoop103</host>
<port>2181</port>
</node>
<node index="3">
<host>hadoop104</host>
<port>2181</port>
</node>
</zookeeper-servers>
<macros>
<replica>hadoop104</replica>
</macros>
<networks>
<ip>::/0</ip>
</networks>
<clickhouse_compression>
<case>
<min_part_size>10000000000</min_part_size>
<min_part_size_ratio>0.01</min_part_size_ratio>
<method>lz4</method>
</case>
</clickhouse_compression>
</yandex>
注意:上面标红的地方需要根据机器不同去修改
首先在三台机器开启Zookeeper
前台启动:
[root@hadoop102 software]# clickhouse-server --config-file=/etc/clickhouse-server/config.xml
后台启动:
[root@hadoop102 software]# nohup clickhouse-server --config-file=/etc/clickhouse-server/config.xml >null 2>&1 &
ClickHouse服务启动:
方式一:service clickhouse-server start
方式二:/etc/init.d/clickhouse-server start
运行 clickhouse-client 命令进入客户端:
clickhouse-client --只支持单行执行
clickhouse-client -m --支持多行执行
clickhouse-client命令行参数:
--host, -h -– 服务端的 host 名称, 默认是 ‘localhost’。 您可以选择使用 host 名称或者 IPv4 或 IPv6 地址。
--port – 连接的端口,默认值: 9000。注意 HTTP 接口以及 TCP 原生接口是使用不同端口的。
--user, -u – 用户名。 默认值: default。
--password – 密码。 默认值: 空字符串。
--query, -q – 非交互模式下的查询语句.
--database, -d – 默认当前操作的数据库. 默认值: 服务端默认的配置 (默认是 default)。
--multiline, -m – 如果指定,允许多行语句查询(Enter 仅代表换行,不代表查询语句完结)。
--multiquery, -n – 如果指定, 允许处理用逗号分隔的多个查询,只在非交互模式下生效。
--format, -f – 使用指定的默认格式输出结果。
--vertical, -E – 如果指定,默认情况下使用垂直格式输出结果。这与 ‘–format=Vertical’ 相同。在这种格式中,每个值都在单独的行上打印,这种方式对显示宽表很有帮助。
--time, -t – 如果指定,非交互模式下会打印查询执行的时间到 ‘stderr’ 中。
--stacktrace – 如果指定,如果出现异常,会打印堆栈跟踪信息。
--config-file – 配置文件的名称。
clickhouse默认是以default用户登录的,拥有读写权限。进入clickhouse-client客户命令后,创建数据库经常会报错。
DB::Exception: Received from localhost:9000, ::1. DB::Exception: Access to file denied: /var/lib/clickhouse/metadata/test.
该问题是由/var/lib/clickhouse/目录的权限导致,需要给clickhouse授权。
chown -R clickhouse /var/lib/clickhouse/
授权后能够正常使用。
参考:
https://blog.csdn.net/weixin_42411818/article/details/108174888
https://www.pianshen.com/article/47341561074/
内容来源于网络,如有侵权,请联系作者删除!