pgXL集群的搭建
1 pgxl 集群搭建
1.0 调研
| GreenPlum | PostgreSQL-XC | PostgreSQL-XL | PostgreSQL-XZ(未开源) | citus | repmgr | |
|---|---|---|---|---|---|---|
| 优点 | √ | √ | 事务性分布式、并行 | 在线扩容 | 高性能的分布式、并行、兼容性 | |
| 缺点 | 无法随意选择支持任意版本的PgSQL、手动扩容 | 手动扩容、限制sql | ||||
| 应用公司 | pivotal | 2ndquadrant(支持) | 腾讯 | 苏宁、cisco、微软 | 2ndquadrant |
注释:
-
如果您需要交互式实时分析和多组户或需要扩展简单交易, 适合做单表查询,且该单表数据量越大,Citus的优势就越明显 :Citus
-
如果您需要多语句ACID事务:Postgres-XL
-
如果您需要运行复杂的报告查询:GreenPlum

1.1 软件下载及安装
1.1.1 VMware - 使用版本:
VMware Workstation 15 Pro
- 官网下载地址
- 密钥: YG5H2-ANZ0H-M8ERY-TXZZZ-YKRV8
1.1.2 Centos 7
- 使用版本:CentOS-7.0-1406-x86_64-DVD
- 下载地址: 官网
- 安装步骤: 软件选择:最小安装 - 配置虚拟机的网络,使之能够上网(这不是重点),使本机能够和虚拟机之间能够ping通,主要能够使用shell连接虚拟机,方便操作
1.1.3 Xshell
- 操作方便
1.1.4 PostGres XL
- 下载git(下载有点慢)
git clone git://git.postgresql.org/git/postgres-xl.git
1.2 pgxl集群搭建
1.2.0 主机规划
| ip | hostname | role | port |
|---|---|---|---|
| 192.168.153.61 | gtm | gtm、coordinator、datanode | 6666、5432、15431 |
| 192.168.153.62 | datanode1 | coordinator、gtm_proxy、datanode1 | 5432、20001、15432 |
| 192.168.153.63 | datanode2 | coordinator、gtm_proxy、datanode2 | 5432、20001、15433 |
1.2.1 配置各个主机的 hosts 文件
- 编辑 hosts文件 :
vi /etc/hosts - 修改内容 :
192.168.153.61 gtm 192.168.153.62 datanode 192.168.153.63 datanode
1.2.2 永久关闭selinux
- 编辑文件
vi /etc/sysconfig/selinux - 修改文件selinux内容
SELINUX=enforcing 替换为 SELINUX=disabled - 重启主机
reboot - 检查修改后的效果
sestatusSELinux status: disabled
1.2.3 关闭防火墙
- 停止firewall:
systemctl stop firewalld.service - 查看防火墙状态
firewlld-cmd --state
1.2.4 SSH无密码登录
su - postgres
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa
chmod 600 ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys `
1.2.5 集群配置
export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin
export PGHOME=/home/postgres/pgxl
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH
验证环境变量是否生效:
pg_ctl --version
生成并修改配置文件
$ pgxc_ctl ---初次执行,会提示Error说没有配置文件,忽略即可
PGXC prepare ---执行该命令将会生成一份配置文件模板
PGXC exit --退出 pgxc_ctl交互
1.3 测试(可以使用Navicat工具操作)
1.3.1数据库
-
集群节点信息:
select * from pgxc_node; -
创建数据库
CREATE DATABASE testdb;
- 进入某个数据库
psql -p 30001 testdb
- 查看数据库中的分布情况
SELECT
xc_node_id,
COUNT (*)
FROM
test2
GROUP BY
xc_node_id;
- 重新分配数据节点
ALTER TABLE test2 ADD NODE (datanode0);
1.3.2数据表(分布表)
建表
CREATE TABLE test (
ID INT PRIMARY KEY,
NAME VARCHAR (10)
) DISTRIBUTE BY HASH (ID) to none();
插入数据
INSERT INTO test2 SELECT
generate_series (1, 1000),
'lottu' || generate_series (1, 1000);
统计数据
select count(*) from test2;
删除节点
$ pgxc_ctl PGXC remove datanode master datanode3 clean
增加节点:
附录(centos7)
防火墙命令
- 停止firewall:
systemctl stop firewalld.service - 查看防火墙状态
firewlld-cmd --state
查看本地分支:
git branch
切换分支:如切换到master:
git checkout master
集群节点信息:
select * from pgxc_node;
问题总结
centos7最小化安装没有
ifconfig命令
yum -y install net-tools
VMware 配置虚拟机的网络的问题https://blog.csdn.net/woailyoo0000/article/details/79506999
centos 7.3 错误设置selinux 导致不能启动 Failed to load SELinux policy. Freezing
安装lrzsz:
yum -y install lrzsz
配置文件后安装初始化时出现错误
psql: could not connect to server: 没有到主机的路由
Done. psql: could not connect to server: 没有到主机的路由 Is the server running on host "datanode1" (192.168.153.62) and accepting TCP/IP connections on port 5432? psql: could not connect to server: 没有到主机的路由 Is the server running on host "datanode2" (192.168.153.63) and accepting TCP/IP connections on port 5432?
- 解决办法: 配置防火墙或者关闭防火墙
psql: FATAL: no pg_hba.conf entry for host "192.168.153.61", user "postgres", database "postgres"
psql: FATAL: no pg_hba.conf entry for host "192.168.153.61", user "postgres", database "postgres" psql: FATAL: no pg_hba.conf entry for host "192.168.153.61", user "postgres", database "postgres" Done. psql: FATAL: no pg_hba.conf entry for host "192.168.153.61", user "postgres", database "postgres" psql: FATAL: no pg_hba.conf entry for host "192.168.153.61", user "postgres", database "postgres" Done.
解决办法: 注意 这个配置coordPgHbaEntries=(172.17.210.0/32)
配置文件 https://blog.csdn.net/liuzongxi/article/details/46380985
gtmProxyNames=(gtm_pxy1 gtm_pxy2 ) # No used if it is not configured
gtmProxyServers=(datanode1 datanode2) # Specify none if you dont' configure it.
gtmProxyPorts=(20001 20001)

浙公网安备 33010602011771号