pgxl9.5安装部署
一 Postgres-XL简介Postgres的-XL是一个基于PostgreSQL数据库的横向扩展开源SQL数据库集群,具有足够的灵活性来处理不同的数据库工作负载: 二 组件简介Global Transaction Monitor (GTM) GTM Standby GTM-Proxy Coordinator Data Node 总结:gtm是负责ACID的,保证分布式数据库全局事务一致性。得益于此,就算数据节点是分布的,但是你在主节点操作增删改查事务时,就如同只操作一个数据库一样简单。Coordinator是调度的,将操作指令发送到各个数据节点。datanodes是数据节点,分布式存储数据。 三、pgxl安装配置3.1主机规划 主机名 IP 角色 端口 nodename 数据目录
每台主机host映射配置 192.168.0.125 pg1 192.168.0.126 pg2 192.168.0.127 pg3 pg1上部署gtm,Coordinator与Datanode节点一般部署在同一台机器上。实际上,GTM-proxy,Coordinator与Datanode节点一般都在同一个机器上,使用时避免端口号与连接池端口号重叠!规划pg2,pg3作为协调节点与数据节点。 3.2 系统环境设置 [root@localhost ~]#vim /etc/selinux/config
设置SELINUX=disabled,保存退出。 SELINUX=disabled
安装依赖包: [root@localhost ~]# yum install -y flex bison readline-devel zlib-devel openjade docbook-style-dsssl
3.3 新建用户 [root@localhost ~]# useradd postgres
[root@localhost ~]# passwd postgres
[root@localhost ~]# su - postgres
[root@localhost ~]# mkdir ~/.ssh
[root@localhost ~]# chmod 700 ~/.ssh
3.4 ssh免密码登录 [root@localhost ~]# su - postgres
[postgres@localhost ~]# ssh-keygen -t rsa
[postgres@localhost ~]# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[postgres@localhost ~]# chmod 600 ~/.ssh/authorized_keys
将刚生成的认证文件拷贝到pg2到pg3中,使得pg1可以免密码登录pg2~pg3的任意一个节点: [postgres@localhost ~]# scp ~/.ssh/authorized_keys postgres@pg2:~/.ssh/
[postgres@localhost ~]# scp ~/.ssh/authorized_keys postgres@pg3:~/.ssh/
3.5 Postgres-XL安装 [root@localhost ~]# tar -zxvf postgres-xl-9.5r1.3.tar.gz
[root@localhost ~]# cd postgres-xl-9.5r1.3
[root@localhost ~postgres-xl-9.5r1.3]# ./configure --prefix=/home/postgres/pgxl9.5/
[root@localhost ~postgres-xl-9.5r1.3]# make
[root@localhost ~postgres-xl-9.5r1.3]# make install
[root@localhost ~postgres-xl-9.5r1.3]# cd contrib/
[root@localhost ~contrib]# make
[root@localhost ~contrib]# make install
cortrib中有很多postgres很牛的工具,一般要装上。如ltree,uuid,postgres_fdw等等。 [root@localhost ~]#su - postgres
[postgres@localhost ~]#vim .bashrc
在打开的文件末尾,新增如下变量配置: export PGHOME=/home/postgres/pgxl9.5
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH
按住esc,然后输入:wq!保存退出。输入以下命令对更改重启生效。 [root@localhost ~]# source .bashrc
#输入以下语句,如果输出变量结果,代表生效
[root@localhost ~]# echo $PGHOME
#应该输出/home/postgres/pgxl9.5代表生效
如上操作,除特别强调以外,是pg1-pg3节点都要配置安装的。 [root@localhost~]# cd /home/postgres
[root@postgres~]# mkdir DATA
[root@localhost~]# chown -R postgres.postgres /home/postgres
4.2 初始化GTM 在pg1机器上,切换到postgres用户下执行初始化: [root@localhost ~]# su - postgres
[postgres@localhost ~]# initgtm -Z gtm -D /home/postgres/DATA/gtm
打开编辑gtm.conf文件设置如下: nodename = 'gtm' #节点名称,任意指定,不能与其他节点重复
listen_addresses = '*' #GTM监听的ip地址,*代表监听所有的集群ip
port =6666 #gtm监控的端口号
startup = ACT #act代表gtm是主库,如果是standy,设置为'STANDBY'
4.3 初始化GTM Proxy 于pg2上执行以下命令: [root@localhost ~]# su - postgres
[root@localhost ~]# initgtm -Z gtm_proxy -D /home/postgres/DATA/gtm_proxy
#pg3上起名字叫gtm_proxy2
修改gtm_proxy.conf文件配置如下: nodename='gtm_proxy1'
port=6666
gtm_host='pg1'
gtm_port=6666
pg3上设置同理如上。 4.3 初始化Coordinators initdb -D /home/postgres/DATA/coord --nodename coord1 -E UTF8 --locale=C -U postgres -W
#pg3上节点名称执行这句时写coord2
修改postgresql.conf与pg_hba.conf文件配置如下: [postgres@localhost ~]#
vim /home/postgres/DATA/coord/postgresql.conf
# - Connection Settings -
listen_addresses = '*'
port = 5432
max_connections = 100
# DATA NODES AND CONNECTION POOLING
#----------------------------------
pooler_port = 6667
max_pool_size = 100
# GTM CONNECTION
#--------------------------
gtm_host = 'pg1' #gtm所在的主机地址
gtm_port = 6666 #gtm配置中,gtm端口号配置为6666
pgxc_node_name = 'coord1'
设置pg_hba.conf [postgres@localhost ~]#
vim /home/postgres/DATA/coord/pg_hba.conf
# "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
在pg2中生成coord2,并配置,步骤如上。注意节点名称都要将coord1换成当下的coord2。 4.4初始化Datanode [root@localhost ~]# su - postgres
[postgres@localhost ~]# initdb -D /home/postgres/DATA/dn --nodename dn1 -E UTF8 --locale=C -U postgres -W
#pg3中是dn2
配置postgresql.conf,pg_hba.conf: [postgres@localhost ~]# vim /home/postgres/DATA/dn/postgresql.conf
CONNECTIONS AND AUTHENTICATION
#------------------------------------
listen_addresses = '*'
port =5433
max_connections = 100
# DATA NODES AND CONNECTION POOLING
#----------------------------------------------
pooler_port = 6668 # 同一台机器要使用不同的连接池端口,如coord1与dn1部署同一个机器,coord1是6667,dn1是6668
max_pool_size = 100
# GTM CONNECTION
#-----------------------------
gtm_host = 'pg1'
gtm_port = 6666 #gtm端口号
pgxc_node_name = 'dn1'
[postgres@localhost ~]# vim /home/postgres/DATA/dn/pg_hba.conf
# "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
配置完dn1,同理配置dn2,注意dn1替换成dn2。 到这里我们基本上完成了大部分工作,接下来就是启动和注册了 4.5.1 启动gtm [postgres@localhost ~]# gtm_ctl start -Z gtm -D /home/postgres/DATA/gtm
4.5.2 启动gtm-proxy 在pg2机器上,启动gtm-proxy: [postgres@localhost ~]# gtm_ctl start -Z gtm_proxy -D /home/postgres/DATA/gtm_proxy
同理启动pg3上的gtm-proxy。 4.5.3 启动datanode 在pg2上启动dn1示范如下: [postgres@localhost ~]# pg_ctl start -Z datanode -D /home/postgres/DATA/dn
同理启动pg3上的dn。 在pg2机器上,启动coordinator节点coord: [postgres@localhost ~]# pg_ctl start -Z coordinator -D /home/postgres/DATA/coord
同理启动pg3上的coord。 六 Postgres-XL集群配置与测试 6.1 集群配置 在pg2以postgres用户下进入psql。coord1配置端口号是5432,直接以psql加端口号进入配置。 [postgres@localhost]$ psql -p 5432
psql (PGXL 9.5r1.3,based on PG 9.5.4 (Postgres-XL 9.5r1.3))
Type "help" for help.
postgres=# select * from pgxc_node;
postgres=# alter node coord1 with (type=coordinator,host='pg2',port=5432);
postgres=# create node coord2 with (type=coordinator,host='pg3',port=5432);
postgres=# create node dn1 with (type=datanode,port=5433,primary,preferred);
postgres=# create node dn2 with (type=datanode,port=5433);
postgres=#select pgxc_pool_reload();
postgres=# select * from pgxc_node;
配置pg2上的dn1如下,以当初配置的5433端口号进入psql: [postgres@localhost]$ psql -p 5433
psql (PGXL 9.5r1.3,based on PG 9.5.4 (Postgres-XL 9.5r1.3))
Type "help" for help.
postgres=# select * from pgxc_node;
postgres=# create node coord1 with (type=coordinator,port=5432);
postgres=# alter node dn1 with (type=datanode,port=5433);
postgres=#select pgxc_pool_reload();
postgres=# select * from pgxc_node;
pg3同理 6.2 创建测试表与数据 [postgres@localhost]$ psql -p 5432
psql (PGXL 9.5r1.3,based on PG 9.5.4 (Postgres-XL 9.5r1.3))
Type "help" for help.
postgres=# create table test1(id integer,name varchar(20));
postgres=# insert into test1(id,name) values(1,'测试');
postgres=# insert into test1(id,name) values(2,name) values(3,name) values(4,name) values(5,name) values(6,name) values(7,name) values(8,'测试');
通过我的本机测试发现,在coord2,dn1,dn2节点中都已创建了一个test1表。且coord1=coord2,而dn1中test1表有5条数据,dn2有3条。 注意:由于所有的数据节点组成了完整的数据视图,所以一个数据节点down机,整个pgxl都启动不了了,所以实际生产中,为了提高可用性,一定要配置数据节点的热备以便进行故障转移准备。 遇到的问题 postgres=# create table test1(id integer,name varchar(20));
LOG: failed to connect to node,connection string (host=192.168.0.125 port=1925 dbname=postgres user=postgres application_name=pgxc sslmode=disable options='-c remotetype=coordinator -c parentnode=coord1 -c DateStyle=iso,mdy -c timezone=prc -c geqo=on -c intervalstyle=postgres -c lc_monetary=C'),connection error (fe_sendauth: no password supplied
)
WARNING: can not connect to node 16384
WARNING: Health map updated to reflect DOWN node (16384)
LOG: Pooler could not open a connection to node 16384
LOG: failed to acquire connections
STATEMENT: create table test1(id integer,name varchar(20));
ERROR: Failed to get pooled connections
HINT: This may happen because one or more nodes are currently unreachable,either because of node or network failure.
Its also possible that the target node may have hit the connection limit or the pooler is configured with low connections.
Please check if all nodes are running fine and also review max_connections and max_pool_size configuration parameters
STATEMENT: create table test1(id integer,name varchar(20));
我的问题是节点的监听配置没有被gtm监听到,希望各位注意。 注:本文借鉴http://www.52php.cn/article/p-nggbtomd-zp.html 至于集群初始化和启动,我测试没有完全成功,如果问题得到解决我会再补充进来。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |