ຖານຂໍ້ມູນ
ຖານຂໍ້ມູນທີ່ມຸ່ງເນັ້ນໃສ່ຖັນສຳລັບການວິເຄາະແບບເວລາຈິງ ແລະ ການປະມວນຜົນຂໍ້ມູນຂະໜາດໃຫຍ່
ສະຖາປັດຕະຍະກຳແບບ column-oriented ພ້ອມການບີບອັດທີ່ເຂັ້ມງວດ ໃຫ້ປະສິດທິພາບດ້ານ storage 10-100x ແລະ ປະສິດທິພາບ query ທີ່ດີເລີດ
ປະມວນຜົນຫຼາຍພັນລ້ານແຖວໃນລະດັບ millisecond ດ້ວຍການປະຕິບັດ query ແບບ vectorized ແລະ ການຂະໜານອັດຕະໂນມັດ
ນຳເຂົ້າຫຼາຍລ້ານແຖວຕໍ່ວິນາທີ ພ້ອມການໃຊ້ query ໄດ້ທັນທີສຳລັບການວິເຄາະແບບ real-time
ສະຖາປັດຕະຍະກຳແບບກະຈາຍຂະຫຍາຍໄປຫາຫຼາຍຮ້ອຍ node ດ້ວຍ sharding ແລະ replication ອັດຕະໂນມັດ
ໄວຍາກອນ SQL ທີ່ຄຸ້ນເຄີຍ ພ້ອມ window function, array, ໂຄງສ້າງຂໍ້ມູນຊ້ອນກັນ ແລະ ອັລກໍລິທຶມປະມານຄ່າ
ຕົວເຊື່ອມຕໍ່ພື້ນເມືອງສຳລັບ Kafka, S3, MySQL, PostgreSQL, MongoDB, HDFS ແລະ ຄວາມສາມາດ federated query
sudo apt update
sudo apt install -y apt-transport-https ca-certificates dirmngr
# Add GPG key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
# Add repository
echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list2. ຕິດຕັ້ງ ClickHouse Server ແລະ Client:sudo apt update
sudo apt install -y clickhouse-server clickhouse-client
# Set default password during installation (or leave blank for no password)3. ເລີ່ມ ClickHouse Service:sudo systemctl start clickhouse-server
sudo systemctl enable clickhouse-server
sudo systemctl status clickhouse-server4. ຕັ້ງຄ່າສຳລັບການເຂົ້າເຖິງຈາກພາຍນອກ:sudo nano /etc/clickhouse-server/config.xmlຊອກຫາແລ້ວເອົາເຄື່ອງໝາຍ comment ອອກ (ຫຼື ເພີ່ມ):<listen_host>0.0.0.0</listen_host>ເລີ່ມ service ໃໝ່:sudo systemctl restart clickhouse-server5. ສ້າງຜູ້ໃຊ້ແອດມິນ:# Connect to ClickHouse
clickhouse-client
# Create user
CREATE USER admin IDENTIFIED BY 'secure_password';
GRANT ALL ON *.* TO admin WITH GRANT OPTION;6. ທົດສອບການຕິດຕັ້ງ:# Connect with client
clickhouse-client --user admin --password secure_password
# Run test query
SELECT 'Hello, ClickHouse!' AS message;
# Create test table
CREATE TABLE test_table (
id UInt32,
name String,
timestamp DateTime
) ENGINE = MergeTree()
ORDER BY (id, timestamp);
# Insert test data
INSERT INTO test_table VALUES (1, 'Alice', now()), (2, 'Bob', now());
# Query data
SELECT * FROM test_table;7. ຕັ້ງຄ່າຜູ້ໃຊ້ (Production):sudo nano /etc/clickhouse-server/users.xmlເພີ່ມຜູ້ໃຊ້ແບບກຳນົດເອງ:<users>
<myuser>
<password_sha256_hex><!-- SHA256 hash of password --></password_sha256_hex>
<networks>
<ip>10.0.0.0/8</ip>
<ip>192.168.0.0/16</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</myuser>
</users>8. ຕັ້ງຄ່າ ZooKeeper ສຳລັບ Replication (ທາງເລືອກ):sudo apt install -y zookeeper zookeeperd
# Configure in config.xml
sudo nano /etc/clickhouse-server/config.xmlເພີ່ມການຕັ້ງຄ່າ ZooKeeper:<zookeeper>
<node>
<host>zk1.example.com</host>
<port>2181</port>
</node>
<node>
<host>zk2.example.com</host>
<port>2181</port>
</node>
<node>
<host>zk3.example.com</host>
<port>2181</port>
</node>
</zookeeper>9. ຕັ້ງຄ່າ Firewall:sudo ufw allow 9000/tcp # Native protocol
sudo ufw allow 8123/tcp # HTTP interface
sudo ufw allow 9009/tcp # Interserver communication10. ກວດສອບການຕິດຕັ້ງ:# Check version
clickhouse-server --version
# Check listening ports
sudo netstat -tlnp | grep clickhouse
# View logs
sudo tail -f /var/log/clickhouse-server/clickhouse-server.log
<listen_host>: ທີ່ຢູ່ IP ທີ່ຈະຟັງ (0.0.0.0 ສຳລັບທັງໝົດ)<http_port>: ພອດ HTTP interface (ຄ່າເລີ່ມຕົ້ນ 8123)<tcp_port>: ພອດ native protocol (ຄ່າເລີ່ມຕົ້ນ 9000)<max_connections>: ຈຳນວນການເຊື່ອມຕໍ່ພ້ອມກັນສູງສຸດ<max_concurrent_queries>: ຈຳກັດຈຳນວນ query ທີ່ເຮັດວຽກຂະໜານ<max_server_memory_usage>80000000000</max_server_memory_usage> <!-- 80GB -->
<max_memory_usage>40000000000</max_memory_usage> <!-- 40GB per query -->
<max_bytes_before_external_group_by>20000000000</max_bytes_before_external_group_by>
<max_threads>8</max_threads> <!-- Parallel query threads -->3. ການຕັ້ງຄ່າ Storage:<storage_configuration>
<disks>
<default>
<path>/var/lib/clickhouse/</path>
</default>
<fast_ssd>
<path>/mnt/fast_ssd/clickhouse/</path>
</fast_ssd>
<slow_hdd>
<path>/mnt/slow_hdd/clickhouse/</path>
</slow_hdd>
</disks>
<policies>
<hot_and_cold>
<volumes>
<hot>
<disk>fast_ssd</disk>
</hot>
<cold>
<disk>slow_hdd</disk>
</cold>
</volumes>
<move_factor>0.2</move_factor>
</hot_and_cold>
</policies>
</storage_configuration>4. ຕົວຢ່າງການສ້າງຕາຕະລາງ:-- MergeTree (basic)
CREATE TABLE events (
event_date Date,
event_time DateTime,
user_id UInt32,
event_type String,
url String
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(event_date)
ORDER BY (event_date, user_id)
SETTINGS index_granularity = 8192;
-- ReplicatedMergeTree (with replication)
CREATE TABLE events_replicated (
event_date Date,
event_time DateTime,
user_id UInt32,
event_type String
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/events', '{replica}')
PARTITION BY toYYYYMM(event_date)
ORDER BY (event_date, user_id);
-- Distributed table (cluster)
CREATE TABLE events_distributed AS events_replicated
ENGINE = Distributed(cluster_name, database_name, events_replicated, rand());5. ປະເພດຂໍ້ມູນ ແລະ ການບີບອັດ:CREATE TABLE metrics (
timestamp DateTime CODEC(Delta, ZSTD),
metric_name LowCardinality(String),
value Float64 CODEC(Gorilla, ZSTD),
tags Array(String),
metadata Map(String, String)
) ENGINE = MergeTree()
ORDER BY (metric_name, timestamp);6. ການປັບປຸງ Query:-- Use PREWHERE for filtering (faster than WHERE)
SELECT * FROM events
PREWHERE event_date >= today() - 7
WHERE user_id IN (SELECT id FROM users WHERE premium = 1);
-- Materialized views for pre-aggregation
CREATE MATERIALIZED VIEW events_hourly
ENGINE = SummingMergeTree()
PARTITION BY toYYYYMM(event_date)
ORDER BY (event_date, event_hour, event_type)
AS SELECT
toDate(event_time) AS event_date,
toHour(event_time) AS event_hour,
event_type,
count() AS event_count
FROM events
GROUP BY event_date, event_hour, event_type;7. ການເກັບຮັກສາຂໍ້ມູນ ແລະ TTL:-- Automatic data expiration
ALTER TABLE events
MODIFY TTL event_date + INTERVAL 90 DAY;
-- Move old data to cold storage
ALTER TABLE events
MODIFY TTL
event_date + INTERVAL 7 DAY TO VOLUME 'hot',
event_date + INTERVAL 30 DAY TO VOLUME 'cold',
event_date + INTERVAL 90 DAY DELETE;8. ການຕິດຕາມ Query:-- System metrics
SELECT * FROM system.metrics;
-- Current queries
SELECT query_id, user, query, elapsed FROM system.processes;
-- Query log analysis
SELECT
query_duration_ms,
read_rows,
read_bytes,
memory_usage,
query
FROM system.query_log
WHERE type = 'QueryFinish'
ORDER BY query_duration_ms DESC
LIMIT 10;
-- Table sizes
SELECT
database,
table,
formatReadableSize(sum(bytes)) AS size,
sum(rows) AS rows
FROM system.parts
WHERE active
GROUP BY database, table
ORDER BY sum(bytes) DESC;ແນວປະຕິບັດທີ່ດີທີ່ສຸດ:ເລີ່ມຕົ້ນໃນນາທີກັບຂະບວນການຕິດຕັ້ງ VPS ງ່າຍດາຍຂອງພວກເຮົາ
ນໍາໃຊ້ໃນປະມານ2ນາທີ • ເຂົ້າເຖິງ root ເຕັມ • ສະຫນັບສະຫນູນໂດຍຜ່ານປີ້ແລະອີເມວ