文章目录
clickhouse安装部署
01节点 metrika.xml 配置文件信息
<?xml version="1.0"?>
<yandex>
<remote_servers>
<_3s2r_cluster> <!-- 集群名称-->
<shard> <!--集群的第一个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<!--该分片的第一个副本-->
<replica>
<host>foton1</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_1</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton2</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_1</default_database>
</replica>
</shard>
<shard> <!--集群的第二个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<replica> <!--该分片的第一个副本-->
<host>foton2</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_2</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton3</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_2</default_database>
</replica>
</shard>
<shard> <!--集群的第三个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<replica> <!--该分片的第一个副本-->
<host>foton3</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_3</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton1</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_3</default_database>
</replica>
</shard>
</_3s1r_cluster>
</remote_servers>
<zookeeper-servers>
<node index="1">
<host>foton1</host>
<port>2181</port>
</node>
<node index="2">
<host>foton2</host>
<port>2181</port>
</node>
<node index="3">
<host>foton3</host>
<port>2181</port>
</node>
</zookeeper-servers>
</yandex>
02节点 metrika.xml 配置文件信息
<?xml version="1.0"?>
<yandex>
<remote_servers>
<_3s2r_cluster> <!-- 集群名称-->
<shard> <!--集群的第一个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<!--该分片的第一个副本-->
<replica>
<host>foton1</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_1</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton2</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_1</default_database>
</replica>
</shard>
<shard> <!--集群的第二个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<replica> <!--该分片的第一个副本-->
<host>foton2</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_2</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton3</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_2</default_database>
</replica>
</shard>
<shard> <!--集群的第三个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<replica> <!--该分片的第一个副本-->
<host>foton3</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_3</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton1</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_3</default_database>
</replica>
</shard>
</_3s1r_cluster>
</remote_servers>
<zookeeper-servers>
<node index="1">
<host>foton1</host>
<port>2181</port>
</node>
<node index="2">
<host>foton2</host>
<port>2181</port>
</node>
<node index="3">
<host>foton3</host>
<port>2181</port>
</node>
</zookeeper-servers>
<macros>
<shard>01</shard>
<replica>cluster01-01-2</replica>
</macros>
<macros>
<shard>03</shard>
<replica>cluster01-02-1</replica>
</macros>
</yandex>
03节点 metrika.xml 配置文件信息
<?xml version="1.0"?>
<yandex>
<remote_servers>
<_3s2r_cluster> <!-- 集群名称-->
<shard> <!--集群的第一个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<!--该分片的第一个副本-->
<replica>
<host>foton1</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_1</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton2</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_1</default_database>
</replica>
</shard>
<shard> <!--集群的第二个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<replica> <!--该分片的第一个副本-->
<host>foton2</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_2</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton3</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_2</default_database>
</replica>
</shard>
<shard> <!--集群的第三个分片-->
<weight>1</weight>
<internal_replication>true</internal_replication>
<replica> <!--该分片的第一个副本-->
<host>foton3</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_3</default_database>
</replica>
<!--该分片的第二个副本-->
<replica>
<host>foton1</host>
<port>9002</port>
<user>default</user>
<password>xxx</password>
<default_database>mycluster_shard_3</default_database>
</replica>
</shard>
</_3s1r_cluster>
</remote_servers>
<zookeeper-servers>
<node index="1">
<host>foton1</host>
<port>2181</port>
</node>
<node index="2">
<host>foton2</host>
<port>2181</port>
</node>
<node index="3">
<host>foton3</host>
<port>2181</port>
</node>
</zookeeper-servers>
<macros>
<shard>01</shard>
<replica>cluster01-02-2</replica>
</macros>
<macros>
<shard>03</shard>
<replica>cluster01-03-2</replica>
</macros>
</yandex>
macros 实例信息编辑
01节点实例信息
02节点实例信息
03节点实例信息
查看结果
建表测试
在ck001服务器上通过客户端执行
create database mycluster_shard_1;
create database mycluster_shard_2;
create database mycluster_shard_3;
在ck002服务器上通过客户端执行
create database mycluster_shard_1;
create database mycluster_shard_2;
create database mycluster_shard_3;
在ck003服务器上通过客户端执行
create database mycluster_shard_1;
create database mycluster_shard_2;
create database mycluster_shard_3;
//在ck001上执行
create table mycluster_shard_1.tbl_rep(
c1 Int32,
mydate Date
) engine = ReplicatedMergeTree('/clickhouse/tables/1/dtbl', '1', mydate, (mydate), 8192);
//在ck002上执行
create table mycluster_shard_1.tbl_rep (
c1 Int32,
mydate Date
) engine = ReplicatedMergeTree('/clickhouse/tables/1/dtbl', '2', mydate, (mydate), 8192);
//在ck002上执行
create table mycluster_shard_2.tbl_rep (
c1 Int32,
mydate Date
) engine = ReplicatedMergeTree('/clickhouse/tables/2/dtbl', '1', mydate, (mydate), 8192);
//在ck003上执行
create table mycluster_shard_2.tbl_rep (
c1 Int32,
mydate Date
) engine = ReplicatedMergeTree('/clickhouse/tables/2/dtbl', '2', mydate, (mydate), 8192);
//在ck003上执行
create table mycluster_shard_3.tbl_rep (
c1 Int32,
mydate Date
) engine = ReplicatedMergeTree('/clickhouse/tables/3/dtbl', '1', mydate, (mydate), 8192);
//在ck001上执行
create table mycluster_shard_3.tbl_rep (
c1 Int32,
mydate Date
) engine = ReplicatedMergeTree('/clickhouse/tables/3/dtbl', '2', mydate, (mydate), 8192);
//在ck001上执行
use default;
create table dtbl (
c1 Int32,
mydate Date
) engine=Distributed('mycluster', '', tbl_rep, rand());
insert into table dtbl values(2, '2019-04-19')
insert into table dtbl values(1, '2019-04-19')
insert into table dtbl values(3, '2019-04-19')
select * from dtbl;
执行结果如下:
三节点三分片双副本
首先查看分布式表,三分片
然后查看本地表数据,由于插入了3条数据,如下每条数据都有2个副本,分别散在各个节点上。