一 .主备机器规划(各节点均进行以下操作)
1 设置host
master,slave两节点都要操作。
vi /etc/hosts
192.168.0.1 host1
192.168.0.1 host2

2.创建系统用户及datadir
useradd postgres
echo “postgres” | passwd postgres --stdin
mkdir /data/postgres/data -p
mkdir /data/postgres/log -p
mkdir /data/postgres/pg_archive -p
chown -R postgres.postgres /data/postgres/

3.解压安装文件;
yum -y update gcc
yum -y install g==
yum -y install g++
yum -y install gcc+
yum install -y libxml2-devel.x86_64
yum search libxml2-devel
yum search gcc
yum -y install libtool
yum -y install gcc-c++.x86_64
yum search readline
yum install -y readline-devel.x86_64
yum install -y zlib-devel.x86_86
cd /usr/local/
tar zxf /root/postgresql-9.5.10.tar.gz
cd /usr/local/postgresql-9.5.10/
./configure --prefix=/usr/local/pgsql --with-libxml
make
make install

4.环境变量配置及yum,各节点均操作
su - postgres
vi .bash_profile

PATH=$PATH:$HOME/.local/bin:$HOME/binexport PATH
export PGHOME=/usr/local/pgsql
export PGDATA=/data/postgres/data/
export PG_PATH=/usr/local/pgsql/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib/
export PATH=$PGHOME/bin:$PATH:
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres
export PGDATABASE=postgres

source .bash_profile

二.主库安装;
1.主库初始化postgresql;
initdb -D /data/postgres/data/ -E UTF-8 --locale=zh_CN.UTF-8

2.修改参数配置(相关参数需要按机器配置调节);
vi /data/postgres/data/postgresql.conf

listen_addresses = '*'          # what IP address(es) to listen on;port = 5432                             # (change requires restart)
max_connections = 1000                  # (change requires restart)shared_buffers = 400MB                 # min 128kBwork_mem = 8MB                          # min 64kB
maintenance_work_mem = 100MB           # min 1MB
dynamic_shared_memory_type = posix      # the default is the first optionbgwriter_delay = 10ms                   # 10-10000ms between rounds
wal_level = hot_standby                 # minimal, archive, hot_standby, or logical# (change requires restart)
synchronous_commit = on         # synchronization level;wal_buffers = 16MB                      # min 32kB, -1 sets based on shared_buffers# (change requires restart)
checkpoint_timeout = 5min               # range 30s-1h
archive_mode = on               # enables archiving; off, on, or alwaysarchive_command = 'cp %p /data/postgres/pg_archive/%f'   # command to use to archive a logfile segmentmax_wal_senders = 8             # max number of walsender processes# (change requires restart)
wal_keep_segments = 128         # in logfile segments, 16MB each; 0 disables# (change requires restart)hot_standby = on                        # "on" allows queries during recoverymax_standby_archive_delay = -1  # max delay before canceling queriesmax_standby_streaming_delay = -1        # max delay before canceling querieswal_receiver_status_interval = 2s       # send replies at least this oftendefault_statistics_target = 100 # range 1-10000
constraint_exclusion = partition        # on, off, or partitionlog_destination = 'csvlog'              # Valid values are combinations oflogging_collector = on                  # Enable capturing of stderr and csvloglog_directory = 'pg_log'                # directory where log files are written,# can be absolute or relative to PGDATA
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,# can include strftime() escapes
log_file_mode = 0600                    # creation mode for log files,log_rotation_age = 60d                  # Automatic rotation of logfiles will# happen after that time.  0 disables.
log_rotation_size = 1000MB              # Automatic rotation of logfiles willlog_statement = 'mod'                   # none, ddl, mod, alllog_timezone = 'PRC'datestyle = 'iso, mdy'
timezone = 'PRC'lc_messages = 'en_US.UTF-8'                     # locale for system error message# strings
lc_monetary = 'en_US.UTF-8'                     # locale for monetary formatting
lc_numeric = 'en_US.UTF-8'                      # locale for number formatting
lc_time = 'en_US.UTF-8'                         # locale for time formatting
default_text_search_config = 'pg_catalog.english'# (change requires restart)# (change requires restart)# directory 'conf.d'
#include '/var/lib/pgsql/tmp/rep_mode.conf' # added by pgsql RA

