1 clickhouse简介
Clickhouse 是一个开源的面向联机分析处理(OLAP, On-Line Analytical Processing)的列式存储数据库管理系统。
优点 | 缺点 |
---|---|
写入快、查询快 | 不支持事务 |
SQL 支持 | 不适合典型的 K/V 存储 |
简单方便,不依赖 Hadoop 技术栈 | 不适合 Blob/Document 存储 |
支持线性扩展 | 不支持完整的 Update/Delete 操作 |
深度列存储 | 非跨平台 |
向量化查询执行 | 并非查询资源控制不好处理 |
数据压缩 | 不支持二级索引 |
并行和分布式查询 | |
实时数据更新 |
2 离线安装
2.1 安装
(1)Clickhouse 仅支持 Linux 操作系统,且机器 CPU 必须支持 SSE 4.2 指令集。
#cat /proc/cpuinfo
(2)第三方机构 Altinity 提供了完整的 rpm 包,支持在 Centos 下安装。
网址 https://packagecloud.io/Altinity/clickhouse 。
以下 4 个 rpm 包即可:
clickhouse-client :包含 clickhouse 客户端交互工具
clickhouse-common:包含 clickhouse 服务端执行脚本
clickhouse-server :包含 clickhouse 服务端配置文件
下载
clickhouse-client-20.5.4.40-1.el7.x86_64.rpm
clickhouse-common-static-20.5.4.40-1.el7.x86_64.rpm
clickhouse-server-20.5.4.40-1.el7.x86_64.rpm
clickhouse-server-common-20.5.4.40-1.el7.x86_64.rpm
(3)安装
#rpm -ivh *.rpm
安装后主要目录分布如下表:
/etc/clickhouse-server :clickhouse 服务端配置文件目录
/etc/clickhouse-client :clickhouse 客户端配置文件目录
/var/lib/clickhouse :clickhouse 默认数据目录
/var/log/clickhouse-server :clickhouse 默认日志目录
/etc/init.d/clickhouse-server :clickhouse 服务端启动脚本
2.2 启动与验证
(1)安装完成后,需要手动启动服务:
#systemctl status clickhouse-server查看
#systemctl start clickhouse-server
(2)进入 Clickhouse 客户端交互界面:
#clickhouse-client
查看数据库
2.3 卸载
yum makecache fast
(1)查看安装情况
yum list installed | grep clickhouse
(2)卸载
yum remove -y clickhouse-common-static
yum remove -y clickhouse-server-common
rm -rf /var/lib/clickhouse
rm -rf /etc/clickhouse-*
rm -rf /var/log/clickhouse-server
(3)卸载报错时强制删除
未实际测试
#删除rpm包的时候不调用卸载脚本
rpm -e clickhouse-server.x86_64 --noscripts
2.4 设置默认用户default的密码
明文密码
(1)查找user.xml文件
#cd /etc/clickhouse-server/
#vi users.xml
<!-- Users and ACL. -->
<users>
<!-- If user name was not specified, 'default' user is used. -->
<default>
<!-- Password could be specified in plaintext or in SHA256 (in hex format).
If you want to specify password in plaintext (not recommended), place it in 'password' element.
Example: <password>qwerty</password>.
Password could be empty.
If you want to specify SHA256, place it in 'password_sha256_hex' element.
Example: <password_sha256_hex>65e84be33532fb784c48129675f9eff3a682b27168c0ea744b2cf58ee02337c5</password_sha256_hex>
Restrictions of SHA256: impossibility to connect to ClickHouse using MySQL JS client (as of July 2019).
If you want to specify double SHA1, place it in 'password_double_sha1_hex' element.
Example: <password_double_sha1_hex>e395796d6546b1b65db9d665cd43f0e858dd4303</password_double_sha1_hex>
If you want to specify a previously defined LDAP server (see 'ldap_servers' in main config) for authentication, place its name in 'server' element inside 'ldap' element.
Example: <ldap><server>my_ldap_server</server></ldap>
How to generate decent password:
Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
In first line will be password and in second - corresponding SHA256.
How to generate double SHA1:
Execute: PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha1sum | tr -d '-' | xxd -r -p | sha1sum | tr -d '-'
In first line will be password and in second - corresponding double SHA1.
-->
<password></password>
<!-- List of networks with open access.
To open access from everywhere, specify:
<ip>::/0</ip>
To open access only from localhost, specify:
<ip>::1</ip>
<ip>127.0.0.1</ip>
Each element of list has one of the following forms:
<ip> IP-address or network mask. Examples: 213.180.204.3 or 10.0.0.1/8 or 10.0.0.1/255.255.255.0
2a02:6b8::3 or 2a02:6b8::3/64 or 2a02:6b8::3/ffff:ffff:ffff:ffff::.
<host> Hostname. Example: server01.yandex.ru.
To check access, DNS query is performed, and all received addresses compared to peer address.
<host_regexp> Regular expression for host names. Example, ^server\d\d-\d\d-\d\.yandex\.ru$
To check access, DNS PTR query is performed for peer address and then regexp is applied.
Then, for result of PTR query, another DNS query is performed and all received addresses compared to peer address.
Strongly recommended that regexp is ends with $
All results of DNS requests are cached till server restart.
-->
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<!-- Settings profile for user. -->
<profile>default</profile>
<!-- Quota for user. -->
<quota>default</quota>
<!-- User can create other users and grant rights to them. -->
<!-- <access_management>1</access_management> -->
</default>
</users>
修改<password></password>之后重启服务
#systemctl restart clickhouse-server
3 在线安装
3.1 安装
(1)检查系统是否支持SSE 4.2
Clickhouse 仅支持 Linux 操作系统,且机器 CPU 必须支持 SSE 4.2 指令集。
#cat /proc/cpuinfo
输出SSE 4.2 supported
(2)安装需要的工具
yum install yum-utils
注意安装完成后需要修改配置文件
vi /usr/bin/yum-config-manager
(3)加入PGP秘钥
rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
(4)添加yum库
yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64
(5)安装
yum install clickhouse-server clickhouse-client
注意:
clickhouse-client :包含 clickhouse 客户端交互工具
clickhouse-server :包含 clickhouse 服务端配置文件
安装后主要目录分布如下表:
/etc/clickhouse-server :clickhouse 服务端配置文件目录
/etc/clickhouse-client :clickhouse 客户端配置文件目录
/var/lib/clickhouse :clickhouse 默认数据目录
/var/log/clickhouse-server :clickhouse 默认日志目录
/etc/init.d/clickhouse-server :clickhouse 服务端启动脚本
3.2 启动与验证
(1)查看是否安装完成
查看版本
(2)安装完成后,需要手动启动服务
#systemctl status clickhouse-server查看
#systemctl start clickhouse-server
(3)进入 Clickhouse 客户端交互界面
#clickhouse-client
查看数据库
3.3 卸载
yum makecache fast
(1)查看安装情况
yum list installed | grep clickhouse
(2)卸载
yum remove -y clickhouse-common-static
yum remove -y clickhouse-server-common
rm -rf /var/lib/clickhouse
rm -rf /etc/clickhouse-*
rm -rf /var/log/clickhouse-server
(3)卸载报错时强制删除
未实际测试
#删除rpm包的时候不调用卸载脚本
rpm -e clickhouse-server.x86_64 --noscripts