postgresql-11主从复制(流复制)部署
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了postgresql-11主从复制(流复制)部署,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4246字,纯文字阅读大概需要7分钟。
内容图文
-
主从机器分配
-
IP地址 DB版本 主从关系 192.168.63.134 11.6 主 192.168.63.141 11.6 从
-
-
安装postgresql
-
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y yum install postgresql11 -y yum install postgresql11-server -y
-
-
主库配置
-
主库初始化
-
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl start postgresql-11
-
- 创建复制用户,进行主从同步使用
-
[root@localhost data]# sudo -i -u postgres -bash-4.2$ psql psql (11.6) 输入 "help" 来获取帮助信息. postgres=# create role repl login replication encrypted password '123456'; CREATE ROLE
-
- 主库上配置从库采用repl账号
-
vim /var/lib/pgsql/11/data/pg_hba.conf #只需要台添加下面两行,repl是用来做备份的用户,后面的192.168.63.0/24是该网段内的IP地址 host replication repl 192.168.63.0/24 md5 host all repl 192.168.63.0/24 trust vim /var/lib/pgsql/11/data/postgresql.conf listen_addresses = '*' # what IP address(es) to listen on; port = 5432 # (change requires restart) max_connections = 512 # (change requires restart) shared_buffers = 128MB # min 128kB dynamic_shared_memory_type = posix # the default is the first option wal_level = hot_standby # minimal, replica, or logical archive_mode = on # enables archiving; off, on, or always archive_command = 'cp %p /var/lib/pgsql/11/data/pg_archive/%f' # command to use to archive a logfile segment max_wal_senders = 6 # max number of walsender processes wal_keep_segments = 10240 # in logfile segments, 16MB each; 0 disables wal_sender_timeout = 60s # in milliseconds; 0 disables log_directory = 'log' # directory where log files are written
- 修改完,要创建刚刚配置的一些目录结构:
-
mkdir /var/lib/pgsql/11/data/pg_archive/
chown -R postgres.postgres /var/lib/pgsql/11/data - 重启主库服务
-
systemctl restart postgresql-11
-
-
-
从库配置
- 从库安装完成后,不初始化,若已经初始化,删除其data目录
-
#把主节点所有的数据文件都会拷贝过来 [root@localhost ~]# pg_basebackup -h 192.168.63.134 -U repl -D /var/lib/pgsql/11/data/ -X stream -P 口令: 25312/25312 kB (100%), 1/1 表空间 [root@localhost ~]# ls /var/lib/pgsql/12/data/ backup_label current_logfiles log pg_commit_ts pg_hba.conf pg_logical pg_notify pg_serial pg_stat pg_subtrans pg_twophase pg_wal postgresql.auto.conf base global pg_archive pg_dynshmem pg_ident.conf pg_multixact pg_replslot pg_snapshots pg_stat_tmp pg_tblspc PG_VERSION pg_xact postgresql.conf
- 从库配置文件,根据下面的配置进行修改。
[root@localhost ~]# vim /var/lib/pgsql/11/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 = 128MB # min 128kB dynamic_shared_memory_type = posix # the default is the first option wal_level = replica # minimal, replica, or logical archive_mode = on # enables archiving; off, on, or always archive_command = 'cp %p /var/lib/pgsql/12/data/pg_archive/%f' # command to use to archive a logfile segment wal_sender_timeout = 60s # in milliseconds; 0 disables hot_standby = on # "on" allows queries during recovery max_standby_streaming_delay = 30s # max delay before canceling queries wal_receiver_status_interval = 10s # send replies at least this often hot_standby_feedback = on # send info from standby to prevent log_directory = 'log' # directory where log files are written,
- 创建恢复文件recovery.conf。
-
[root@localhost 11]# cp /usr/pgsql-11/share/recovery.conf.sample /var/lib/pgsql/11/data/recovery.conf [root@localhost 11]# vim /var/lib/pgsql/11/data/recovery.conf # 调整参数: recovery_target_timeline = 'latest' #同步到最新数据 standby_mode = on #指明从库身份
trigger_file = 'failover.now' primary_conninfo = 'host=192.168.63.134 port=5432 user=repl password=123456' #连接到主库信息 - 启动从库
systemctl start postgresql-11
-
- 验证主从配置
- 在主库上运行以下命令
postgres=# select client_addr,sync_state from pg_stat_replication; client_addr | sync_state ----------------+------------ 192.168.63.141 | async (1 行记录)
- 在主库上运行以下命令
- 可以创建一个数据库自行验证
内容总结
以上是互联网集市为您收集整理的postgresql-11主从复制(流复制)部署全部内容,希望文章能够帮你解决postgresql-11主从复制(流复制)部署所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。