运行环境:

Primary: 192.168.0.11

Standby: 192.168.0.21, 192.168.0.22

OS: CentOS 6.2

PostgreSQL: 9.1.2 版本以上才支持Streaming Replication。

1. 环境规划

   Primary和Standby节点最好有相同的环境。

2. 安装PostgreSQL

1)在Primary和Standy节点上安装PostgreSQL软件,安装路径为/opt/pgsql

2)设置postgres用户的环境变量

     PGHOME=/opt/pgsql

     PGDATA=/home/postgres/main

     PATH=$PG_HOME/bin:$PATH:$HOME/bin

3. Primary节点

1)切换到postgres用户

    $su - postgres

2)初始化数据库

    $initdb

3)配置pg_hba.conf

     在# IPv4 local connections下面添加一行,设置PostgreSQL的访问及其权限

     host    all             all             192.168.0.1/24        trust

     在# replication privilege.下面添加一行,设置replication用户及权限

     host     replication     postgres        192.168.0.1/24       trust

4)配置postgresql.conf

     配置监听,修改listen_addresses = 'localhost'

     listen_addresses = '*'     # what IP address(es) to listen on;

     配置Primary Replication参数

     wal_level = hot_standby

     max_wal_senders = 8

     wal_keep_segments = 32

     archive_mode = on

     archive_command = 'cp %p /home/postgres/archive/%f < /dev/null'

     "/home/postgres/archive"是Replication的archive的存储路径。PostgreSQL会将Replication的WAL保存在 "/home/postgres/archive"路径下。

5) 启动Primary上的PostgreSQL数据库

    $pg_ctl start

6) 在primary上执行以下命令

    $psql -c "SELECT pg_start_backup('label', true);"

    将Primary的PGDATA目录下的文件,除了postmaster.pid复制到Standby节点的“/home/postgres/main”目录下,该目录是 Standby节点上的PostgreSQL数据库的PGDATA目录。

    $rsync -a ${PGDATA}/ postgres@192.168.0.21:/home/postgres/main --exclude postmaster.pid

    $psql -c "SELECT pg_stop_backup();"

    192.168.0.21的/home/postgres/main目录下的内容为

4. Standby节点

    PGDATA=/home/postgres/main

    Standby节点的PGDATA路径就是Primary节点的PGDATA的副本

1)配置postgresql.conf

     设置hot_standby为

     hot_standby= on

2)编辑recovery.conf,文件路径为$(PGDATA)/recovery.conf,内容为

---------------------------------------------------------------------------------------------------------------------------

# Specifies whether to start the server as a standby. In streaming replication,

# this parameter must to be set to on.
standby_mode  = 'on'

# Specifies a connection string which is used for the standby server to connect
# with the primary.
primary_conninfo = 'host=192.168.0.11 port=5432 user=postgres'
# Specifies a trigger file whose presence should cause streaming replication to
# end (i.e., failover).
trigger_file = '/home/postgres/trigger'

# Specifies a command to load archive segments from the WAL archive. If
# wal_keep_segments is a high enough number to retain the WAL segments
# required for the standby server, this may not be necessary. But
# a large workload can cause segments to be recycled before the standby
# is fully synchronized, requiring you to start again from a new base backup.
restore_command = 'cp /home/postgres/archive/%f %p'

--------------------------------------------------------------------------------



3)复制pg_xlog下的所有文件到/home/postgres/archive目录下
4)启动Standby节点,完成Replication。
完成Streaming Replication配置。

5. 验证

使用psql连接primary,创建test数据库。刷新从节点,可以看到在其上也生成了test数据库。

6. 问题

1)Standby的data目录是空的,其所有配置均是在rsync之后;

2)recovery.conf文件其实只需要修改standby_mode 和 primary_info,其余并不是必须的;

3)注意Primary的防火墙,必要时关闭,免得干扰集群配置;

4)如果从节点PostgreSQL已有数据,需要全部删除。

参考:

