Postgres-XL 是一个完全满足ACID的、开源的、可方便进行水平扩展的、多租户安全的。支持share-nothing;支持海量数据并行处理-MPP(Massively Parallel Processing)。是不是跟 greenplum很相似。
主机分配
3台主机,安装centos6.2。当然可以准备多台服务器;这个视场景而定合理安排(gtm为一台独立的主机;例外每台机器最好同时配置一个Coordinator和一个Datanode,这样既不用担心二者的负载均衡,而且可以降低网络流量);
192.168.1.201 (gtm)
192.168.1.202 (coordinator,datanode)
192.168.1.203 (coordinator,datanode)
Postgres-XL下载安装
下载地址 -- http://www.postgres-xl.org/download/
下载包 :--postgres-xl-v9.2-src.tar.gz
在每一个节点上安装依赖包 ;
yum install -y flex bison readline-devel zlib-devel openjade docbook-style-dsssl gcc
安装Postgres-XL
在每个节点执行
# tar -zxvf postgres-xl-v9.2-src.tar.gz
# cd postgres-xl1
# ./configure --prefix=/usr/local/pgxl-9.2 --安装目录;可以不带。
# make
# make install
在gtm主机;即192.168.1.201执行 安装工具pgxc_ctl
# cd contrib/pgxc_ctl
# make
# make install
创建用户
# useradd postgres
# passwd postgres
配置环境变量
export PGUSER=postgres
export PGHOME=/usr/local/pgxl-9.2
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$HOME/bin:$PGHOME/bin:$PATH
在postgres家目录下的.bashrc文件添加上面内容;并source .bashrc使之生效!
配置ssh免密码登录for pgxc_ctl;
$ ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
$ scp ~/.ssh/authorized_keys [email protected]:~/.ssh/
$ scp ~/.ssh/authorized_keys [email protected]:~/.ssh/
若其他服务器没有.ssh目录;可手动创建下 mkdir .ssh;chmod 700 .ssh
配置集群并使用pgxc_ctl初始化集群;
在gtm节点服务器操作;新建192.168.1.201服务器的/home/postgres/pgxc_ctl/pgxc_ctl.conf文件;添加如下内容
#user and path pgxcOwner=postgres pgxcUser=$pgxcOwner pgxcInstallDir=/usr/local/pgxl-9.2 #gtm and gtmproxy gtmMasterDir=$HOME/pgxc/nodes/gtm gtmMasterPort=6666 gtmMasterServer=192.168.1.201 gtmSlave=n #gtm proxy gtmProxy=n #coordinator coordMasterDir=$HOME/pgxc/nodes/coord coordNames=(coord1 coord2) coordPorts=(5432 5432) poolerPorts=(6667 6668) coordPgHbaEntries=(192.168.1.0/32) coordMasterServers=(192.168.1.202 192.168.1.203) coordMasterDirs=($coordMasterDir/coord1 $coordMasterDir/coord2) coordMaxWALsernder=0 coordMaxWALSenders=($coordMaxWALsernder $coordMaxWALsernder) coordSlave=n coordSpecificExtraConfig=(none none none) coordSpecificExtraPgHba=(none none none) #datanode datanodeNames=(datanode1 datanode2) datanodePorts=(15432 15432) datanodePoolerPorts=(6669 6670) datanodePgHbaEntries=(192.168.1.0/32) datanodeMasterServers=(192.168.1.202 192.168.1.203) datanodeMasterDir=$HOME/pgxc/nodes/datanode datanodeMasterDirs=($datanodeMasterDir/datanode1 $datanodeMasterDir/datanode2) datanodeMaxWalSender=0 datanodeMaxWALSenders=($datanodeMaxWalSender $datanodeMaxWalSender) datanodeSlave=n primaryDatanode=datanode1
初始化集群
pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all
启动/关闭集群
pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf start all
pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf stop all
配置集群信息
在coordinator,datanode节点操作
在服务器192.168.1.202,192.168.1.203操作进入psql目录下 psql -p 5432 -d postgres ,psql -p 15432 -d postgres其他node做对应的操作;本地node只坐修改即可;其他都要create node。
select * from pgxc_node;
create node coord1 with (type=coordinator,host=‘192.168.1.202‘, port=5432);
create node coord2 with (type=coordinator,host=‘192.168.1.203‘, port=5432);
alter node coord1 with (type=coordinator,host=‘192.168.1.202‘, port=5432);
alter node coord2 with (type=coordinator,host=‘192.168.1.203‘, port=5432);
create node datanode1 with (type=datanode, host=‘192.168.1.202‘,port=15432,primary=true);
create node datanode2 with (type=datanode, host=‘192.168.1.203‘,port=15432);
alter node datanode1 with (type=datanode, host=‘192.168.1.202‘,port=15432,primary=true);
alter node datanode2 with (type=datanode, host=‘192.168.1.203‘,port=15432);
select pgxc_pool_reload();
测试环境OK?
以上步骤做好了;开始测试操作
[[email protected] datanode1]$ psql -p 5432 postgres psql (PGXL 9.2.0, based on PG 9.2.4 (Postgres-XL 9.2.0)) Type "help" for help. postgres=# create role lottu nosuperuser login encrypted password ‘li0924‘; CREATE ROLE postgres=# create tablespace tbs_lottu owner postgres location ‘/home/postgres/data/lottu‘; ERROR: directory "/home/postgres/data/lottu" does not exist postgres=# create tablespace tbs_lottu owner postgres location ‘/home/postgres/data/lottu‘; CREATE TABLESPACE postgres=# create database lottu owner lottu template template0 encoding ‘UTF8‘ tablespace tbs_lottu; CREATE DATABASE postgres=# \c lottu lottu lottu=> create table lottu01 (id int primary key, name varchar(10)); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "lottu01_pkey" for table "lottu01" CREATE TABLE lottu=> insert into lottu01 select generate_series(1,1000),‘lottu‘||generate_series(1,1000); INSERT 0 1000 [[email protected] datanode1]$ psql -p 5432 lottu lottu psql (PGXL 9.2.0, based on PG 9.2.4 (Postgres-XL 9.2.0)) Type "help" for help. lottu=> select count(*) from lottu01; count ------- 1000 (1 row) lottu=> \q [[email protected] datanode1]$ psql -p 15432 lottu lottu psql (PGXL 9.2.0, based on PG 9.2.4 (Postgres-XL 9.2.0)) Type "help" for help. lottu=> select count(*) from lottu01; count ------- 492 (1 row) [[email protected] ~]$ psql -p 15432 lottu lottu psql (PGXL 9.2.0, based on PG 9.2.4 (Postgres-XL 9.2.0)) Type "help" for help. lottu=> select count(*) from lottu01; count ------- 508 (1 row)
【FAQ】
1. 在配置集群信息出现
“WARNING: can not connect to GTM: No route to host
WARNING: Xid is invalid.
ERROR: GTM error, could not obtain snapshot XID = 0”
分析原因:看提示“No route to host”跟网络路由有关;也可以能跟防火墙有关
解决方案:配置防火墙或者关闭防火墙
2. 在创建role时出现“ERROR: Failed to get pooled connections”
分析原因:
1.首先我查看了pool进程是否存在;
2.核对检查下pgxc_pool的配置是否OK;
3.执行psql -h 192.168.1.203 -p 5432 发现超时;这就跟pg_hba.conf文件有关。
解决方案:
添加host all all 192.168.1.0/32 trust
其中的32跟主机设置的netmask有关
参考文献
--https://ruihaijiang.wordpress.com/2015/09/17/postgres-xl-installation-example-on-linux/