0.ClickHouse
参考资料 :
Clickhouse 在腾讯的应用实践 : http://www.yidianzixun.com/article/0NaOwJjF?appid=mibrowser
0.基础概念
0.0.概述
俄罗斯 Yandex 2016 开源 列式存储数据库 DBMS
0.1.应用场景
在线分析处理查询OLAP – 使用SQL实时生成分析数据报告
0.2.适用场景
只有几列常用 查询非常快
1.安装及启动
1.1.方式一 单机模式
-
安装/卸载
-
1.确保CentOS支持外网
$ ping Baidu.com
-
2.确保CentOS支持SSE
$ grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
-
3.CentOS取消打开文件数限制
vi /etc/security/limits.conf # 在文件末尾追加配置 * soft nofile 65536 * hard nofile 65536 * soft nproc 131072 * hard nproc 131072 vi /etc/security/limits.d/20-nproc.conf # 在文件末尾追加配置 * soft nofile 65536 * hard nofile 65536 * soft nproc 131072 * hard nproc 131072
-
4.CentOS取消SELINUX
vi /etc/selinux/config # 修改SELINUX的值 SELINUX=disabled
-
5.创建安装目录/opt/software/clickhouse(不用)
$ mkdir /opt/software/clickhouse $ cd /opt/software $ ll
-
6.上传安装包
-
7.安装
-
8.解决依赖
$ yum install libicu.x86_64
-
9.重新安装
-
-
启动/关闭服务
-
1.启动服务
# 全局目录下 $ service clickhouse-server start
- 默认重启服务器服务自启动
-
2.关闭服务
-
3.卸载
$ yum list installed | grep clickhouse $ 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
-
-
进出客户端/交互模式 – 同集群模式
-
客户端内使用/交互模式内使用 – 同集群模式
1.2.方式二 分布式/集群模式
- 节点分布 : 10.255.175.240 10.255.175.241 10.255.175.242
-
安装/卸载 – 每个节点执行
-
0.分布式部署前提
-
0.1关闭防火墙
$ firewall-cmd --state $ systemctl stop firewalld $ firewall-cmd --state $ systemctl disable firewalld.service $ systemctl list-unit-files | grep firewalld
-
0.2修改主机名
$ vi /etc/hostname 第1行主机名改成 clickhousex $ reboot $ hostname
-
0.3修改主机名与IP映射
$ vi /etc/hosts 添加以下3行 10.255.175.240 clickhouse1 10.255.175.241 clickhouse2 10.255.175.242 clickhouse3
-
0.4配置SSH免密登录
# 1.开启Authentication免登陆 — 每个节点都操作 $ vi /etc/ssh/sshd_config 以下三行去掉注释 RSAAuthentication yes PubkeyAuthentication yes PermitRootLogin yes # 如果非root用户这行不需要 # 2.生成authorized_keys -- 每个节点都操作 $ ssh-keygen -t rsa # 生成key 会在/root/.ssh生成:authorized_keys id_rsa.pub id_rsa 三个文件 一直回车 # 3.合并公钥到authorized_keys文件 — master操作 $ cd /root/.ssh # 将三个节点的公钥逐一追加到master的authorized_key文件 $ cat id_rsa.pub>> authorized_keys $ ssh root@10.255.65.2 cat ~/.ssh/id_rsa.pub>> authorized_keys $ ssh root@10.255.65.3 cat ~/.ssh/id_rsa.pub>> authorized_keys # 将合并后信息持有三个公钥的authorized_key文件copy给其他两个slave节点 $ scp authorized_keys 10.255.65.2:/root/.ssh/ $ scp authorized_keys 10.255.65.3:/root/.ssh/ # 4.修改authorized_keys文件权限为只当前用户读写 — 每个节点都操作 $ cd /root/.ssh $ chmod 600 authorized_keys # 5.重启SSH服务 — 每个节点都操作 $ service sshd restart # 6.测试免密登录 — 每个节点都操作 $ ssh 10.255.175.x 测试互相访问对方是否不需要输入密码就可连接
-
5.创建软件文件夹 — 每个节点都操作
$ mkdir /opt/software $ cd /opt/software $ ll
-
6.CentOS上安装lrzsz工具
$ yum install lrzsz
-
7.安装zookeeper集群
-
-
1.确保CentOS支持外网$ ping Baidu.com
-
2.确保CentOS支持SSE
-
3.CentOS取消打开文件数限制
-
4.CentOS取消SELINUX
-
5.创建安装目录/opt/software/clickhouse
-
6.上传安装包
-
7.安装
-
8.解决依赖
-
9.重新安装
- 以上1~9步同单机模式
-
-
配置分布式部署
每台节点执行以下步骤 :
-
1.配置config.xml
vi /etc/clickhouse-server/config.xml # 把这行代码注释去掉 使其他IP可访问本机 <listen_host>::</listen_host>
-
2.新建metrika.xml
vi /etc/metrika.xml # 编写如下内容 <macros>部分根据不同机器更改 <yandex> # 服务器集群设置 <clickhouse_remote_servers> # 集群名 可自定义 张三 <clickhouse_cluster> # 数据分片1/分片信息(分片:我的数据有9条 我设置3个分片的话 就一个分片存储3条 分片就是一块储存区域 3个分片也一定在不同的节点上) <shard> # 开启自动复制/启用自动表备份 <internal_replication>true</internal_replication> # 副本 -- 指定本分片/节点上的数据的备份 要放在的哪写些节点上做备份 -- 节点2上放一份 节点3上放一份就要再加一个<reploca>标签 <replica> <host>hadoop102</host> <port>9000</port> </replica> </shard> # 数据分片2 <shard> <internal_replication>true</internal_replication> <replica> <host>hadoop103</host> <port>9000</port> </replica> </shard> # 数据分片3 <shard> <internal_replication>true</internal_replication> <replica> <host>hadoop104</host> <port>9000</port> </replica> </shard> </clickhouse_cluster> </clickhouse_remote_servers> # 配置高可用时需要ZK <zookeeper-servers> <node index="1"> <host>hadoop102</host> <port>2181</port> </node> <node index="2"> <host>hadoop103</h
-