1. 配置主机添加内容

10.10.10.11    pgcmdn11.com        pgcmdn11
10.10.10.12    pgcmdn12.com        pgcmdn12
10.10.10.13    pgcmdn13.com        pgcmdn13
10.10.10.14    pgcmdn14.com        pgcmdn14
10.10.10.15    pgcmcoord1.com      pgcmcoord1
10.10.10.16    pgcmcoord2.com      pgcmcoord2
10.10.10.17    gtmmaster.com       gtmmaster
10.10.10.18    gtmslave.com        gtmslave

2.配置网卡,配置主机名

# vim /etc/hosts
[root@pgcmdn01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens37
[root@pgcmdn01 ~]# hostnamectl set-hostname pgcmdn11
[root@pgcmdn01 ~]# 
[root@pgcmdn11 ~]# vim /etc/hosts
[root@pgcmdn11 ~]# scp /etc/hosts  10.10.10.12:/etc/hosts
root@10.10.10.12's password: 
hosts                                                                                                                                      100%  514   786.2KB/s   00:00    
[root@pgcmdn11 ~]# scp /etc/hosts  10.10.10.13:/etc/hosts
root@10.10.10.13's password: 
hosts                                                                                                                                      100%  514   720.8KB/s   00:00    
[root@pgcmdn11 ~]# scp /etc/hosts  10.10.10.14:/etc/hosts
root@10.10.10.14's password: 
hosts                                                                                                                                      100%  514   830.1KB/s   00:00    
[root@pgcmdn11 ~]# scp /etc/hosts  10.10.10.15:/etc/hosts
root@10.10.10.15's password: 
hosts                                                                                                                                      100%  514   723.9KB/s   00:00    
[root@pgcmdn11 ~]# scp /etc/hosts  10.10.10.16:/etc/hosts
root@10.10.10.16's password: 
hosts                                                                                                                                      100%  514   634.5KB/s   00:00    
[root@pgcmdn11 ~]# scp /etc/hosts  10.10.10.17:/etc/hosts
root@10.10.10.17's password: 
hosts                                                                                                                                      100%  514   620.9KB/s   00:00    
[root@pgcmdn11 ~]# scp /etc/hosts  10.10.10.18:/etc/hosts
root@10.10.10.18's password: 
hosts                                                                                                                                      100%  514   731.2KB/s   00:00    
[root@pgcmdn11 ~]# ssh 10.10.10.15 "hostnamectl set-hostname pgcmcoord1"
root@10.10.10.15's password: 
[root@pgcmdn11 ~]# ssh 10.10.10.16 "hostnamectl set-hostname pgcmcoord2"
root@10.10.10.16's password: 
[root@pgcmdn11 ~]# ssh 10.10.10.17 "hostnamectl set-hostname gtmmaster"
root@10.10.10.17's password: 
[root@pgcmdn11 ~]# ssh 10.10.10.18 "hostnamectl set-hostname gtmslave"
root@10.10.10.18's password: 
[root@pgcmdn11 ~]#

    

    

3. 配置sshd_config                                                

# vim /etc/ssh/sshd_config 
                                            
PubkeyAuthentication yes

编辑完毕后重启

# vim /etc/ssh/sshd_config 
# systemctl restart sshd

4. #做root互信

for ip in `tail -8 /etc/hosts |awk '{print $1}'`
do 
ssh ${ip}   "ssh-keygen -t rsa";
done
在11节点上 /root/.ssh/目录下会生成
-rw------- 1 root root 2770 Oct 12 00:02 authorized_keys
-rw------- 1 root root 1679 Oct 11 23:50 id_rsa
-rw-r--r-- 1 root root  395 Oct 11 23:50 id_rsa.pub
ssh-copy-id root@pgcmdn12
然后到第二个节点上
cat *.pub >>authorized_keys
scp authorized_keys root@10.10.10.13:/root/.ssh
然后到第三个节点上
cat *.pub >>authorized_keys
scp authorized_keys root@10.10.10.14:/root/.ssh
然后到第四个节点上
cat *.pub >>authorized_keys
scp authorized_keys root@10.10.10.15:/root/.ssh
然后到第五个节点上
cat *.pub >>authorized_keys
scp authorized_keys root@10.10.10.16:/root/.ssh
然后到第六个节点上
cat *.pub >>authorized_keys
scp authorized_keys root@10.10.10.17:/root/.ssh
然后到第七个节点上
cat *.pub >>authorized_keys
scp authorized_keys root@10.10.10.18:/root/.ssh
然后到第八个节点上
cat *.pub >>authorized_keys
scp authorized_keys root@10.10.10.11:/root/.ssh
scp authorized_keys root@10.10.10.12:/root/.ssh
scp authorized_keys root@10.10.10.13:/root/.ssh
scp authorized_keys root@10.10.10.14:/root/.ssh
scp authorized_keys root@10.10.10.15:/root/.ssh
scp authorized_keys root@10.10.10.16:/root/.ssh
scp authorized_keys root@10.10.10.17:/root/.ssh

以下是操作的出现结果

[root@gtmmaster .ssh]# cat *.pub >>authorized_keys
[root@gtmmaster .ssh]# scp authorized_keys 10.10.10.18:/root/.ssh/
The authenticity of host '10.10.10.18 (10.10.10.18)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.18' (ECDSA) to the list of known hosts.
root@10.10.10.18's password: 
authorized_keys                 
[root@gtmslave ~]# cd .ssh/
[root@gtmslave .ssh]# ll
total 12
-rw------- 1 root root 1679 Oct 11 23:50 id_rsa
-rw-r--r-- 1 root root  395 Oct 11 23:50 id_rsa.pub
[root@gtmslave .ssh]# scp authorized_keys 10.10.10.11:/root/.ssh/
The authenticity of host '10.10.10.11 (10.10.10.11)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.11' (ECDSA) to the list of known hosts.
root@10.10.10.11's password: 
authorized_keys                                                                                                                            100% 2770     3.3MB/s   00:00    
[root@gtmslave .ssh]# scp authorized_keys 10.10.10.12:/root/.ssh/
The authenticity of host '10.10.10.12 (10.10.10.12)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.12' (ECDSA) to the list of known hosts.
root@10.10.10.12's password: 
authorized_keys                                                                                                                            100% 2770     3.2MB/s   00:00    
[root@gtmslave .ssh]# scp authorized_keys 10.10.10.13:/root/.ssh/
The authenticity of host '10.10.10.13 (10.10.10.13)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.13' (ECDSA) to the list of known hosts.
root@10.10.10.13's password: 
authorized_keys                                                                                                                            100% 2770     3.3MB/s   00:00    
[root@gtmslave .ssh]# scp authorized_keys 10.10.10.14:/root/.ssh/
The authenticity of host '10.10.10.14 (10.10.10.14)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.14' (ECDSA) to the list of known hosts.
root@10.10.10.14's password: 
authorized_keys                                                                                                                            100% 2770     3.2MB/s   00:00    
[root@gtmslave .ssh]# scp authorized_keys 10.10.10.15:/root/.ssh/
The authenticity of host '10.10.10.15 (10.10.10.15)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.15' (ECDSA) to the list of known hosts.
root@10.10.10.15's password: 
authorized_keys                                                                                                                            100% 2770     2.7MB/s   00:00    
[root@gtmslave .ssh]# scp authorized_keys 10.10.10.16:/root/.ssh/
The authenticity of host '10.10.10.16 (10.10.10.16)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.16' (ECDSA) to the list of known hosts.
root@10.10.10.16's password: 
authorized_keys                                                                                                                            100% 2770     3.4MB/s   00:00    
[root@gtmslave .ssh]# scp authorized_keys 10.10.10.17:/root/.ssh/
The authenticity of host '10.10.10.17 (10.10.10.17)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.17' (ECDSA) to the list of known hosts.
root@10.10.10.17's password: 
authorized_keys                                                                                                                            100% 2770     4.0MB/s   00:00    
for ip in `tail -8 /etc/hosts |awk '{print $1}'`;
do 
ssh ${ip}  "systemctl stop firewalld;systemctl disable firewalld;\
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config;setenforce 0;";
done

5. 关闭防火墙

for ip in `tail -8 /etc/hosts |awk '{print $1}'`;
do 
ssh ${ip} date;
done

6. 最好配置ntp

7. 创建postgres用户

for ip in `tail -8 /etc/hosts |awk '{print $1}'`;
do 
ssh ${ip}  "groupadd -g 10001 postgres ;\
useradd -u 10001 -g postgres postgres ;\
echo postgres |passwd --stdin postgres;\
mkdir -p /data01/;chown -R postgres.postgres /data01";
done

由于我已经创建了/data01,因此就不用再配置了。

for ip in `tail -8 /etc/hosts |awk '{print $1}'`;
do 
ssh ${ip}  "groupadd -g 10001 postgres ;\
useradd -u 10001 -g postgres postgres ;\
echo postgres |passwd --stdin postgres;\
chown -R postgres.postgres /data01";
done
groupadd: group 'postgres' already exists
useradd: user 'postgres' already exists
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
groupadd: group 'postgres' already exists
useradd: user 'postgres' already exists
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
groupadd: group 'postgres' already exists
useradd: user 'postgres' already exists
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
groupadd: group 'postgres' already exists
useradd: user 'postgres' already exists
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
groupadd: group 'postgres' already exists
useradd: user 'postgres' already exists
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
groupadd: group 'postgres' already exists
useradd: user 'postgres' already exists
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
groupadd: group 'postgres' already exists
useradd: user 'postgres' already exists
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
groupadd: group 'postgres' already exists
useradd: user 'postgres' already exists
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
[root@pgcmdn11 ~]#

6. postgres之间做互信  配置方法跟root一致

for ip in `tail -8 /etc/hosts |awk '{print $1}'`
do 
ssh ${ip}   "ssh-keygen -t rsa";
done
[postgres@pgcmdn11 .ssh]$ ssh-copy-id postgres@pgcmdn12
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/postgres/.ssh/id_rsa.pub"
The authenticity of host 'pgcmdn12 (10.10.10.12)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
postgres@pgcmdn12's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh 'postgres@pgcmdn12'"
and check to make sure that only the key(s) you wanted were added.
[postgres@pgcmdn11 .ssh]$ 
-rw------- 1 postgres postgres  399 Oct 12 00:44 authorized_keys
-rw------- 1 postgres postgres 1675 Oct 12 00:39 id_rsa
-rw-r--r-- 1 postgres postgres  399 Oct 12 00:39 id_rsa.pub
[postgres@pgcmdn12 .ssh]$ cat *.pub >>authorized_keys 
[postgres@pgcmdn12 .ssh]$ scp authorized_keys pgcmdn13
[postgres@pgcmdn12 .ssh]$ scp authorized_keys pgcmdn13:/home/postgres/.ssh/
The authenticity of host 'pgcmdn13 (10.10.10.13)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'pgcmdn13,10.10.10.13' (ECDSA) to the list of known hosts.
postgres@pgcmdn13's password: 
authorized_keys                                                                                                                            100%  798     1.2MB/s   00:00    
[postgres@pgcmdn12 .ssh]$

做好authorized_keys后,要同步到之前的节点上。

Last login: Sun Oct 11 22:41:00 2020 from gateway
[root@gtmslave ~]# su - postgres
Last login: Sun Sep 20 21:40:16 CST 2020 on pts/1
[postgres@gtmslave ~]$ cd .ssh
[postgres@gtmslave .ssh]$ ll
total 12
-rw------- 1 postgres postgres 2798 Oct 12 00:50 authorized_keys
-rw------- 1 postgres postgres 1679 Oct 12 00:40 id_rsa
-rw-r--r-- 1 postgres postgres  399 Oct 12 00:40 id_rsa.pub
[postgres@gtmslave .ssh]$ cat *.pub >> authorized_keys
[postgres@gtmslave .ssh]$ scp authorized_keys 10.10.10.11:/home/postgres/.ssh/
The authenticity of host '10.10.10.11 (10.10.10.11)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.11' (ECDSA) to the list of known hosts.
postgres@10.10.10.11's password: 
authorized_keys                                                                                                                            100% 3197     3.9MB/s   00:00    
[postgres@gtmslave .ssh]$ scp authorized_keys 10.10.10.12:/home/postgres/.ssh/
The authenticity of host '10.10.10.12 (10.10.10.12)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.12' (ECDSA) to the list of known hosts.
postgres@10.10.10.12's password: 
authorized_keys                                                                                                                            100% 3197     3.9MB/s   00:00    
[postgres@gtmslave .ssh]$ scp authorized_keys 10.10.10.13:/home/postgres/.ssh/
The authenticity of host '10.10.10.13 (10.10.10.13)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.13' (ECDSA) to the list of known hosts.
postgres@10.10.10.13's password: 
authorized_keys                                                                                                                            100% 3197     3.5MB/s   00:00    
[postgres@gtmslave .ssh]$ scp authorized_keys 10.10.10.14:/home/postgres/.ssh/
The authenticity of host '10.10.10.14 (10.10.10.14)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.14' (ECDSA) to the list of known hosts.
postgres@10.10.10.14's password: 
authorized_keys                                                                                                                            100% 3197     3.5MB/s   00:00    
[postgres@gtmslave .ssh]$ scp authorized_keys 10.10.10.15:/home/postgres/.ssh/
The authenticity of host '10.10.10.15 (10.10.10.15)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.15' (ECDSA) to the list of known hosts.
postgres@10.10.10.15's password: 
authorized_keys                                                                                                                            100% 3197     3.0MB/s   00:00    
[postgres@gtmslave .ssh]$ scp authorized_keys 10.10.10.16:/home/postgres/.ssh/
The authenticity of host '10.10.10.16 (10.10.10.16)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.16' (ECDSA) to the list of known hosts.
postgres@10.10.10.16's password: 
authorized_keys                                                                                                                            100% 3197     3.2MB/s   00:00    
[postgres@gtmslave .ssh]$ scp authorized_keys 10.10.10.17:/home/postgres/.ssh/
The authenticity of host '10.10.10.17 (10.10.10.17)' can't be established.
ECDSA key fingerprint is SHA256:VPAdFpj/Lxd0pMBN2ehaex2lKxqbafflKWSX6p/JKAc.
ECDSA key fingerprint is MD5:85:70:ed:1e:4c:94:04:f9:87:6e:38:e1:e8:0e:64:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.17' (ECDSA) to the list of known hosts.
postgres@10.10.10.17's password: 
Permission denied, please try again.
postgres@10.10.10.17's password: 
authorized_keys                                                                                                                            100% 3197     3.7MB/s   00:00    
[postgres@gtmslav

验证互信,排除输入yes等后我们就可以做下边了。

for ip in `tail -8 /etc/hosts |awk '{print $1}'`;
do 
ssh ${ip} date;
done
ssh pgcmdn11 date; ssh pgcmdn12 date; ssh pgcmdn12 date; ssh pgcmdn14 date; ssh pgcmcoord1 date;  ssh pgcmcoord2 date; ssh gtmmaster date; ssh gtmslave date;

7.创建pack放包的文件目录

for ip in `tail -8 /etc/hosts |awk '{print $1}'`

do 

ssh ${ip}   "mkdir -p pack";

done

8. 传输所有的包到各个节点上。

[postgres@pgcmdn11 pack]$ for ip in `tail -7 /etc/hosts |awk '{print $1}'`; do  scp /home/postgres/pack/postgres-xl-10r1.1.tar.gz ${ip}:/home/postgres/pack/; done
postgres-xl-10r1.1.tar.gz                                                                                                                                                                                                   100%   27MB 109.9MB/s   00:00    
postgres-xl-10r1.1.tar.gz                                                                                                                                                                                                   100%   27MB 112.6MB/s   00:00    
postgres-xl-10r1.1.tar.gz                                                                                                                                                                                                   100%   27MB 111.1MB/s   00:00    
postgres-xl-10r1.1.tar.gz                                                                                                                                                                                                   100%   27MB 112.3MB/s   00:00    
postgres-xl-10r1.1.tar.gz                                                                                                                                                                                                   100%   27MB 111.2MB/s   00:00    
postgres-xl-10r1.1.tar.gz                                                                                                                                                                                                   100%   27MB 117.7MB/s   00:00    
postgres-xl-10r1.1.tar.gz                                                                                                                                                                                                   100%   27MB 115.0MB/s   00:00    
[postgres@pgcmdn11 pack]$ for ip in `tail -8 /etc/hosts |awk '{print $1}'`; do  ssh ${ip}   "cd /home/postgres/pack/;tar -zxf postgres-xl-10r1.1.tar.gz"; done
[postgres@pgcmdn11 pack]$

验证是否都解压

[postgres@pgcmdn11 pack]$ for ip in `tail -8 /etc/hosts |awk '{print $1}'`; do  ssh ${ip}   "ls /home/postgres/pack/ -h"; done
postgres-xl-10r1.1
postgres-xl-10r1.1.tar.gz
postgres-xl-10r1.1
postgres-xl-10r1.1.tar.gz
postgres-xl-10r1.1
postgres-xl-10r1.1.tar.gz
postgres-xl-10r1.1
postgres-xl-10r1.1.tar.gz
postgres-xl-10r1.1
postgres-xl-10r1.1.tar.gz
postgres-xl-10r1.1
postgres-xl-10r1.1.tar.gz
postgres-xl-10r1.1
postgres-xl-10r1.1.tar.gz
postgres-xl-10r1.1
postgres-xl-10r1.1.tar.gz
[postgres@pgcmdn11 pack]$

验证是否都解压。

for ip in `tail -8 /etc/hosts |awk '{print $1}'`; 
do  
echo '${ip}  ---->';
ssh ${ip}   "ls /home/postgres/pack/ -lh"; 
done
[postgres@pgcmdn11 pack]$ for ip in `tail -8 /etc/hosts |awk '{print $1}'`; 
> do  
> echo '${ip}  ---->';
> ssh ${ip}   "ls /home/postgres/pack/ -lh"; 
> done
${ip}  ---->
total 27M
drwxrwxr-x 6 postgres postgres 292 Mar 11  2019 postgres-xl-10r1.1
-rw-r--r-- 1 postgres postgres 27M Oct 12 01:00 postgres-xl-10r1.1.tar.gz
${ip}  ---->
total 27M
drwxrwxr-x 6 postgres postgres 292 Mar 11  2019 postgres-xl-10r1.1
-rw-r--r-- 1 postgres postgres 27M Oct 12 01:17 postgres-xl-10r1.1.tar.gz
${ip}  ---->
total 27M
drwxrwxr-x 6 postgres postgres 292 Mar 11  2019 postgres-xl-10r1.1
-rw-r--r-- 1 postgres postgres 27M Oct 12 01:17 postgres-xl-10r1.1.tar.gz
${ip}  ---->
total 27M
drwxrwxr-x 6 postgres postgres 292 Mar 11  2019 postgres-xl-10r1.1
-rw-r--r-- 1 postgres postgres 27M Oct 12 01:17 postgres-xl-10r1.1.tar.gz
${ip}  ---->
total 27M
drwxrwxr-x 6 postgres postgres 292 Mar 11  2019 postgres-xl-10r1.1
-rw-r--r-- 1 postgres postgres 27M Oct 12 01:17 postgres-xl-10r1.1.tar.gz
${ip}  ---->
total 27M
drwxrwxr-x 6 postgres postgres 292 Mar 11  2019 postgres-xl-10r1.1
-rw-r--r-- 1 postgres postgres 27M Oct 12 01:17 postgres-xl-10r1.1.tar.gz
${ip}  ---->
total 27M
drwxrwxr-x 6 postgres postgres 292 Mar 11  2019 postgres-xl-10r1.1
-rw-r--r-- 1 postgres postgres 27M Oct 12 01:17 postgres-xl-10r1.1.tar.gz
${ip}  ---->
total 27M
drwxrwxr-x 6 postgres postgres 292 Mar 11  2019 postgres-xl-10r1.1
-rw-r--r-- 1 postgres postgres 27M Oct 12 01:17 postgres-xl-10r1.1.tar.gz
[postgres@pgcmdn11 pack]$

7. 安装依赖包

for ip in `tail -8 /etc/hosts |awk '{print $1}'`; 
do  
ssh ${ip} " yum install -y \
libicu-devel.x86_64 \
icu.x86_64 \
tcl.x86_64 \
tcl-devel.x86_64 \
perl-ExtUtils-Embed.noarch \
readline-devel.x86_64 \
zlib-devel \
globus-gssapi-gsi.x86_64 \
globus-gssapi-gsi-develx86_64 \
openssl-devel \
pam-devel.x86_64 \
libxml++ \
libxml++-devel \
libxslt-devel \
zlib-devel \
openldap-devel.x86_64 \
systemd-devel.x86_64 \
python-devel \
flex-devel.x86_64 \
flex.x86_64
";
done
yum install -y \
libicu-devel.x86_64 \
icu.x86_64 \
tcl.x86_64 \
tcl-devel.x86_64 \
perl-ExtUtils-Embed.noarch \
readline-devel.x86_64 \
zlib-devel \
openssl-devel \
pam-devel.x86_64 \
libxml2 \
libxml2-devel \
libxslt-devel \
zlib-devel \
openldap-devel.x86_64

10.先编译一台

./configure \
--prefix=/data01/pg10/ \
--bindir=/data01/pg10/bin \
--sysconfdir=/data01/pg10/etc \
--libdir=/data01/pg10/lib \
--includedir=/data01/pg10/include \
--datarootdir=/data01/pg10/share/ \
--datadir=/data01/pg10/share \
--localedir=/data01/pg10/share/locale \
--mandir=/data01/pg10/share/man \
--docdir=/data01/pg10/share/doc/postgresql \
--htmldir=/data01/pg10/share/html \
--enable-nls='zn_CN' \
--with-pgport=10001 \
--with-perl \
--with-python \
--with-tcl \
--with-gssapi \
--with-icu \
--with-openssl \
--with-pam \
--with-ldap \
--with-systemd \
--with-readline \
--with-libxml \
--with-libxslt \
--with-segsize=1 \
--with-blocksize=8 \
--with-wal-segsize=16 \
--with-wal-blocksize=8 \
--with-zlib

11. 再编译剩余7台

for ip in `tail -7 /etc/hosts |awk '{print $1}'`; 
do  
ssh ${ip} "cd /home/postgres/pack/postgres-xl-10r1.1;make clean;./configure \
--prefix=/data01/pg10/ \
--bindir=/data01/pg10/bin \
--sysconfdir=/data01/pg10/etc \
--libdir=/data01/pg10/lib \
--includedir=/data01/pg10/include \
--datarootdir=/data01/pg10/share/ \
--datadir=/data01/pg10/share \
--localedir=/data01/pg10/share/locale \
--mandir=/data01/pg10/share/man \
--docdir=/data01/pg10/share/doc/postgresql \
--htmldir=/data01/pg10/share/html \
--enable-nls='zn_CN' \
--with-pgport=10001 \
--with-perl \
--with-python \
--with-tcl \
--with-gssapi \
--with-icu \
--with-openssl \
--with-pam \
--with-ldap \
--with-systemd \
--with-readline \
--with-libxml \
--with-libxslt \
--with-segsize=1 \
--with-blocksize=8 \
--with-wal-segsize=16 \
--with-wal-blocksize=8 \
--with-zlib";
done
for ip in `tail -8 /etc/hosts |awk '{print $1}'`; 
do  
ssh ${ip} "cd /home/postgres/pack/postgres-xl-10r1.1;make -j8 && make install -j8";
done

以下内容显示为成功。

make[4]: Entering directory `/home/postgres/pack/postgres-xl-10r1.1/src/backend'
make[4]: Nothing to be done for `submake-errcodes'.
make[4]: Leaving directory `/home/postgres/pack/postgres-xl-10r1.1/src/backend'
make[3]: Leaving directory `/home/postgres/pack/postgres-xl-10r1.1/src/port'
make -C ../../../src/common all
make[3]: Entering directory `/home/postgres/pack/postgres-xl-10r1.1/src/common'
make -C ../backend submake-errcodes
make[4]: Entering directory `/home/postgres/pack/postgres-xl-10r1.1/src/backend'
make[4]: Nothing to be done for `submake-errcodes'.
make[4]: Leaving directory `/home/postgres/pack/postgres-xl-10r1.1/src/backend'
make[3]: Leaving directory `/home/postgres/pack/postgres-xl-10r1.1/src/common'
make[2]: Leaving directory `/home/postgres/pack/postgres-xl-10r1.1/src/test/isolation'
make -C test/perl install
make[2]: Entering directory `/home/postgres/pack/postgres-xl-10r1.1/src/test/perl'
make[2]: Nothing to be done for `install'.
make[2]: Leaving directory `/home/postgres/pack/postgres-xl-10r1.1/src/test/perl'
/usr/bin/mkdir -p '/data01/pg10/lib/postgresql/pgxs/src'
/usr/bin/install -c -m 644 Makefile.global '/data01/pg10/lib/postgresql/pgxs/src/Makefile.global'
/usr/bin/install -c -m 644 Makefile.port '/data01/pg10/lib/postgresql/pgxs/src/Makefile.port'
/usr/bin/install -c -m 644 ./Makefile.shlib '/data01/pg10/lib/postgresql/pgxs/src/Makefile.shlib'
/usr/bin/install -c -m 644 ./nls-global.mk '/data01/pg10/lib/postgresql/pgxs/src/nls-global.mk'
make[1]: Leaving directory `/home/postgres/pack/postgres-xl-10r1.1/src'
Postgres-XL installation complete.
[postgres@pgcmdn11 ~]$

12.配置环境变量

cat >/data01/pg10/postgresql.env<<EOF
export PGHOME=/data01/pg10
export PGDATA=\${PGHOME}/pgdata
export PGDATABASE=postgres
export PGPORT=10001
export PATH=\${PGHOME}/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:\$PATH
export LD_LIBRARY_PATH=\$PATH/lib:/usr/lib:/usr/lib64:/lib:/lib64:/sur/local/lib:/usr/local/lib64:\$LD_LIBRARY_PATH
export MANPATH=\{PGHOME}/share/man:\$MANPATH
EOF
echo ". /data01/pg10/postgresql.env"  >>/home/postgres/.bashrc
source ~/.bashrc
echo $PGDATA

也可以尝试用自动化。

for ip in `tail -8 /etc/hosts |awk '{print $1}'`; 
do  
ssh ${ip} "cat >/data01/pg10/postgresql.env<<EOF
export PGHOME=/data01/pg10
export PGDATA=\${PGHOME}/pgdata
export PGDATABASE=postgres
export PGPORT=10001
export PATH=\${PGHOME}/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:\$PATH
export LD_LIBRARY_PATH=\$PATH/lib:/usr/lib:/usr/lib64:/lib:/lib64:/sur/local/lib:/usr/local/lib64:\$LD_LIBRARY_PATH
export MANPATH=\{PGHOME}/share/man:\$MANPATH
EOF"
ssh ${ip} "echo ". /data01/pg10/postgresql.env"  >>/home/postgres/.bashrc";
ssh ${ip} "source ~/.bashrc";
done

#初始化 可以不做

#initdb --pgdata=$PGDATA  --nodename=pgcmdn01

13.配置gtm  按照步骤一步一步的做

[postgres@pgcmdn11 ~]$ mkdir pgxc_ctl
[postgres@pgcmdn11 ~]$ cd pgxc_ctl/
[postgres@pgcmdn11 pgxc_ctl]$ touch pgxc_ctl.conf
[postgres@pgcmdn11 pgxc_ctl]$ pgxc_ctl
/usr/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
PGXC help
You are using pgxc_ctl, the configuration utility for PGXL
Type:
        help <command>
        where <command> is either add, Createdb, Createuser, clean,
                configure, deploy, failover, init, kill, log, monitor,
                prepare, q, reconnect, remove, set, show, start, 
                stop or unregister
PGXC prepare
PGXC exit
[postgres@pgcmdn11 pgxc_ctl]$ ll
total 20
-rw-rw-r-- 1 postgres postgres 18082 Oct 12 15:22 pgxc_ctl.conf
drwxrwxr-x 2 postgres postgres    32 Oct 12 15:21 pgxc_log
[postgres@pgcmdn11 pgxc_ctl]$

14. 初始化配置文件

再节点1上10.10.10.11上创建存放初始化配置文件的目录和配置文件

postgres用户10.10.10.11上主节点

mkdir pgxc_ctl
cd pgxc_ctl/
touch pgxc_ctl.conf

postgres执行命令生成配置模版

主节点

pgxc_ctl
prepare
exit

编辑配置模版

配置

[postgres@pgcmdn11 pgxc_ctl]$ egrep -v "^$|^#" pgxc_ctl.conf 
pgxcInstallDir=$HOME/pgxc
pgxcOwner=$USER                 # owner of the Postgres-XC databaseo cluster.  Here, we use this
                                                # both as linus user and database user.  This must be
                                                # the super user of each coordinator and datanode.
pgxcUser=$pgxcOwner             # OS user of Postgres-XC owner
tmpDir=/tmp                                     # temporary dir used in XC servers
localTmpDir=$tmpDir                     # temporary dir used here locally
configBackup=n                                  # If you want config file backup, specify y to this value.
configBackupHost=pgxc-linker    # host to backup config file
configBackupDir=$HOME/pgxc              # Backup directory
configBackupFile=pgxc_ctl.bak   # Backup file name --> Need to synchronize when original changed.
gtmName=gtm
gtmMasterServer=gtmmaster
gtmMasterPort=20001
gtmMasterDir=/pgxc/nodes/gtm
gtmExtraConfig=none                     # Will be added gtm.conf for both Master and Slave (done at initilization only)
gtmMasterSpecificExtraConfig=none       # Will be added to Master's gtm.conf (done at initialization only)
gtmSlave=y                                      # Specify y if you configure GTM Slave.   Otherwise, GTM slave will not be configured and
                                                        # all the following variables will be reset.
gtmSlaveName=gtmSlave
gtmSlaveServer=gtmslave         # value none means GTM slave is not available.  Give none if you don't configure GTM Slave.
gtmSlavePort=20001                      # Not used if you don't configure GTM slave.
gtmSlaveDir=/pgxc/nodes/gtm     # Not used if you don't configure GTM slave.
gtmSlaveSpecificExtraConfig=none # Will be added to Slave's gtm.conf (done at initialization only)
gtmProxyDir=/pgxc/nodes/gtm_pxy
gtmProxy=y                              # Specify y if you conifugre at least one GTM proxy.   You may not configure gtm proxies
                                                # only when you dont' configure GTM slaves.
                                                # If you specify this value not to y, the following parameters will be set to default empty values.
                                                # If we find there're no valid Proxy server names (means, every servers are specified
                                                # as none), then gtmProxy value will be set to "n" and all the entries will be set to
                                                # empty values.
gtmProxyNames=(gtm_pxy1 gtm_pxy2)       # No used if it is not configured
gtmProxyServers=(gtmmaster gtmslave)                    # Specify none if you dont' configure it.
gtmProxyPorts=(30001 30001)                             # Not used if it is not configured.
gtmProxyDirs=($gtmProxyDir $gtmProxyDir)        # Not used if it is not configured.
gtmPxyExtraConfig=none          # Extra configuration parameter for gtm_proxy.  Coordinator section has an example.
gtmPxySpecificExtraConfig=(none none none none)
coordMasterDir=/pgxc/nodes/coord
coordSlaveDir=/pgxc/nodes/coord_slave
coordArchLogDir=/pgxc/nodes/coord_archlog
coordNames=(pgcmcoord1 pgcmcoord2)              # Master and slave use the same name
coordPorts=(20004 20005)                        # Master ports
poolerPorts=(20010 20011)                       # Master pooler ports
coordPgHbaEntries=(10.10.10.0/24)                               # Assumes that all the coordinator (master/slave) accepts
                                                                                                # the same connection
                                                                                                # This entry allows only $pgxcOwner to connect.
                                                                                                # If you'd like to setup another connection, you should
                                                                                                # supply these entries through files specified below.
coordMasterServers=(pgcmcoord1)         # none means this master is not available
coordMasterDirs=($coordMasterDir)
coordMaxWALsernder=10   # max_wal_senders: needed to configure slave. If zero value is specified,
                                                # it is expected to supply this parameter explicitly by external files
                                                # specified in the following.   If you don't configure slaves, leave this value to zero.
coordMaxWALSenders=($coordMaxWALsernder)
                                                # max_wal_senders configuration for each coordinator.
coordSlave=y                    # Specify y if you configure at least one coordiantor slave.  Otherwise, the following
                                                # configuration parameters will be set to empty values.
                                                # If no effective server names are found (that is, every servers are specified as none),
                                                # then coordSlave value will be set to n and all the following values will be set to
                                                # empty values.
coordUserDefinedBackupSettings=n        # Specify whether to update backup/recovery
                                                                        # settings during standby addition/removal.
coordSlaveSync=y                # Specify to connect with synchronized mode.
coordSlaveServers=(pgcmcoord2)                  # none means this slave is not available
coordSlavePorts=(20004)                 # Master ports
coordSlavePoolerPorts=(20010)                   # Master pooler ports
coordSlaveDirs=($coordSlaveDir)
coordArchLogDirs=($coordArchLogDir)
coordExtraConfig=coordExtraConfig       # Extra configuration file for coordinators.  
                                                # This file will be added to all the coordinators'
                                                # postgresql.conf
cat > $coordExtraConfig <<EOF
log_destination = 'stderr'
logging_collector = on
log_directory = 'pg_log'
listen_addresses = '*'
max_connections = 100
EOF
coordSpecificExtraConfig=(none none none none)
coordExtraPgHba=none    # Extra entry for pg_hba.conf.  This file will be added to all the coordinators' pg_hba.conf
coordSpecificExtraPgHba=(none none none none)
coordAdditionalSlaves=n         # Additional slave can be specified as follows: where you
coordAdditionalSlaveSet=(cad1)          # Each specifies set of slaves.   This case, two set of slaves are
                                                                                        # configured
cad1_Sync=n                             # All the slaves at "cad1" are connected with asynchronous mode.
                                                        # If not, specify "y"
                                                        # The following lines specifies detailed configuration for each
                                                        # slave tag, cad1.  You can define cad2 similarly.
cad1_Servers=(node08 node09 node06 node07)      # Hosts
cad1_dir=$HOME/pgxc/nodes/coord_slave_cad1
cad1_Dirs=($cad1_dir $cad1_dir $cad1_dir $cad1_dir)
cad1_ArchLogDir=$HOME/pgxc/nodes/coord_archlog_cad1
cad1_ArchLogDirs=($cad1_ArchLogDir $cad1_ArchLogDir $cad1_ArchLogDir $cad1_ArchLogDir)
datanodeMasterDir=/data01/pgxc/nodes/dn_master
datanodeSlaveDir=/data01/pgxc/nodes/dn_slave
datanodeArchLogDir=/data01/pgxc/nodes/datanode_archlog
primaryDatanode=pgcmdn11                                # Primary Node.
datanodeNames=(pgcmdn11 pgcmdn12)
datanodePorts=(20008 20009)     # Master ports
datanodePoolerPorts=(20012 20013)       # Master pooler ports
datanodePgHbaEntries=(10.10.10.0/24)    # Assumes that all the coordinator (master/slave) accepts
                                                                                # the same connection
                                                                                # This list sets up pg_hba.conf for $pgxcOwner user.
                                                                                # If you'd like to setup other entries, supply them
                                                                                # through extra configuration files specified below.
datanodeMasterServers=(pgcmdn11 pgcmdn12)       # none means this master is not available.
                                                                                                        # This means that there should be the master but is down.
                                                                                                        # The cluster is not operational until the master is
                                                                                                        # recovered and ready to run.
datanodeMasterDirs=($datanodeMasterDir $datanodeMasterDir )
datanodeMaxWalSender=10                                                         # max_wal_senders: needed to configure slave. If zero value is 
                                                                                                        # specified, it is expected this parameter is explicitly supplied
                                                                                                        # by external configuration files.
                                                                                                        # If you don't configure slaves, leave this value zero.
datanodeMaxWALSenders=($datanodeMaxWalSender $datanodeMaxWalSender)
                                                # max_wal_senders configuration for each datanode
datanodeSlave=y                 # Specify y if you configure at least one coordiantor slave.  Otherwise, the following
                                                # configuration parameters will be set to empty values.
                                                # If no effective server names are found (that is, every servers are specified as none),
                                                # then datanodeSlave value will be set to n and all the following values will be set to
                                                # empty values.
datanodeUserDefinedBackupSettings=n     # Specify whether to update backup/recovery
                                                                        # settings during standby addition/removal.
datanodeSlaveServers=(pgcmdn13 pgcmdn14)        # value none means this slave is not available
datanodeSlavePorts=(20008 20009)        # value none means this slave is not available
datanodeSlavePoolerPorts=(20012 20013)  # value none means this slave is not available
datanodeSlaveSync=y             # If datanode slave is connected in synchronized mode
datanodeSlaveDirs=($datanodeSlaveDir $datanodeSlaveDir)
datanodeArchLogDirs=( $datanodeArchLogDir $datanodeArchLogDir)
datanodeExtraConfig=none        # Extra configuration file for datanodes.  This file will be added to all the 
                                                        # datanodes' postgresql.conf
datanodeSpecificExtraConfig=(none none none none)
datanodeExtraPgHba=none         # Extra entry for pg_hba.conf.  This file will be added to all the datanodes' postgresql.conf
datanodeSpecificExtraPgHba=(none none none none)
datanodeAdditionalSlaves=n      # Additional slave can be specified as follows: where you
                                                                                        # configured
                                                        # If not, specify "y"
                                                        # The following lines specifies detailed configuration for each
                                                        # slave tag, cad1.  You can define cad2 similarly.
walArchive=n    # If you'd like to configure WAL archive, edit this section.
                                # Pgxc_ctl assumes that if you configure WAL archive, you configure it
                                # for all the coordinators and datanodes.
                                # Default is "no".   Please specify "y" here to turn it on.
walArchiveSet=(war1 war2)
war1_source=(master)    # you can specify master, slave or ano other additional slaves as a source of WAL archive.
                                        # Default is the master
wal1_source=(slave)
wal1_source=(additiona_coordinator_slave_set additional_datanode_slave_set)
war1_host=node10        # All the nodes are backed up at the same host for a given archive set
war1_backupdir=$HOME/pgxc/backup_war1
wal2_source=(master)
war2_host=node11
war2_backupdir=$HOME/pgxc/backup_war2
[postgres@pgcmdn11 pgxc_ctl]$

创建相应的目录

[postgres@pgcmdn11 pgxc_ctl]$ egrep -v "^$|^#" pgxc_ctl.conf |egrep '/' |awk -F'=' '{print $2}'
$HOME/pgxc
/tmp                                    # temporary dir used in XC servers
$HOME/pgxc              # Backup directory
/pgxc/nodes/gtm
/pgxc/nodes/gtm # Not used if you don't configure GTM slave.
/pgxc/nodes/gtm_pxy
/pgxc/nodes/coord
/pgxc/nodes/coord_slave
/pgxc/nodes/coord_archlog
(10.10.10.0/24)                         # Assumes that all the coordinator (master/slave) accepts
n       # Specify whether to update backup/recovery
$HOME/pgxc/nodes/coord_slave_cad1
$HOME/pgxc/nodes/coord_archlog_cad1
/data01/pgxc/nodes/dn_master
/data01/pgxc/nodes/dn_slave
/data01/pgxc/nodes/datanode_archlog
(10.10.10.0/24) # Assumes that all the coordinator (master/slave) accepts
n       # Specify whether to update backup/recovery
$HOME/pgxc/backup_war1
$HOME/pgxc/backup_war2

目录分为root下执行的,跟postgres下执行的。/pgxc这个是root下的。当然也可以配置成postgres目录/data02这个,属主属组都为postgres

[postgres@pgcmdn11 pgxc_ctl]$ egrep -v "^$|^#" pgxc_ctl.conf |egrep '/' |awk -F'=' '{print $2}'
mkdir -p $HOME/pgxc
mkdir -p /tmp                                    
mkdir -p $HOME/pgxc             
mkdir -p /pgxc/nodes/gtm
mkdir -p /pgxc/nodes/gtm 
mkdir -p /pgxc/nodes/gtm_pxy
mkdir -p /pgxc/nodes/coord
mkdir -p /pgxc/nodes/coord_slave
mkdir -p /pgxc/nodes/coord_archlog                     
mkdir -p $HOME/pgxc/nodes/coord_slave_cad1
mkdir -p $HOME/pgxc/nodes/coord_archlog_cad1
mkdir -p /data01/pgxc/nodes/dn_master
mkdir -p /data01/pgxc/nodes/dn_slave
mkdir -p /data01/pgxc/nodes/datanode_archlog
mkdir -p $HOME/pgxc/backup_war1
mkdir -p $HOME/pgxc/backup_war2

这个为postgers用户下执行。

mkdir -p /data01/pgxc/nodes/dn_master                   
mkdir -p /data01/pgxc/nodes/dn_slave                    
mkdir -p /data01/pgxc/nodes/datanode_archlog                                                                            
mkdir -p /home/postgres/pgxc                                               
mkdir -p /home/postgres/pgxc/nodes/coord_slave_cad1              
mkdir -p /home/postgres/pgxc/nodes/coord_archlog_cad1                       
mkdir -p /home/postgres/pgxc/backup_war1                         
mkdir -p /home/postgres/pgxc/backup_war2

            

这个是root执行

mkdir -p /pgxc/nodes/gtm                                
mkdir -p /pgxc/nodes/gtm                                
mkdir -p /pgxc/nodes/gtm_pxy                            
mkdir -p /pgxc/nodes/coord                              
mkdir -p /pgxc/nodes/coord_slave                        
mkdir -p /pgxc/nodes/coord_archlog

                                                                      

  权限                           

chown postgres.postgres -R /pgxc/nodes/gtm                                  
chown postgres.postgres -R /pgxc/nodes/gtm                                  
chown postgres.postgres -R /pgxc/nodes/gtm_pxy                              
chown postgres.postgres -R /pgxc/nodes/coord                                
chown postgres.postgres -R /pgxc/nodes/coord_slave                          
chown postgres.postgres -R /pgxc/nodes/coord_archlog                        
chown postgres.postgres -R /home/postgres/pgxc/nodes/coord_slave_cad1       
chown postgres.postgres -R /home/postgres/pgxc/nodes/coord_archlog_cad1     
chown postgres.postgres -R /data01/pgxc/nodes/dn_master                     
chown postgres.postgres -R /data01/pgxc/nodes/dn_slave                      
chown postgres.postgres -R /data01/pgxc/nodes/datanode_archlog              
chown postgres.postgres -R /home/postgres/pgxc/backup_war1                  
chown postgres.postgres -R /home/postgres/pgxc/backup_war2                  
chown postgres.postgres -R /home/postgres/pgxc

再10.10.10.11上执行

root用户

for ip in `tail -8 /etc/hosts |awk '{print $1}'`; 
do  
ssh ${ip} "
mkdir -p /pgxc/nodes/gtm                                
mkdir -p /pgxc/nodes/gtm                                
mkdir -p /pgxc/nodes/gtm_pxy                            
mkdir -p /pgxc/nodes/coord                              
mkdir -p /pgxc/nodes/coord_slave                        
mkdir -p /pgxc/nodes/coord_archlog"
ssh ${ip} "chown postgres.postgres -R /pgxc";
done

postgres用户在10.10.10.11上执行

for ip in `tail -8 /etc/hosts |awk '{print $1}'`; 
do  
ssh ${ip} "
mkdir -p /data01/pgxc/nodes/dn_master                   
mkdir -p /data01/pgxc/nodes/dn_slave                    
mkdir -p /data01/pgxc/nodes/datanode_archlog                                                                            
mkdir -p /home/postgres/pgxc                                               
mkdir -p /home/postgres/pgxc/nodes/coord_slave_cad1              
mkdir -p /home/postgres/pgxc/nodes/coord_archlog_cad1                       
mkdir -p /home/postgres/pgxc/backup_war1                         
mkdir -p /home/postgres/pgxc/backup_war2";
done

postgres用户上执行

pgxc_ctl 后

会出现

PGXC  这个,然后可以通过输入help,看看这个下边可以出现的命令。

输入init all,就可以进行安装了。

PGXC init all
Initialize GTM master
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.
fixing permissions on existing directory /pgxc/nodes/gtm ... ok
creating configuration files ... ok
creating control file ... ok
Success.
Done.
Start GTM master
server starting
Initialize GTM slave
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.
fixing permissions on existing directory /pgxc/nodes/gtm ... ok
creating configuration files ... ok
creating control file ... ok
Success.
Done.
Start GTM slaveserver starting
Done.
Initialize all the gtm proxies.
Initializing gtm proxy gtm_pxy1.
Initializing gtm proxy gtm_pxy2.
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.
fixing permissions on existing directory /pgxc/nodes/gtm_pxy ... ok
creating configuration files ... ok
Success.
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.
fixing permissions on existing directory /pgxc/nodes/gtm_pxy ... ok
creating configuration files ... ok
Success.
Done.
Starting all the gtm proxies.
Starting gtm proxy gtm_pxy1.
Starting gtm proxy gtm_pxy2.
server starting
server starting
Done.
Initialize all the coordinator masters.
Initialize coordinator master coord.
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /pgxc/nodes/coord ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... creating cluster information ... ok
syncing data to disk ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success.
Done.
Starting coordinator master.
Starting coordinator master coord
2020-10-12 19:21:48.738 CST [47336] LOG:  listening on IPv4 address "0.0.0.0", port 20004
2020-10-12 19:21:48.738 CST [47336] LOG:  listening on IPv6 address "::", port 20004
2020-10-12 19:21:48.739 CST [47336] LOG:  listening on Unix socket "/tmp/.s.PGSQL.20004"
2020-10-12 19:21:48.746 CST [47336] LOG:  redirecting log output to logging collector process
2020-10-12 19:21:48.746 CST [47336] HINT:  Future log output will appear in directory "pg_log".
Done.
Initialize all the coordinator slaves.
Initialize the coordinator slave coord.
Done.
Starting all the coordinator slaves.
Starting coordinator slave coord.
2020-10-12 19:21:52.380 CST [47761] LOG:  listening on IPv4 address "0.0.0.0", port 20004
2020-10-12 19:21:52.380 CST [47761] LOG:  listening on IPv6 address "::", port 20004
2020-10-12 19:21:52.381 CST [47761] LOG:  listening on Unix socket "/tmp/.s.PGSQL.20004"
2020-10-12 19:21:52.388 CST [47761] LOG:  redirecting log output to logging collector process
2020-10-12 19:21:52.388 CST [47761] HINT:  Future log output will appear in directory "pg_log".
Done
Initialize all the datanode masters.
Initialize the datanode master pgcmdn11.
Initialize the datanode master pgcmdn12.
ERROR: target directory (/data01/pgxc/nodes/dn_master) exists and not empty. Skip Datanode initilialization
ERROR: target directory (/data01/pgxc/nodes/dn_master) exists and not empty. Skip Datanode initilialization
Done.
Starting all the datanode masters.
Starting datanode master pgcmdn11.
Starting datanode master pgcmdn12.
2020-10-12 19:21:57.374 CST [51693] LOG:  listening on IPv4 address "0.0.0.0", port 20008
2020-10-12 19:21:57.374 CST [51693] LOG:  listening on IPv6 address "::", port 20008
2020-10-12 19:21:57.375 CST [51693] LOG:  listening on Unix socket "/tmp/.s.PGSQL.20008"
2020-10-12 19:21:57.382 CST [51693] LOG:  redirecting log output to logging collector process
2020-10-12 19:21:57.382 CST [51693] HINT:  Future log output will appear in directory "pg_log".
2020-10-12 19:21:57.375 CST [47553] LOG:  listening on IPv4 address "0.0.0.0", port 20009
2020-10-12 19:21:57.375 CST [47553] LOG:  listening on IPv6 address "::", port 20009
2020-10-12 19:21:57.376 CST [47553] LOG:  listening on Unix socket "/tmp/.s.PGSQL.20009"
2020-10-12 19:21:57.383 CST [47553] LOG:  redirecting log output to logging collector process
2020-10-12 19:21:57.383 CST [47553] HINT:  Future log output will appear in directory "pg_log".
Done.
Initialize all the datanode slaves.
Initialize datanode slave pgcmdn11
Initialize datanode slave pgcmdn12
Starting all the datanode slaves.
Starting datanode slave pgcmdn11.
Starting datanode slave pgcmdn12.
2020-10-12 19:22:01.589 CST [47488] LOG:  listening on IPv4 address "0.0.0.0", port 20008
2020-10-12 19:22:01.589 CST [47488] LOG:  listening on IPv6 address "::", port 20008
2020-10-12 19:22:01.590 CST [47488] LOG:  listening on Unix socket "/tmp/.s.PGSQL.20008"
2020-10-12 19:22:01.598 CST [47488] LOG:  redirecting log output to logging collector process
2020-10-12 19:22:01.598 CST [47488] HINT:  Future log output will appear in directory "pg_log".
2020-10-12 19:22:01.591 CST [47783] LOG:  listening on IPv4 address "0.0.0.0", port 20009
2020-10-12 19:22:01.591 CST [47783] LOG:  listening on IPv6 address "::", port 20009
2020-10-12 19:22:01.592 CST [47783] LOG:  listening on Unix socket "/tmp/.s.PGSQL.20009"
2020-10-12 19:22:01.600 CST [47783] LOG:  redirecting log output to logging collector process
2020-10-12 19:22:01.600 CST [47783] HINT:  Future log output will appear in directory "pg_log".
Done.
ALTER NODE coord WITH (HOST='pgcmcoord1', PORT=20004);
ALTER NODE
CREATE NODE pgcmdn11 WITH (TYPE='datanode', HOST='pgcmdn11', PORT=20008, PRIMARY);
CREATE NODE
CREATE NODE pgcmdn12 WITH (TYPE='datanode', HOST='pgcmdn12', PORT=20009);
CREATE NODE
SELECT pgxc_pool_reload();
 pgxc_pool_reload 
------------------
 t
(1 row)
Done.
EXECUTE DIRECT ON (pgcmdn11) 'CREATE NODE coord WITH (TYPE=''coordinator'', HOST=''pgcmcoord1'', PORT=20004)';
EXECUTE DIRECT
EXECUTE DIRECT ON (pgcmdn11) 'ALTER NODE pgcmdn11 WITH (TYPE=''datanode'', HOST=''pgcmdn11'', PORT=20008, PRIMARY)';
EXECUTE DIRECT
EXECUTE DIRECT ON (pgcmdn11) 'CREATE NODE pgcmdn12 WITH (TYPE=''datanode'', HOST=''pgcmdn12'', PORT=20009)';
EXECUTE DIRECT
EXECUTE DIRECT ON (pgcmdn11) 'SELECT pgxc_pool_reload()';
 pgxc_pool_reload 
------------------
 t
(1 row)
EXECUTE DIRECT ON (pgcmdn12) 'CREATE NODE coord WITH (TYPE=''coordinator'', HOST=''pgcmcoord1'', PORT=20004)';
EXECUTE DIRECT
EXECUTE DIRECT ON (pgcmdn12) 'CREATE NODE pgcmdn11 WITH (TYPE=''datanode'', HOST=''pgcmdn11'', PORT=20008, PRIMARY)';
EXECUTE DIRECT
EXECUTE DIRECT ON (pgcmdn12) 'ALTER NODE pgcmdn12 WITH (TYPE=''datanode'', HOST=''pgcmdn12'', PORT=20009)';
EXECUTE DIRECT
EXECUTE DIRECT ON (pgcmdn12) 'SELECT pgxc_pool_reload()';
 pgxc_pool_reload 
------------------
 t
(1 row)
Done.
PGXC

然后登陆进去。

[postgres@pgcmdn11 pgxc_ctl]$ psql -h pgcmcoord1 -p 20004 -U postgres
psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))
Type "help" for help.
postgres=# select * from pgxc_node;
 node_name | node_type | node_port | node_host  | nodeis_primary | nodeis_preferred |   node_id   
