热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Postgresxl集群部署文档

Postgres-xl集群部署文档文档介绍文档介绍了如何部署PostgreSQL集群文档结构划分系统和安装流程图安装规划安装环境介绍安装准备安装过程安装验证1.系统和安装流程图概述
Postgres-xl集群部署文档

文档介绍

文档介绍了如何部署PostgreSQL集群

文档结构划分

  1. 系统和安装流程图
  2. 安装规划
  3. 安装环境介绍
  4. 安装准备
  5. 安装过程
  6. 安装验证

1.系统和安装流程图

概述:整体系统图,主要在展示整个安装系统图

如图所示:(系统图)

《Postgres-xl集群部署文档》 system.png

如图所示:(安装流程图)

《Postgres-xl集群部署文档》 liuchengtu.png

2.安装规划

概述:安装规划,主要给不同服务器划分为不同角色。
角色介绍:
1).Global Transaction Monitor (GTM)
全局事务管理器,确保群集范围内的事务一致性。
GTM负责发放事务ID和快照作为其多版本并发控制的一部分。
集群可选地配置一个备用GTM,以改进可用性。
此外,可以在协调器间配置代理GTM,可用于改善可扩展性,减少GTM的通信量。
2)GTM Standby
GTM的备节点,在pgxc,pgxl中,GTM
控制所有的全局事务分配,如果出现问题,就会导致整个集群不可用,
为了增加可用性,增加该备用节点。当GTM出现问题时,GTMStandby
可以升级为GTM,保证集群正常工作。
3)GTM-Proxy
GTM需要与所有的Coordinators通信,为了降低压力,
可以在每个Coordinator机器上部署一个GTM-Proxy。
4).Coordinator
协调员管理用户会话,并与GTM和数据节点进行交互。
协调员解析,并计划查询,并给语句中的每一个组件发送下一个序列化的全局性计划。
为节省机器,通常此服务和数据节点部署在一起。
5).Data Node
数据节点是数据实际存储的地方。数据的分布可以由
DBA来配置。为了提高可用性,可以配置数据节点的热备以便进行故障转移准备。
总结:
gtm是负责ACID的,保证分布式数据库全局事务一致性。得益于此,就算数据节点是分布的,但是你在主节点操作增删改查事务时,就如同只操作一个数据库一样简单。
Coordinator是调度的,将操作指令发送到各个数据节点。
datanodes是数据节点,分布式存储数据。

规划表:

《Postgres-xl集群部署文档》 规划图.png

注意:PGHOME=/home/pgxl_9.5

3.安装环境介绍

1).操作环境
Window7 64位系统 电脑一台
2).使用工具
putty:连接服务器
pscp:主要用于windows向linux发送文件,或由linux系统向windows发送文件;
3).服务器
3台服务器,并各自建立有3个虚拟机,系统版本统一为 Ubuntu(16.04.3)系统;
4).postgres-xl 版本: postgres-xl-9.5r1.4.tar.gz

4.安装准备

概述:安装准备,主要进行安装时,一些准备工作。

4.1下载源码压缩包—-postgres-xl

1)下载方式:
a.git方式下载:
git clone git://git.postgresql.org/git/postgres-xl.git
注意:请安装git,可采用sudo apt-get install git
b.网页下载:
网址为:https://sourceforge.net/projects/postgres-xl/
下载完后将软件包放入D盘根目录下 注意:这里采用网页方式下载,主要是因为ubuntu安装的git,下载该软件包比较麻烦。
2)将下载好的压缩包传送到规划表中IP地址172.17.30.15 -- 172.17.30.22 共8个系统中
(1) 采用Putty连接服务器:
a) 点击Session:
Host Name(or IP address):输入连接服务器的IP,点击Open连接到服务器
b) 在根目录下新建文件夹 postgres-xl_installPackage ,用以存放postgres-xl压缩包
(2) 采用pscp传送文件:
a) 下载pscp工具:
下载网址:https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
b) 将下载好的pscp.exe文件放到putty.exe一样的目录
c) 开始-运行-打开cmd窗口:
1) 进入到pscp.exe目录
2) 输入如下命令进行传送:
pscp 传送文件 主机名@IP:传送目录
如:
pscp D:\postgres-xl-9.5r1.4.tar.gz ubuntu@172.17.30.16:./postgres-xl_installPackage
注意:如果传送失败的话,可将传送目录更改到:/home/ubuntu/ 下,然后再将其移动到根目录下postgres-xl_installPackage文件夹中

5.安装过程

