centos6.5下postgres-XC集群安装与配置(两台)

一、系统环境

系统平台:centos 6.5

postgres-XC版本:pgxc-v1.2.1.tar.gz

防火墙关闭 selinux设置SELINUX=disabled

主机名

IP地址

角色

端口

nodename

数据目录

postgresql01

172.16.0.134

GTM

6666

gtm

/gtm

Coordinator

1921

coord1

/coordinator/cd1

Coordinator

1925

coord2

/coordinator/cd2

postgresql02

172.16.0.135

Datanode

15431

db1

/datanode/dn1

Datanode

15432

db2

/datanode/dn2

 

二、安装依赖包

yum install -y bison flex perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++   openssl-devel cmake

三、创建用户(两台操作)

groupadd pgxc

useradd pgxc -g pgxc

passwd pgxc

四、源码安装(两台操作)

tar zxvf pgxc-v1.2.1.tar.gz

cd postgres-xc-1.2.1/

./configure --prefix=/opt/pgxc --with-perl --with-python

gmake

gmake install

 

五、创建存放路径

在172.16.0.134主机操作如下:

[root@postgresql01 ~]# mkdir /gtm

[root@postgresql01 ~]# mkdir -p /coordinator/cd1

[root@postgresql01 ~]# mkdir -p /coordinator/cd2

[root@postgresql01 ~]# chown -R pgxc:pgxc /gtm

[root@postgresql01 ~]# chown -R pgxc:pgxc /coordinator

在172.16.0.135主机操作如下:

[root@postgresql02 ~]# mkdir -p /datanode/dn1

[root@postgresql02 ~]# mkdir -p /datanode/dn2

[root@postgresql02 ~]# chown -R pgxc:pgxc /datanode

六、配置环境变量

在172.16.0.134主机上

[pgxc@postgresql01 ~]$ vi .bash_profile

export PGPORT=1921

export PGDATA=/pgsql/data

export.utf8

export PGHOME=/opt/pgxc

export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib

export DATE=`date +"%Y%m%d%H%M"`

export PATH=$PGHOME/bin:$PATH:.

export MANPATH=$PGHOME/share/man:$MANPATH

alias rm='rm -i'

alias ll='ls -lh'

[pgxc@postgresql01 ~]$ source .bash_profile

 

[pgxc@postgresql02 ~]$ vi .bash_profile

export PGPORT=15431

export PGDATA=/datanode/dn1

export.utf8

export PGHOME=/opt/pgxc

export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib

export DATE=`date +"%Y%m%d%H%M"`

export PATH=$PGHOME/bin:$PATH:.

export MANPATH=$PGHOME/share/man:$MANPATH

alias rm='rm -i'

alias ll='ls -lh'

[pgxc@postgresql02 ~]$ source .bash_profile

七、初始化

1.在172.16.0.134操作如下:

[root@postgresql01 ~]# su - pgxc

[pgxc@postgresql01 ~]# initgtm -Z gtm -D /gtm

[pgxc@postgresql01 ~]# initdb -D /coordinator/cd1 --nodename coord1 -E UTF8 --locale=C -U pgxc -W

[pgxc@postgresql01 ~]# initdb -D /coordinator/cd2 --nodename coord2 -E UTF8 --locale=C -U pgxc -W

2.配置参数

配置gtm

[pgxc@postgresql01 ~]$ cd /gtm/

[pgxc@postgresql01 gtm]$ vi gtm.conf

nodename = 'gtm'

listen_addresses = '*'

port = 6666

startup = ACT

配置coordinator

[pgxc@postgresql01 ~]$ cd /coordinator/cd1/

[pgxc@postgresql01 cd1]$ vi postgresql.conf

# - Connection Settings -

listen_addresses = '*'

port = 1921

max_connections = 100

# DATA NODES AND CONNECTION POOLING

#----------------------------------

pooler_port = 6667

min_pool_size = 1

max_pool_size = 100

 

# GTM CONNECTION

#--------------------------

gtm_host = '172.16.0.134'

gtm_port = 6666

pgxc_node_name = 'coord1'

 

[pgxc@postgresql01 cd1]$ vi pg_hba.conf

# IPv4 local connections:

host    all             all             127.0.0.1/32            trust

host    all             all             172.16.0.0/24           trust

host    all             all             0.0.0.0/0               md5

 

[pgxc@postgresql01 cd1]$ cd /coordinator/cd2/

[pgxc@postgresql01 cd2]$ vi postgresql.conf

# - Connection Settings -

listen_addresses = '*' 

port = 1925

max_connections = 100

 

# DATA NODES AND CONNECTION POOLING

#------------------------------------------

pooler_port = 6668

min_pool_size = 1

