设置多磁盘存储
clickhouse安装完成以后,配置了一个默认的存储空间, 这个只能配置一个目录,如果要使用多个磁盘目录,则需要配置磁盘组策略
查看当前的存储策略
select name, path, formatReadableSize(free_space) as free, formatReadableSize(total_space) as total, formatReadableSize(keep_free_space) as reserved from system.disks;
可以看到只有一个default
┌─name────┬─path─────────────────────┬─free─────┬─total────┬─reserved─┐
│ default │ /data06/clickhouse/ │ 1.54 TiB │ 1.82 TiB │ 0.00 B │
└─────────┴──────────────────────────┴──────────┴──────────┴──────────┘
准备好磁盘目录
mkdir /data01/clickhouse
mkdir /data02/clickhouse
mkdir /data03/clickhouse
mkdir /data04/clickhouse
mkdir /data05/clickhouse
chown -R clickhouse:clickhouse /data01/clickhouse
chown -R clickhouse:clickhouse /data02/clickhouse
chown -R clickhouse:clickhouse /data03/clickhouse
chown -R clickhouse:clickhouse /data04/clickhouse
chown -R clickhouse:clickhouse /data05/clickhouse
添加配置
添加配置到/etc/clickhouse-server/config.xml 中
<storage_configuration>
<disks>
<disk_hot1> <!-- 自定义磁盘名称 -->
<path>/data01/clickhouse/</path>
</disk_hot1>
<disk_hot2>
<path>/data02/clickhouse/</path>
</disk_hot2>
<disk_hot3>
<path>/data03/clickhouse/</path>
</disk_hot3>
<disk_hot4>
<path>/data04/clickhouse/</path>
</disk_hot4>
<disk_hot5>
<path>/data05/clickhouse/</path>
</disk_hot5>
<disk_cold>
<path>/root/clickhouse_storage/cold/</path>
<keep_free_space_bytes>1073741824</keep_free_space_bytes>
</disk_cold>
</disks>
<policies>
<jbod_police> <!-- 自定义策略名称 -->
<volumes>
<jbod> <!-- 自定义磁盘组名称 -->
<disk>disk_hot1</disk>
<disk>disk_hot2</disk>
<disk>disk_hot3</disk>
<disk>disk_hot4</disk>
<disk>disk_hot5</disk>
</jbod>
</volumes>
</jbod_police>
<hot_cold_police>
<volumes>
<hot>
<disk>disk_hot1</disk>
<disk>disk_hot2</disk>
<max_data_part_size_bytes>1048576</max_data_part_size_bytes>
</hot>
<cold>
<disk>disk_cold</disk>
</cold>
</volumes>
<move_factor>0.2</move_factor>
</hot_cold_police>
</policies>
</storage_configuration>
- keep_free_space_bytes:选填项,表示不被使用的磁盘空间大小
- jbod策略只需要配置一个磁盘组,part(如202107_0_0_0)储存轮询每个disk;适用于挂载了多块磁盘,但未配置RAID
- hot/cold策略配置hot和cold两个磁盘组, part未超过(max_data_part_size_bytes[选填项] * move_factor[选填项, 默认0.1])则储存在hot磁盘组,超过则储存在cold磁盘组;适用于挂载了SSD和HDD磁盘
- 磁盘策略可以配置多个
配置生效
依次重启每个节点:
/etc/init.d/clickhouse-server restart
再看磁盘disk就有多个了:
:) select name, path, formatReadableSize(free_space) as free, formatReadableSize(total_space) as total, formatReadableSize(keep_free_space) as reserved from system.disks;
┌─name──────┬─path─────────────────────┬─free─────┬─total────┬─reserved─┐
│ default │ /data03/clickhouse/ │ 1.54 TiB │ 1.82 TiB │ 0.00 B │
│ disk_hot1 │ /data06/clickhouse/ │ 1.58 TiB │ 1.82 TiB │ 0.00 B │
│ disk_hot2 │ /data07/clickhouse/ │ 1.61 TiB │ 1.82 TiB │ 0.00 B │
│ disk_hot3 │ /data08/clickhouse/ │ 1.58 TiB │ 1.82 TiB │ 0.00 B │
│ disk_hot4 │ /data09/clickhouse/ │ 1.58 TiB │ 1.82 TiB │ 0.00 B │
│ disk_hot5 │ /data10/clickhouse/ │ 1.60 TiB │ 1.82 TiB │ 0.00 B │
└───────────┴──────────────────────────┴──────────┴──────────┴──────────┘
存储策略也可以看到了,这个存储策略在建表的时候,可以指定
:) select policy_name, volume_name, volume_priority, disks, formatReadableSize(max_data_part_size) max_data_part_size, move_factor from system.storage_policies;
┌─policy_name─┬─volume_name─┬─volume_priority─┬─disks─────────────────────────────────────────────────────────┬─max_data_part_size─┬─move_factor─┐
│ default │ default │ 1 │ ['default'] │ 0.00 B │ 0 │
│ jbod_police │ jbod │ 1 │ ['disk_hot1','disk_hot2','disk_hot3','disk_hot4','disk_hot5'] │ 0.00 B │ 0.1 │
└─────────────┴─────────────┴─────────────────┴───────────────────────────────────────────────────────────────┴────────────────────┴─────────────┘