ReplicatedMergeTree分布式表引擎,同一分区下利用zookeeper进行同步数据。
Distributed有点类似于mysql merge存储引擎,比较适合读取。
那如果有四台机器,2个分片2个副本,怎么样才能写入快,读取快,并且写入的时候各个分片数据都比较均衡呢?
1,查看集群情况
testjian :] select cluster,shard_num,replica_num,host_name from system.clusters;
SELECT
cluster,
shard_num,
replica_num,
host_name
FROM system.clusters
┌─cluster────────────────┬─shard_num─┬─replica_num─┬─host_name──┐
│ clickhouse_test_netjoy │ 1 │ 1 │ 10.0.55.17 │
│ clickhouse_test_netjoy │ 1 │ 2 │ 10.0.10.23 │
│ clickhouse_test_netjoy │ 2 │ 1 │ 10.0.55.16 │
│ clickhouse_test_netjoy │ 2 │ 2 │ 10.0.10.24 │
└────────────────────────┴───────────┴─────────────┴────────────┘
4 rows in set. Elapsed: 0.001 sec.
分片号一样在同一分片,也就是说我只要写10.0.55.17 和10.0.55.16,或者写入10.0.10.23和10.0.10.24 ,四台机器都会有数据。
2,安装nginx-mod-stream
yum install nginx-mod-stream
3,配置nginx
stream{
upstream clickhouse8123{
server 10.0.55.17:8123 weight=1;
server 10.0.55.16:8123 weight=1;
}
server{
listen 8123;
proxy_pass clickhouse;
}
upstream clickhouse9000{
server 10.0.55.17:9000 weight=1;
server 10.0.55.16:9000 weight=1;
}
server{
listen 9000;
proxy_pass clickhouse9000;
}
}
注意,配置不能放到http中,配置不能放到http中,配置不能放到http中。
如果不装nginx-mod-stream,进行配置时,会报以下错误。
nginx: [emerg] unknown directive "stream" in /etc/nginx/conf.d/clickhouse.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/clickhouse/2530.html