转载:PostgreSQL-XC : Installation
来源:互联网 发布:匡恩网络市值是多少 编辑:程序博客网 时间:2024/05/01 10:32
转载:http://francs3.blog.163.com/blog/static/405767272012532308480/
PostgreSQL-XC : Installation
上篇( http://francs3.blog.163.com/blog/static/4057672720125315352442/) 介绍了 PostgreSQL-XC 基本
原理,对 PostgreSQL-XC 体系结构和组件已经有了初步的认识,今天计划在虚拟机环境上安装 PostgreSQL-XC,
以做进一步学习分析,下面是 PostgreSQL-XC 安装的整个过程
一 安装准备
--1.1 requiremetns
硬件需求:官方建议使用 64 位的系统,内存至少 4GB
系统需求:64bit CentOS 5.4 或者其它其它 LINUX 系统
软件需求:GNU make version: 3.80 or newer
Flex: 2.5.31 or later
Perl: 5.8 or later
GCC: Recent versions of GCC are recommendable
软件需求,具体可参考 http://postgres-xc.sourceforge.net/docs/1_0/install-requirements.html
--1.2 实际安装环境
两台笔记本虚拟机 RHEL 6.2 ,内存 512 M
IP 192.168.1.35 ;192.168.1.36
--1.3 安装规划
一个GTM节点,两个协调(Coordinator)节点,二个数据节点;这是第一次安装,为了操作简便,没有安装
GTM-Standby,节点和 GTM-Proxy,这两个节点可以后期测试。
GTM节点: gtm 6666
协调节点一: coord1 1921
协调节点二: coord1 1925
192.168.1.36
数据节点一: db_1 15431
数据节点二: db_2 15432
--1.4 安装规划图
二 系统配置 ( 两台 )
--2.1 创建 pgxc 系统用户并赋权
[root@redhatB bin]# groupadd pgxc
[root@redhatB bin]# useradd pgxc -g pgxc
[root@redhatB bin]# passwd pgxc
Changing password for user pgxc.
New password:
BAD PASSWORD: it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
[root@redhatB pgxc]# chown -R pgxc:pgxc /pgdata_xc
--2.2 系统层面其它配置
根据需要配置其它系统层参数,由于是在虚拟机上运行,其它系统参数暂不修改。
三 安装 postgresql-xc ( 两台都安装 )
--3.1 pgxc_v1.0beta2 下载
https://sourceforge.net/projects/postgres-xc/files/
下载 pgxc_v1.0beta2.tar.gz
--3.2 将安装包解压 ( 两台 )
tar zxvf pgxc_v1.0beta2.tar.gz
备注:解压后,产生目录 pgxc
-3.3 -配置
备注:conifugre 过程中如有提示缺少相关包,yum 安装即可。
--3.4 编译
备 注:编译后,如果出现"All of PostgreSQL successfully made. Ready to install.",说明编译成功。
--3.5 安装 PostgreSQL XC
备注:安装后如果提示 "PostgreSQL installation complete." 说明安装成功。
四 配置数据节点 ( 192.168.1.36 )
--4.1 修改环境变量( .bash_profile )
export PGDATA=/pgdata_xc/db_1/pg_root
export LANG=en_US.utf8
export PGHOME=/opt/pgsql_xc
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
alias rm='rm -i'
alias ll='ls -lh'
--4.2 创建数据目录
pgxc@redhatB pgdata_xc]$ mkdir -p /pgdata_xc/db_1/pg_root[pgxc@redhatB pgdata_xc]$ mkdir -p /pgdata_xc/db_2/pg_root
--4.3 初始化数据节点1
--4.4 修改数据节点一配置文件 postgresql.conf 参数
port = 15431
# - Where to Log -
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
gtm_host = 'localhost'
# GTM CONNECTION
gtm_host = '192.168.1.35'
gtm_port = 6666
pgxc_node_name = 'db_1'
# DATA NODES AND CONNECTION POOLING
pooler_port = 6667
max_pool_size = 100
--4.5修改数据节点一 pg_hba.conf ,增加以下
host all all 192.168.1.35/32 trusthost all all 0.0.0.0/0 md5
--4.6 初始化数据节点2
--4.7 修改数据节点二配置文件 postgresql.conf 参数
# - Connection Settings -port = 15432
# - Where to Log -
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
gtm_host = 'localhost'
# GTM CONNECTION
gtm_host = '192.168.1.35'
gtm_port = 6666
pgxc_node_name = 'db_2'
# DATA NODES AND CONNECTION POOLING
pooler_port = 6667
max_pool_size = 100
--4.8 修改数据节点一 pg_hba.conf ,增加以下
host all all 0.0.0.0/0 md5
五 配置 gtm 节点 ( 192.168.1.35 )
--5.1 修改 .bash_profile
export PGPORT=1921
export PGDATA=/database/1922/pgdata1/pgdata_xc/coord1
export LANG=en_US.utf8
export PGHOME=/opt/pgsql_xc
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
alias rm='rm -i'
alias ll='ls -lh'
--5.2 创建 gtm 数据目录
--5.3 install gtm
[pgxc@redhat6 bin]$ initgtm -Z gtm -D /database/1922/pgdata1/pgdata_xc/gtm
The files belonging to this GTM system will be owned by user "pgxc".
This user must also own the server process.
fixing permissions on existing directory /database/1922/pgdata1/pgdata_xc/gtm ... ok
creating configuration files ... ok
Success. You can now start the GTM server using:
gtm -D /database/1922/pgdata1/pgdata_xc/gtm
or
gtm_ctl -Z gtm -D /database/1922/pgdata1/pgdata_xc/gtm -l logfile start
六 配置 coordinator 节点
--6.1 创建 coordinator 数据目录
[pgxc@redhat6 pgdata_xc]$ mkdir -p /database/1922/pgdata1/pgdata_xc/coord2
--6.2 install coord1
--6.3 修改 coord1 配置文件 postgresql.conf
listen_addresses = '*'
port = 1921
# - Where to Log -
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
gtm_host = 'localhost'
# GTM CONNECTION
gtm_host = 'localhost'
gtm_port = 6666
pgxc_node_name = 'coord1'
# DATA NODES AND CONNECTION POOLING
pooler_port = 6667
max_pool_size = 100
--6.4 配置 coord1 pg_hba.conf
host all all 0.0.0.0/0 md5
--6.5 install coord2
initdb -D /database/1922/pgdata1/pgdata_xc/coord2 --nodename coord2 -E UTF8 --locale=C -U postgres -W
--6.6 配置 coord2 配置文件 postgresql.conf
# - Connection Settings -
listen_addresses = '*'
port = 1925
# - Where to Log -
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
gtm_host = 'localhost'
# GTM CONNECTION
gtm_host = 'localhost'
gtm_port = 6666
pgxc_node_name = 'coord2'
# DATA NODES AND CONNECTION POOLING
pooler_port = 6668
max_pool_size = 100
--6.7 配置 coord1 pg_hba.conf
host all all 192.168.1.36/32 trusthost all all 0.0.0.0/0 md5
--6.8 修改防火墙,打开相应端口 ( 两台)
为了测试简便,先暂时关闭防火墙和 seliniux。
七 启动 PostgreSQL-XC
--7.1 start gtm
[1] 6185
--查看 gtm 是否启动
pid: 6185
data: /database/1922/pgdata1/pgdata_xc/gtm
active: 1
[pgxc@redhat6 bin]$ ps -ef | grep gtm
pgxc 6185 6135 0 20:50 pts/4 00:00:00 gtm -D /database/1922/pgdata1/pgdata_xc/gtm
备注: gtm 进程已经正常启动。
--7.2 启动数据节点( 192.168.1.36 )
postgres -X -D /pgdata_xc/db_1/pg_root -p 15431 -i &postgres -X -D /pgdata_xc/db_2/pg_root -p 15432 -i &
备注:-X 表示 datanode 节点。
-- 查看数据节点是否启动
[pgxc@redhatB pg_log]$ ps -ef | grep pgxcroot 371 351 0 09:16 pts/0 00:00:00 su - pgxc
pgxc 372 371 0 09:16 pts/0 00:00:00 -bash
root 420 398 0 09:16 pts/1 00:00:00 su - pgxc
pgxc 421 420 0 09:16 pts/1 00:00:00 -bash
pgxc 588 421 0 09:28 pts/1 00:00:00 postgres -X -D /pgdata_xc/db_1/pg_root -p 15431 -i
pgxc 589 588 0 09:28 ? 00:00:00 postgres: logger process
pgxc 591 588 0 09:28 ? 00:00:00 postgres: writer process
pgxc 592 588 0 09:28 ? 00:00:00 postgres: wal writer process
pgxc 593 588 0 09:28 ? 00:00:00 postgres: autovacuum launcher process
pgxc 594 588 0 09:28 ? 00:00:00 postgres: stats collector process
pgxc 595 421 0 09:28 pts/1 00:00:00 postgres -X -D /pgdata_xc/db_2/pg_root -p 15432 -i
pgxc 596 595 0 09:28 ? 00:00:00 postgres: logger process
pgxc 598 595 0 09:28 ? 00:00:00 postgres: writer process
pgxc 599 595 0 09:28 ? 00:00:00 postgres: wal writer process
pgxc 600 595 0 09:28 ? 00:00:00 postgres: autovacuum launcher process
pgxc 601 595 0 09:28 ? 00:00:00 postgres: stats collector process
--7.3 启动 coordinator 节点
postgres -C -D /database/1922/pgdata1/pgdata_xc/coord1 -p 1921 -i &postgres -C -D /database/1922/pgdata1/pgdata_xc/coord2 -p 1925 -i &
备注:-C 表示 coordinator 节点。
--查看 coordinator 节点是否启来
pgxc 11634 11633 0 10:25 ? 00:00:00 postgres: logger process
pgxc 11637 11633 0 10:25 ? 00:00:00 postgres: pooler process
pgxc 11638 11633 0 10:25 ? 00:00:00 postgres: writer process
pgxc 11639 11633 0 10:25 ? 00:00:00 postgres: wal writer process
pgxc 11640 11633 0 10:25 ? 00:00:00 postgres: autovacuum launcher process
pgxc 11641 11633 0 10:25 ? 00:00:00 postgres: stats collector process
pgxc 11643 8961 0 10:25 pts/3 00:00:00 postgres -C -D /database/1922/pgdata1/pgdata_xc/coord2 -p 1925 -i
pgxc 11644 11643 0 10:26 ? 00:00:00 postgres: logger process
pgxc 11647 11643 0 10:26 ? 00:00:00 postgres: pooler process
pgxc 11648 11643 0 10:26 ? 00:00:00 postgres: writer process
pgxc 11649 11643 0 10:26 ? 00:00:00 postgres: wal writer process
pgxc 11650 11643 0 10:26 ? 00:00:00 postgres: autovacuum launcher process
pgxc 11651 11643 0 10:26 ? 00:00:00 postgres: stats collector process
pgxc 12203 11633 0 10:53 ? 00:00:00 postgres: postgres postgres ::1(13531) idle
pgxc 12372 11643 0 11:01 ? 00:00:00 postgres: postgres postgres ::1(14789) idle
pgxc 12661 11643 0 11:16 ? 00:00:00 postgres: francs francs ::1(14825) idle
备注:coord1,coord2 节点分别多了个 pooler process 进程,pooler process 用来与数据节点进行通信的。
--7.4 查看GTM,POOL连接
[root@redhat6 ~]# netstat -anp | grep gtmtcp 0 0 0.0.0.0:6666 0.0.0.0:* LISTEN 11620/gtm
tcp 0 0 :::6666 :::* LISTEN 11620/gtm
tcp 0 0 ::1:6666 ::1:52228 ESTABLISHED 11620/gtm
[root@redhat6 ~]# ps -ef | grep pool
pgxc 11637 11633 0 10:25 ? 00:00:00 postgres: pooler process
pgxc 11647 11643 0 10:26 ? 00:00:00 postgres: pooler process
root 13375 11658 0 11:53 pts/2 00:00:00 grep pool
备注:如果到了这步,没有看到 pooler process ,或者没有 gtm 相关连接,说明配置有问题。
八:注册节点
--8.4 在 coord1,cord2 上注册数据节点
CREATE NODE db_2 WITH (TYPE='datanode',HOST = '192.168.1.36', PORT=15432);
CREATE NODE coord2 WITH (TYPE='coordinator',HOST = 'localhost', PORT=1925);
CREATE NODE coord1 WITH (TYPE='coordinator',HOST = 'localhost', PORT=1921);
[pgxc@redhat6 gtm]$ psql -p 1921 -U postgres
psql (PGXC 1.0beta2, based on PG 9.1.3)
Type "help" for help.
postgres=# select * from pgxc_node;
node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id
-----------+-----------+-----------+-----------+----------------+------------------+------------
coord1 | C | 5432 | localhost | f | f | 1885696643
(1 row)
postgres=# CREATE NODE db_1 WITH (TYPE='datanode',HOST = '192.168.1.36', PORT=15431,PRIMARY, PREFERRED);
CREATE NODE
postgres=# CREATE NODE db_2 WITH (TYPE='datanode',HOST = '192.168.1.36', PORT=15432);
CREATE NODE
postgres=# CREATE NODE coord2 WITH (TYPE='coordinator',HOST = '192.168.1.35', PORT=1925);
CREATE NODE
postgres=# select * from pgxc_node;
node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id
-----------+-----------+-----------+--------------+----------------+------------------+-------------
coord1 | C | 5432 | localhost | f | f | 1885696643
db_1 | D | 15431 | 192.168.1.36 | f | f | 1356996994
db_2 | D | 15432 | 192.168.1.36 | f | f | -822936791
coord2 | C | 1925 | localhost | f | f | -1197102633
postgres=# select pgxc_pool_reload();
pgxc_pool_reload
------------------
t
(1 row)
备注:到了这里, PostgreSQL-XC 安装完成,接下来验证下。
九 测试
--9.1 coord1 创建测试库和表
psql (PGXC 1.0beta2, based on PG 9.1.3)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+------------------------
francs | postgres | UTF8 | C | C | =Tc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | francs=C*T*c*/postgres
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=# create database test_xc;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+------------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
test_xc | postgres | UTF8 | C | C |
(5 rows)
postgres=# \c test_xc
You are now connected to database "test_xc" as user "postgres".
test_xc=# create table test_1 (id integer,name varchar(32));
CREATE TABLE
test_xc=# insert into test_1 select generate_series(1,100),'test_xc';
INSERT 0 100
备注:在 coord1 节点上创建了测试库 test_xc,并在里面创建了一张表,接下来看看 coord2, db_1,db_2 节点情况。
--9.2 coord2 上验证
psql (PGXC 1.0beta2, based on PG 9.1.3)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+------------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
test_xc | postgres | UTF8 | C | C |
(5 rows)
postgres=# \c test_xc
You are now connected to database "test_xc" as user "postgres".
test_xc=# \d
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | test_1 | table | postgres
(1 row)
test_xc=# select count(*) from test_1;
count
-------
100
(1 row)
--9.3 数据节点 db_1 上验证
psql (PGXC 1.0beta2, based on PG 9.1.3)
Type "help" for help.
test_xc=# \d
WARNING: Do not have a GTM snapshot available
WARNING: Do not have a GTM snapshot available
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | test_1 | table | postgres
(1 row)
test_xc=# select count(*) from test_1;
WARNING: Do not have a GTM snapshot available
WARNING: Do not have a GTM snapshot available
count
-------
42
(1 row)
--9.4 数据节点 db_2 上验证
[pgxc@redhatB pg_log]$ psql -p 15432 -U postgres -d test_xcpsql (PGXC 1.0beta2, based on PG 9.1.3)
Type "help" for help.
test_xc=# select count(*) from test_1;
WARNING: Do not have a GTM snapshot available
WARNING: Do not have a GTM snapshot available
count
-------
58
(1 row)
备注:表共有100条记录,数据节点一分布了 42 条,数据节点二分布了 58 条,可见数据已经分片到数据节点上。
当然在创建表时,也可以设置 replication 模式,这样数据就会完全复制到每个节点。
十 可能出现的ERROR
postgres=# create database test;
ERROR: Failed to get pooled connections
备注:如果在 coord1 节点上操作时,报 "ERROR: Failed to get pooled connections",可能的原因很多,
可能是节点没有注册好,这时要查看 pgxc_node 视图;也有可能是 pg_hba.conf,防火墙,selinux
等问题,总之逐一排查。
十一 总结
1 本次测试只是简单将 PostgreSQL-XC 搭建起来了,其中 gmt_standby ,GTM-Proxy 没有配置,这个以后可
以测试下;
2 由于在 PostgreSQL-XC 体系中,coordinator 并不存储数据,数据被分片在数据节点中,这种机制与GreenPlumn
有点类似;而 coordinator 节点新增了 pooler process 进程,个人觉得 coordinator 很像一个连接池。
3 PostgreSQL-XC 所谓的多主节点( muti-master) 同时对外服务,实际上对应用服务的是 coordinator 节点,而
不是数据 节点本身;原来俺的理解是数据节点同时读写(多份数据,mater 同时读写),而在 PostgreSQL-XC 中
并不是这样。
4 由于每个数据节点存储一部分数据,那么如果数据节点 down 掉,整个 PostgreSQL-XC 将不可用,不知是否有
更好的方案,例如给每个数据节点配置个 standby 节点?
5 由于在 PostgreSQL-XC 体系中数据分片在多个数据节点中,IO 性能会提升,同时对网络压力会提升;具体性能
目前还没有测试。
6 尽管疑问重多,但还是要感谢来自日本的 PostgreSQL-XC 开发团队,他们为 PostgreSQL 带来了 muti-master
的集群方案。
十二 参考
http://postgres-xc.sourceforge.net/
http://postgres-xc.sourceforge.net/docs/1_0/index.html\
http://blog.163.com/digoal@126/blog/static/16387704020121952051174/
http://michael.otacoo.com/tag/postgres-xc/
- 转载:PostgreSQL-XC : Installation
- 转载:PostgreSQL-XC: Introduction
- 转载:PostgreSQL-XC : Data Replication or Distribution
- PostgreSQL-XC
- postgresql xc 的安装配置过程
- XC
- xc
- PostgreSQL installation on Ubuntu
- PostgreSQL XL Installation Guide
- 转载:Postgres-XC: online data redistribution
- postgresql Installation from Source Code
- 转载:Implement Postgres-XC 0.9.7 with 8 servers
- 转载:Postgres-XC: Waiting for online data redistribution
- 转载:PostgreSQL的分区表
- 转载:postgresql性能详解
- 转载:Postgresql-xl 调研
- 转载:PostgreSQL 内部概貌
- 转载:Complex DML queries and clause push-down in Postgres-XC
- JVM 性能监控与常用工具学习总结
- 默认构造函数
- UTMI及USB 2.0 PHY高速传输特性分析
- 在Mac下结合Xcode搭建Cocos2d-X开发环境!
- Codeforces Round #194 (Div. 2) D. Chips
- 转载:PostgreSQL-XC : Installation
- STM32F103 系列芯片读写AT45DB161芯片的程序和写入/读取字库文件的方法
- MySql中的流程函数
- JVM性能监控学习总结
- scheduler转PDF的时候出现中文乱码
- USB枚举过程分析
- 转载:PostgreSQL-XC: Introduction
- mahout 源码解析之聚类--聚类分类模型
- uva 10785 The Mad Numerologist(遍历+sort排序)