PolarDB for PostgreSQL 三节点开源版 3主机集群部署实践

本文涉及的产品
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
简介: PolarDB for PostgreSQL 三节点开源版本在3台主机上的部署例子.

背景

PolarDB for PostgreSQL 三节点开源版本在3台主机上的部署例子.

视频回放

加入POLARDB社区

https://github.com/alibaba/PolarDB-for-PostgreSQL

环境

3台ecs

8c 64g 2T ssd  
内网ip:  
172.17.164.62  
172.17.164.63  
172.17.164.64

系统环境部署

请参考这篇文档:

《PolarDB 为什么要解决FPW的性能问题?》

部署好后继续.

环境依赖

1、操作系统

cat /etc/redhat-release   
CentOS Linux release 7.9.2009 (Core)

2、内核

uname -a  
Linux iZbp18r4s9zxcmpkulkmkyZ 3.10.0-1160.31.1.el7.x86_64 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

3、GCC版本

gcc -v  
Using built-in specs.  
COLLECT_GCC=gcc  
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper  
Target: x86_64-redhat-linux  
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux  
Thread model: posix  
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

部署步骤

1、安装依赖包

yum install -y bison flex libzstd-devel libzstd zstd cmake openssl-devel protobuf-devel readline-devel libxml2-devel libxslt-devel zlib-devel bzip2-devel lz4-devel snappy-devel python-devel unzip

2、添加OS用户, 用于部署PolarDB数据库集群

useradd digoal

3、设置用户密码

passwd digoal

4、下载PolarDB for PostgreSQL源码

su - digoal  
wget https://github.com/alibaba/PolarDB-for-PostgreSQL/archive/refs/heads/master.zip  
unzip master.zip

5、配置PolarDB OS用户主机之间的ssh互认, 配置ssh互认后, 方便集群管理, 这也是Greenplum使用的方法.

all node:

产生ssh key

su - digoal  
ssh-keygen  
chmod 700 ~/.ssh
chmod 400 ~/.ssh/id_rsa*

all node:

配置互相认证

su - digoal  
ssh-copy-id -f digoal@172.17.164.62  
ssh-copy-id -f digoal@172.17.164.63  
ssh-copy-id -f digoal@172.17.164.64  
输入目标主机digoal用户登陆密码, 完成互认证

all node:

验证是否不需要密码, 返回日期表示已经完成互认

su - digoal  
ssh 'digoal@172.17.164.62' date  
ssh 'digoal@172.17.164.63' date  
ssh 'digoal@172.17.164.64' date

6、配置环境变量

all node:

su - digoal  
vi ~/.bashrc  
export POLARDBHOME="$HOME/polardb"  
export PATH="$POLARDBHOME/bin:$PATH"  
export LD_LIBRARY_PATH="$POLARDBHOME/lib:$LD_LIBRARY_PATH"  
export PGUSER=digoal  
export PGDATABASE=postgres  
export PGHOST=/tmp  
export PGPORT=10001

应用环境变量生效

su - digoal  
. ~/.bashrc

7、编译安装PolarDB for PostgreSQL二进制软件.

all node:

su - digoal  
cd ~/PolarDB-for-PostgreSQL-master

设置安装目录

export PG_INSTALL=$HOME/polardb

其他部署详情, 可以看一下build.sh脚本的内容.

编译安装二进制软件:

sh build.sh debug   ## 开发环境 
sh build.sh deploy  ## 生产环境

8、配置PolarDB 3主机集群.

创建配置文件存放目录

all node:

su - digoal  
mkdir $POLARDBHOME/etc

创建存放PolarDB集群数据文件的目录

su - root  
mkdir -p /data01/polardb/data  
chown -R digoal:digoal /data01/polardb  
chmod 700 /data01/polardb

生成集群部署配置文件模板(这个只需要在master主机执行即可, 172.17.164.62)

master node:

