设为首页 收藏本站
查看: 2218|回复: 0

[经验分享] centos6.5下postgres-XC集群安装与配置(两台)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-29 08:35:04 | 显示全部楼层 |阅读模式
一、系统环境
系统平台: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

五、创建存放路径
在172.16.0.134主机操作如下:
[iyunv@postgresql01 ~]# mkdir /gtm
[iyunv@postgresql01 ~]# mkdir -p /coordinator/cd1
[iyunv@postgresql01 ~]# mkdir -p /coordinator/cd2
[iyunv@postgresql01 ~]# chown -R pgxc:pgxc /gtm
[iyunv@postgresql01 ~]# chown -R pgxc:pgxc /coordinator
在172.16.0.135主机操作如下:
[iyunv@postgresql02 ~]# mkdir -p /datanode/dn1
[iyunv@postgresql02 ~]# mkdir -p /datanode/dn2
[iyunv@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操作如下:
[iyunv@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操作如下:
[iyunv@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=#

说明上面成功



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-91705-1-1.html 上篇帖子: corosync+pacemaker+crmsh实现高可用 下篇帖子: corosync+pacemaker+crmsh实现3节点高可用web服务
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表