Postgres-xl集群部署文档
来源:互联网 发布:极品飞车10 知乎 编辑:程序博客网 时间:2024/04/28 08:30
Postgres-xl集群部署文档
文档介绍
文档介绍了如何部署PostgreSQL集群
文档结构划分
- 系统和安装流程图
- 安装规划
- 安装环境介绍
- 安装准备
- 安装过程
- 安装验证
1.系统和安装流程图
概述:系统图和安装流程图,主要在展示整个安装系统图和安装流程图
如图所示:(系统图)
如图所示:(安装流程图)
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是数据节点,分布式存储数据。
如下表格显示:
注意:PGHOME=/home/pgxl_9.5
3.安装环境介绍
1).操作环境 Window7 64位系统2).使用工具 putty:连接服务器 pscp:主要用于windows向linux发送文件,或由linux系统向windows发送文件3).服务器 Ubuntu(16.04.3)系统
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/ 注意:这里采用网页方式下载,主要是因为ubuntu安装的git,不能通过git方式下载2)将下载好的压缩包传送到linux (1) 采用Putty连接服务器: a) 点击Session: Host Name(or IP address):输入连接服务器的IP,点击Open打开 (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:\postgre-xl\postgres-xl-9.5r1.4.tar.gz ubuntu@172.17.30.204:./postgres_anzhuangbao/ 注意:传送目录一般在/home/用户名/传送目录,不然的话,可能有问题,这里的传送目录为:/home/ubuntu/postgres_anzhuangbao
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安装前,一些配置。分为: 5.1.0.0:转移postgres-xl压缩包和解压postgres-xl压缩包 5.1.0.1:创建一个用户,用户名为postgres,密码为123456 5.1.0.2:为postgres用户设置免密登录 5.1.0.3:修改/etc/hosts中内容 5.1.0.4:安装postgrex-xl相关依赖包
5.1.0.0 转移postgres-xl压缩包和解压postgrex-xl压缩包
1)转移Postgres-xl安装到/postgres_installPackage目录下 采用如下命令: sudo mv 路径ostgres压缩包 转移目录 例如:这里是,sudo mv /home/ubuntu/postges-xl-9.5r1.4.tar.gz /postgres_installPackage. 注意:在根目录下创建postgres_installPackage目录,可采用如下命令:sudo mkdir /postgres_installPackage 主要是因为在安装的过程中需要创建用户,所以建议,将安装包放到根目录下2)解压Postgres-xl压缩包 (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删除。注意:除了安装负载均衡的服务器外,都要安装。
如图所示:
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
如图所示:
(2)密钥传输 命令:ssh-copy-id -i ~/.ssh/id_rsa.pub postgres@172.17.30.204注意:!!! 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(例子)
5.1.0.3:修改/etc/hosts中内容
概述:配置主机IP及对应的主机名1).采用命令:sudo vi /etc/hosts2).验证:ping Ip eg: ping 172.17.30.2043).如果验证不通过,可能需要重启:sudo reboot注意: !!! 1.除了安装负载均衡的服务器外,都要进行修改。 2.每台服务器(除了安装负载均衡的服务器),都要添加(除了安装负载均衡的服务器)的所有IP和主机名eg:如果有三台服务器,每台服务器添加添加内容: 172.17.30.204 devcenter04 172.17.30.215 devcenter15 172.17.30.220 devcenter20
如图所示:
5.1.0.4 安装postgres-xl相关依赖包
概述:安装postgres-xl进行编译时,所需要的依赖包依赖包:make 、flex、bison、openjade、docbook-dssslreadline、zlibubuntu:安装命令sudo apt-get install 安装包名注意: 1.readline,zlib在ubuntu就存在了 2.可以通过如下命令进行查看: ldconfig -p | grep readline 3.可以安装: sudo apt-get install libreadline6-dev
5.1.1 编译安装postgres-xl
概述:如何安装postgres-xl注意:如下操作,请切换到postgres用户下进行。采用su postgres切换1).编译安装postgres-xl a.进入到postgres-xl的解压目录 eg: cd /postgres-xl_installPackpage/pgxlgres-xl-9.5rl.4 b.在/home/postgres下创建目录 采用命令: sudo mkdir /home/postgres/pgxl_9.5 c.执行如下命令: ./configure --prefix=/home/postgres/pgxl_9.5 主要是将编译好的一些文件放在指定目录下 d.执行如下命令:(编译) make e.执行安装命令: sudo make install注意:sudo make install有错误时,请执行make install安装
如图所示:(./configure –prefex=/home/postgres/pgxl_9.5)
如图所示:(make)
如图所示:(sudo make install)
5.1.2 设置postgres环境变量
概述:主要将/home/postgres/.bashrc添加内容内容如下:#set postgres pathexport PGHOME=/home/postgres/pgxl_9.5export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATHexport PATH=$PGHOME/bin:$PATH1). 使得修改的内容生效:source /home/postgres/.bashrc2).验证如下:输入echo $PGHOME 出现:/home/postgres/pgxl_9.5
5.1.3 初始化gtm,coordinator,datanode
概述:初始化gtm,coordinator,datanode生成相关配置文件 1.根据如上,规划表格。创建相应目录gtm,coordinator,datanode目录 eg: 在172.17.30.215的创建/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)
如图所示:(初始化coordinator)
如图所示:(初始化datanode)
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 trust4).修改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)
如图所示:(修改coordinator)
修改一:
修改二:
修改三:
如图所示:(修改datanode)
修改一:
修改二:
修改三:
5.1.5:启动postgres-xl
概述:介绍如何启动postgres-xl.1).启动gtm:gtm_ctl start -Z gtm -D /home/postgres/pgxl_9.5/data/gtm2).启动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/dn23).启动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)
如图所示:(启动datanode)
如图所示: (启动coordinator)
如图所示:(修改coordinator,datanode中的pg_hba.conf文件)
5.1.6:postgres-xl集群部署
概述:介绍配置postgres-xl集群,这里的配置针对角色为coordinator和datanodede的服务器1).以postgres用户进入psql:psql -p 对应角色的端口号, 如:打开角色为coord2,端口为5301,可以输入psql -p 53022).配置coordinator (1)select * from pgxc_node; 查询存在的配置的节点 (2) 更新存在的节点:aliter node 节点名字 with(type=节点类型,host='对应角色Ip', port='对应角色Ip'); 如:如果查询存在coord2,就更新:alter node coord2 with (type=coordinator,host='172.17.30.204', port=5302);其中172.17.30.204 对应的是所角色所在的服务器IP.5302:对应角色所在服务器的端口。 注意:根据实际情况修改 (3)制造节点coordinator,datanode节点:aliter node 节点名字 with(type=节点类型, host='对应角色Ip', port='对应角色Ip'); 如:create node coord1(节点名字) with (type=coordinator,host='172.17.30.204', port=5301); (4)设置第一个数据数据节点:为第一优先 如: create node dn1 with (type=datanode, host='172.17.30.215',port=5401,primary,preferred); (5)重新载入修改的节点:select pgxc_pool_reload(); (6) 查询修改后的节点:select * from pgxc_node;3).配置datanode节点: (1)和coordinator配置一样注意:上面的配置针对角色为coordinator和datanodede的服务器都要设置具体修改可参考: (1) 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.204', port=5302); postgres=# create node coord1 with (type=coordinator,host='172.17.30.204', port=5301); postgres=# create node dn1 with (type=datanode, host='172.17.30.215',port=5401,primary,preferred); postgres=# create node dn2 with (type=datanode, host='172.17.30.215',port=5402); postgres=# create node dn3 with (type=datanode, host='172.17.30.220',port=5401); postgres=# create node dn4 with (type=datanode, host='172.17.30.220',port=5402); postgres=# select pgxc_pool_reload(); postgres=# select * from pgxc_node; (2) [postgres@pgxlsrv3 ~]$ psql -p 5401 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 coord1 with (type=coordinator,host='192.168.1.41', port=5301); postgres=# create node coord2 with (type=coordinator,host='192.168.1.41', port=5302); postgres=# alter node dn3 with (type=datanode, host='192.168.1.43',port=5401); postgres=# create node dn1 with (type=datanode, host='192.168.1.42',port=5401,primary,preferred); postgres=# create node dn2 with (type=datanode, host='192.168.1.42',port=5402); postgres=# create node dn4 with (type=datanode, host='192.168.1.43',port=5402); postgres=# select pgxc_pool_reload(); postgres=# select * from pgxc_node;
如图所示:(针对每台coordinator和datanode)
5.1.7:测试安装
概述:主要测试postgres-xl安装是否成功1).测试分布模式的测试表并插入数据 1).以postgres用户进入psql:psql -p 对应角色的端口号, 如:打开角色为coord2,端口为5301,可以输入psql -p 5302 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用户进入psql:psql -p 端口号 如:psql -p 5302 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;注意这里每个节点都能查看相同数据
如图所示:(数据查询)
5.3安装Haproxy
概述:安装Haproxy负载均衡。 注意:选择新的服务器安装,不安装在安装在postgres的服务器上1).安装Haporxy (1)安装命令:sudo apt-get install haproxy2).修改配置文件haproxy.cfg (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-sslv3defaults 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 *:5301 #对外提供的接口 mode tcp default_backend psql_serverbackend psql_server balance leastconn #配置排程演算法:最小连续线排程法 option pgsql-check user postgres #haproxy内置的postgres检测模块,后面的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 TRUE3)检测修改文件是否有错 (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:数量上没有限制
如图所示:(登录成功)
如图所示:(连接测试)
阅读全文
0 0
- Postgres-xl集群部署文档
- Postgres-XL集群的搭建
- Postgres-XL:基于PostgreSQL的开源可扩展数据库集群
- Postgres-XL集群的搭建和测试详解
- Postgres-XL测试
- Postgres-XL介绍
- 基于PostgreSQL的可扩展的开源大数据集群数据库:Postgres-XL
- PG的两种集群技术:Pgpool-II与Postgres-XL
- PG的两种集群技术:Pgpool-II与Postgres-XL
- Postgres-XL9.5简介与集群部署
- Postgres-XL 9.5简易搭建
- Redis集群部署文档
- weblogic集群部署文档
- Postgres-XC/XL/X2分布式数据库安装
- postgres-xl 基于pgxc_ctl搭建安装
- Postgres-XL 9.5 R1 (Beta 1) 编译
- 基于Postgres-XL的mpp分布式方案
- postgres-xl 数据库 安装中文分词 zhparser
- c3p0数据库连接池不能取到连接An attempt by a client to checkout a Connection has timed out
- 第一章:快速上手注意点
- h5 利用canvas手写签名并保存
- python实现二叉树的遍历
- mp4文件格式解析
- Postgres-xl集群部署文档
- Matlab绘图高级部分
- 机器学习之降维
- leetcode 391. Perfect Rectangle 完美矩形的寻找 + 一个很笨的却很直接的方法
- node.js安装
- 干干干干干货 早期BIT音乐是如何做的
- 用getServletContext().getRealPath(FILE_PATH)获取绝对路径为null
- mysql视图
- C