Postgre2015大象会,大家都很关注PostgreSQL的集群,目前,开发人员已经转向Postgres-X2,近期根据自己和同事部署xl的过程部署了一下Postgres-X2。本次部署试验是利用pgxc_ctl部署的,更加灵活的部署集群。
1、整体概括:
? ? 一共四个节点,一个gtm,一个coordinator,两个datanode。
?a. GTM节点
? ? ? ? IP:192.168.238.129
? ? ? ? nodename:gtm
? ? ? ? port:6666
? ? b.coordinator
? ? ? ? IP:192.168.238.130
? ? ? ? nodename:coord1
? ? ? ? port:5432
? ? ? ? pooler_port:6668
? ? c.datanode1
? ? ? ? IP:192.168.238.131
? ? ? ? nodename:datanode1
? ? ? ? port:15432
? ? ? ? pooler_port:6669
? ? d.datanode2
? ? ? ? IP:192.168.238.132
? ? ? ? nodename:datanode2
? ? ? ? port:15432
? ? ? ? pooler_port:6669
2、准备工作(不特别指明,四个节点做相同的操作):
a.编译安装pgx2,同时编译contrib。
./configure --prefix=/opt/pgx2
make; make install
cd contrib
make; make install
b.建立用户postgres,将安装目录属主赋给postgres。
chown -R postgres:postgres pgx2
c.配置ssh连接
[postgres@localhost~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ea:c9:48:2d:dc:0d:ab:9b:3d:99:cb:bd:db:3b:ba:fa root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|? ? ? ? ? ? ? ? |
|? ? ? ? ? ? ? ? |
|? ? ? ? ? ? ? ? |
|? ? ? ? ? ? ? ? |
|? ? ? . S? ? ? ? |
|? . o =? ? ? ? |
|? ? + =o.? ? ? ? |
|? . X+o ..? ? ? |
|? ? =.O=E=oo? ? |
+-----------------+
[postgres@localhost~]#
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
?
vi /etc/hosts
192.168.238.129 localhost.localdomain
?
--分发密钥,gtm节点向其他节点分发
scp ~/.ssh/authorized_keys postgres@192.168.238.130
scp ~/.ssh/authorized_keys postgres@192.168.238.131
scp ~/.ssh/authorized_keys postgres@192.168.238.132
d.配置环境变量
[postgres@localhost ~]$ cat .bashrc
# .bashrc
?
# Source global definitions
if [ -f /etc/bashrc ]; then
? ? . /etc/bashrc
fi
?
export PGHOME=/opt/pgx2/
export PGUSER=postgres
export LD_LIBRARY_PATH=$PGHOME/lib
export PATH=$PGHOME/bin:$PATH
?
# User specific aliases and functions
[postgres@localhost ~]$
建议:
在ssh连接时效率很慢,可以用ssh -v进行检测,这里就不做说明了。
?
修改/etc/ssh/sshd_config中的GSSAPIAuthentication和UseDNS为no就可提高ssh连接速度。
为了方便起见我将所有节点的iptables关闭,大家可自行配置。
3、部署节点
a.配置pgxc_ctl.conf
--在/home/postgres/pgxc_ctl下
?
--conf内容
cat pgxc_ctl.conf
#user and path
pgxcOwner=postgres
pgxcUser=$pgxcOwner
pgxcInstallDir=/opt/pgx2
?
#gtm and gtmproxy
gtmMasterDir=$HOME/pgxc/nodes/gtm
gtmMasterPort=6666
gtmMasterServer=192.168.238.129
gtmSlave=n
?
#gtmproxy
gtmProxy=n
gtmProxyDir=$HOME/pgxc/nodes/coord
gtmProxyNames=(gtm_pxy1)
gtmProxyServers=(192.168.238.130)
gtmProxyPorts=(20001)
gtmProxyDirs=($gtmProxyDir/gtm_pxy1)
gtmPxyExtraConfig=(none)
gtmPxySpecificExtraConfig=(none)
?
#coordinator
coordMasterDir=$HOME/pgxc/nodes/coord
coordNames=(coord1)
coordPorts=(5432)
poolerPorts=(6668)
coordPgHbaEntries=(192.168.238.0/24)
coordMasterServers=(192.168.238.130)
coordMasterDirs=($coordMasterDir/coord1)
coordMaxWALsernder=0
coordMaxWALSenders=($coordMaxWALsernder)
coordSlave=n
coordSpecificExtraConfig=(none)
coordSpecificExtraPgHba=(none)
?
#datanode
datanodeNames=(datanode1 datanode2)
datanodePorts=(15432 15432)
datanodePoolerPorts=(6669 6669)
datanodePgHbaEntries=(192.168.238.0/24)
datanodeMasterServers=(192.168.238.131 192.168.238.132)
datanodeMasterDir=$HOME/pgxc/nodes/dn_master
datanodeMasterDirs=($datano