max_pool_size = 100

 

# GTM CONNECTION

#------------------------------------

gtm_host = '172.16.0.134'

gtm_port = 6666

pgxc_node_name = 'coord2'

 

[pgxc@postgresql01 cd2]$ vi pg_hba.conf

# IPv4 local connections:

host    all             all             127.0.0.1/32            trust

host    all             all             172.16.0.0/24           trust

host    all             all             0.0.0.0/0               md5

 

3.在172.16.0.135操作如下:

[root@postgresql02 ~]# su - pgxc

[pgxc@postgresql02 ~]$ initdb -D /datanode/dn1 --nodename db1 -E UTF8 --local=C -U pgxc -W

[pgxc@postgresql02 ~]$ initdb -D /datanode/dn2 --nodename db2 -E UTF8 --local=C -U pgxc -W

 

4.配置参数

[pgxc@postgresql02 ~]$ cd /datanode/dn1/

[pgxc@postgresql02 dn1]$ vi postgresql.conf

CONNECTIONS AND AUTHENTICATION

#------------------------------------

listen_addresses = '*' 

port = 15431 

max_connections = 100 

# DATA NODES AND CONNECTION POOLING

#----------------------------------------------

pooler_port = 6667 

#min_pool_size = 1

max_pool_size = 100

 

# GTM CONNECTION

#-----------------------------

gtm_host = '172.16.0.134'

gtm_port = 6666 

pgxc_node_name = 'db1'

 

[pgxc@postgresql02 dn1]$ vi pg_hba.conf

# IPv4 local connections:

host    all             all             127.0.0.1/32            trust

host    all             all             172.16.0.0/24           trust

host    all             all             0.0.0.0/0               md5

 

[pgxc@postgresql02 dn1]$ cd /datanode/dn2/

# - Connection Settings -

listen_addresses = '*'

port = 15432

max_connections = 100

#------------------------------------------------------------------------------

# DATA NODES AND CONNECTION POOLING

#--------------------------------

pooler_port = 6667  

#min_pool_size = 1 

max_pool_size = 100 

#------------------------------------------------------------------------------

# GTM CONNECTION

#----------------------------

gtm_host = '172.16.0.134'

gtm_port = 6666

pgxc_node_name = 'db2'

 

[pgxc@postgresql02 dn2]$ vi pg_hba.conf

# IPv4 local connections:

host    all             all             127.0.0.1/32            trust

host    all             all             172.16.0.0/24           trust

host    all             all             0.0.0.0/0               md5

 

 

八、启动

1.在172.16.0.134启动gtm

[pgxc@postgresql01 ~]$ gtm -D /gtm &

2.查看是否启动成功

[pgxc@postgresql01 ~]$ gtm_ctl status -Z gtm -D /gtm

gtm_ctl: server is running (PID: 2153)

 "-D" "/gtm"

1 master

 

3.在172.16.0.135主机启动datanode

[pgxc@postgresql02 ~]$ pg_ctl start -D /datanode/dn1 -Z datanode

[pgxc@postgresql02 ~]$ pg_ctl start -D /datanode/dn2 -Z datanode

 

4.查看是否启动成功

[pgxc@postgresql02 ~]$ ps -ef | grep pgxc

root      2087  2047  0 21:54 pts/0    00:00:00 su - pgxc

pgxc      2088  2087  0 21:54 pts/0    00:00:00 -bash

pgxc      2168     1  0 22:13 pts/0    00:00:00 /opt/pgxc/bin/postgres --datanode -D /datanode/dn1

pgxc      2170  2168  0 22:13 ?        00:00:00 postgres: checkpointer process                   

pgxc      2171  2168  0 22:13 ?        00:00:00 postgres: writer process                         

pgxc      2172  2168  0 22:13 ?        00:00:00 postgres: wal writer process                     

pgxc      2173  2168  0 22:13 ?        00:00:00 postgres: autovacuum launcher process            

pgxc      2174  2168  0 22:13 ?        00:00:00 postgres: stats collector process                

pgxc      2179     1  0 22:14 pts/0    00:00:00 /opt/pgxc/bin/postgres --datanode -D /datanode/dn2

pgxc      2181  2179  0 22:14 ?        00:00:00 postgres: checkpointer process                   

pgxc      2182  2179  0 22:14 ?        00:00:00 postgres: writer process                         

pgxc      2183  2179  0 22:14 ?        00:00:00 postgres: wal writer process                     

pgxc      2184  2179  0 22:14 ?        00:00:00 postgres: autovacuum launcher process            

pgxc      2185  2179  0 22:14 ?        00:00:00 postgres: stats collector process                

pgxc      2190  2088  0 22:14 pts/0    00:00:00 ps -ef

