三节点,使用环境centos7
使用root账号开始进行以下操作
目前安装的xl兼容版本为postgresql10版本。
修改/etc/hosts
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config
setenforce = 0
yum install -y flex bison readline-devel zlib-devel openjade docbook-style-dsssl git gcc
reboot
useradd postgres
passwd postgres
这里注意要每个节点均创建.ssh目录和其权限设置,免密的公钥私钥可以不进行创建
su - postgres
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys postgres@datanode1:~/.ssh/
scp ~/.ssh/authorized_keys postgres@datanode2:~/.ssh/
su root
cd /opt
git clone git://git.postgresql.org/git/postgres-xl.git
cd postgres-xl/
./configure --prefix=/home/postgres/pgxl/
make
make install
cd contrib
make
make install
su - postgres
vim .bashrc
文件最后增加以下内容:
export PGHOME=/home/postgres/pgxl
export LD_LIBRARY_PATH= P G H O M E / l i b : PGHOME/lib: PGHOME/lib:LD_LIBRARY_PATH
export PATH= P G H O M E / b i n : PGHOME/bin: PGHOME/bin:PATH
source .bashrc
echo $PGHOME
mkdir pgxc
mkdir pgxc_bak
基础环境安装完成,以下步骤为集群配置,集群发起从GTM所在服务器进行执行即可
pgxc_ctl
PGXC prepare
PGXG exit
pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all
默认初始化完成后已经启动了集群了,平常进行开启关闭使用以下语句
pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf start all
pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf stop all
psql -p 20004
进入其他远程节点
psql -h datanode2 -p 20008 -U postgres
查询集群状态
select * from pgxc_node;
postgres=# select * from pgxc_node;
node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred
| node_id
-----------±----------±----------±----------±---------------±----------------
-±-----------
datanode1 | D | 20008 | datanode1 | t | f
| 888802358
datanode2 | D | 20008 | datanode2 | f | f
| -905831925
coord1 | C | 20004 | gtm | f | f
| 1885696643
(3 rows)
查看节点是否运行:
[postgres@gtm ~]$ pgxc_ctl monitor all
/bin/bash
Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.
Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.
Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf
Finished reading configuration.
******** PGXC_CTL START ***************
Current directory: /home/postgres/pgxc_ctl
Running: gtm master
Running: gtm proxy gtm_pxy1
Running: gtm proxy gtm_pxy2
Running: coordinator master coord1
Running: datanode master datanode1
Running: datanode master datanode2