绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
postgres-xl 集群数据库系统-0002-源码编译安装
2022-05-06 16:18:13

0、背景

准备搭建一个 postgres-xl 集群:

4 个节点,1 个 GTM,1 个 Coordinator,2 个 Datanode。

然后研究一下 postgres-xl 技术架构 ~

本篇研究从源码编译安装 postgres-xl ~

(1)本系列文章

格瑞图:postgres-xl 集群数据库系统-0001-准备虚机环境

1、编译安装

(0)克隆代码

git clone https://git.postgresql.org/git/postgres-xl.git

(1)安装依赖工具

下载工具 wget 用于下载代码(代码提前下载好,放在了自己的 nginx 服务器上)

解压工具 unzip 用于解压代码

readline-devel 和 zlib-devel 在编译 postgres-xl 代码时会用到

# #########################################################
# step1.install tools
# #########################################################
pdsh -w xl[122-125] -l root "yum install -y wget unzip readline-devel zlib-devel"
# #########################################################

(2)下载代码

# #########################################################
# step2.download src
# #########################################################
pdsh -w xl[122-125] -l postgres "wget http://192.168.1.100:8080/tools/postgres-xl.zip -O /tmp/postgres-xl.zip"
pdsh -w xl[122-125] -l postgres "unzip -d /home/postgres /tmp/postgres-xl.zip"
pdsh -w xl[122-125] -l postgres "rm -rf /home/postgres/__MACOSX"
pdsh -w xl[122-125] -l postgres "mv /home/postgres/postgres-xl /home/postgres/xlsrc"
# #########################################################

(3)编译安装 postgres-xl

# #########################################################
# step3.build & install pgsql
# #########################################################
pdsh -w xl[122-125] -l postgres 'mkdir -p /home/postgres/pgsql'
pdsh -w xl[122-125] -l postgres 'cd /home/postgres/xlsrc && ./configure --prefix=/home/postgres/pgsql'
pdsh -w xl[122-125] -l postgres 'cd /home/postgres/xlsrc && gmake'
pdsh -w xl[122-125] -l postgres 'cd /home/postgres/xlsrc && gmake install'
# #########################################################

(4)编译安装 pgxc_ctl

# #########################################################
# step4.build & install pgxc_ctl
# #########################################################
pdsh -w xl122 -l postgres 'cd /home/postgres/xlsrc/contrib/pgxc_ctl && gmake'
pdsh -w xl122 -l postgres 'cd /home/postgres/xlsrc/contrib/pgxc_ctl && gmake install'
# #########################################################

(5)配置环境变量

# #########################################################
# step5.export to path
# #########################################################
pdsh -w xl[122-125] -l postgres "sed -i '/pgsql/d' /home/postgres/.bashrc"
pdsh -w xl[122-125] -l postgres "echo \"export PATH=/home/postgres/pgsql/bin:\\\$PATH\" >> /home/postgres/.bashrc"
# #########################################################

(6)创建配置文件

#!/bin/sh

PGDAT=/home/postgres/pgdat/nodes/

pgxc_ctl prepare config empty
pgxc_ctl add gtm         master gtm       gtm       20001       "$PGDAT/gtm"
pgxc_ctl add coordinator master coord1    coord1    30001 31001 "$PGDAT/coord1"    none none
pgxc_ctl add datanode    master datanode1 datanode1 40001 41001 "$PGDAT/datanode1" none none none
pgxc_ctl add datanode    master datanode2 datanode2 40002 41002 "$PGDAT/datanode2" none none none
pgxc_ctl monitor all createdb -p 30001 test

运行结果

[postgres@xl122 pgxc_ctl]$ nano init.sh
[postgres@xl122 pgxc_ctl]$ chmod u+x init.sh
[postgres@xl122 pgxc_ctl]$ ls
init.sh
[postgres@xl122 pgxc_ctl]$ ./init.sh
/usr/bin/bash
Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.
ERROR: File "/home/postgres/pgxc_ctl/pgxc_ctl.conf" not found or not a regular file. No such file or directory
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
/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
Initialize GTM master
The authenticity of host 'gtm (192.168.1.122)' can't be established.
ECDSA key fingerprint is SHA256:nAUN5wyvQDca4fMPJ9NVwZRum6ZJxJlYdg48F5tJlKE.
ECDSA key fingerprint is MD5:94:b9:5b:57:8e:6d:1a:87:f6:58:89:f3:1a:ff:65:01.
Are you sure you want to continue connecting (yes/no)? yes
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 /home/postgres/pgdat/nodes/gtm ... ok
creating configuration files ... ok
creating control file ... ok