su - digoal  
touch $POLARDBHOME/etc/polardb_paxos.conf  
pgxc_ctl -v -c $POLARDBHOME/etc/polardb_paxos.conf prepare standalone

修改配置文件内容, 匹配我们的三主机环境

vi $POLARDBHOME/etc/polardb_paxos.conf  
#!/usr/bin/env bash  
#  
# polardb Configuration file for pgxc_ctl utility.   
#  
# Configuration file can be specified as -c option from pgxc_ctl command.   Default is  
# $PGXC_CTL_HOME/pgxc_ctl.org.  
#  
# This is bash script so you can make any addition for your convenience to configure  
# your polardb.  
#  
#========================================================================================  
#  
#  
# pgxcInstallDir variable is needed if you invoke "deploy" command from pgxc_ctl utility.  
# If don't you don't need this variable.  
# 修改  
pgxcInstallDir=$HOME/polardb  
#---- OVERALL -----------------------------------------------------------------------------  
#  
# 建议db superuser和os user使用同名  
pgxcOwner=digoal      # 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=digoal           # 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.  
# 修改  
standAlone=n  
# 修改  
dataDirRoot=/data01/polardb/data  
#---- Datanodes -------------------------------------------------------------------------------------------------------  
#---- Shortcuts --------------  
datanodeMasterDir=$dataDirRoot/dn_master  
datanodeSlaveDir=$dataDirRoot/dn_slave  
datanodeLearnerDir=$dataDirRoot/dn_learner  
datanodeArchLogDir=$dataDirRoot/datanode_archlog  
#---- Overall ---------------  
primaryDatanode=datanode_1        # Primary Node.  
datanodeNames=(datanode_1)  
datanodePorts=(10001)         # Master and slave use the same port!  
#datanodePoolerPorts=(10011)        # Master and slave use the same port!  
#datanodePgHbaEntries=(::1/128)     # 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.  
datanodePgHbaEntries=(172.17.164.62/32 172.17.164.63/32 172.17.164.64/32)     # Same as above but for IPv4 connections  
#---- Master ----------------  
datanodeMasterServers=(172.17.164.62)         # 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)  
datanodeMaxWalSender=16               # 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)  
            # max_wal_senders configuration for each datanode  
