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

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:

一、系统环境

系统平台: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=#

 

说明上面成功

 

 本文转自 jxzhfei  51CTO博客,原文链接:http://blog.51cto.com/jxzhfei/1679422

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
19天前
|
Linux 网络安全 开发工具
Centos6.5安装并配置Telnet服务
该内容是一个关于如何安装配置Telnet服务的教程。首先,通过yum安装vim、xinetd、telnet和telnet-server。接着,修改/etc/xinetd.d/telnet配置文件,将disable改为no,并设置访问限制(如限定特定网段和时间)。关闭防火墙,重启服务。创建测试用户后,分别使用CentOS和Windows的Telnet客户端进行连接测试,显示成功,实验完成。
25 1
|
7天前
|
Linux
CentOS 7 配置yum阿里源 (三步即可)
CentOS 7 配置yum阿里源 (三步即可)
|
18天前
|
网络协议 Java 应用服务中间件
记录_centos7离线环境和虚拟机共享文件安装jdk和tomcat(配置环境变量)
记录_centos7离线环境和虚拟机共享文件安装jdk和tomcat(配置环境变量)
11 0
|
19天前
|
Linux 网络安全 开发工具
Centos7 sendmail服务安装与配置
该文本描述了在Linux系统中设置邮件服务的步骤。首先,启用httpd的邮件发送功能,然后安装sendmail、sendmail-cf和dovecot。接着配置/sendmail.mc,设定IP和邮件域名。在dovecot配置文件中启用imap、pop3和lmtp协议,取消明文认证限制,设定mail_location,并开启SSL。创建用户mail3和mail4,给予相应权限。停止postfix服务,编辑访问控制、提交配置、本地主机名等文件。最后,重置sendmail、dovecot和saslauthd服务。
45 0
|
19天前
|
运维 网络协议 Linux
【运维系列】Centos7安装并配置PXE服务
PXE是Intel开发的预启动执行环境,允许工作站通过网络从远程服务器启动操作系统。它依赖DHCP分配IP,DNS服务分配主机名,TFTP提供引导程序,HTTP/FTP/NFS提供安装源。要部署PXE服务器,需关闭selinux和防火墙,安装dhcpd、httpd、tftp、xinetd及相关服务,配置引导文件和Centos7安装源。最后,通过syslinux安装引导文件,并创建pxelinux.cfg/default配置文件来定义启动参数。
56 0
|
19天前
|
运维 网络协议 Linux
【运维系列】Centos7安装并配置postfix服务
安装CentOS7的Postfix和Dovecot,配置Postfix的`main.cf`文件,包括修改完全域名、允许所有IP、启用邮箱等。然后,配置Dovecot的多个配置文件以启用auth服务和调整相关设置。重启Postfix和Dovecot,设置开机自启,并关闭防火墙进行测试。最后,创建邮箱账户并在Windows邮箱客户端中添加账户设置。
17 0
|
19天前
|
网络协议 Linux 网络安全
Centos7 配置DNS服务
该教程指导配置DNS服务器:首先通过yum安装bind和cach件,然后修改IP设置。接着,编辑/etc/named.conf,将第13行和21行的参数改为"any"。在/etc/named.rfc1912中更新正向和反向域名。创建正向解析文件/var/named.localhost和反向解析文件/var/named.loopback,按指定格式添加解析记录。最后,重启服务,确保防火墙关闭,通过nslookup检查DNS配置效果。
26 1
|
19天前
|
Linux 网络安全
Centos6.5安装并配置NFS服务
该内容描述了在Linux系统中设置NFS服务的步骤。首先挂载yum源,然后安装NFS服务,并编辑配置文件。接着,重启rpcbind和NFS服务,可能需要重复此过程以解决初始可能出现的问题。此外,关闭防火墙策略,并再次重启服务。最终,根目录被共享,特定IP网段被允许访问。
26 0
|
19天前
|
开发工具 数据安全/隐私保护
Centos6.5安装并配置samba服务
配置Samba服务,执行`yum -y install samba`。创建finance、sales、manager组及对应用户:user1, user2(finance组),user3(sales组),manager(manager组)。设定用户密码。创建共享目录,给予finance组对finance目录的读写权限,编辑`smb.conf`。manager拥有所有共享目录的读写权限。确保用户对其共享文件夹有完全权限,其他用户只读写。重启服务。共享/opt/public_share为share,创建无登陆权用户Tonny,允许所有用户读写,文件属主为Tonny。最后,重启服务。
13 0
|
19天前
|
网络协议
Centos6.5配置网络适配器
使用`vi /etc/sysconfig/network/ifcfg-eth0`配置网卡,将ONBOOT设为YES,移除dhcp,设定IP为192.168.10.1,子网掩码255.255.255.0,网关192.168.10.254。可选设置DNS。最后,重启网络服务`service network restart`。
19 0