-----------+-----------+-----------+------------+----------------+------------------+-------------
 coord     | C         |     20004 | pgcmcoord1 | f              | f                |  -629959615
 pgcmdn11  | D         |     20008 | pgcmdn11   | t              | f                |   587784628
 pgcmdn12  | D         |     20009 | pgcmdn12   | f              | f                | -1394571061
(3 rows)
postgres=# select relname from pg_class where relname ~ 'pgxc';
         relname          
--------------------------
 pgxc_node
 pgxc_class_pcrelid_index
 pgxc_node_oid_index
 pgxc_node_name_index
 pgxc_group_name_index
 pgxc_group_oid
 pgxc_node_id_index
 pgxc_class
 pgxc_group
 pgxc_prepared_xacts
(10 rows)
postgres=# create user pgxc_user1 with password 'pgxc_user1';
CREATE ROLE
postgres=# create database db_pgxc with owner = pgxc_user1;
CREATE DATABASE
postgres=# exit
postgres-# \c pgxc_user1 pgxc_user1
FATAL:  no pg_hba.conf entry for host "10.10.10.11", user "pgxc_user1", database "pgxc_user1", SSL off
Previous connection kept
postgres-# exit
postgres-# \q
[postgres@pgcmdn11 pgxc_ctl]$

关闭所有的库。

[postgres@pgcmdn11 pgxc_ctl]$ pgxc_ctl 
/usr/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
PGXC stop all
Stopping all the coordinator slaves.
Stopping the coordinator slave coord.
Stopping all the coordinator masters.
Stopping coordinator master coord.
Done.
Stopping all the datanode slaves.
Stopping datanode slave pgcmdn11.
Stopping datanode slave pgcmdn12.
Stopping all the datanode masters.
Stopping datanode master pgcmdn11.
Stopping datanode master pgcmdn12.
Done.
Stopping all the gtm proxies.
Stopping gtm proxy gtm_pxy1.
Stopping gtm proxy gtm_pxy2.
waiting for server to shut down.... done
server stopped
waiting for server to shut down.... done
server stopped
Done.
Stop GTM slave
waiting for server to shut down.... done
server stopped
Stop GTM master
waiting for server to shut down.... done
server stopped
PGXC