huhahapz 发表于 2016-11-21 09:06:01

PostgreSQL HA双机热备份配置

  自PostgreSQL 9.0开始,添加了流复制(Streaming Repulication)。
  SR源于pg早起的“同步日志传送复制”(Synchronous Log Shipping Repulication)--一个高可用的(HA)解决方案。
  安装与配置(Linux--PostgreSQL9.X)
  说明:Primary_IP 表示主服务器IP地址
  Standby_IP 表示备用服务器IP地址
  1.在主服务器中安装PostgreSQL(备用服务器同理)
  cd ./root/Desktop (打开安装文件所在目录)
  ./configure
  make
  make install
  2.在主服务器的PostgreSQL中配置../data/postgresql.conf
  vi postgresql.conf
  listen_address = '*'
  wal_level = hot_standby
  max_wal_zenders = 30 (根据实际情况自己设置即可)
  archive_mode = on
  archive_command = 'cd'
  3.在主服务器的PostgreSQL中配置pg_hba_conf文件中的参数
  vi pg_hba.conf
  host replication all/postgres Standby_IP/32 trust (all与postgres仅选其一)
  4.启动主服务器中的PostgreSQL数据库,执行基础备份:
  psql -U posgres
  postgres#select pg_start_backup('hot_backup'); (可使用任意符号做备份标记)
  postgres#\q
  tar -zcvf pgsql.tar.gz pgsql
  psql -U posgres
  postgres#select pg_stop_backup();
  5.将基础备份拷贝到备用服务器:
  scp pgsql.tar.gzStandby_IP:/usr/local/
  6.在备用服务器的PostgreSQL中配置postgresql.conf文件中的参数
  vi postgresql.conf
  hot_standby = on
  7.在备用服务器PostgreSQL的data目录下建立recovery.conf文件
  vi recovery.conf
  standby_mode = ‘on’
  primary_conninfo = 'host=Primay_IP user=posgres port=5432'
  安装配置完毕,重启主服务器,然后重启备用服务器。
         一定要确保修改后的参数更新完毕,例如可以通过postgres#show wal_level来查看wal_level的参数。
         如果参数没有更新则服务器无法运行,所以一定要保证参数更新,方法是:关闭所有postgres服务后重新启动。      
  运行PostgreSQL数据库后,在priamy的任何修该都会同步到standby中,standby不能对数据库做修改只能查看。
        注意:1 一定要把防火墙关闭,否则主-备服务器无法获得连接,会出现如下问题:               
  FATAL: could not connect to the primary server: could not connect to server: No route to host
                  Is the server running on host "192.168.100.112" and accepting
                  TCP/IP connections on port 5432?
                    具体解决方法(将firewall设置为disable):
  # setup
                  # geten
  getenforcegetent
  # geten
  getenforcegetent
  # getenforce
  Permissive
  (更多问题可以查看pg英文文档。)
页: [1]
查看完整版本: PostgreSQL HA双机热备份配置