当前位置:首页>编程>Mysql>postgresql数据库安装部署搭建主从节点的详细过程(业务库)

postgresql数据库安装部署搭建主从节点的详细过程(业务库)

PostgreSQL是一种功能强大的开源对象关系数据库系统,它使用和扩展了SQL语言结合了许多特性,能安全地存储和处理在网络中的大量数据工作负载,本文将详细介绍如何在Linux环境下安装部署搭建PostgreSQL主从节点的过程。

环境准备

1、操作系统:CentOS 7.x

postgresql数据库安装部署搭建主从节点的详细过程(业务库)

2、PostgreSQL版本:10.x

3、PostgreSQL客户端:psql (pgAdmin)

4、服务器硬件配置:至少2GB内存

安装PostgreSQL

1、更新系统软件包

sudo yum update -y

2、安装PostgreSQL所需的依赖库

sudo yum install -y readline-devel zlib-devel bison-devel flex libxml2-devel libxslt-devel openssl-devel gcc perl-ExtUtils-MakeMaker

3、下载PostgreSQL源码包

postgresql数据库安装部署搭建主从节点的详细过程(业务库)

wget https://ftp.postgresql.org/pub/source/v10.x/postgresql-10.x.tar.gz

4、解压源码包并进入目录

tar -zxvf postgresql-10.x.tar.gz
cd postgresql-10.x

5、配置编译选项并编译安装

./configure --prefix=/usr/local/pgsql --with-perl --with-python --enable-thread-safety --with-openssl --with-libxml --with-libxslt --with-gssapi --with-ldap --with-pam --with-systemdunitdir=no --with-uuid=ossp --with-icu --with-zlib --with-llvm=/usr/bin/llvm-config --enable-debug --enable-tap-tests --enable-nls --with-bonjour --with-librsvg --with-libxmlsec --with-libevent=/usr/local/opt/libevent --with-event_core_dir=/usr/local/Cellar/libevent/2.1.12/include/event2 --with-event_extra_libs=-lssl -lcrypto --with-event_openssl_dir=/usr/local/opt/openssl@1.1 --with-event_pthreads_dir=/usr/local/opt/libevent/2.1.12/deps --with-json=yes --with-isc_srp=no --with-isc_hba=no --with-isc_db=no --with-isc_trgm=no --with-isc_fb=no --with-isc_inet6=no --with-isc_mutex_initval=0 --with-isc_rng=no --with-isc_tracing=no --with-isc_stats=no --with-isc_stack=no --with-mb=yes --with-archive_mode=off --with-wal_level=replicate --enable-dtrace --enable-debug --enable-tap --enable-fpm --enable-ipv6 --enable-largefile --without-pcre --without-readline --without-zlib --without-gssapi --without-ldap --without-pam --without-systemdunitdir --without-uuid --without-icu --without-xmlsec --without-libxmlsec --without-librsvg --without-event --without-json --without-openssl --without-pq --without-ecpg --without-netbsdsockets --without-plugins --without-tcltk --without-docbook_xsl --without-docbook_ns --without-docbook_mathml --without-docbook_fodt --without-docbook_dtdvalid --without-docbook_html --without-docbook_manpages --without-docbook_xindy --without-docbook_nwalsh --without-docbook_hyphenation --without-docbook_stylebooks --without-docbook_publishers --without-docbook_utils --without-docbook_xsltcpdffilters --without-docbook_xsltcrunsfilters --without-docbook_xsltdctohtmlfilters --without–docbook–xsltcsaxonfilters  
make && make install

6、创建用户和组

groupadd postgres
useradd -g postgres postgres -M -N -r

7、更改文件权限

chown -R postgres:postgres /usr/local/pgsql
chmod -R 700 /usr/local/pgsql
chmod -R 755 /usr/local/pgsql/*bin* /usr/local/pgsql/*share* /usr/local/pgsql/*man* /usr/local/pgsql/*script* /usr/local/pgsql/*conf* /usr/local/pgsql/*sample* /usr/local/pgsql/*deps* /usr/local/pgsql/*include* /usr/local/pgsql/*pkgconfig* /usr/local/pgsql/*py* /usr/local/pgsql/*src* /usr/local/pgsql/*doc* /usr/local/pgsql/*dict* /usr//ocal//pgsql/*template* /usr//ocal//pgsql/*misc* /usr//ocal//pgsql/*backup* /usr//ocal//pgsql/*debian* /usr//ocal//pgsql/*contrib* /usr//ocal//pgsql/*RELEASE* /usr//ocal//pgsql/*bki* /usr//ocal//pgsql/*locale* /usr//ocal//pgsql/*opcodes* /usr//ocal//pgsql/*pl* /usr//ocal//pgsql/*tcltk* /usr//ocal//pgsql/*test* /usr//ocal//pgsql/*benchmarks* /usr//ocal//pgsql/*contrib*/examples/* /usr//ocal//pgsql/*contrib*/tools/* /usr//ocal//pgsql/*contrib*/extras/* /usr//ocal//pgsql/*contrib*/regression/* /usr//ocal//pgsql/*contrib*/bki/* /usr//ocal//pgsql/*contrib*/deps/* /usr//ocal//pgsql/*contrib*/include/* /usr//ocal//pgsql/*contrib*/pkgconfig/* /usr//ocal//pgsql/*contrib*/python*/sitepackages/* /usr//ocal//pgsql/*contrib*/python*/demo*/buildout.cfg  

8、初始化数据库集群

su postgres -c "/usr/local/pgsql/bin/initdb -D /data"

9、启动PostgreSQL服务并设置开机自启动

postgresql数据库安装部署搭建主从节点的详细过程(业务库)

su postgres -c "/usr/local/pgsql/bin/postgres -D /data &"  
echo "/usr/local/pgsql/bin/postgres -D /data &" >> /etc/rc.d/rc.local  
chmod +x /etc/rc.d/rc.local  
service postgresql start  
chkconfig postgresql on  

主从节点配置与搭建

1、修改主节点配置文件postgresql.conf,设置以下参数

listen_addresses = '*'                监听所有IP地址,方便其他机器访问主节点数据库服务。  
wal_level = replica                    设置WAL级别为复制模式,用于支持主从同步。  
max_wal_senders = 3                  设置最大WAL发送进程数,用于支持并发复制。  
wal_keep_segments = 8                设置保留的最大WAL文件个数,用于防止WAL文件过多导致空间不足。  
hot_standby = on                      开启热备功能,允许从节点读取主节点上的WAL日志进行实时备份。  

2、修改主节点配置文件pg_hba.conf,添加以下内容

host    replication     all             0.0.0.0/0               md5                允许所有IP地址通过md5加密方式连接到主节点数据库。  
host    all             all             0.0.0.0/0               trust              允许所有IP地址通过信任方式连接到主节点数据库。  

3、修改从节点配置文件postgresql.conf,设置以下参数

listen_addresses = '*'                监听所有IP地址,方便其他机器访问从节点数据库服务。  
wal_level

    给TA打赏
    共{{data.count}}人
    人已打赏

    相关文章

    Mysql

    Postgresql自定义函数详解

    2024-3-17 18:37:22

    Mysql

    数据库表的创建、管理和数据操作(实验一)

    2024-3-17 18:44:02

    {{yiyan[0].hitokoto}}
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    有新私信 私信列表
    搜索