1.下载
下载地址:https://packagecloud.io/Altinity/clickhouse
2.上传rpm
上传rpm包到服务器node01、node02、node03服务器上的/kkb/soft路径下
3.每台节点安装下面的2个依赖
sudo yum install -y libtool
sudo yum install -y *unixODBC*
每台节点安装ck服务
cd /kkb/soft/
sudo rpm -ivh clickhouse*rpm
#注意:请确保soft目录下没有除ClickHouse.rpm结尾以外的rpm结尾的安装包
4.修改配置文件
修改config.xml三台机器都修改配置文件
# node01
sudo vim /etc/clickhouse-server/config.xml
#放开注释的这一行
<listen_host>::</listen_host>
#将配置文件拷贝到其他机器上面去
sudo scp /etc/clickhouse-server/config.xml node02:/etc/clickhouse-server/
sudo scp /etc/clickhouse-server/config.xml node03:/etc/clickhouse-server/
#注意:如果此不报错,则说明第三部操作失败 ,请从第三部重试。
创建metrika.xml
#node01
sudo vim /etc/metrika.xml
<yandex>
<!-- 集群配置 -->
<clickhouse_remote_servers>
<bip_ck_cluster>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node01</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node02</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node03</host>
<port>9000</port>
</replica>
</shard>
</bip_ck_cluster>
</clickhouse_remote_servers>
<!-- 本节点副本,不同的机器配置不同 -->
<macros>
<replica>node01</replica>
</macros>
<!-- ZK -->
<zookeeper-servers>
<node index="1">
<host>node01</host>
<port>2181</port>
</node>
<node index="2">
<host>node02</host>
<port>2181</port>
</node>
<node index="3">
<host>node03</host>
<port>2181</port>
</node>
</zookeeper-servers>
<!-- 监听网络 -->
<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>
node02服务器创建metrika.xml
#node02
sudo vim /etc/metrika.xml
<yandex>
<!-- 集群配置 -->
<clickhouse_remote_servers>
<bip_ck_cluster>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node01</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node02</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node03</host>
<port>9000</port>
</replica>
</shard>
</bip_ck_cluster>
</clickhouse_remote_servers>
<!-- 本节点副本,不同的机器配置不同 -->
<macros>
<replica>node02</replica>
</macros>
<!-- ZK -->
<zookeeper-servers>
<node index="1">
<host>node01</host>
<port>2181</port>
</node>
<node index="2">
<host>node02</host>
<port>2181</port>
</node>
<node index="3">
<host>node03</host>
<port>2181</port>
</node>
</zookeeper-servers>
<!-- 监听网络 -->
<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>
node03服务器创建metrika.xml
#node03
sudo vim /etc/metrika.xml
<yandex>
<!-- 集群配置 -->
<clickhouse_remote_servers>
<bip_ck_cluster>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node01</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node02</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node03</host>
<port>9000</port>
</replica>
</shard>
</bip_ck_cluster>
</clickhouse_remote_servers>
<!-- 本节点副本,不同的机器配置不同 -->
<macros>
<replica>node03</replica>
</macros>
<!-- ZK -->
<zookeeper-servers>
<node index="1">
<host>node01</host>
<port>2181</port>
</node>
<node index="2">
<host>node02</host>
<port>2181</port>
</node>
<node index="3">
<host>node03</host>
<port>2181</port>
</node>
</zookeeper-servers>
<!-- 监听网络 -->
<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>
给予权限
#创建目录
sudo mkdir -p /var/lib/clickhouse/data
sudo mkdir -p /var/lib/clickhouse/metadata
sudo chmod -R 777 /var/lib/clickhouse/data
sudo chmod -R 777 /var/lib/clickhouse/metadata
搭建clickhouse过程中会生成对应的目录
配置文件路径:/etc/clickhouse-server/config.xml
日志文件路径:/var/log/clickhouse-server/
建表信息路径:/data/clickhouse/metadata/
分区数据路径:/data/clickhouse/data/
5.启动ClickHouse启动
sudo service clickhouse-server start
# 命令查看ck是否启动成功
ps -ef | grep clickhouse
连接客户端
clickhouse-client
show databases;
ClickHouse的服务停止
三个节点执行
sudo server clickhouse-server stop
5.命令行客户端连接ClickHouse
clickhouse-client -m -u [username] -h [ip] --password [password] --port [port]
--user 或者 -u
用户名。 默认值: default。
--password
密码。 默认值:空字符串。
--host 或者 -h
服务端的 host 名称, 默认是 'localhost'
--port
连接的端口,默认值: 9000。
--multiline 或者 -m
如果指定,允许多行语句查询(Enter 仅代表换行,不代表查询语句完结)。
演示:开启多行查询
clickhouse-client -m 或者 clickhouse-client -multiline