Postgres-XL 10 集羣搭建

簡介

Postgres-XL是一個橫向擴展的開源數據庫集羣,具備足夠的靈活性來處理不一樣的數據庫工做負載。Postgres-XL的最終目標是提供橫跨全部類型數據庫工做負載的ACID一致性的數據庫可伸縮性html

ACID,指數據庫事務正確執行的四個基本要素的縮寫。包含:原子性(Atomicity)、一致性(Consistency)、隔離性(Isolation)、持久性(Durability)。一個支持事務(Transaction)的數據庫,必需要具備這四種特性,不然在事務過程(Transaction processing)當中沒法保證數據的正確性,交易過程很可能達不到交易方的要求。node

Postgres-XL主要組件

Postgres-XL由三個主要組件組成:GTM (Global Transaction Manager)、Coordinator和 Datanode。sql

GTM (Global Transaction Manager)

負責ACID,保證分佈式數據庫全局事務一致性。益於此,就算數據節點是分佈的,可是你在主節點操做增刪改查事務時,就如同只操做一個數據庫同樣簡單。shell

GTM Standby

GTM的備節點,增長該備用節點。當GTM出現問題時,GTM Standby能夠升級爲GTM,保證集羣正常工做。數據庫

GTM-Proxy

GTM須要與全部的Coordinators通訊,爲了下降壓力,能夠在每一個Coordinator機器上部署一個GTM-Proxy。vim

Coordinator

負責處理每一個來自Application的SQL任務,而且決定由哪一個Datanode執行,而後將任務計劃派發給相應的Datanode,根據須要收集結果返還給Application;centos

Datanode

負責存儲表的數據和本地執行由Coordinator派發的SQL任務。ruby

快速入門

模擬環境

本次的模擬環境使用的系統是centos7.2bash

hostname IP function
gtm 192.168.72.150 gtm
node1 192.168.72.151 coordinator & datanode
node2 192.168.72.152 coordinator & datanode

爲方便測試,全部節點關閉防火牆和SELINUXssh

配置hosts

全部節點添加如下解析:

# vim /etc/hosts
192.168.72.150	gtm
192.168.72.151	node1
192.168.72.152	node2

建立用戶

全部節點建立用戶

useradd postgres
passwd postgres

ssh免密登陸

#在gtm節點建立key
su postgres
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

#複製key到其它節點
scp ~/.ssh/authorized_keys postgres@node1:~/.ssh/
scp ~/.ssh/authorized_keys postgres@node2:~/.ssh/

安裝postgres-xl

如下全部配置,在每一個節點都須要運行

安裝所需依賴包:

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

安裝postgres-xlpgxc_ctl

#下載解壓
wget https://www.postgres-xl.org/downloads/postgres-xl-10alpha2.tar.bz2
tar -jxvf postgres-xl-10alpha2.tar.bz2


#安裝
./configure --prefix=/home/postgres/pgxl/
make
make install
cd contrib/	
make
make install

編輯環境變量

# vim ~/.bashrc
export PGHOME=/home/postgres/pgxl
export PGUSER=postgres
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH

運行生效:

source ~/.bashrc

配置羣集

接下來,就要配置羣集,在gtm節點,運行pgxc_ctl,生成配置文件:

[postgres@gtm ~]$ pgxc_ctl
PGXC$  prepare config empty #生成一個空的配置文件/home/postgres/pgxc_ctl/pgxc_ctl.config
PGXC$  exit

修改配置文件

# vim ~/pgxc_ctl/pgxc_ctl.config
# 修改如下三項
pgxcInstallDir=$HOME/pgxl
pgxcOwner=postgres
dataDirRoot=$HOME/DATA/pgxl/nodes

# 添加如下配置
#===================================================
# gtm
gtmName=gtm
gtmMasterServer=gtm
gtmMasterPort=20001
gtmMasterDir=$dataDirRoot/gtm
#----End of reconfiguration -------------------------
#===================================================

# coordinator
coordNames=( coord1 coord2  )
coordMasterServers=( node1 node2  )
coordPorts=( 30001 30001  )
poolerPorts=( 30011 30011 )
coordPgHbaEntries=(0.0.0.0/0)	
coordMasterDirs=( $dataDirRoot/coord_master.1 $dataDirRoot/coord_master.2  )
coordMaxWALSenders=( 5 5  )
coordSlave=n
coordSlaveServers=( none none  )
coordSlavePorts=( none none  )
coordSlavePoolerPorts=( none none  )
coordSlaveDirs=( none none  )
coordArchLogDirs=( none none  )
coordSpecificExtraConfig=( none none  )
coordSpecificExtraPgHba=( none none  )
#----End of reconfiguration -------------------------
#===================================================
# database

datanodeNames=( dn1 dn2  )
datanodeMasterServers=( node1 node2  )
datanodePorts=( 40001 40001 )
datanodePoolerPorts=( 40011 40011  )
datanodePgHbaEntries=(0.0.0.0/0)
datanodeMasterDirs=( $dataDirRoot/dn_master.1 $dataDirRoot/dn_master.2  )
datanodeMasterWALDirs=( none none  )
datanodeMaxWALSenders=( 5 5  )
datanodeSpecificExtraConfig=( none none  )
datanodeSpecificExtraPgHba=( none none  )
#----End of reconfiguration -------------------------

初始化全部配置:

[postgres@gtm ~]$ pgxc_ctl init all

查看運行狀態:

[postgres@gtm ~]$ pgxc_ctl
PGXC$ monitor all
Running: gtm master
Running: coordinator master coord1
Running: coordinator master coord2
Running: datanode master dn1
Running: datanode master dn2

測試集羣

鏈接安裝了coordinator節點的主機,建立數據庫,查看同步狀況。

# 在node1節點上
$  psql -p 30001 postgres
postgres=# CREATE DATABASE testdb;
CREATE DATABASE
postgres=# \q

#在node2節點,剛纔建立的數據庫是否同步過來
$  psql -p 30001 testdb
testdb=# SELECT * FROM pgxc_node;
 node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred |   node_id   
-----------+-----------+-----------+-----------+----------------+------------------+-------------
 coord1    | C         |     30001 | node1     | f              | f                |  1885696643
 coord2    | C         |     30001 | node2     | f              | f                | -1197102633
 dn1       | D         |     40001 | node1     | f              | t                |  -560021589
 dn2       | D         |     40001 | node2     | f              | f                |   352366662
(4 rows)

能夠看到,在node2節點上,已經把在node1建立的數據庫同步過來。

參考連接: https://blog.csdn.net/yeruby/article/details/48996027 https://www.biaodianfu.com/postgres-xl.html https://www.postgres-xl.org/overview/ https://www.2ndquadrant.com/en/resources/postgres-xl/

相關文章
相關標籤/搜索