环境
三台服务器,ip分别 10.0.1.12,10.0.1.13,10.0.1.14
hostname分别为gtm,dbnode01,dbnode02,其中gtm为master
即:物理节点,三台,分别为gtm,dbnode01,dbnode02
逻辑节点,七个,分别为gtm,coordinator01,datanode11,datanode12,
coordinator02,datanode21,datanode22
下载源码
http://sourceforge.net/projects/postgres-xl/files/Releases/Version_9.2rc/postgres-xl-v9.2-src.tar.gz/download
目前的版本是基于postgresql9.2版本修改的,9.5版本也有,但是还没有正式发布。
解压编译安装
tar xvf postgres-xl-v9.2-src.tar.gz
./configure
make&make install
增加postgres用户
useradd postgres
passwd postgres
创建数据目录
sudo mkdir /pgdata
chown -R postgres:postgres /pgdata
初始化节点
GTM节点(gtm)
initgtm -Z gtm -D /pgdata/
coordinator&datanode节点(dbnode01)
initdb -D /pgdata/coordinator --nodename coordinator01
initdb -D /pgdata/datanode11 --nodename datanode11
initdb -D /pgdata/datanode12 --nodename datanode12
coordinator&datanode节点(dbnode02)
initdb -D /pgdata/coordinator --nodename coordinator02
initdb -D /pgdata/datanode21 --nodename datanode21
initdb -D /pgdata/datanode22 --nodename datanode22
7. 配置文件修改
每个物理节点hosts文件修改
vim /etc/hosts
10.0.1.13 gtm
10.0.1.14 dbnode01
10.0.1.15 dbnode02
master节点(gtm)
vim /pgdata/gtm.conf
nodename = 'gtm' listen_addresses = '*' port = 10000 startup = ACT
coordinator01&datanode11/datanode12节点(dbnode01)
coordinator01
vim /pgdata/coordinator/postgresql.conf
listen_addresses = '0.0.0.0' port = 10010 shared_buffers = 1000M pooler_port = 11010 gtm_host = 'gtm' gtm_port = 10000 pgxc_node_name = 'coordinator01'
datanode11
vim /pgdata/datanode11/postgresql.conf
listen_addresses = '0.0.0.0' port = 10011 pooler_port = 11011 shared_buffers = 1000M gtm_host = 'gtm' gtm_port = 10000 pgxc_node_name = 'datanode11'
datanode12
vim /pgdata/datanode12/postgresql.conf
listen_addresses = '0.0.0.0' port = 10012 pooler_port = 11012 shared_buffers = 1000M gtm_host = 'gtm' gtm_port = 10000 pgxc_node_name = 'datanode12'
三个节点的pg_hba.conf文件都增加
host all all 10.0.1.13/32 trust host all all 10.0.1.14/32 trust host all all 10.0.1.15/32 trust
coordinator02&datanode21/datanode22节点(dbnode02)
coordinator02
vim /pgdata/coordinator/postgresql.conf
listen_addresses = '0.0.0.0' port = 10020 pooler_port = 11020 shared_buffers = 1000M gtm_host = 'gtm' gtm_port = 10000 pgxc_node_name = 'coordinator02'
datanode21
vim /pgdata/datanode11/postgresql.conf
listen_addresses = '0.0.0.0' port = 10021 pooler_port = 11021 shared_buffers = 1000M gtm_host = 'gtm' gtm_port = 10000 pgxc_node_name = 'datanode21'
datanode22
vim /pgdata/datanode12/postgresql.conf
listen_addresses = '0.0.0.0' port = 10022 pooler_port = 11022 shared_buffers = 1000M gtm_host = 'gtm' gtm_port = 10000 pgxc_node_name = 'datanode22'
三个节点的pg_hba.conf文件都增加
host all all 10.0.1.13/32 trust host all all 10.0.1.14/32 trust host all all 10.0.1.15/32 trust
8. 启动各个节点
gtm节点(gtm)
gtm_ctl -Z gtm start -D /pgdata/
coordinator01、datanode11、datanode12(dbnode01)
pg_ctl -Z datanode start -D /pgdata/datanode11 pg_ctl -Z datanode start -D /pgdata/datanode12 pg_ctl -Z coordinator start -D /pgdata/coordinator
coordinator02、datanode21、datanode22(dbnode02)
pg_ctl -Z datanode start -D /pgdata/datanode21 pg_ctl -Z datanode start -D /pgdata/datanode22 pg_ctl -Z coordinator start -D /pgdata/coordinator
启动完成后节点进程
9. 添加节点信息到数据库
dbnode01,coordinator01节点
psql -p 10010
ALTER NODE coordinator01 WITH (TYPE=coordinator,host=dbnode01,PORT = 10010); CREATE NODE coordinator02 WITH (TYPE=coordinator,host=dbnode02,PORT = 10020); CREATE NODE datanode11 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10011); CREATE NODE datanode12 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10012); CREATE NODE datanode21 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10021); CREATE NODE datanode22 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10022); SELECT pgxc_pool_reload();
dbnode01,datanode11节点
psql -p 10011
CREATE NODE coordinator01 WITH (TYPE=coordinator,host=dbnode01,PORT = 10010); CREATE NODE coordinator02 WITH (TYPE=coordinator,host=dbnode02,PORT = 10020); ALTER NODE datanode11 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10011); CREATE NODE datanode12 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10012); CREATE NODE datanode21 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10021); CREATE NODE datanode22 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10022); SELECT pgxc_pool_reload();
dbnode01,datanode12节点
psql -p 10012
CREATE NODE coordinator01 WITH (TYPE=coordinator,host=dbnode01,PORT = 10010); CREATE NODE coordinator02 WITH (TYPE=coordinator,host=dbnode02,PORT = 10020); ALTER NODE datanode11 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10011); CREATE NODE datanode12 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10012); CREATE NODE datanode21 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10021); CREATE NODE datanode22 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10022); SELECT pgxc_pool_reload();
dbnode02,coordinator02节点
psql -p 10020
CREATE NODE coordinator01 WITH (TYPE=coordinator,host=dbnode01,PORT = 10010); ALTER NODE coordinator02 WITH (TYPE=coordinator,host=dbnode02,PORT = 10020); CREATE NODE datanode11 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10011); CREATE NODE datanode12 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10012); CREATE NODE datanode21 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10021); CREATE NODE datanode22 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10022); SELECT pgxc_pool_reload();
dbnode02,datanode21节点
psql -p 10021
CREATE NODE coordinator01 WITH (TYPE=coordinator,host=dbnode01,PORT = 10010); CREATE NODE coordinator02 WITH (TYPE=coordinator,host=dbnode02,PORT = 10020); CREATE NODE datanode11 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10011); CREATE NODE datanode12 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10012); ALTER NODE datanode21 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10021); CREATE NODE datanode22 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10022); SELECT pgxc_pool_reload();
dbnode02,datanode22节点
psql -p 10022
CREATE NODE coordinator01 WITH (TYPE=coordinator,host=dbnode01,PORT = 10010); CREATE NODE coordinator02 WITH (TYPE=coordinator,host=dbnode02,PORT = 10020); CREATE NODE datanode11 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10011); CREATE NODE datanode12 WITH (TYPE=datanode,host =dbnode01 ,PORT = 10012); CREATE NODE datanode21 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10021); ALTER NODE datanode22 WITH (TYPE=datanode,host =dbnode02 ,PORT = 10022); SELECT pgxc_pool_reload();
10. 查看节点加载情况
select * from pgxc_node;
11. 简单测试验证
postgresql-xl只有coordinator有写入权限,datanode只有只读权限。
psql -p 10010
create table t1(f1 int); create table t2(f1 int); insert into t1 values(1); insert into t2 values(2);
分别连接coordinator01,coordinator02,查看表和记录情况
minmin[postgres@postgres]> \dt
minmin[postgres@postgres]> select * from t1;
如果两个C节点都可以正常显示,那说明配置成功。
12. 完