概述:安装过程,主要详细介绍部署Postgresql集群的每一步安装步骤
整个安装过程可以分为两大部分:
5.1.postgres-xl部分:图中除了LoadBlance的部分
5.2.负载均衡部分:图中的LoadBlance部分,这里采用Haporxy

5.1安装postgres-xl

概述:安装Postgres-xl,介绍了如何部署Postgres-xl
安装过程分为:
5.1.0:安装postgres-xl前配置
5.1.1:编译安装postgres-xl
5.1.2:设置postgres环境变量
5.1.3:初始化gtm,coordinator,datanode
5.1.4:修改postgres-xl配置文件
5.1.5:启动postgres-xl
5.1.6:配置postgres-xl集群部署
5.1.7:测试安装
注意:除了安装负载均衡的服务器外,都要安装。

5.1.0 安装Postgres-xl前配置

概述:介绍在Postgres-xl安装前,一些配置。
分为:
1:解压postgres-xl压缩包
2:创建一个用户,用户名为postgres,密码为123456
3:为postgres用户设置免密登录
4:修改/etc/hosts中内容
5:安装postgrex-xl相关依赖包
6:编译安装postgres-xl
7:设置postgres-xl环境变量

5.1.0.0 解压postgrex-xl压缩包

1)将文件夹postgres_installPackage 目录下的压缩包解压
(1)进入压缩包目录cd /postgres_installPackage
(2)解压文件:sudo tar –zvxf postgres-xl-9.5rl.4.tar.gz

5.1.0.1 创建一个用户,用户名为postgres,密码为123456

(1)创建用户,用户名:posgres,密码为:123456
a. 创建用户:sudo adduser postgres
b. 设置用户密码:按提示输入即可
c. 如下图所示
d. 删除用户时,使用命令:sudo deluser 用户名
注意:建议使用sudo useradd postgres创建,如果创建了,请输入sudo userdel postgres删除。
注意:除了安装负载均衡的服务器外,都要安装。

如图所示:

《Postgres-xl集群部署文档》 add_user.png

5.1.0.2 为postgres用户设置免密登录

在ubuntu中用户输入:sudo usermod –a –G sudo postgres
切换用户为postgres: 输入如下命令sudo postgres
(1)设置密钥
输入命令 sudo ssh-keygen,一直接按enter即可
注意:如果sudo ssh-keygen有错误,可尝试ssh-keygen

如图所示:

《Postgres-xl集群部署文档》 ssh-keygen_error.png

(2)密钥传输(除了当前IP地址,每个IP地址都传输一次)
命令:ssh-copy-id -i ~/.ssh/id_rsa.pub postgres@172.17.30.14
注意:!!!
1.除了安装负载均衡的服务器外,都要进行密钥传输。可以简单理解:假如有三台服务器用来部署postgres-xl,分别A,B,C.在进行密钥传输时,A的密钥,传输给B,C;B的密钥,传输给A,C;C的密钥,传送给A,B; 2.主要修改postgres@172.17.30.204。将IP=172.17.30.204改为要传输服务器的IP即可 3.可以通过ifconfig 进行查询Ip

如图所示:配置IP:172.17.30.204 传送到172.17.30.204(例子)

《Postgres-xl集群部署文档》 220_204(postgres).png

5.1.0.3:修改/etc/hosts中内容

概述:配置主机IP及对应的主机名
1).采用命令:sudo vi /etc/hosts
2).验证:ping Ip eg: ping 172.17.30.204
3).如果验证不通过,可能需要重启:sudo reboot
注意: !!!
1.除了安装负载均衡的服务器外,都要进行修改。
2.每台服务器(除了安装负载均衡的服务器),都要添加(除了安装负载均衡的服务器)的所有IP和主机名
eg:如果有三台服务器,每台服务器添加
添加内容:
172.17.30.15 devcenter015
172.17.30.16 devcenter016
172.17.30.17 devcenter017
172.17.30.18 devcenter018
172.17.30.19 devcenter019
172.17.30.20 devcenter020
172.17.30.21 devcenter021
172.17.30.22 devcenter022
172.17.30.204 devcenter04
172.17.30.215 devcenter15
172.17.30.220 devcenter20

如图所示:

《Postgres-xl集群部署文档》 image

5.1.0.4 安装postgres-xl相关依赖包

