#建立用户Postgresql groupadd Postgresqlnode
useradd Postgresql -g Postgresqlpython
#修改密码 passwd Postgresqlgit
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 cmakegithub
#下载Postgres-XC的安装包 到Postgres-XC下载 要求pg的版本最少9.1sql
#直接把安装包放在/home下面数据库
#解压,进入文件夹 cd /home/postgres-x2-XC1_0_BETA2_PG9_1bash
#配置 ./configure --prefix=/home/Postgresql/ --without-readline --without-zlib 编辑器
makepost
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
一、初始化节点
./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个数据节点