3.启动主数据库并建立同步用户
pg_ctl -D /data/postgres/data -l /data/postgres/log/pg_server.log start &
create role replicator login replication encrypted password ‘replicator’;
管理账号:
postgres=# create role admin superuser encrypted password ‘admin’;

4.配置
4.1 pg_hba IP限制;
vi /data/postgres/data/pg_hba.conf
添加下面内容
host replication replicator 10.39.43.0/24 trust

4.2 pg_hba生效:
pg_ctl -D /data/postgres/data/ reload

三.从库安装;(多从,步骤相同)
1.不需要初始化,直接从主库备份就行,如有DATA直接删掉或改名掉
pg_basebackup -h 192.168.0.1 -U replicator -F p -P -D /data/postgres/data/
可能得输入密码
备注:
-h,主库主机,-p,主库服务端口;
-U,复制用户;
-F,p是默认输出格式,输出数据目录和表空间相同的布局,t表示tar格式输出;
-P,同–progress,显示进度;
-D,输出到指定目录;

2.从上创建恢复文件recovery.conf

2.1.文件来源 此步可忽略
cp /usr/local/pgsql/share/recovery.conf.sample /data/postgres/data/recovery.conf

2.2
recovery文件中的参数
cat >>/data/postgres/data/recovery.conf <<EOF
standby_mode = on
primary_conninfo = ‘host=192.168.0.1 port=5432 user=replicator password=replicator’
recovery_target_timeline=‘latest’
EOF

备注:
vim ~/data/recovery.conf #在做基础备份时,也可通过-R参数在备份结束后自动生产一个recovery.conf文件
standby_mode = on #指明从库身份
primary_conninfo = ‘host=10.39.45.24 port=5432 user=同步用的用户名 password=密码’ #连接到主库信息
ecovery_target_timeline = ‘latest’ #同步到最新数据
指定触发文件,文件存在时,将触发从库提升为主库,前提是必须设置”standby_mode = on”;如果不设置此参数,也可采用”pg_ctl promote“触发从库切换成主库
#trigger_file = ‘/postgres/data/trigger_activestandby’
因为主库采用的是md5认证,这里需要密码认证。

3.启动从库数据服务
chmod 0700 /data/postgres/data/ -R
pg_ctl -D /data/postgres/data -l /data/postgres/log/pg_server.log start &

4.验证主从配置
2.4.1查看主库sender进程
ps -ef|grep postgres
查看有wal sender process 数据库中创建的同步用的用户名 从库地址

2.4.2查看从库sender进程
ps -ef|grep postgres
查看有wal receiver process

2.4.3用SQL看主从状态
psql
select * from pg_stat_replication;
主库会显示sync_state为async 地址是从库地址
从库查状态无记录