#---- Slave -----------------  
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.  
datanodeSlaveServers=(172.17.164.63)  # value none means this slave is not available  
datanodeSlavePorts=(10001)      # Master and slave use the same port!  
#datanodeSlavePoolerPorts=(10011) # Master and slave use the same port!  
datanodeSlaveSync=y         # If datanode slave is connected in synchronized mode  
datanodeSlaveDirs=($datanodeSlaveDir)  
datanodeArchLogDirs=($datanodeArchLogDir)  
datanodeRepNum=2            #  no HA setting 0, streaming HA and active-active logcial replication setting 1 replication,  paxos HA setting 2 replication.    
datanodeSlaveType=(3)         # 1 is streaming HA, 2 is active-active logcial replication, 3 paxos HA.  
#---- Learner -----------------  
datanodeLearnerServers=(172.17.164.64)  # value none means this learner is not available  
datanodeLearnerPorts=(10001)    # learner port!  
#datanodeSlavePoolerPorts=(10011) # learner pooler port!  
datanodeLearnerSync=y       # If datanode learner is connected in synchronized mode  
datanodeLearnerDirs=($datanodeLearnerDir)  
# ---- Configuration files ---  
# You may supply your bash script to setup extra config lines and extra pg_hba.conf entries here.  
# These files will go to corresponding files for the master.  
# Or you may supply these files manually.  
datanodeExtraConfig=datanodeExtraConfig   
cat > $datanodeExtraConfig <<EOF
#================================================  
# Added to all the datanode postgresql.conf  
# Original: $datanodeExtraConfig  
log_destination = 'csvlog'  
unix_socket_directories = '., /tmp'  
logging_collector = on  
log_directory = 'log'  
listen_addresses = '0.0.0.0'  
max_connections = 1000  
hot_standby = on  
synchronous_commit = on  
max_worker_processes = 30  
cron.database_name = 'postgres'  
tcp_keepalives_idle = 30  
tcp_keepalives_interval = 10    
tcp_keepalives_count = 6                           
shared_buffers = 16GB  
maintenance_work_mem = 1GB  
bgwriter_delay = 10ms  
bgwriter_lru_maxpages = 1000  
bgwriter_lru_multiplier = 5.0  
effective_io_concurrency = 0  
parallel_leader_participation = off  
max_wal_size = 48GB  
min_wal_size = 8GB  
wal_keep_segments = 4096 
wal_sender_timeout = 5s  
random_page_cost = 1.1  
effective_cache_size = 32GB  
log_truncate_on_rotation = on  
log_min_duration_statement = 3s  
log_checkpoints = on  
log_lock_waits = on  
log_statement = 'ddl'  
log_autovacuum_min_duration = 0  
autovacuum_freeze_max_age = 800000000  
autovacuum_multixact_freeze_max_age = 900000000  
autovacuum_vacuum_cost_delay = 0ms  
vacuum_freeze_min_age = 700000000  
vacuum_freeze_table_age = 850000000  
vacuum_multixact_freeze_min_age = 700000000  
vacuum_multixact_freeze_table_age = 850000000  
statement_timeout = 0                    # in milliseconds, 0 is disabled  
lock_timeout = 0                         # in milliseconds, 0 is disabled  
idle_in_transaction_session_timeout = 0  # in milliseconds, 0 is disabled  
shared_preload_libraries = 'pg_cron'  
max_parallel_replay_workers = 0        
EOF
# Additional Configuration file for specific datanode master.  
# You can define each setting by similar means as above.  
datanodeSpecificExtraConfig=(none)  
datanodeSpecificExtraPgHba=(none)

9、初始化三节点集群

master node:

pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf clean all  
pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf init all
psql
postgres=# select * from pg_stat_replication ;
-[ RECORD 1 ]----+------------------------------
pid              | 18745
usesysid         | 10
usename          | digoal
application_name | walreceiver
client_addr      | 172.17.164.63
client_hostname  | 
client_port      | 53338
backend_start    | 2021-08-16 16:10:59.414899+08
backend_xmin     | 
state            | streaming
sent_lsn         | 0/4000120
write_lsn        | 0/4000120
flush_lsn        | 0/4000120
replay_lsn       | 0/4000120
write_lag        | 
flush_lag        | 
replay_lag       | 
sync_priority    | 0
sync_state       | async
-[ RECORD 2 ]----+------------------------------
pid              | 19166
usesysid         | 10
usename          | digoal
application_name | walreceiver
client_addr      | 172.17.164.64
client_hostname  | 
client_port      | 50968
backend_start    | 2021-08-16 16:11:09.975107+08
backend_xmin     | 
state            | streaming
sent_lsn         | 0/4000120
write_lsn        | 0/4000120
flush_lsn        | 0/4000120
replay_lsn       | 0/4000120
write_lag        | 
flush_lag        | 
replay_lag       | 
sync_priority    | 0
sync_state       | async

10、常用管理命令

检查三节点状态

pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf monitor all  
/bin/bash  
Installing pgxc_ctl_bash script as /home/digoal/pgxc_ctl/pgxc_ctl_bash.  
Installing pgxc_ctl_bash script as /home/digoal/pgxc_ctl/pgxc_ctl_bash.  
Reading configuration using /home/digoal/pgxc_ctl/pgxc_ctl_bash --home /home/digoal/pgxc_ctl --configuration /home/digoal/polardb/etc/polardb_paxos.conf  
Finished reading configuration.  
   ******** PGXC_CTL START ***************  
Current directory: /home/digoal/pgxc_ctl  
Running: datanode master datanode_1  
Running: datanode slave datanode_1  
Running: datanode learner datanode_1

