前期准备
至少预留70GB空间,用于安装6台虚拟机。下图是刚安装后,还没怎么用过的分布式环境的空间占用情况,所以建议预留足够空间。安装配置单台虚拟机的步骤参考官网安装前准备,里边有傻瓜化操作步骤,不再赘述。
名词解释
CN:协调节点,coordinate node
DN:数据节点,data node
分布式安装模式选择
按照官网6.1节描述,有3种可选模式,本文选用最常见的“常规模式”。常规模式是1台服务器作为CN(协调者节点),N(N > 1)台服务器作为DN(工作节点),每个节点都是高可用方式部署 ,本次安装采用1个CN和2个DN的结构,每个节点都按1主1备方式部署,因此共需要6台服务器。
IP规划
IP | 备注 |
192.168.100.200 | 虚拟IP需要与配置的主备服务器在同一个网段,并且虚拟IP在本网段中没有被分配 |
192.168.100.101 | CN主节点 |
192.168.100.102 | CN备节点,也就是101节点的备份 |
192.168.100.103 | DN1主节点 |
192.168.100.104 | DN2主节点 |
192.168.100.105 | DN1备节点,也就是103节点的备份 |
192.168.100.106 | DN2备节点,也就是105节点的备份 |
整体拓扑图如下:
安装步骤
安装步骤参考官网即可,保姆级攻略,GUI安装和非GUI安装没啥本质的区别。
这里提一点,就是需要修改一个分布式参数canopy.shard_count,将其修改为32,目的只为测试分布式功能,不改关系也不大。
对分布式模式LightDB的一些小测试
lightdb@test1=# --创建一个普通本地表
lightdb@test1=# create table test_table(id int primary key, name text);
CREATE TABLE
lightdb@test1=# --插入10w条测试数据
lightdb@test1=# insert into test_table select v, v || 'name' from generate_series(1,100000) as v;
INSERT 0 100000
lightdb@test1=# --把普通表改为分布式表
lightdb@test1=# select create_distributed_table('test_table', 'id');
NOTICE: Copying data from local table...
NOTICE: copying the data has completed
DETAIL: The local data in the table is no longer visible, but is still on disk.
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$public.test_table$$)
create_distributed_table
--------------------------
(1 row)
lightdb@test1=# --测试一个查询操作,查看是否走分布式执行计划
lightdb@test1=# explain select count(*) from test_table;
QUERY PLAN
--------------------------------------------------------------------------------------------------------
Aggregate (cost=250.00..250.02 rows=1 width=8)
-> Custom Scan (Canopy Adaptive) (cost=0.00..0.00 rows=100000 width=8)
Task Count: 32
Tasks Shown: One of 32
-> Task
Node: host=localhost port=5432 dbname=test1
-> Aggregate (cost=43.99..44.00 rows=1 width=8)
-> Seq Scan on test_table_102008 test_table (cost=0.00..38.59 rows=2159 width=0)
(8 rows)
lightdb@test1=# --查看分布式表信息
lightdb@test1=# \x
Expanded display is on.
lightdb@test1=# select * from canopy_tables;
-[ RECORD 1 ]-------+------------
table_name | test_table
canopy_table_type | distributed
distribution_column | id
colocation_id | 1
table_size | 7488 kB
shard_count | 32
table_owner | lightdb
access_method | heap
lightdb@test1=# --查看表数据的分布情况
lightdb@test1=# \x
Expanded display is off.
lightdb@test1=# select table_name,shardid,shard_name,nodename,nodeport from canopy_shards;
table_name | shardid | shard_name | nodename | nodeport
------------+---------+-------------------+-----------+----------
test_table | 102008 | test_table_102008 | localhost | 5432
test_table | 102009 | test_table_102009 | localhost | 5432
test_table | 102010 | test_table_102010 | localhost | 5432
test_table | 102011 | test_table_102011 | localhost | 5432
test_table | 102012 | test_table_102012 | localhost | 5432
test_table | 102013 | test_table_102013 | localhost | 5432
test_table | 102014 | test_table_102014 | localhost | 5432
test_table | 102015 | test_table_102015 | localhost | 5432
test_table | 102016 | test_table_102016 | localhost | 5432
test_table | 102017 | test_table_102017 | localhost | 5432
test_table | 102018 | test_table_102018 | localhost | 5432
test_table | 102019 | test_table_102019 | localhost | 5432
test_table | 102020 | test_table_102020 | localhost | 5432
test_table | 102021 | test_table_102021 | localhost | 5432
test_table | 102022 | test_table_102022 | localhost | 5432
test_table | 102023 | test_table_102023 | localhost | 5432
test_table | 102024 | test_table_102024 | localhost | 5432
test_table | 102025 | test_table_102025 | localhost | 5432
test_table | 102026 | test_table_102026 | localhost | 5432
test_table | 102027 | test_table_102027 | localhost | 5432
test_table | 102028 | test_table_102028 | localhost | 5432
test_table | 102029 | test_table_102029 | localhost | 5432
test_table | 102030 | test_table_102030 | localhost | 5432
test_table | 102031 | test_table_102031 | localhost | 5432
test_table | 102032 | test_table_102032 | localhost | 5432
test_table | 102033 | test_table_102033 | localhost | 5432
test_table | 102034 | test_table_102034 | localhost | 5432
test_table | 102035 | test_table_102035 | localhost | 5432
test_table | 102036 | test_table_102036 | localhost | 5432
test_table | 102037 | test_table_102037 | localhost | 5432
test_table | 102038 | test_table_102038 | localhost | 5432
test_table | 102039 | test_table_102039 | localhost | 5432
(32 rows)