PostgreSQL配置Streaming Replication集群(http://www.cnblogs.com/marsprj/archive/2013/03/04/2943373.html)

http://opensourcedbms.com/dbms/setup-replication-with-postgres-9-2-on-centos-6redhat-el6fedora/

配置PostgreSQL Streaming Replication集群的更多相关文章

  1. postgresql Streaming Replication监控与注意事项

    一监控Streaming Replication集群 1 pg_stat_replication视图(主库端执行) pid Wal sender process的进程ID usesysid 执行流复制 ...

  2. 【Quartz】配置最简单的集群

    在许多情况,我们希望我们的定时任务是可靠的,不会因系统故障.机器宕机而导致某一笔定时任务不能按时运行.这种情况下,我们就需要为Quartz做个集群. 最简单的情况,有两台机器或两个应用,同时维护一批定 ...

  3. 配置drbd高可用集群

    前期准备: 同步时间 (两个节点) 节点一(172.16.21.6) [root@stu21 heartbeat2]# ntpdate 172.16.0.1 31 Dec 20:59:25 ntpda ...

  4. Tomcat集群,Nginx集群,Tomcat+Nginx 负载均衡配置,Tomcat+Nginx集群

    Tomcat集群,Nginx集群,Tomcat+Nginx 负载均衡配置,Tomcat+Nginx集群 >>>>>>>>>>>> ...

  5. 大数据项目之_15_帮助文档_NTP 配置时间服务器+Linux 集群服务群起脚本+CentOS6.8 升级到 python 到 2.7

    一.NTP 配置时间服务器1.1.检查当前系统时区1.2.同步时间1.3.检查软件包1.4.修改 ntp 配置文件1.5.重启 ntp 服务1.6.设置定时同步任务二.Linux 集群服务群起脚本2. ...

  6. 在 Linux 多节点安装配置 Apache Zookeeper 分布式集群

    规划: 三台物理服务器就形成了(法定人数).对于高可用性集群,您可以使用高于3的任何奇数.例如,如果设置5台服务器,则集群可以处理两个故障节点等. 物理服务器需要开启的端口 2888 , 3888 和 ...

  7. dubbo配置负载均衡、集群环境

    再用dubbo作为项目架构的时候,给consumer消费者用nginx提供了负载均衡策略和集群的实现, 但是想了下,consumer再多,但是提供者还是一个,最后还不都是落到了这一个provider上 ...

  8. db2 数据库配置HADR+TSA添加集群节点

    Db2配置HADR高可用+TSA添加集群节点 一.服务器资源 Master IP:10.78.10.1 数据库:dbclassSlave IP:10.78.10.2 数据库:dbclassVIP:10 ...

  9. kubernetes配置(kubeconfig)对多集群的访问

    配置对多集群的访问 本文展示如何使用配置文件来配置对多个集群的访问. 在将集群.用户和上下文定义在一个或多个配置文件中之后,用户可以使用 kubectl config use-context 命令快速 ...

随机推荐

  1. ios开发——实用技术篇&应用间跳转

    应用之间的跳转 说明:本文介绍app如何打开另一个app,并且传递数据. 一.简单说明 新建两个应用,分别为应用A和应用B. 实现要求:在appA的页面中点击对应的按钮,能够打开appB这个应用. 1 ...

  2. ORB:新一代 Linux 应用

    Orbital Apps 给我们带来了一种新的软件包类型 ORB,它具有便携软件.交互式安装向导支持,以及离线使用的能力. 便携软件很方便.主要是因为它们能够无需任何管理员权限直接运行,也能够带着所有 ...

  3. Control.Refresh Control.Invalidate 和 Control.OnPaint之间的联系和区别

    1.Control.Invalidate会放一个WM_PAINT消息到消息队列,当Control处理到该消息的时候,就调用OnPaint. 2.Control.Refresh相当于以下两行:Contr ...

  4. Clairewd’s message

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

  5. A + B Again

    Problem Description There must be many A + B problems in our HDOJ , now a new one is coming.Give you ...

  6. Android(java)学习笔记264:Android下的属性动画高级用法(Property Animation)

    1. 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是最常用的一些用法,这些用法足以覆盖我们平时大多情况下的动画需求了.但是,正如上篇文章当中所说到的,属性动画对补间动画 ...

  7. Error reading from file 解决办法

    最近安装程序遇见这个问题: Error reading from file. 解决办法: 给这个程序添加权限: 添加SYSTEM的读写改..如果比较懒,直接全部允许. 然后Retry.

  8. vs克隆新建团队项目

    团队资源——克隆,完成后打开: 在解决方案资源中,添加——新建项目——web——ASP.NET web应用程序——空的,并将其设为启动项目:

  9. 八、android jni 之C语言基础

    *含义 1.乘法 3*5 2.定义指针变量 int * p://定义了一个名字叫p的变量,能够存放int数据类型的地址 3.指针运算符, //如果p是一个已经定义好的指针变量则*p表示以p的内容为地址 ...

  10. 一个WebForm中连接SQL Server的例子

    .cs using System; using System.Collections; using System.ComponentModel; using System.Data; using Sy ...