pgxc      2191  2088  0 22:14 pts/0    00:00:00 grep pgxc

 

 

5.在172.16.0.134主机启动coordinator

[pgxc@postgresql01 ~]$ pg_ctl start -D /coordinator/cd1 -Z coordinator

[pgxc@postgresql01 ~]$ pg_ctl start -D /coordinator/cd2 -Z coordinator

6.查看是否成功

[pgxc@postgresql01 ~]$ ps -ef | grep pgxc

root      2055  2036  0 21:42 pts/0    00:00:00 su - pgxc

pgxc      2056  2055  0 21:42 pts/0    00:00:00 -bash

pgxc      2153  2056  0 22:11 pts/0    00:00:00 gtm -D /gtm

pgxc      2168     1  0 22:16 pts/0    00:00:00 /opt/pgxc/bin/postgres --coordinator -D /coordinator/cd1

pgxc      2170  2168  0 22:16 ?        00:00:00 postgres: pooler process                               

pgxc      2171  2168  0 22:16 ?        00:00:00 postgres: checkpointer process                         

pgxc      2172  2168  0 22:16 ?        00:00:00 postgres: writer process                               

pgxc      2173  2168  0 22:16 ?        00:00:00 postgres: wal writer process                           

pgxc      2174  2168  0 22:16 ?        00:00:00 postgres: autovacuum launcher process                  

pgxc      2175  2168  0 22:16 ?        00:00:00 postgres: stats collector process                      

pgxc      2180     1  0 22:17 pts/0    00:00:00 /opt/pgxc/bin/postgres --coordinator -D /coordinator/cd2

pgxc      2182  2180  0 22:17 ?        00:00:00 postgres: pooler process                               

pgxc      2183  2180  0 22:17 ?        00:00:00 postgres: checkpointer process                         

pgxc      2184  2180  0 22:17 ?        00:00:00 postgres: writer process                               

pgxc      2185  2180  0 22:17 ?        00:00:00 postgres: wal writer process                           

pgxc      2186  2180  0 22:17 ?        00:00:00 postgres: autovacuum launcher process                  

pgxc      2187  2180  0 22:17 ?        00:00:00 postgres: stats collector process                      

pgxc      2201  2056  0 22:17 pts/0    00:00:00 ps -ef

pgxc      2202  2056  0 22:17 pts/0    00:00:00 grep pgxc

 

九、配置集群节点信息

在172.16.0.134配置集群信息

[pgxc@postgresql01 ~]$ psql -p1921 postgres

psql (PGXC , based on PG 9.3.2)

Type "help" for help.

 

postgres=#select * from pgxc_node;

node_name | node_type | node_port |  node_host   | nodeis_primary | nodeis_preferred |   node_id  

-----------+-----------+-----------+--------------+----------------+------------------+-------------

 coord1    | C         |      5432 | localhost    | f              | f                |  1885696643

 

postgres=# create node db1 with(type='datanode',host='172.16.0.135',port=15431,primary,preferred);

 

postgres=# create node db2 with(type='datanode',host='172.16.0.135',port=15432);

 

postgres=# create node coord2 with(type='coordinator',host='172.16.0.134',port=1925);

 

 

postgres=# select * from pgxc_node;

 node_name | node_type | node_port |  node_host   | nodeis_primary | nodeis_preferred |   node_id  

-----------+-----------+-----------+--------------+----------------+------------------+-------------

 coord1    | C         |      5432 | localhost    | f              | f                |  1885696643

 db1       | D         |     15431 | 172.16.0.135 | t              | t                |    -2885965

 db2       | D         |     15432 | 172.16.0.135 | f              | f                |   -79866771

 coord2    | C         |      1925 | 172.16.0.134 | f              | f                | -1197102633

 

postgres=# select pgxc_pool_reload();

 

十、测试

[pgxc@postgresql01 ~]$ psql -p 1921 postgres

psql (PGXC , based on PG 9.3.2)

Type "help" for help.

 

postgres=# select * from pgxc_node;

 node_name | node_type | node_port |  node_host   | nodeis_primary | nodeis_preferred |   node_id  

-----------+-----------+-----------+--------------+----------------+------------------+-------------

 coord1    | C         |      5432 | localhost    | f              | f                |  1885696643

 db1       | D         |     15431 | 172.16.0.135 | t              | t                |    -2885965

 db2       | D         |     15432 | 172.16.0.135 | f              | f                |   -79866771

 coord2    | C         |      1925 | 172.16.0.134 | f              | f                | -1197102633

 

postgres=# create database test_xc;

CREATE DATABASE

 

postgres=#

 

说明上面成功

 

 

 

你可能感兴趣的:(Postgres-XC,postgres-XC集群)