概述:安装postgres-xl进行编译时,所需要的依赖包
依赖包:
make 、flex、bison、openjade、docbook-dsssl
readline、zlib
ubuntu:安装命令sudo apt-get install 安装包名
注意:
1.readline,zlib在ubuntu就存在了
2.可以通过如下命令进行查看:
ldconfig -p | grep readline
3.可以安装: sudo apt-get install libreadline6-dev 4.安装zlib:
官网下载:http://www.zlib.net/
解压之后,安装:
a:./configure
b: make
c:make install

5.此时可以通过如下命令安装:
1)postgres-xl:
./configure --prefix=/home/postgres/pgxl_9.5 --with-readline --with-zlib

2)编译postgres-contrib:
a:make
b:make install

5.1.1 编译安装postgres-xl

概述:如何安装postgres-xl
注意:如下操作,请切换到postgres用户下进行。采用
su postgres切换
1).编译安装postgres-xl
a.在/home/postgres下创建目录
采用命令: sudo mkdir /home/postgres/pgxl_9.5

b.进入到postgres-xl的解压目录
eg:
cd /postgres-xl_installPackpage/pgxlgres-xl-9.5rl.4 c.执行如下命令:
./configure --prefix=/home/postgres/pgxl_9.5 --without-readline --without-zlib
主要是将编译好的一些文件放在指定目录下 d.执行如下命令:(编译)
make
e.执行安装命令:
sudo make install
注意:sudo make install有错误时,请执行make install安装

如图所示:(./configure –prefex=/home/postgres/pgxl_9.5)

《Postgres-xl集群部署文档》 make_before.png

如图所示:(make)

《Postgres-xl集群部署文档》 image

如图所示:(sudo make install)

《Postgres-xl集群部署文档》 make_install.png

5.1.2 设置postgres环境变量

概述:主要将/home/postgres/.bashrc添加内容
内容如下:
#set postgres path
export PGHOME=/home/postgres/pgxl_9.5
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH
1). 使得修改的内容生效:source /home/postgres/.bashrc
2).验证如下:输入echo $PGHOME 出现:/home/postgres/pgxl_9.5

5.1.3 初始化gtm,coordinator,datanode

概述:初始化gtm,coordinator,datanode生成相关配置文件
1.根据规划表格,创建相应目录gtm,coordinator,datanode目录
eg:
在172.17.30.16的创建/home/postgres/pgxl_9.5/data,以及/home/postgres/pgxl_9.5/data/dn1和/home/postgres/pgxl_9.5/data/dn2目录 2.初始化gtm角色
1).设置目录权限:eg:sudo chown postgres /home/postgres/pgxl_9.5/data/gtm
2).执行命令:initgtm -Z gtm -D /home/postgres/pgxl_9.5/data/gtm 3.初始化coordinator角色
1).设置目录权限:eg:sudo chown postgres /home/postgres/pgxl_9.5/data/coord1
2).执行命令:initdb -D /home/postgres/pgxl_9.5/data/coord1 --nodename coord1 -E UTF8 --locale=C -U postgres -W 4.初始化datanode角色
1).设置目录权限:eg:sudo chown postgres /home/postgres/pgxl_9.5/data/dn1
2).执行命令:initdb -D /home/postgres/pgxl_9.5/data/dn1 --nodename dn1 -E UTF8 --locale=C -U postgres –W
注意:
nodename dn1:根据创建目录名字修改。如/home/postgres/pgxl_9.5/data/dn3初始化时,为initdb -D /home/postgres/pgxl_9.5/data/dn3 --nodename dn3 -E UTF8 --locale=C -U postgres –W 注意:
1.请在安规表格中分配角色,进行相应的初始化操作。如,172.17.30.215中分配两个datanode角色,相应目录为/home/postgres/pgxl_9.5/data/dn1,/home/postgres/pgxl_9.5/data/dn2,所以初始化时执行initdb -D /home/postgres/pgxl_9.5/data/dn1 --nodename dn1 -E UTF8 --locale=C -U postgres –W和initdb -D /home/postgres/pgxl_9.5/data/dn2 --nodename dn2 -E UTF8 --locale=C -U postgres –W

2.如果不执行设置目录权限,可能直接执行初始化命令,会出错

如图所示:(初始化gtm)

《Postgres-xl集群部署文档》 gtm.png

如图所示:(初始化coordinator)

《Postgres-xl集群部署文档》 image

如图所示:(初始化datanode)

《Postgres-xl集群部署文档》 image

5.1.4 修改postgrex-xl配置文件

