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

本文涉及的产品
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 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数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
27天前
|
数据库
|
1月前
|
存储 关系型数据库 MySQL
MySQL vs. PostgreSQL:选择适合你的开源数据库
在众多开源数据库中,MySQL和PostgreSQL无疑是最受欢迎的两个。它们都有着强大的功能、广泛的社区支持和丰富的生态系统。然而,它们在设计理念、性能特点、功能特性等方面存在着显著的差异。本文将从这三个方面对MySQL和PostgreSQL进行比较,以帮助您选择更适合您需求的开源数据库。
117 4
|
2月前
|
存储 关系型数据库 分布式数据库
使用开源PolarDB和imgsmlr进行高效的图片存储和相似度搜索
使用开源PolarDB和imgsmlr进行高效的图片存储和相似度搜索
|
2月前
|
SQL JSON 关系型数据库
MySQL是一个广泛使用的开源关系型数据库管理系统,它有许多不同的版本
【10月更文挑战第3天】MySQL是一个广泛使用的开源关系型数据库管理系统,它有许多不同的版本
154 5
|
2月前
|
人工智能 自然语言处理 关系型数据库
阿里云云原生数据仓库 AnalyticDB PostgreSQL 版已完成和开源LLMOps平台Dify官方集成
近日,阿里云云原生数据仓库 AnalyticDB PostgreSQL 版已完成和开源LLMOps平台Dify官方集成。
|
2月前
|
关系型数据库 分布式数据库 数据库
PolarDB 开源:推动数据库技术新变革
在数字化时代,数据成为核心资产,数据库的性能和可靠性至关重要。阿里云的PolarDB作为新一代云原生数据库,凭借卓越性能和创新技术脱颖而出。其开源不仅让开发者深入了解内部架构,还促进了数据库生态共建,提升了稳定性与可靠性。PolarDB采用云原生架构,支持快速弹性扩展和高并发访问,具备强大的事务处理能力及数据一致性保证,并且与多种应用无缝兼容。开源PolarDB为国内数据库产业注入新活力,打破国外垄断,推动国产数据库崛起,降低企业成本与风险。未来,PolarDB将在生态建设中持续壮大,助力企业数字化转型。
96 2
|
3月前
|
关系型数据库 分布式数据库 数据库
开源云原生数据库PolarDB PostgreSQL 15兼容版本正式发布
PolarDB进行了深度的内核优化,从而实现以更低的成本提供商业数据库的性能。
|
3月前
惊世骇俗!开源 PolarDB-X 部署安装大冒险,全程心跳与惊喜不断!
【9月更文挑战第8天】作为技术爱好者的我,近期成功完成了开源 PolarDB-X 的部署安装。尽管过程中遇到不少挑战,但通过精心准备环境、下载安装包、配置参数及启动服务等步骤,最终顺利实现部署。本文将详细介绍部署全过程及可能遇到的问题,为您的 PolarDB-X 探索之旅提供参考与启发,希望能让大家在技术海洋里畅游得更加顺利!
159 2
|
3月前
|
Cloud Native 关系型数据库 分布式数据库
PolarDB开源项目未来展望:技术趋势与社区发展方向
【9月更文挑战第5天】随着云计算技术的发展,阿里云推出的云原生分布式数据库PolarDB受到广泛关注。本文探讨PolarDB的未来展望,包括云原生与容器化集成、HTAP及实时分析能力提升、智能化运维与自动化管理等技术趋势;并通过加强全球开源社区合作、拓展行业解决方案及完善开发者生态等措施推动社区发展,目标成为全球领先的云原生数据库之一,为企业提供高效、可靠的服务。
105 5
|
3月前
|
关系型数据库 MySQL 分布式数据库
PolarDB开源社区动态:最新版本功能亮点与更新解读
【9月更文挑战第6天】随着云计算技术的发展,分布式数据库系统成为企业数据处理的核心。阿里云的云原生数据库PolarDB自开源以来备受关注,近日发布的最新版本在内核稳定性、性能、分布式CDC架构及基于时间点的恢复等方面均有显著提升,并新增了MySQL一键导入功能。本文将解读这些新特性并提供示例代码,帮助企业更好地利用PolarDB处理实时数据同步和离线分析任务,提升数据安全性。未来,PolarDB将继续创新,为企业提供更高效的数据处理服务。
192 3

热门文章

最新文章

相关产品

  • 云原生数据库 PolarDB