環境node
三臺服務器,ip分別 10.0.1.12,10.0.1.13,10.0.1.14sql
hostname分別爲gtm,dbnode01,dbnode02,其中gtm爲master數據庫
即:物理節點,三臺,分別爲gtm,dbnode01,dbnode02vim
邏輯節點,七個,分別爲gtm,coordinator01,datanode11,datanode12,服務器
coordinator02,datanode21,datanode22post
下載源碼
測試http://sourceforge.net/projects/postgres-xl/files/Releases/Version_9.2rc/postgres-xl-v9.2-src.tar.gz/downloadspa
目前的版本是基於postgresql9.2版本修改的,9.5版本也有,可是尚未正式發佈。.net
解壓編譯安裝postgresql
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/
coordinator0一、datanode十一、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
coordinator0二、datanode2一、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. 完