#创建用户Postgresql groupadd Postgresql
useradd Postgresql -g Postgresql
#修改密码 passwd Postgresql
安装依赖包
yum -y install gcc* libtool* libxml2-devel readline-devel flex bison crypto* perl-ExtUtils-Embed zlib-devel pam-devel libxslt-devel openldap-devel python-devel openssl-devel cmake
#下载Postgres-XC的安装包 到Postgres-XC下载 要求pg的版本最少9.1
#直接把安装包放在/home下面
#解压,进入文件夹 cd /home/postgres-x2-XC1_0_BETA2_PG9_1
#配置
./configure --prefix=/home/Postgresql/ --without-readline --without-zlib
make
make install
cd /home/Postgresql
#创建文件夹 mkdir PostgresqlCluster
#更改文件所属
chown -R Postgresql:Postgresql *
到 /home/Postgresql文件夹下面显示隐藏文件,有个文件叫.bash_profile,用编辑器打开,增加环境变量 export PGPORT=15431
export PGDATA=/home/Postgresql/PostgresqlCluster/db_1/data
export PGHOME=/home/Postgresql
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
export MANPATH=$PGHOME/share/man:$MANPATH
退出Postgresql用户
su - Postgresql
set
查看环境变量配置是否已经生效
#初始化数据库1和2 ./bin/initdb -D PostgresqlCluster/db_1/data --nodename db_1
./bin/initdb -D PostgresqlCluster/db_2/data --nodename db_2
#注意192.168.234.128是本机ip
#修改Postgresql.conf参数
/home/Postgresql/PostgresqlCluster/db_1/data的Postgresql.conf
listen_addresses = '*'
port = 15431
gtm_host = '192.168.234.128'
gtm_port = 6666
/home/Postgresql/PostgresqlCluster/db_2/data
port = 15432,其他修改都一样
#修改PG_ hba.conf
host all all 192.168.234.128/32 trust
host all all 0.0.0.0/0 md5
#初始化节点 ./bin/initgtm -Z gtm -D PostgresqlCluster/gtm/data
1、初始化节点
./bin/initdb -D PostgresqlCluster/coor_1/data --nodename coor_1
./bin/initdb -D PostgresqlCluster/coor_2/data --nodename coor_2
#修改Postgresql.conf参数 修改配置文件在/home/Postgresql/PostgresqlCluster/coor_1/data
listen_addresses = '192.168.234.128'
port = 1921
gtm_host = '192.168.234.128'
gtm_port = 6666
PGxc_node_name = 'coor_1'
pooler_port = 6667
(第2个节点配置在/home/Postgresql/PostgresqlCluster/coor_2/data为
port = 1922
pgxc_node_name = 'coor_2'
pooler_port=6668 其他都一样修改 )
#修改PG_ hba.conf host all all 192.168.234.128/32 trust host all all 0.0.0.0/0 md5
启动顺序为GTM->GTM-Proxy->Coordinators->Datanodes 关闭顺序为Coordinators->Datanodes-> GTM-Proxy->GTM
#启动GTM
./bin/gtm -D PostgresqlCluster/gtm/data &
#查看 gtm 是否启动 ps -ef | grep gtm
#启动数据节点( 192.168.234.128 )
./bin/postgres -X -D PostgresqlCluster/db_1/data/ &
./bin/postgres -X -D PostgresqlCluster/db_2/data/ &
#启动coor节点( 192.168.234.128 )
./bin/postgres -C -D PostgresqlCluster/coor_1/data/ &
./bin/postgres -C -D PostgresqlCluster/coor_2/data/ &
备注:-C 表示 coordinator 节点。
#查看期待状态,查看GTM、POOl连接
netstat -anp | grep gtm
ps -ef | grep pool
#注册节点
drop node coor_1;
drop node coor_2;
create node coor_1 with(TYPE=coordinator,HOST='192.168.234.128',PORT=1921);
create node coor_2 with(TYPE=coordinator,HOST='192.168.234.128',PORT=1922);
drop node db_1;
drop node db_2;
create node db_1 with(TYPE=datanode,HOST='192.168.234.128',PORT=15431,primary=false);
create node db_2 with(TYPE=datanode,HOST='192.168.234.128',PORT=15432,primary=false);
alter node coor_1 with(TYPE='coordinator',HOST='192.168.234.128',PORT=1921);
alter node coor_2 with(TYPE='coordinator',HOST='192.168.234.128',PORT=1922);
alter node db_1 with(TYPE=datanode,HOST='192.168.234.128',PORT=15431,primary=true);
alter node db_2 with(TYPE=datanode,HOST='192.168.234.128',PORT=15432,primary=false);
select pgxc_pool_reload();
select * from pgxc_node;
#分别连接端口1921和1922的coor节点,把上面注册节点的sql执行一遍
./bin/psql -d postgres -p1921
./bin/psql -d postgres -p1922
#在端口是1921下面创建测试数据SQl
create database test;
create table test(id int);
insert into test select generate_series(1,10);
select * from test;
在coor1和coor2可以看到全部的数据,连接15431和15432数据节点,可以看到数据分布在2个数据节点
转载于:https://my.oschina.net/u/146747/blog/807377