Postgresq9.6主从部署
发表于:2025-02-08 作者:千家信息网编辑
千家信息网最后更新 2025年02月08日,Postgresq9.6主从部署实验环境名称IP系统Master172.17.10.190Centos 6.5Slave172.17.10.189Centos 6.51.yun安装rpm -ivh h
千家信息网最后更新 2025年02月08日Postgresq9.6主从部署
Postgresq9.6主从部署
实验环境
名称 | IP | 系统 |
Master | 172.17.10.190 | Centos 6.5 |
Slave | 172.17.10.189 | Centos 6.5 |
1.yun安装
rpm -ivh https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpmyum install postgresql96.x86_64 postgresql96-server.x86_64 -y
2.主从配置
2.1 主数据库配置
启动master
/etc/init.d/postgresql-9.6 initdb/etc/init.d/postgresql-9.6 startsu - postgrespsql
授权
create role repl login replication encrypted password '51idc.com';
编辑hba文件
/var/lib/pgsql/9.6/data/pg_hba.conf
新增
host replication repl 172.17.10.0/24 md5host all repl 172.17.10.0/24 trust
编辑配置文件
/var/lib/pgsql/9.6/data/postgresql.conf
listen_addresses = 172.17.10.190wal_level = hot_standby #热备模式max_wal_senders= 6 #可以设置最多几个流复制链接,差不多有几个从,就设置多少wal_keep_segments = 10240 #重要配置 wal_send_timeout = 60s max_connections = 512 #从库的 max_connections要大于主库archive_mode = on #允许归档 archive_command = 'cp %p /url/path%f' #根据实际情况设置
2.2 从数据库配置
su - postgres
如果开始为启动数据库可忽略下一步
rm -rf /var/lib/pgsql/9.6/data/* #开始没有启动从数据库,这一步可以省略 pg_basebackup -h 172.17.10.190 -U repl -D /var/lib/pgsql/9.6/data -X stream -Pcp /usr/pgsql-9.6/share/recovery.conf.sample /var/lib/pgsql/9.6/data/recovery.conf
修改配置文件recovery.conf
standby_mode = onprimary_conninfo = 'host=172.17.10.190 port=5432 user=repl password=51idc.com'trigger_file = '/var/lib/pgsql/9.6/data/trigger.kenyon' #主从切换时后的触发文件recovery_target_timeline = 'latest'
配置postgresql.conf文件
listen_addresses = 172.17.10.189wal_level = hot_standby max_connections = 1000 #一般从的最大链接要大于主的。 hot_standby = on #说明这台机器不仅仅用于数据归档,也用于查询 max_standby_streaming_delay = 30s wal_receiver_status_interval = 10s #多久向主报告一次从的状态。 hot_standby_feedback = on #如果有错误的数据复制,是否向主进行范例
检测
select client_addr,sync_state from pg_stat_replication;
查看主从状态
select * from pg_stat_replication;
脚本监控主从
github地址
#!/bin/bash# mail xuel@51idc.comdata=`date +%Y-%M-%d" "%H:%m`netstat -lntup|grep 5432 && ps -ef|grep postmasterif [ $? -eq 0 ];thenfor IP in 172.17.10.188 172.17.10.189do/usr/bin/psql -h 172.17.10.190 -p 5432 -U repl -d postgres --command "select * from pg_stat_replication"|grep $IPif [ "$?" != "0" ];thenecho "postgresql master-slave status is error! please login check!"|mail -r "xuel@51idc.com" -s "postgresql master-slave status is error" xuel@51idc.com \&& echo "$data postgresql postgresql master-slave status is error!">>/var/log/postgresql-error.logfidoneelseecho "postgresql master-slave status is error! please login check!"|mail -r "xuel@51idc.com" -s "postgresql master-slave status is error" xuel@51idc.com \&& echo "$data postgresql postgresql master-slave status is error!">>/var/log/postgresql-error.logfi
2.3主从切换
主库查看进程为sender
备库
停止主库
查看slave的日志
创建触发文件,切换主
touch trigger.kenyon
查看slave的日志,面前已经切换为主
使用pg_controldata
备机状态为: in archive recovery
主库状态为:in production
配置
主从
数据
文件
数据库
状态
切换
日志
链接
最大
重要
差不多
不仅仅
主报
名称
地址
实际
情况
机器
模式
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
.net软件开发招聘西安
给数据库设置密码
信息化软件开发设施价钱
人工智能与网络安全的构想
自己公司的服务器域名备案问题
企业服务政府网络安全
会计软件开发需要学什么
带你一分钟了解网络安全法
住房公积金网络安全执法检查
nec服务器导轨
凤凰县网络安全保卫大队
榆林市国家网络安全宣传活动
机器学习数据库入门
使命召唤16不同服务器可以玩吗
局网络安全协调处置机制
安卓系统软件开发服务平台
山大地纬软件开发公司
中文数据库官网
域服务器分布式管理
近年来的网络安全
笔记本玩穿越火线服务器断开
狮子座伴奏软件开发
杭州仕佳网络技术上班怎么样
数据库多表关联是并行执行吗
防范网络安全风险需
尚肯上海互联网科技
车主联互联网科技
sr590 服务器尺寸
服务器托管哪个机房好
攻击网络安全技巧