概述:根据初始化gtm,coordinator,datanode生成的配置文件,进行相应的修改
1).修改gtm生成的配置文件:gtm.conf.文件所在目录为:/home/postgres/pgxl_9.5/data/gtm
修改内容为:
nodename = 'gtm'
listen_addresses = '*'
port =6666 #gtm端口
startup = ACT
注意:有的前面有‘#’,去掉#号
2).修改coordinator生成的配置文件:postgresql.conf文件。文件所在目录:/home/postgres/pgxl_9.5/coordinator角色目录。eg:/home/postgres/pgxl_9.5/coord1
修改内容:
# - Connection Settings - (修改一)
listen_addresses = '*'
port = 5301 #coordinator端口设置,coord1和coord2端口都为5301
max_cOnnections= 100

# DATA NODES AND CONNECTION POOLING (修改二)
#----------------------------------
pooler_port = 6701 #coord2这个端口也改为6701
max_pool_size = 100

# GTM CONNECTION
#--------------------------
gtm_host = '172.17.30.16' # gtm所在的主机地址
gtm_port = 6666 #gtm配置中,gtm端口号配置为6666 注意:根据实际情况进行修改
3).修改coordinator,datanode中的pg_hba.conf文件,文件所在目录:/home/postgres/pgxl_9.5/相应角色目录。eg:/home/postgres/pgxl_9.5/coord1
修该内容:
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 trust
4).修改datanode生成的配置文件:postgresql.conf文件。文件所在目录:/home/postgres/pgxl_9.5/datanode角色目录。eg:/home/postgres/pgxl_9.5/coord1
修改内容:
# - Connection Settings - (修改一)
listen_addresses = '*'
port = 5401 #注意:同一台服务器中端口不同,但不同服务器的端口可以相同dn2,dn3,dn4配置文件分别改为5402、5401、5402,dn3和dn4在一台服务器上
max_cOnnections= 100

# DATA NODES AND CONNECTION POOLING (修改二)
#----------------------------------
pooler_port = 6801 #dn2,dn3,dn4配置文件都改为6801
#同一台机器要使用不同的端口,如dn1,dn2在同一台机器上分别是6801,6802
#dn3,dn4上端口号也是6801,6802。就是同一机器端口号不同即可。
max_pool_size = 100

# GTM CONNECTION
#--------------------------
gtm_host = '172.17.30.16' # gtm所在的主机地址
gtm_port = 6666 #gtm配置中,gtm端口号配置为6666 注意:根据实际情况进行修改
5).重启gtm,coordinator,datanode服务器
采用命令:sudo reboot

注意:当sudo reboot有问题时,可以采用reboot命令

如图所示:(修改gtm)

《Postgres-xl集群部署文档》 image

如图所示:(修改coordinator)

修改一:

《Postgres-xl集群部署文档》 coord1_conf1.png

修改二:

《Postgres-xl集群部署文档》 image

修改三:

《Postgres-xl集群部署文档》 coord1_conf2.png

如图所示:(修改datanode)

修改一:

《Postgres-xl集群部署文档》 dn1.conf1.png

修改二:

《Postgres-xl集群部署文档》 dn1_conf2.png

修改三:

《Postgres-xl集群部署文档》 image

5.1.5:启动postgres-xl

概述:介绍如何启动postgres-xl.
1).启动gtm:gtm_ctl start -Z gtm -D /home/postgres/pgxl_9.5/data/gtm
2).启动datanode:pg_ctl start -Z datanode -D /home/postgres/pgxl_9.5/data/dn1
注意:有多少个datanode,就得启动多少个datanode,注意修改目录,如启动datanode2:pg_ctl start -Z datanode -D /home/postgres/pgxl_9.5/data/dn2
3).启动coordinator:pg_ctl start -Z coordinator -D /home/postgres/pgxl_9.5/data/coord1
注意:有多少个coordinator,就得启动多少个coordinator,注意修改目录,如启动pg_ctl start -Z coordinator -D /home/postgres/pgxl_9.5/data/coord2

如图所示:(启动gtm)

《Postgres-xl集群部署文档》 gtm_start.png

如图所示:(启动datanode)

《Postgres-xl集群部署文档》 dn1_start.png

如图所示: (启动coordinator)

《Postgres-xl集群部署文档》 image

如图所示:(修改coordinator,datanode中的pg_hba.conf文件)

《Postgres-xl集群部署文档》

5.1.6:postgres-xl集群部署

概述:介绍配置postgres-xl集群,这里的配置针对角色为coordinator和datanodede的服务器
1).以postgres用户进入psql:psql -p 端口号
如:psql -p 5301
2).配置coordinator
a.查询节点select * from pgxc_node; 查询存在的配置的节点

