設置多磁盤存儲
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/clickhousechown -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 │
└─────────────┴─────────────┴─────────────────┴───────────────────────────────────────────────────────────────┴────────────────────┴─────────────┘