查看三节点配置

pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf show configuration all

start cluster or node

pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf start all

stop cluster or node

pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf stop all

failover datanode (datanode_1 is node name configured in polardb_paxos.conf).

pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf failover datanode datanode_1

cluster health check (check cluster status and start failed node).

pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf healthcheck all

examples of other commands

pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf kill all  
pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf log var datanodeNames  
pgxc_ctl -c $POLARDBHOME/etc/polardb_paxos.conf show configuration all
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
1月前
|
SQL 关系型数据库 MySQL
开源新发布|PolarDB-X v2.4.2开源生态适配升级
PolarDB-X v2.4.2开源发布,重点完善生态能力:新增客户端驱动、开源polardbx-proxy组件,支持读写分离与高可用;强化DDL变更、扩缩容等运维能力,并兼容MySQL主备复制及MCP AI生态。
开源新发布|PolarDB-X v2.4.2开源生态适配升级
|
29天前
|
SQL 关系型数据库 MySQL
开源新发布|PolarDB-X v2.4.2开源生态适配升级
PolarDB-X v2.4.2发布,新增开源Proxy组件与客户端驱动,支持读写分离、无感高可用切换及DDL在线变更,兼容MySQL生态,提升千亿级大表运维稳定性。
479 24
开源新发布|PolarDB-X v2.4.2开源生态适配升级
|
2月前
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
3月前
|
人工智能 关系型数据库 MySQL
开源PolarDB-X:单节点误删除binlog恢复
本文由邵亚鹏撰写,分享了在使用开源PolarDB-X过程中,因误删binlog导致数据库服务无法启动的问题及恢复过程。作者结合实践经验,详细介绍了在无备份情况下如何通过单节点恢复机制重启数据库,并提出了避免类似问题的几点建议,包括采用高可用部署、定期备份及升级至最新版本等。
|
存储 关系型数据库 MySQL
开源PolarDB- X|替换Opengemini时序数据场景下产品力校验
本文作者:黄周霖,数据库技术专家,就职于南京北路智控股份有限公司,负责数据库运维及大数据开发。
|
6月前
|
存储 Cloud Native 关系型数据库
PolarDB开源:云原生数据库的架构革命
本文围绕开源核心价值、社区运营实践和技术演进路线展开。首先解读存算分离架构的三大突破,包括基于RDMA的分布式存储、计算节点扩展及存储池扩容机制,并强调与MySQL的高兼容性。其次分享阿里巴巴开源治理模式,涵盖技术决策、版本发布和贡献者成长体系,同时展示企业应用案例。最后展望技术路线图,如3.0版本的多写多读架构、智能调优引擎等特性,以及开发者生态建设举措,推荐使用PolarDB-Operator实现高效部署。
362 3
|
5月前
|
存储 关系型数据库 测试技术
拯救海量数据:PostgreSQL分区表性能优化实战手册(附压测对比)
本文深入解析PostgreSQL分区表的核心原理与优化策略,涵盖性能痛点、实战案例及压测对比。首先阐述分区表作为继承表+路由规则的逻辑封装,分析分区裁剪失效、全局索引膨胀和VACUUM堆积三大性能杀手,并通过电商订单表崩溃事件说明旧分区维护的重要性。接着提出四维设计法优化分区策略,包括时间范围分区黄金法则与自动化维护体系。同时对比局部索引与全局索引性能,展示后者在特定场景下的优势。进一步探讨并行查询优化、冷热数据分层存储及故障复盘,解决分区锁竞争问题。
677 2
|
关系型数据库 分布式数据库 PolarDB
《阿里云产品手册2022-2023 版》——PolarDB for PostgreSQL
《阿里云产品手册2022-2023 版》——PolarDB for PostgreSQL
554 0
|
存储 缓存 关系型数据库

相关产品

  • 云原生数据库 PolarDB