b.更新存在的节点:alter node 节点名字 with(type=节点类型,host='对应角色Ip',
port='对应角色Ip');
如:如果查询存在coord2,就更新:alter node coord2 with (type=coordinator,host='172.17.30.18', port=5301);其中172.17.30.18
对应的是所角色所在的服务器IP.5301:对应角色所在服务器的端口。
注意:根据实际情况修改
c.制造节点coordinator,datanode节点:alter node 节点名字 with(type=节点类型, host='对应角色Ip', port='对应角色Ip');
如:create node coord1(节点名字) with (type=coordinator,host='172.17.30.18', port=5301);

d.设置第一个数据数据节点:为第一优先
如:
create node dn1 with (type=datanode, host='172.17.30.19',port=5401,primary,preferred); e.重新载入修改的节点:select pgxc_pool_reload(); f.查询修改后的节点:select * from pgxc_node;
3).配置datanode节点:
(1)和coordinator配置一样
注意:上面的配置针对角色为coordinator和datanodede的服务器都要设置

具体修改可参考:

coord1:

psql (PGXL 9.5r1.5, based on PG 9.5.6 (Postgres-XL 9.5r1.5))
Type "help" for help.
postgres=# select * from pgxc_node;
postgres=# alter node coord1 with (type=coordinator,host='172.17.30.17', port=5301);
postgres=# create node coord2 with (type=coordinator,host='172.17.30.18', port=5301);
postgres=# create node dn1 with (type=datanode, host='172.17.30.19',port=5401,primary,preferred);
postgres=# create node dn2 with (type=datanode, host='172.17.30.20',port=5401);
postgres=# create node dn3 with (type=datanode, host='172.17.30.21',port=5401);
postgres=# create node dn4 with (type=datanode, host='172.17.30.22',port=5401);
postgres=# select pgxc_pool_reload();
postgres=# select * from pgxc_node;

coord2

psql (PGXL 9.5r1.5, based on PG 9.5.6 (Postgres-XL 9.5r1.5))
Type "help" for help.
postgres=# select * from pgxc_node;
postgres=# alter node coord2 with (type=coordinator,host='172.17.30.18', port=5301);
postgres=# create node coord1 with (type=coordinator,host='172.17.30.17', port=5301);
postgres=# create node dn1 with (type=datanode, host='172.17.30.19',port=5401,primary,preferred);
postgres=# create node dn2 with (type=datanode, host='172.17.30.20',port=5401);
postgres=# create node dn3 with (type=datanode, host='172.17.30.21',port=5401);
postgres=# create node dn4 with (type=datanode, host='172.17.30.22',port=5401);
postgres=# select pgxc_pool_reload();
postgres=# select * from pgxc_node;

dn1

psql (PGXL 9.5r1.5, based on PG 9.5.6 (Postgres-XL 9.5r1.5))
Type "help" for help.
postgres=# select * from pgxc_node;
postgres=# create node coord2 with (type=coordinator,host='172.17.30.18', port=5301);
postgres=# create node coord1 with (type=coordinator,host='172.17.30.17', port=5301);
postgres=# alter node dn1 with (type=datanode, host='172.17.30.19',port=5401,primary,preferred);
postgres=# create node dn2 with (type=datanode, host='172.17.30.20',port=5401);
postgres=# create node dn3 with (type=datanode, host='172.17.30.21',port=5401);
postgres=# create node dn4 with (type=datanode, host='172.17.30.22',port=5401);
postgres=# select pgxc_pool_reload();
postgres=# select * from pgxc_node;

dn2

psql (PGXL 9.5r1.5, based on PG 9.5.6 (Postgres-XL 9.5r1.5))
Type "help" for help.
postgres=# select * from pgxc_node;
postgres=# create node coord2 with (type=coordinator,host='172.17.30.18', port=5301);
postgres=# create node coord1 with (type=coordinator,host='172.17.30.17', port=5301);
postgres=# create node dn1 with (type=datanode, host='172.17.30.19',port=5401,primary,preferred);
postgres=# alter node dn2 with (type=datanode, host='172.17.30.20',port=5401);
postgres=# create node dn3 with (type=datanode, host='172.17.30.21',port=5401);
postgres=# create node dn4 with (type=datanode, host='172.17.30.22',port=5401);
postgres=# select pgxc_pool_reload();
postgres=# select * from pgxc_node;

dn3