Success.
Done.
Start GTM master
waiting for server to shut down.... done
server stopped
server starting
/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
Actual Command: ssh postgres@coord1 "( PGXC_CTL_SILENT=1 initdb -D /home/postgres/pgdat/nodes//coord1 --nodename coord1 ) > /tmp/gtm_STDOUT_11805_0 2>&1" < /dev/null > /dev/null 2>&1
The authenticity of host 'coord1 (192.168.1.123)' can't be established.
ECDSA key fingerprint is SHA256:n+OHPOXAdayvNt5CLgHXEABWT6kd4HnVBQ0ZmzSKLgs.
ECDSA key fingerprint is MD5:7e:9d:9d:15:2f:b8:7e:95:ec:f4:f6:9c:9a:4e:eb:ba.
Are you sure you want to continue connecting (yes/no)? yes
Bring remote stdout: scp postgres@coord1:/tmp/gtm_STDOUT_11805_0 /tmp/STDOUT_11805_1 > /dev/null 2>&1
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.

creating directory /home/postgres/pgdat/nodes/coord1 ... 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.
Starting coordinator master coord1
2022-04-26 00:51:05.086 CST [11210] LOG:  listening on IPv4 address "0.0.0.0", port 30001
2022-04-26 00:51:05.086 CST [11210] LOG:  listening on IPv6 address "::", port 30001
2022-04-26 00:51:05.128 CST [11210] LOG:  listening on Unix socket "/tmp/.s.PGSQL.30001"
2022-04-26 00:51:05.178 CST [11210] LOG:  redirecting log output to logging collector process
2022-04-26 00:51:05.178 CST [11210] HINT:  Future log output will appear in directory "pg_log".
Done.
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
/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
Actual Command: ssh postgres@datanode1 "( PGXC_CTL_SILENT=1 initdb -D /home/postgres/pgdat/nodes//datanode1   --nodename datanode1 ) > /tmp/gtm_STDOUT_11843_0 2>&1" < /dev/null > /dev/null 2>&1
The authenticity of host 'datanode1 (192.168.1.124)' can't be established.
ECDSA key fingerprint is SHA256:qr0DbV3TKrQ5ufCH1uOhTlItjU6a7lOSSTJTwTB5NAU.
ECDSA key fingerprint is MD5:e3:05:69:68:45:b8:66:4b:d3:3a:48:99:c5:4d:a8:17.
Are you sure you want to continue connecting (yes/no)? yes
Bring remote stdout: scp postgres@datanode1:/tmp/gtm_STDOUT_11843_0 /tmp/STDOUT_11843_1 > /dev/null 2>&1
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.

creating directory /home/postgres/pgdat/nodes/datanode1 ... 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.
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
pg_dumpall: could not connect to database "template1": FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "template1"

Actual Command: ssh postgres@datanode1 "( pg_ctl start -w -Z restoremode -D /home/postgres/pgdat/nodes//datanode1 -o -i ) > /tmp/gtm_STDOUT_11843_3 2>&1" < /dev/null > /dev/null 2>&1
Bring remote stdout: scp postgres@datanode1:/tmp/gtm_STDOUT_11843_3 /tmp/STDOUT_11843_4 > /dev/null 2>&1
2022-04-26 00:51:12.471 CST [11311] LOG:  listening on IPv4 address "0.0.0.0", port 40001
2022-04-26 00:51:12.471 CST [11311] LOG:  listening on IPv6 address "::", port 40001
2022-04-26 00:51:12.513 CST [11311] LOG:  listening on Unix socket "/tmp/.s.PGSQL.40001"
2022-04-26 00:51:12.574 CST [11311] LOG:  redirecting log output to logging collector process
2022-04-26 00:51:12.574 CST [11311] HINT:  Future log output will appear in directory "pg_log".
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
Actual Command: ssh postgres@datanode1 "( pg_ctl stop -w -Z restoremode -D /home/postgres/pgdat/nodes//datanode1 ) > /tmp/gtm_STDOUT_11843_5 2>&1" < /dev/null > /dev/null 2>&1
Bring remote stdout: scp postgres@datanode1:/tmp/gtm_STDOUT_11843_5 /tmp/STDOUT_11843_6 > /dev/null 2>&1
Starting datanode master datanode1.
2022-04-26 00:51:16.296 CST [11400] LOG:  listening on IPv4 address "0.0.0.0", port 40001
2022-04-26 00:51:16.296 CST [11400] LOG:  listening on IPv6 address "::", port 40001
2022-04-26 00:51:16.329 CST [11400] LOG:  listening on Unix socket "/tmp/.s.PGSQL.40001"
2022-04-26 00:51:16.381 CST [11400] LOG:  redirecting log output to logging collector process
2022-04-26 00:51:16.381 CST [11400] HINT:  Future log output will appear in directory "pg_log".
Done.
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
/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
Actual Command: ssh postgres@datanode2 "( PGXC_CTL_SILENT=1 initdb -D /home/postgres/pgdat/nodes//datanode2   --nodename datanode2 ) > /tmp/gtm_STDOUT_11910_0 2>&1" < /dev/null > /dev/null 2>&1
The authenticity of host 'datanode2 (192.168.1.125)' can't be established.
ECDSA key fingerprint is SHA256:6iLZPCwlBeOi0lyomrluQ+16RTbebKDKBArueyEY/TU.
ECDSA key fingerprint is MD5:76:a6:10:e5:ce:32:c4:8f:b6:15:8f:12:9c:99:08:32.
Are you sure you want to continue connecting (yes/no)? yes
Bring remote stdout: scp postgres@datanode2:/tmp/gtm_STDOUT_11910_0 /tmp/STDOUT_11910_1 > /dev/null 2>&1
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.