postgres主从配置相关推荐

  1. postgres主从配置和切换

    本文档用于说明PostgresSQL数据库流复制(Streaming Replication)配置和主从切换过程. 参考博客地址:https://blog.csdn.net/ywd1992/artic ...

  2. Postgresql12主从配置及切换

    一.主从安装 1.依据"Centos7安装最新版Postgresql"操作,注意个别细节选择主从配置 2.注意:从服务器只能查询,不能写入 3.主库IP=103,备库IP=104 ...

  3. Redis——学习之路四(初识主从配置)

    首先我们配置一台master服务器,两台slave服务器.master服务器配置就是默认配置 端口为6379,添加就一个密码CeshiPassword,然后启动master服务器. 两台slave服务 ...

  4. Redis数据库搭建主从同步(主从概念、主从配置、主从数据操作)

    1. 主从概念 ⼀个master可以拥有多个slave,⼀个slave⼜可以拥有多个slave,如此下去,形成了强⼤的多级服务器集群架构 master用来写数据,slave用来读数据,经统计:网站的读 ...

  5. 虚拟机CENTOS7下 安装8.0版本MySQL MySQL主从配置详细~

    全部代码,写在后面吧! 全部的代码在后面. 1.安装mysql 先rz命令上传一下!出现未响应是很正常的情况!等会就好啦. ls查看一下,已经出现啦~ xz -d mysql-8.0.13-linux ...

  6. mysql主从配置流程

    一.mysql主从配置原理 1.master将操作记录写到二进制日志中(binary log)中: 2.slave IO 线程将master的binary log events读写到它的中继日志(re ...

  7. mysql主从配置安装_mysql主从配置完整版(二进制安装)

    系统基础 centos6.5 mysql5.6 防火墙关闭,目录挂载等 fdisk /dev/sdb vgcreate datavg /dev/sdb1 lvcreate -L 99G -n data ...

  8. Redis主从配置及通过Keepalived实现Redis自动切换高可用

    Redis主从配置及通过Keepalived实现Redis自动切换高可用 [日期:2014-07-23] 来源:Linux社区  作者:fuquanjun [字体:大 中 小] 一:环境介绍: Mas ...

  9. Centos DNS服务(二)-bind主从配置与基于TSIG加密的动态更新

    DNS的主从配置 DNS从服务器也叫辅服DNS服务器,如果网络上某个节点只有一台DNS服务器的话,首先服务器的抗压能力是有限的,当压力达到一定的程度,服务器就可能会宕机罢工, 其次如果这台服务器出现了 ...

最新文章

  1. Homebrew--MacOSX下的套件管理器
  2. 安装阴阳师出现错误“选择的驱动器或UNC共享不存在或不能访问“怎么解决?
  3. 转 使用 HttpClient 4 进行文件上传
  4. 【BLE】BLE中常用的UUID(标准)
  5. 为什么磁盘存储引擎用 b+树来作为索引结构?
  6. 【渝粤教育】电大中专办公设备使用与维护 (2)_1作业 题库
  7. LeetCode 58. 最后一个单词的长度
  8. electron 打包把node代理服务打包进去_专题:让C++给node做技术加持(三)编译electron本地模块踩坑记
  9. Android Jenkins自动化构建之路
  10. 大数据驱动5G网络与服务优化
  11. 用python做测试实现高性能测试工具(4)—系统架构
  12. bat中ERRORLEVEL的使用介绍
  13. 图论算法——有向图的可达性与寻路
  14. pytest-Mark数据驱动
  15. 图的连通度问题的求法(转)
  16. 盐城哪里学计算机表格,盐城办公自动化周末班
  17. Unity Shader Alpha Blend 填坑记录
  18. 物联网安全 - 对称加密算法
  19. 华硕台式计算机光盘怎么启动不了,华硕台式机U盘启动不了怎么回事
  20. 苹果手机Safri浏览器 js 解析问题

热门文章

  1. 电脑硬盘数据线_这40种电脑故障的排除技巧你都掌握了吗?
  2. 帝国CMS7.2 7.5微信登录插件
  3. mysql编号用什么类型_mysql 之编码配置、引擎介绍、字段操作、数据类型及约束条件...
  4. 好玩的表情包机器人小程序源码_支持直接搜索仿聊天界面获取源码
  5. thinkphp开发发卡网源码
  6. BBE Sound Sonic Sweet(激励混音效果器)v4.2.0 绿色版
  7. Spring Boot集成Redis缓存之RedisTemplate的方式
  8. 四十个非常实用的轻量级JavaScript库
  9. Python设置默认语言编码
  10. 事务(注解声明式事务管理)