PostgreSQL_配置Citus(分布式-单机多实例)

创建目录 一个cn节点 两个worker节点

[postgres@myserver01 Citus-main]$ su - postgres
[postgres@myserver01 ~]$ mkdir -p /home/postgres/data_cn
[postgres@myserver01 ~]$ mkdir -p /home/postgres/data_worker01
[postgres@myserver01 ~]$ mkdir -p /home/postgres/data_worker02

修改权限(可不修改)

[postgres@myserver01 ~]$ su root
[root@myserver01 postgres]# chown postgres.postgres -R /home/postgres/data_cn
[root@myserver01 postgres]# chmod -0700 -R /home/postgres/data_cn/*
[root@myserver01 postgres]# chown postgres.postgres -R /home/postgres/data_worker01
[root@myserver01 postgres]# chmod -0700 -R /home/postgres/data_worker01/*
[root@myserver01 postgres]# chown postgres.postgres -R /home/postgres/data_worker02
[root@myserver01 postgres]# chmod -0700 -R /home/postgres/data_worker02/*

每个实例都初始化一个实例

[postgres@myserver01 ~]$ initdb -D /home/postgres/data_cn -k
[postgres@myserver01 ~]$ initdb -D /home/postgres/data_worker01 -k
[postgres@myserver01 ~]$ initdb -D /home/postgres/data_worker02 -k

配置监听和pg_hba 和端口

[postgres@myserver01 ~]$ vi data_cn/pg_hba.conf 
[postgres@myserver01 ~]$ vi data_cn/postgresql.conf 
[postgres@myserver01 ~]$ vi data_worker01/pg_hba.conf 
[postgres@myserver01 ~]$ vi data_worker01/postgresql.conf 
[postgres@myserver01 ~]$ vi data_worker02/pg_hba.conf 
[postgres@myserver01 ~]$ vi data_worker02/postgresql.conf 
host    all             all             10.10.20.0/24            trust
listen_addresses = '*'
port = 1921   #注意 不同的实例 端口不同

启动每个数据库实例(一定要指定目录和端口)

[postgres@myserver01 ~]$ pg_ctl start -D /home/postgres/data_cn -l /tmp/logfile_cn -o "-p 1921"
waiting for server to start.... done
server started
[postgres@myserver01 ~]$ pg_ctl start -D /home/postgres/data_worker01 -l /tmp/logfile_01 -o "-p 7000"
waiting for server to start.... done
server started
[postgres@myserver01 ~]$ pg_ctl start -D /home/postgres/data_worker02 -l /tmp/logfile_02 -o "-p 8000"
waiting for server to start.... done
server started

编译安装citus(有些版本不支持 详情看官网吧)

[postgres@myserver01 citus-9.0.0]$ su root
[root@myserver01 citus-9.0.0]# yum install -y libcurl libcurl-devel

[postgres@myserver01 ~]$ cd /home/postgres/resoruce/
[postgres@myserver01 resoruce]$ ll
-rw-r--r--.  1 postgres postgres   7341325 Jul 11 11:15 Citus-main.zip
[postgres@myserver01 resoruce]$ unzip Citus-main
[postgres@myserver01 resoruce]$ cd Citus-main

[postgres@myserver01 Citus-main]$ su root
[root@myserver01 Citus-main]# yum install -y autoconf automake libtool

[root@myserver01 Citus-main]# su - postgres
[postgres@myserver01 ~]$ cd /home/postgres/resoruce/Citus-main
[postgres@myserver01 Citus-main]$ ./autogen.sh
[postgres@myserver01 Citus-main]$ ./configure
[postgres@myserver01 Citus-main]$ make
[postgres@myserver01 Citus-main]$ make install

每个实例添加预加载库

[postgres@myserver01 resoruce]$ vi /home/postgres/data_cn/postgresql.conf 
[postgres@myserver01 resoruce]$ vi /home/postgres/data_worker01/postgresql.conf 
[postgres@myserver01 resoruce]$ vi /home/postgres/data_worker02/postgresql.conf 
shared_preload_libraries = 'citus'

每个实例创建超级用户

[root@myserver01 resoruce]# psql -U postgres -d postgres -p 1921
postgres=# create user pgadmin with superuser password '1qaz@WSX';

每个实例创建扩展

postgres=# CREATE EXTENSION citus;
[postgres@myserver01 citus-9.0.0]$ psql -U postgres -d postgres -p 7000
psql (12.0)
Type "help" for help.

postgres=# create user pgadmin with superuser password '1qaz@WSX';
CREATE ROLE
postgres=# CREATE EXTENSION citus;
CREATE EXTENSION


[postgres@myserver01 citus-9.0.0]$ psql -U postgres -d postgres -p 8000
psql (12.0)
Type "help" for help.

postgres=# create user pgadmin with superuser password '1qaz@WSX';
CREATE ROLE
postgres=# CREATE EXTENSION citus;
CREATE EXTENSION

 设置1921为协调节点 7000 和8000为worker节点

[postgres@myserver01 citus-9.0.0]$ psql -U postgres -d postgres -p 1921
postgres=# SELECT citus_set_coordinator_host('myserver01', 1921);
postgres=# SELECT citus_add_node('myserver01', 7000);
postgres=# SELECT citus_add_node('myserver01', 8000);
postgres=# SELECT rebalance_table_shards();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值