Postgres-XL集群的搭建和测试详解
CentOS6.5 192.168.0.101
CentOS6.5 192.168.0.102
CentOS6.5 192.168.0.103
CentOS6.5 192.168.0.104
一、主机规划
cnode1 (gtm)
cnode2 (gtm_proxy,coordinator,datanode)
cnode3 (gtm_proxy,coordinator,datanode)
cnode4 (gtm_proxy,coordinator,datanode)
cnode5 (gtm_proxy,coordinator,datanode)
二、在每个节点配置主机Host
#vim /etc/hosts
192.168.0.101 cnode1
192.168.0.102 cnode2
192.168.0.103 cnode3
192.168.0.104 cnode4
三、安装postgres-xl
1.在每一个节点上安装依赖包
# yum install -y flex bison readline-devel zlib-devel openjade docbook-style-dsssl
或者:
yum -y install flex
yum -y install bison
yum -y install openjade.x86_64
yum -y install jadetex.noarch
yum -y install docbook*
2.在每一个节点上安装postgres-xl
# tar -zxvf postgres-xl-v9.2-src.tar.gz
# cd postgres-xl
# ./configure --prefix=/usr/local/pgxl-9.2
# make
# make install
3.在cnode1(gtm)中安装集群管理工具pgxc_ctl
在gtm或任意一台机器上上解压源码
# tar -zxvf postgres-xl-v9.2-src.tar.gz
# cd /opt/pgxl/postgres-xl/contrib/pgxc_ctl/
# make
# make install
这样pgxc_ctl就安装完成了,后续集群的初始化、启动和停止就可以用该命令来进行了。
默认会生成/home/postgres/pgxc_ctl目录,执行pgxc_ctl命令的时候,会默认读取该目录下的配置文件pgxc_ctl.conf。
四、配置集群
1.在每一个节点上创建用户Postgres
为每台主机创建用户postgres。
# useradd postgres
# passwd postgres
# 输入密码 12345678
2.在每一个节点上设置环境变量
# su - postgres
$ vi .bashrc #注意这里环境变量一定要添加到.bashrc文件中,否则会找不到相关命令
export PGHOME=/usr/local/pgxl-9.2
export PGUSER=postgres
export LD_LIBRARY_PATH=$PGHOME/lib
export PATH=$PGHOME/bin:$PATH
3.在每一个节点赋给目录权限
安装过程中需要在datanode上创建目录,所以需要有$PGHOME目录的写权限。
在每台datanode和coordinator主机上执行以下命令:
chown -R postgres:postgres /usr/local/pgxl-9.2
五、在各个节点之间配置免密码连入(pgxc_ctl初始化集群的时候需要连入其他节点)
ssh-keygen -t rsa (in ~/.ssh目录下)
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
若不是在本地安装,需要把该文件的内容添加到其他需要安装的机器的authorized_keys文件中。
scp authorized_keys postgres@cnode2:/home/postgres/.ssh/
scp authorized_keys postgres@cnode3:/home/postgres/.ssh/
scp authorized_keys postgres@cnode4:/home/postgres/.ssh/
这样posgres用户就可以免密码登陆node1到node4主机了。
修改authorized_keys权限:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
测试免密码连入(第一次需要输入密码):
scp test_scp.txt postgres@cnode2:/home/postgres/
scp test_scp.txt postgres@cnode3:/home/postgres/
scp test_scp.txt postgres@cnode4:/home/postgres/
我这里是在GTM主机上执行安装过程的,所以需要在gtm机器上执行以上命令,并把生成的
id_rsa.pub 文件追加到其他datanode和coordinator主机的.ssh/authorized_keys上。
六、配置集群并使用pgxc_ctl初始化集群
首先:
在每一个协调者和数据节点上创建以下目录并赋权:
mkdir -p /data/pg/pg92data
chown -R postgres:postgres /data/pg/pg92data
其次:
#在cnode1节点(gtm)上创建集群的配置文件:pgxc_ctl.conf
#在目录/home/postgres/pgxc_ctl目录中创建pgxc_ctl.conf文件
#每一个节点的配置信息的具体含义参考:http://files.postgres-xl.org/documentation/pgxc_ctl.html
#pgxc_ctl.conf 的内容如下:
===========================
#user and path
pgxcOwner=postgres
pgxcUser=$pgxcOwner
pgxcInstallDir=/usr/pgxl-9.2
#gtm and gtmproxy
gtmMasterDir=/usr/pgxl-9.2/gtm
gtmMasterPort=