• postgres 流复制集群配置(一)


    一,环境准备

      主机名 ip
    master kafka01 192.168.0.188
    slave pg_standby 192.168.0.187

        以及两主机里面安装好postgres软件

    二,环境操作

      01,hosts文件添加解析(主备)

       02,创建集群使用的环境用户(主)

    [postgres@kafka01 ~]$ psql
    psql (10.12)
    Type "help" for help.
    
    postgres=# CREATE USER replica replication LOGIN CONNECTION LIMIT 3 ENCRYPTED PASSWORD '123456';
    CREATE ROLE

      03,配置pg_hba.conf(主)

     

       04,配置postgressql.conf(主)

    listen_addresses = '*' 
    port = 5432 
    max_wal_senders = 1 
    wal_level = replica
    archive_mode = on 
    archive_command = 'cd ./'
    hot_standby = on
    wal_keep_segments = 64
    full_page_writes = on
    wal_log_hints = on

      05,启动主库,备库拉取数据(主备)

    --启动主库
    [postgres@kafka01 psql]$ cat stop.sh
    PGPORT=5432
    PGDATA=/data/pgdata
    /data/postgres/bin/pg_ctl stop -D ${PGDATA} -s -m fast
    
    [postgres@kafka01 psql]$ ./stop.sh
    
    [postgres@kafka01 psql]$ cat start.sh
    PGPORT=5432
    PGDATA=/data/pgdata
    /data/postgres/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 -l /tmp/logfile
    
    [postgres@kafka01 psql]$ ./start.sh
    --备库拉取数据
    [postgres@pg_standby data]$ pg_basebackup -h 192.168.0.188 -U replica -F p -X stream -P -R -D /data/pgdata/ -l back20200609 -w
    4565171/4565171 kB (100%), 2/2 tablespaces
    
    
    --注意拉取的时候注意假如存在目录有数据的话会报错,清理即可

      查看slave节点的pg_hba.conf 看是否正确

      06,配置recovery.conf (主备)

      这个文件在安装目录下面的share,

    ---主库配置
    [
    postgres@kafka01 pgdata]$ cp ../postgres/share/recovery.conf.sample recovery.done [postgres@kafka01 pgdata]$ vim recovery.done recovery_target_timeline = 'latest' standby_mode = on primary_conninfo = 'host=pg_standby port=5432 user=replica password=123456' trigger_file = '/data/trigger_file'

    ---备库配置
    [postgres@pg_standby pgdata]$ cp ../postgres/share/recovery.conf.sample recovery.done
    [postgres@pg_standby pgdata]$ vim recovery.done

    recovery_target_timeline = 'latest' standby_mode = on primary_conninfo = 'host=master port=5432 user=repuser password=repuser' trigger_file = '/home/postgres/data/trigger_file'

        07,密码文件配置(主备)

    --
    [postgres@kafka01 data]$ cat ~/.pgpass
    pg_standby:5432:postgres:replica:12345
    [postgres@pg_standby pgdata]$ chmod 0600 ~/.pgpass
    --
    
    [postgres@pg_standby pgdata]$ cat ~/.pgpass
    kafka01:5432:postgres:replica:123456
    
    [postgres@pg_standby pgdata]$ chmod 0600 ~/.pgpass

      08,启动,同步测试

    ---分别启动主库,然后启动备库
    --主库测试
    
    [postgres@kafka01 pgdata]$ psql -d kingledb -U kingle
    psql (10.12)
    Type "help" for help.
    
    kingledb=> create table tmp01 (id int);
    CREATE TABLE
    kingledb=> insert into tmp01 values(1);
    INSERT 0 1
    kingledb=> select * from tmp01
    kingledb-> ;
     id
    ----
      1
    (1 row)
    
    kingledb=>
    
    
    --备库查询
    
    
    
    [postgres@pg_standby psql]$ psql -d kingledb -U kingle
    psql (10.12)
    Type "help" for help.
    
    kingledb=>  select * from tmp01;
     id
    ----
      1
    (1 row)
    
    kingledb=>
    
    
    
    --完美-

      

  • 相关阅读:
    Linux source命令
    pythoy 基础一: python的特点 if 语句 whlie语句
    linux 基础
    python的游戏之旅( 数字 字符串 列表 元组 字典 即为游戏职业)
    html 基础
    《SQL Server 2008 从入门到精通》 学习笔记 第五天
    [转载] Visual Studio 2010 MSDN Help Library文档位置、错误、重新安装及安装注意事项
    ASP.NET后台通过输出JavaScript弹出窗口小结
    网上搜集的webbrower的资料,很有借鉴价值
    解决MSSQL 2008不能用IP登录的问题 和 打开可以用SA登录SQL2008的方法
  • 原文地址:https://www.cnblogs.com/kingle-study/p/13071039.html
Copyright © 2020-2023  润新知