psql (PGXL 9.5r1.5, based on PG 9.5.6 (Postgres-XL 9.5r1.5))
Type "help" for help.
postgres=# select * from pgxc_node;
postgres=# create node coord2 with (type=coordinator,host='172.17.30.18', port=5301);
postgres=# create node coord1 with (type=coordinator,host='172.17.30.17', port=5301);
postgres=# create node dn1 with (type=datanode, host='172.17.30.19',port=5401,primary,preferred);
postgres=# create node dn2 with (type=datanode, host='172.17.30.20',port=5401);
postgres=# alter node dn3 with (type=datanode, host='172.17.30.21',port=5401);
postgres=# create node dn4 with (type=datanode, host='172.17.30.22',port=5401);
postgres=# select pgxc_pool_reload();
postgres=# select * from pgxc_node;

dn4

psql (PGXL 9.5r1.5, based on PG 9.5.6 (Postgres-XL 9.5r1.5))
Type "help" for help.
postgres=# select * from pgxc_node;
postgres=# create node coord2 with (type=coordinator,host='172.17.30.18', port=5301);
postgres=# create node coord1 with (type=coordinator,host='172.17.30.17', port=5301);
postgres=# create node dn1 with (type=datanode, host='172.17.30.19',port=5401,primary,preferred);
postgres=# create node dn2 with (type=datanode, host='172.17.30.20',port=5401);
postgres=# create node dn3 with (type=datanode, host='172.17.30.21',port=5401);
postgres=# alter node dn4 with (type=datanode, host='172.17.30.22',port=5401);
postgres=# select pgxc_pool_reload();
postgres=# select * from pgxc_node;

5.1.7:测试安装

概述:主要测试postgres-xl安装是否成功
1).测试分布模式的测试表并插入数据
1).以postgres用户进入172.17.30.17:psql -p 端口号
如:psql -p 5301 2).coordinator角色建立表和插入数据
如:
postgres=# create table t1(id integer, name varchar(20));
postgres=# insert into t1 values(1,'测试1');
postgres=# insert into t1 values(2,'测试2');
postgres=# insert into t1 values(3,'测试3');
postgres=# insert into t1 values(4,'测试4'); 3).查询数据是否插入成功:
(1):datanode:有点数据节点可能查询不到数据
(2):coordinator:每个coordinator角色都能查询插入的全部数据
4).数据查询:
1)这里采用:postgres=# select * from t1;
2).测试复制模式的测试表并插入数据
1).以postgres用户进入172.17.30.18:psql -p 端口号
如:psql -p 5301 2).coordinator角色建立表和插入数据
如:
postgres=# create table t2(id integer, name varchar(20))distribute by replication;;
postgres=# insert into t2 values(1,'测试1');
postgres=# insert into t2 values(2,'测试2');
postgres=# insert into t2 values(3,'测试3');
postgres=# insert into t2 values(4,'测试4'); 3).查询数据是否插入成功:
(1):datanode:每个datanode角色都能查到数据
(2):coordinator:每个coordinator角色都能查询插入的全部数据
4).数据查询
可以采用:postgres=# select * from t2;注意这里每个节点都能查看相同数据

如图所示:(数据查询)

《Postgres-xl集群部署文档》 data_check.png

5.3安装Haproxy

概述:安装Haproxy负载均衡。 注意:选择单独服务器安装,172.17.30.14
1).安装Haporxy
(1)安装命令:sudo apt-get install haproxy
2).修改配置文件haproxy.conf
(1)文件所在目录:/etc/haproxy/haproxy.cfg
(2)修改时进入文件:
出现:
Swap file "/etc/haproxy/.haproxy.cfg.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: 请选择:e进入 (3)修改如下内容:
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
maxconn 4095 #指定同步连上服务的最大连线数
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECD H+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode tcp #修改:mode http ---->mode tcp
option tcplog #修改:option httplog--->option tcplog
option dontlognull
timeout connect 10s #修改:连接超时时间
timeout client 60s #修改:连接客户端超时时间
timeout server 60s #修改:连接服务器端超时时间
#---------------------添加内容----------------------------
frontend http-in
bind *:8888 #对外提供的接口
mode tcp
default_backend psql_server
backend psql_server
balance leastconn #配置排程演算法:最小连续线排程法
option pgsql-check user postgres
server pgsql_coord1 172.17.30.204:5301 weight 1 check inter 1s rise 2 fall 3
server pgsql_coord2 172.17.30.204:5302 weight 1 check inter 1s rise 2 fall 3
#-----------设置统计页面配置------------
listen admin-stats
mode http
option httplog
bind 0.0.0.0:8888 #监听端口
stats enable
stats refresh 30s #设置统计页面自动刷新时间
stats uri /dbs
stats realm welcome login\ Haproxy
stats auth admin:admin #设置登录统计页面的用户名:admin,密码:admin
stats admin if TRUE
3)检测修改文件是否有错
(1)输入:haproxy -f /etc/haproxy/haproxy.cfg -c
出现:
Configuration file is valid (配置有效) (2)重启服务
sudo service haproxy restart4).验证如下:
(1):在浏览器中输入:http://172.17.30.13:8888/dbs
a.弹出登录对话框:
用户名:admin 密码为:admin
b.如图所示 (2):连接测试:
a. sudo apt-get install postgresql-client
b. psql -h 172.17.30.13 -p 5301 -U postgres

