zoukankan      html  css  js  c++  java
  • PostgreSQL 10.7 linux 主从配置

    PostgreSQL 10.7 主从安装

    硬件环境

    云服务商:华为云

    Linux: CentOS7.1

    工具:Xshell Xftp

    IP:114.115.251.168

    Port: 5432 5433

    postgresql二进制安装包从https://www.enterprisedb.com/download-postgresql-binaries

     

    一.Master数据库安装配置

    1创建PG数据库的用户postgres

     

    2使用root用户给postgres用户相关文件夹赋权并切换至postgres用户

    chown -R postgres:postgres /home

     

    3解压PostgreSQL

     

     4创建PGM应用目录,data为数据,log为日志目录,文件夹赋权777

     

     5初始化数据库

    ./initdb -E utf8 -D /home/postgresql_master/PGM/data

     

    6Master数据库库参数配置

     

    首先修改pg_hba.conf

    在最下边添加两行代码,意为允许远程连接

    host    replication      all      0.0.0.0/0    trust

    host    all                   all     0.0.0.0/0     trust

    接下来修改postgresql.conf

    listen_addresses = ‘*’   #监听所有ip

    port = 5432    #设置IP端口

    archive_mode = on   #开启归档模式

    archive_command = ‘cp %p /var/lib/postgresql/10/main/%f’   #归档命令

    wal_level = hot_standby    #热备模式

    max_wal_senders = 2   #最多有2个流复制连接

    wal_sender_timeout = 60s    #流复制超时时间

    max_connections = 100   #最大连接时间,必须要小于从库的配置

    7启动Master数据库

    ./pg_ctl –D /home/postgresql_master/PGM/data -l /home/postgresql_master/PGM/log/logfile start

     

     8创建热备用户并赋权

    create role repl login replication encrypted password 'repl';

    grant all privileges on database postgres to repl;

     

    二.StandBy数据库安装配置(先重复Master数据库前5个步骤,注意data文件夹权限必须为700) 

    1生成基础备份

    ./pg_basebackup -h 114.115.251.168 -p 5432 -U repl -F p -P -R -D /home/postgresql_standby/PGS/data -l postgresbackup20190402

     

    pg_basebackup支持两种全量备份的方式,

    1.以fetch的方式,先备份数据在备份日志

    2.以stream的方式,并行的备份数据和日志

    pg_basebackup对于全量备份的数据和日志,提供了串行备份和并行备份的方式。fetch模式也就是串行备份需要保证在备份数据的过程中,备份开始时刻的日志需要一直保存下来, 也就说pg的wal_keep_segments需要足够大去保存日志文件,如果备份数据期间,日志开始时刻的日志已经被移除,那么备份就会失败。而stream模式,也就是并行备份过程中wal_max_sender必须保证不小于2。 而stream模式不支持,将数据和日志以流的方式输出到标准输出。

    2配置参数

      

    配置recovery.conf

    standby_mode = on    # 说明该节点是从服务器

    primary_conninfo = 'host=114.115.251.168 port=5432 user=repl password=repl'  # 主服务器的信息以及连接的用户

    recovery_target_timeline = 'latest' 

    配置postgresql.conf

    Port = 5433

    wal_level = hot_standby    #热备模式

    max_connections = 300   #最大连接时间

    hot_standby = on  #说明这台机器不仅用于数据归档,还可以用于数据查询

    max_standby_streaming_delay = 30s #流备份的最大延迟时间

    wal_receiver_status_interval = 10s  #向主机汇报本机状态的间隔时间

    hot_standby_feedback = on #r出现错误复制,向主机反馈

    3启动从库

     

    4创建从库用户

     

      

    三.主从验证

    主库查询系统信息正常,接下来测试下数据即可

     

  • 相关阅读:
    个人兴趣与公司业务的关系
    分析能力的8个等级(转)
    DSL应用的优点
    架构师应具备的概要技能
    Cheetah
    不能运行VS2005的DSL Tool例子
    推荐:原型工具GUI Design Studio
    Viewpoints 1.0 for Visual Studio .NET 2008
    原创故事 - 不死鸡和不死牛的故事
    Antlr构建表达式引擎
  • 原文地址:https://www.cnblogs.com/tplife2019/p/10402472.html
Copyright © 2011-2022 走看看