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

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: 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数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
23天前
|
关系型数据库 Serverless 分布式数据库
【公测】PolarDB PostgreSQL版Serverless功能免费使用​!
【公测】PolarDB PostgreSQL版Serverless功能免费使用​,公测于2024年3月28日开始,持续三个月,公测期间可以免费使用!
|
1月前
|
关系型数据库 分布式数据库 数据库
PolarDB常见问题之数据库不能自己减少节点如何解决
PolarDB是阿里云推出的下一代关系型数据库,具有高性能、高可用性和弹性伸缩能力,适用于大规模数据处理场景。本汇总囊括了PolarDB使用中用户可能遭遇的一系列常见问题及解答,旨在为数据库管理员和开发者提供全面的问题指导,确保数据库平稳运行和优化使用体验。
|
1月前
|
关系型数据库 分布式数据库 数据库
PolarDB PostgreSQL版:Oracle兼容的高性能数据库
PolarDB PostgreSQL版是一款高性能的数据库,具有与Oracle兼容的特性。它采用了分布式架构,可以轻松处理大量的数据,同时还支持多种数据类型和函数,具有高可用性和可扩展性。它还提供了丰富的管理工具和性能优化功能,为企业提供了可靠的数据存储和处理解决方案。PolarDB PostgreSQL版在数据库领域具有很高的竞争力,可以满足各种企业的需求。
|
1月前
|
关系型数据库 Serverless 分布式数据库
PolarDB PostgreSQL版Serverless功能上线公测啦,公测期间免费使用!
Serverless数据库能够使得数据库集群资源随客户业务负载动态弹性扩缩,将客户从复杂的业务资源评估和运维工作中解放出来。PolarDB PostgreSQL版 Serverless提供了CPU、内存、存储、网络资源的实时弹性能力,构建计算与存储分离架构下的 PolarDB PostgreSQL版产品新形态。
|
3天前
|
关系型数据库 OLAP 分布式数据库
「杭州*康恩贝」4月26日PolarDB开源数据库沙龙,开启报名!
4月26日周五,PolarDB开源社区联合康恩贝将共同举办开源数据库技术沙龙,本次沙龙我们邀请了众多数据库领域的专家,期待大家的参与!
「杭州*康恩贝」4月26日PolarDB开源数据库沙龙,开启报名!
|
13天前
|
运维 关系型数据库 分布式数据库
「合肥 * 讯飞」4 月 19 日 PolarDB 开源数据库沙龙,报名中!
4月19日周五,PolarDB开源社区联合科大讯飞共同举办开源数据库技术沙龙,本次沙龙我们邀请了众多数据库领域的专家,期待大家的参与!
「合肥 * 讯飞」4 月 19 日 PolarDB 开源数据库沙龙,报名中!
|
1月前
|
关系型数据库 分布式数据库 PolarDB
稳健前行:PolarDB开源社区调研开始啦!
PolarDB开源社区调研持续进行中!我们会重视每一位开发者的反馈,对提供建设性建议的开发者将会提供精美周边礼品!欢迎大家参与!
|
2月前
|
SQL 关系型数据库 分布式数据库
在PolarDB for PostgreSQL中,你可以使用LIKE运算符来实现类似的查询功能,而不是使用IF函数
在PolarDB for PostgreSQL中,你可以使用LIKE运算符来实现类似的查询功能,而不是使用IF函数
43 7
|
2月前
|
关系型数据库 分布式数据库 数据库
云原生数据库PolarDB快速入门实验
【2月更文挑战第2天】很基础的PolarDB入门操作实验考试,假期闲着无聊考着玩玩。云原生数据库 PolarDB MySQL 版是阿里云自研产品,100%兼容 MySQL。PolarDB产品具有多主多写、多活容灾、HTAP 等特性,交易性能最高可达开源数据库的6倍,分析性能最高可达开源数据库的400倍,TCO 低于自建数据库50%。
|
27天前
|
关系型数据库 分布式数据库 数据库
成都晨云信息技术完成阿里云PolarDB数据库产品生态集成认证
近日,成都晨云信息技术有限责任公司(以下简称晨云信息)与阿里云PolarDB PostgreSQL版数据库产品展开产品集成认证。测试结果表明,晨云信息旗下晨云-站群管理系统(V1.0)与阿里云以下产品:开源云原生数据库PolarDB PostgreSQL版(V11),完全满足产品兼容认证要求,兼容性良好,系统运行稳定。

热门文章

最新文章

相关产品

  • 云原生数据库 PolarDB