Postgres

阅读: 评论:0

Postgres

Postgres

一、集群的规划

hostnameiprouleport
gtm192.168.1.1gtm6666
datanode1192.168.1.5coordinator & datanode1 & gtm proxy5432 5433
datanode2192.168.1.6coordinator & datanode2 & gtm proxy
backupnode1192.168.1.7datanode1 slaver15433
backupnode2192.168.1.8datanode2 slaver & gtm slaver20001

注:角色都可以根据自己的需求来划分,可灵活的调整

二、创建用户并装备环境,以下操作无特殊说明,每个节点都需要进行操作
1、创建postgres用户,并且创建ssh免密登陆的目录,授予权限

 useradd postgres passwd postgressu - postgresmkdir ~/.sshchmod 700 ~/.ssh

2、关闭防火墙和selinux

 systemctl stop firewalldsystemctl disable firewalld   #重启不会启动systemctl status firewalld    #查看一下状态,确定一下关闭selinux,编辑/etc/selinux/config文件将SELINUX的值设置为disabled

3、进行域名解析,配置/etc/hosts,在末尾添加如下内容

192.168.1.1 gtm
192.168.1.5 datanode1
192.168.1.6 datanode2
192.168.1.7 backupnode1
192.168.1.8 backupnode2

4、配置gtm到其他节点免密ssh登陆,在gtm节点操作

 su – postgresssh-keygen -t rsa    #这里一定要一直按回车,不要输入任何字符cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys scp ~/.ssh/authorized_keys postgres@datanode1:~/.ssh/authorized_keysscp ~/.ssh/authorized_keys postgres@datanode2:~/.ssh/authorized_keysscp ~/.ssh/authorized_keys postgres@backupnode1:~/.ssh/authorized_keysscp ~/.ssh/authorized_keys postgres@backupnode2:~/.ssh/authorized_keys

注:我们配置完可以验证一下,在gtm上用postgres用户ssh其他机器

#ssh postgres@datanode1      其他测试方法相同,看gtm能否免密登陆其他设备

三、安装postgress数据库,我们采用的源码安装方式,每个节点需要安装,切换为root用户
1、安装基础环境

yum install -y make gcc tar readline readline-devel zlib zlib-devel flex bison openjade docbook-style-dsssl

2、上传postgres-xl-9.5r1.压缩包
3、安装postgres-xl和pgxc_ctl

tar -zxvf postgres-xl-9.5r1.
cd postgres-xl
./configure --prefix=/home/postgres/pgxl/
make
make install
cd contrib/
make
make install

4、配置环境变量,在每个节点操作,需切换到postgres用户

su – postgres
# vi ~/.bashrc
export PGHOME=/usr/local/pgsql
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH
# source ~/.bashrc

注:可以用echo $PGHOME查看变量是否生效
5、每个节点目录权限设置,切换为root用户

su root
# chown -R postgres:postgres /usr/local/pgsql

6、配置集群配置文件,仅在gtm上配置,先生成一份模板,在修改其中内容,然后同步到其他设备,

gxc_ctl              ---忽略错误提示
PGXC prepare         ---该命令会生成一份模板配置文件
PGXC ^C

编辑/home/postgres/pgxc_ctl/f

#---- GTM Master -----------------------------------------------#---- Overall ----
gtmName=gtm
gtmMasterServer=gtm
gtmMasterPort=6666
gtmMasterDir=$HOME/pgxc/nodes/gtm#---- Configuration ---
gtmExtraConfig=none                     # Will be f for both Master and Slave (done at initilization only)
gtmMasterSpecificExtraConfig=none       # Will be added to Master'f (done at initialization only)#---- GTM Slave -----------------------------------------------# Because GTM is a key component to maintain database consistency, you may want to configure GTM slave
# for backup.#---- Overall ------
gtmSlave=y                                      # Specify y if you configure GTM Slave.   Otherwise, GTM slave will not be configured and# all the following variables will be reset.
gtmSlaveName=gtm_slaver
gtmSlaveServer=backupnode1              # value none means GTM slave is not available.  Give none if you don't configure GTM Slave.
gtmSlavePort=20001                      # Not used if you don't configure GTM slave.
gtmSlaveDir=$HOME/pgxc/nodes/gtm        # Not used if you don't configure GTM slave.
# Please note that when you have GTM failover, then there will be no slave available until you configure the slave
# again. (pgxc_add_gtm_slave function will handle it)#---- Configuration ----
gtmSlaveSpecificExtraConfig=none # Will be added to Slave'f (done at initialization only)

注:我只贴出部分配置,每个模块都一样,根据自己的规划图来配置

四、初始化集群并且启动集群,在gtm上初始化,操作会自动初始化(配置)各个节点。

pgxc_ctl  init all      #会初始化其他节点
pgxc_ctl  monitor all   #查看节点是否运行

五、测试集群
可以在任意节点上输入以下命令,查看除gtm以外的所有节点的配置情况:

select * from pgxc_node;

简单的测试,在datanode1节点上创建一个数据库test,并创建一个表test,插入数据:

psql -p 20004 -U postgres 
CREATE DATABASE test;
c test
CREATE TABLE test(id int);
INSERT INTO test VALUES(1);
SELECT * FROM test;
q

在datanode2节点上查看刚刚在datanode1节点的更改:

psql -p 20004 -U postgres  
c test
SELECT * FROM test;
q

测试是有数据,至此我们的pg_xl集群搭建完毕!

本文发布于:2024-02-01 11:35:46,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170675854636316.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:Postgres
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23