c.如图所示
5)Haproxy配置文件解析:(服务器,也称伺服器)
(1)glabal(全域):设定能配置用于执行Haproxy的所有伺服器。
eg:
global
log 127.0.0.1 local2
maxconn 4000
user haproxy
group haproxy
daemon

说明:
log::(记录)所有条目到本地的syslog伺服器。这个可以是/var/log/syslog或使用者指定的地方

maxconn:指定同步连上服务的最大连线数量。

user与group能用来指定haproxy程序所属的使用者名与群组名称
daemon:能让haproxy后台运行
(2)default设定:(预设)能用来配置套用frontend(前端)、backend(后端),listen(监听)等配置项目的所有代理小结。
注意:任何配置于proxy子节(frontend,backend,或listen)的参数,都会盖过default中参数

eg:
defaults
mode http
log global
option httplog
option dontlognull
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m

说明:
mode:指定了Haproxy instance所使用的通讯协定。使用http模式将来源请求连接至根基于http的真实服务器,试用网页服务器的负载平衡。对于其他应用程式来说,请使用tcp模式

log:会指定日志将条目写入的日志与syslog的设施。global值参照了global一节中的log参数中所指定的Harproxy instance option httplog能记录HTTP session的多种值,包括http请求,session状态、连线数,来源位址,以及连线计数器等等

option dontlognull:停用了对null连线的记录,表示Haproxy不会记录不会记录未传任何资料的连线。这不建议在用在网络路上的环境中(例如网页应用程式),因为null可能表示恶意活动 retries:指定了在无法第一次就连上时,真实服务器会重试连线的次数

timeout:指定某个给定请求的非活动时间,单位为秒或微秒
(3)frontend:设定会配置服务器监听来自用户端的socket.
eg:
frontend mian
bind 192.168.0.10:80

说明:
名为main的fronend透过bind参数将Ip位址设为192.168.0.10,并监听连接80后,user backend会指定所有来自session的连线连往app后端
(4)backend:设定真实服务器的IP地址,以及负载平衡程式的排程演算法。
eg:
backend app
balance roundrobin
server app1 192.168.1.1:80 check
server app2 192.168.1.2:80 check
server app3 192.168.1.3:80 check inter 2s rise 4 fall 3
server app4 192.168.1.4:80 backup

说明:
后端服务器名为app。balance会指定负载平衡程式的排程演算法。

server 行指定了后端可以使用的服务器。ap1到ap4时内部服务器的名称

位址:指定的Ip地址,Ip冒号后面的是服务器连接端口号。check 选项标志定期【健康检查】的服务器,以确保服务器的可用性,得以发送资料并服务session的请求。服务器app3也配置健康检查的间隔,是时间为2秒,app3用来决定服务器是否健康的检查次数(rise 4)、以及服务器直至认定为失败的重试次数(fall 3).
6)排程演算法介绍:
(1).leastconn:将请求分散到连线数较少的真实伺服器。当处于一个动态式且包含各种session或连线长的环境中,对管理员来说,这个排程可能会较适合其环境。这也适用包含了一组拥有不同生产力的真实伺服器的环境中,因为透过排程器管理。
结合上述配置理解:
backend psql_server
balance leastconn #配置排程演算法:最小连续线排程法
option pgsql-check user postgres
server pgsql_coord1 172.17.30.204:5301 weight 1 check inter 1s rise 2 fall 3
server pgsql_coord2 172.17.30.204:5302 weight 1 check inter 1s rise 2 fall 3