creating directory /home/postgres/pgdat/nodes/datanode2 ... 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.
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
pg_dumpall: could not connect to database "template1": FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "template1"

Actual Command: ssh postgres@datanode2 "( pg_ctl start -w -Z restoremode -D /home/postgres/pgdat/nodes//datanode2 -o -i ) > /tmp/gtm_STDOUT_11910_3 2>&1" < /dev/null > /dev/null 2>&1
Bring remote stdout: scp postgres@datanode2:/tmp/gtm_STDOUT_11910_3 /tmp/STDOUT_11910_4 > /dev/null 2>&1
2022-04-26 00:51:25.202 CST [11831] LOG:  listening on IPv4 address "0.0.0.0", port 40002
2022-04-26 00:51:25.202 CST [11831] LOG:  listening on IPv6 address "::", port 40002
2022-04-26 00:51:25.235 CST [11831] LOG:  listening on Unix socket "/tmp/.s.PGSQL.40002"
2022-04-26 00:51:25.288 CST [11831] LOG:  redirecting log output to logging collector process
2022-04-26 00:51:25.288 CST [11831] HINT:  Future log output will appear in directory "pg_log".
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
Actual Command: ssh postgres@datanode2 "( pg_ctl stop -w -Z restoremode -D /home/postgres/pgdat/nodes//datanode2 ) > /tmp/gtm_STDOUT_11910_5 2>&1" < /dev/null > /dev/null 2>&1
Bring remote stdout: scp postgres@datanode2:/tmp/gtm_STDOUT_11910_5 /tmp/STDOUT_11910_6 > /dev/null 2>&1
Starting datanode master datanode2.
2022-04-26 00:51:28.893 CST [11921] LOG:  listening on IPv4 address "0.0.0.0", port 40002
2022-04-26 00:51:28.893 CST [11921] LOG:  listening on IPv6 address "::", port 40002
2022-04-26 00:51:28.927 CST [11921] LOG:  listening on Unix socket "/tmp/.s.PGSQL.40002"
2022-04-26 00:51:28.979 CST [11921] LOG:  redirecting log output to logging collector process
2022-04-26 00:51:28.979 CST [11921] HINT:  Future log output will appear in directory "pg_log".
Done.
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
psql: FATAL:  no pg_hba.conf entry for host "192.168.1.122", user "postgres", database "postgres"
/usr/bin/bash
pgxc_ctl: invalid option -- 'p'
Invalid optin value, received code 077
[postgres@xl122 pgxc_ctl]$

(7)查看集群状态

[postgres@xl122 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 monitor all
Running: gtm master
Running: coordinator master coord1
Running: datanode master datanode1
Running: datanode master datanode2
PGXC

2、后记

(1)关闭集群

PGXC stop all
Stopping all the coordinator masters.
Stopping coordinator master coord1.
Done.
Stopping all the datanode masters.
Stopping datanode master datanode1.
Stopping datanode master datanode2.
Done.
Stop GTM master
waiting for server to shut down.... done
server stopped
PGXC monitor all
Not running: gtm master
Not running: coordinator master coord1
Not running: datanode master datanode1
Not running: datanode master datanode2
PGXC

集群算是创建出来了

但是 init.sh 脚本后的测试库 test 没有创建成功

来源 https://zhuanlan.zhihu.com/p/505031415

分享好友

分享这个小栈给你的朋友们,一起进步吧。

Postgres-XL
创建时间:2022-02-18 17:49:48
Postgres-XL
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • itt0918
    专家
戳我,来吐槽~