#建立用戶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個數據節點