假如:172.17.30.204:5301被连接的次数较少时,下一次,连接时,会连接172.17.30.204:5301; 总结一句话:'谁比较闲,就用谁' (2).roundrobin:将请求依序发给集区中的伺服器。使用此算法,所有真实伺服器不管能力如何,都会被视为平等。此排程模式类似循环DNS(round-robin DNS)法,但更为细致,因为这样是以网络连线为基础,而非以主机为基础。Load Balancer的循环配置资源排程也不会因为快取DNS的查询项目而导致不平衡。然而,在Haproxy中,因为伺服器权重的配置能轻易透过此排程器。因此各个后端的启用中的伺服器数量会被限制为4095。

假如:上述配置为:roundrobin,时,172.17.30.204:5301和172.17.30.204:5302在被连接时,将采用循环调用的。

总结一句话:'循环调用'

(3).静态循环法(static-rr):一般地在一组伺服器之间循环性地分散各项请求。不过不允许动态式配置伺服器的权重。然而,基于伺服器权重的静态配置,后端中不会有伺服器启用数量上的限制。

比较: roundrobin 和 static-rr

权重:
1)roundrobin:可以动态配置伺服器权重
2)static-rr:不允许动态配置伺服器权重

伺服器启用数量:
1)roundrobin:数量上的限制,数量限制为4095.
2)static-rr:数量上没有限制

如图所示:(登录成功)

《Postgres-xl集群部署文档》 haproxy_login.png

如图所示:(连接测试)

《Postgres-xl集群部署文档》 test1.png


推荐阅读
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了软件测试知识点之数据库压力测试方法小结相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 一句话解决高并发的核心原则
    本文介绍了解决高并发的核心原则,即将用户访问请求尽量往前推,避免访问CDN、静态服务器、动态服务器、数据库和存储,从而实现高性能、高并发、高可扩展的网站架构。同时提到了Google的成功案例,以及适用于千万级别PV站和亿级PV网站的架构层次。 ... [详细]
  • 基于PgpoolII的PostgreSQL集群安装与配置教程
    本文介绍了基于PgpoolII的PostgreSQL集群的安装与配置教程。Pgpool-II是一个位于PostgreSQL服务器和PostgreSQL数据库客户端之间的中间件,提供了连接池、复制、负载均衡、缓存、看门狗、限制链接等功能,可以用于搭建高可用的PostgreSQL集群。文章详细介绍了通过yum安装Pgpool-II的步骤,并提供了相关的官方参考地址。 ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 如何用UE4制作2D游戏文档——计算篇
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何用UE4制作2D游戏文档——计算篇相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • 关于我们EMQ是一家全球领先的开源物联网基础设施软件供应商,服务新产业周期的IoT&5G、边缘计算与云计算市场,交付全球领先的开源物联网消息服务器和流处理数据 ... [详细]
  • 本文介绍了Redis中RDB文件和AOF文件的保存和还原机制。RDB文件用于保存和还原Redis服务器所有数据库中的键值对数据,SAVE命令和BGSAVE命令分别用于阻塞服务器和由子进程执行保存操作。同时执行SAVE命令和BGSAVE命令,以及同时执行两个BGSAVE命令都会产生竞争条件。服务器会保存所有用save选项设置的保存条件,当满足任意一个保存条件时,服务器会自动执行BGSAVE命令。此外,还介绍了RDB文件和AOF文件在操作方面的冲突以及同时执行大量磁盘写入操作的不良影响。 ... [详细]
  • 本文详细介绍了git常用命令及其操作方法,包括查看、添加、提交、删除、找回等操作,以及如何重置修改文件、抛弃工作区修改、将工作文件提交到本地暂存区、从版本库中删除文件等。同时还介绍了如何从暂存区恢复到工作文件、恢复最近一次提交过的状态,以及如何合并多个操作等。 ... [详细]
  • 如何使用代理服务器进行网页抓取?
    本文介绍了如何使用代理服务器进行网页抓取,并探讨了数据驱动对竞争优势的重要性。通过网页抓取,企业可以快速获取并分析大量与需求相关的数据,从而制定营销战略。同时,网页抓取还可以帮助电子商务公司在竞争对手的网站上下载数百页的有用数据,提高销售增长和毛利率。 ... [详细]
  • 本文介绍了一个React Native新手在尝试将数据发布到服务器时遇到的问题,以及他的React Native代码和服务器端代码。他使用fetch方法将数据发送到服务器,但无法在服务器端读取/获取发布的数据。 ... [详细]
  • 上图是InnoDB存储引擎的结构。1、缓冲池InnoDB存储引擎是基于磁盘存储的,并将其中的记录按照页的方式进行管理。因此可以看作是基于磁盘的数据库系统。在数据库系统中,由于CPU速度 ... [详细]
author-avatar
holy190
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有