ClickHouse单机以及集群部署方式
ClickHouse单机以及集群部署方式
单机部署
第一步:下载
yum install yum-utils
rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64
第二步:安装与卸载
yum install clickhouse-server clickhouse-client
如果需要卸载clickhouse:
yum remove clickhouse-server clickhouse-client
第三步:修改配置文件
clickhouse配置文件地址:/etc/clickhouse-server/config.xml
- 创建文件夹,用来存储日志以及数据
mkdir -p //clickhouse/log/clickhouse-server
mkdir -p //clickhouse/tmp
mkdir -p //clickhouse/user_files
mkdir -p //clickhouse/format_schemas
mkdir -p //clickhouse/access
- 修改目录所有者和群组
在修改目录所有者和群组之前需要先创建一个clickhouse的用户
#创建clickhouse的用户在群组clickhouse下面
useradd -m -g clickhouse clickhouse
#更改文件属性,让文件可写
chattr -i /etc/passwd
#修改目录所有者和群组
chown -R clickhouse:clickhouse //clickhouse
chown -R clickhouse:clickhouse /etc/clickhouse-server
- 修改配置文件权限
chmod 777 /etc/clickhouse-server/config.xml
chmod 777 /etc/clickhouse-server/users.xml
- 修改配置文件config和user
修改config.xml的如下标签
<log>//clickhouse/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>//clickhouse/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<path>//clickhouse/</path>
<tmp_path>//clickhouse/tmp/</tmp_path>
<user_files_path>//clickhouse/user_files/</user_files_path>
<format_schema_path>//clickhouse/format_schemas/</format_schema_path>
<path>//clickhouse/access/</path>
<max_table_size_to_drop>0</max_table_size_to_drop>
<max_partition_size_to_drop>0</max_partition_size_to_drop>
<listen_host>::</listen_host>
user.xml
<!--添加客户端链接的密码-->
<password>clickhouse</password>
- 服务的命令
#启动:
systemctl start clickhouse-server
#停止:
systemctl stop clickhouse-server
#查看状态:
systemctl status clickhouse-server
集群部署
集群部署在所有机器单机部署完成后进行
第一步:添加分布式配置文件
vi /etc/metrika.xml
文件内容
<?xml version="1.0" encoding="utf-8"?>
<yandex>
<clickhouse_remote_servers>
<!-- 集群名字,自定义 -->
<clickhouse_cluster>
<!-- 定义一个分片 -->
<shard>
<!-- Optional. Shard weight when writing data. Default: 1. -->
<weight>1</weight>
<!-- Optional. Whether to write data to just one of the replicas. Default: false (write data to all replicas). -->
<internal_replication>true</internal_replication>
<!-- 这个分片的副本存在在哪些机器上 -->
<replica>
<host>ch3</host>
<port>9001</port>
</replica>
<replica>
<host>ch2</host>
<port>9001</port>
</replica>
</shard>
</clickhouse_cluster>
</clickhouse_remote_servers>
<zookeeper-servers>
<node>
<host>ch1</host>
<port>8888</port>
</node>
</zookeeper-servers>
<!-- 在分布式表中的这个 shard 内只选择一个合适的 replica 写入数据。如果为本地表引擎为 ReplicatedMergeTree ,多个副本之间的数据交由引擎自己处理 -->
<macros>
<layer>01</layer>
<shard>03</shard>
<replica>ch2</replica>
</macros>
</yandex>
第二步:修改config.xml
首先删除config.xml中的remote_servers标签的所有配置,新增如下配置(添加了incl后会去metrika.xml中读取对应的配置)
<remote_servers incl="clickhouse_remote_servers" />
<zookeeper incl="zookeeper-servers" optional="true" />
<macros incl="macros" optional="true" />
第三步:启动集群验证
每台机器都启动clickhouse,验证集群是否启动成功
SELECT * FROM system.clusters;

浙公网安备 33010602011771号