1、上传并解压
tar -zxvf citus-11.1.5.tar.gz
2、安装依赖
yum install -y libcurl-devel lz4-devel libzstd-devel
3、编译安装
./configure --without-lz4 --without-zstd
make && make install
4、创建数据目录,初始化集簇
mkdir -p /home/pg14/{data_cn,data_worker01,data_worker02}
initdb -D /home/pg14/data_cn -k -U postgres -W
initdb -D /home/pg14/data_worker01 -k -U postgres -W
initdb -D /home/pg14/data_worker02 -k -U postgres -W
5、修改参数,启动数据库
vi /home/pg14/data_cn/postgresql.auto.conf
port=1921
shared_preload_libraries='citus'
listen_addresses='*'
vi /home/pg14/data_worker01/postgresql.auto.conf
port=7000
shared_preload_libraries='citus'
listen_addresses='*'
vi /home/pg14/data_worker02/postgresql.auto.conf
port=8000
shared_preload_libraries='citus'
listen_addresses='*'
pg_ctl -D /home/pg14/data_cn -l /tmp/logfile_cn start
pg_ctl -D /home/pg14/data_worker01 -l /tmp/logfile_w1 start
pg_ctl -D /home/pg14/data_worker02 -l /tmp/logfile_w2 start
6、创建citus 扩展
psql -U postgres -d postgres -p 1921
psql -U postgres -d postgres -p 7000
psql -U postgres -d postgres -p 8000
create extension citus;
7、配置hba文件
三个数据库集簇添加如下内容
# IPv4 local connections:
host all all 192.168.18.0/24 trust
pg_ctl reload -D /home/pg14/data_cn
pg_ctl reload -D /home/pg14/data_worker01
pg_ctl reload -D /home/pg14/data_worker02
8、配置协调节点
select * from citus_set_coordinator_host('192.168.18.66',1921);
9、添加数据节点
select * from citus_add_node('192.168.18.66',7000);
select * from citus_add_node('192.168.18.66',8000);
10、验证
postgres=# select * from citus_get_active_worker_nodes();
node_name | node_port
---------------+-----------
192.168.18.66 | 7000
192.168.18.66 | 8000