当前位置: 首页 > news >正文

PostgreSQL配置主从同步

PostgreSQL配置主从同步

1 主、备库安装postgresql软件

su - pg12
cd /home/pg12/resource
tar -zxvf postgresql-12.9.tar.gz 
cd postgresql-12.9/
./configure --prefix=/home/pg12/soft/
make -j 16 && make install

2 主、备库配置环境变量

vi   ~/.bash_profile export PGHOME=/home/pg12/soft
export PGDATA=/home/pg12/repmgr
export PGPORT=5432
export PGUSER=postgres
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
export PATH=$PGHOME/bin:$PATHsource  ~/.bash_profile

3 主、备库安装repmgr软件

cd /home/pg12/resource/
tar -zxvf repmgr-5.1.0.tar.gz  
cd repmgr-5.1.0/
./configure
make -j 8 && make install

4 配置ssh免密

– 主节点,root用户执行

cd /home/pg12/resource/
chmod +x sshUserSetup.sh
./sshUserSetup.sh -user pg12  -hosts "192.168.10.100 192.168.10.101" -advanced exverify -confirmchmod 600 /home/pg12/.ssh/config

5 主库初始化

su - pg12
initdb -D /home/pg12/repmgr -U postgres -k

6 主库配置 pg_hba.conf

vi /home/pg12/repmgr/pg_hba.conf 
host replication all all trust
host all all all trust

7 主库配置 postgresql.conf

vi  /home/pg12/repmgr/postgresql.conf  
listen_addresses = '*'
port=5432
shared_preload_libraries ='repmgr'
wal_log_hints=on

8 重启主库

pg_ctl start -D /home/pg12/repmgr

9 创建复制用户repmgr

createuser -p 5432 -s repmgr

10 创建repmgr的配置目录

--两个节点
mkdir /home/pg12/conf/

11 主库配置 repmgr.conf

vi /home/pg12/conf/repmgr.confnode_id=1
node_name=test1
conninfo='host=192.168.10.100 user=repmgr port=5432 dbname=postgres'
data_directory='/home/pg12/repmgr'
log_file='/home/pg12/conf/repmgr.log'
pg_bindir='/home/pg12/soft/bin'monitoring_history=yes
monitor_interval_secs=1
failover='automatic'
reconnect_attempts=6 
reconnect_interval=5
promote_command='repmgr standby promote -f /home/pg12/conf/repmgr.conf --log-to-file'
follow_command='repmgr standby follow -f /home/pg12/conf/repmgr.conf --log-to-file --upstream-node-id=%n'

12 备库配置 repmgr.conf

vi /home/pg12/conf/repmgr.conf node_id=2
node_name=test2
conninfo='host=192.168.10.101 user=repmgr port=5432 dbname=postgres'
data_directory='/home/pg12/repmgr'
log_file='/home/pg12/conf/repmgr.log'
pg_bindir='/home/pg12/soft/bin'monitoring_history=yes
monitor_interval_secs=1
failover='automatic'
reconnect_attempts=6 
reconnect_interval=5
promote_command='repmgr standby promote -f /home/pg12/conf/repmgr.conf --log-to-file'
follow_command='repmgr standby follow -f /home/pg12/conf/repmgr.conf --log-to-file --upstream-node-id=%n'

13 创建软链接

--两个节点
su - root
ln -s /home/pg12/conf/repmgr.conf /etc/repmgr.conf
chown pg12.pg12 /etc/repmgr.conf

14 主库注册

su - pg12
repmgr -f /home/pg12/conf/repmgr.conf primary register
repmgr -f /home/pg12/conf/repmgr.conf cluster show
repmgrd -d -f /home/pg12/conf/repmgr.conf

15 备库注册

su - pg12
repmgr -h 192.168.10.100 -U repmgr -d postgres -f /home/pg12/conf/repmgr.conf standby clone --force
pg_ctl -D /home/pg12/repmgr start
repmgr -f /home/pg12/conf/repmgr.conf standby register
repmgr -f /home/pg12/conf/repmgr.conf cluster show
repmgrd -d -f /home/pg12/conf/repmgr.conf

16 查看主从状态

–主库执行

[pg12@test1 repmgr]$ repmgr -f /home/pg12/conf/repmgr.conf cluster showID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                        
----+-------+---------+-----------+----------+----------+----------+----------+-----------------------------------------------------------1  | test1 | primary | * running |          | default  | 100      | 1        | host=192.168.10.100 user=repmgr port=5432 dbname=postgres2  | test2 | standby |   running | test1    | default  | 100      | 1        | host=192.168.10.101 user=repmgr port=5432 dbname=postgres

–备库执行

[pg12@test2 ~]$ repmgr -f /home/pg12/conf/repmgr.conf cluster showID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                        
----+-------+---------+-----------+----------+----------+----------+----------+-----------------------------------------------------------1  | test1 | primary | * running |          | default  | 100      | 1        | host=192.168.10.100 user=repmgr port=5432 dbname=postgres2  | test2 | standby |   running | test1    | default  | 100      | 1        | host=192.168.10.101 user=repmgr port=5432 dbname=postgres
http://www.lryc.cn/news/438524.html

相关文章:

  • 基于python+django+vue的鲜花商城系统
  • 李飞飞任CEO,空间智能公司World Labs亮相,全明星阵容曝光
  • PyTorch详解-可视化模块
  • Bootstrap 警告信息(Alerts)使用介绍
  • uniapp(H5)设置反向代理,设置成功后页面报错
  • define、typedef和using的使用
  • vue element时间选择不能超过今天 时间选中长度不能超过7天
  • 如何 吧一个 一维数组 切分成相同等分,一维数组作为lstm的输入(三维数据)的数据预处理 collate_fn的应用
  • Remix 学习 - @remix-run/react 中主要的 hooks
  • STL之stack
  • 如何用3个月零基础入门网络安全?_网络安全零基础怎么学习
  • 适合学生党开学买的蓝牙耳机?分享开放式耳机排行榜前十名
  • 汽车租赁系统1.0版本
  • DockerDocker Compose安装(离线+在线)
  • 【泰克生物】酵母展示建库技术解析:构建高质量抗体文库的实用指南
  • QT Mode/View之View
  • URP 线性空间 ui资源制作规范
  • 如何精确统计Pytorch模型推理时间
  • Mybatis-plus-Generator 3.5.5 自定义模板支持 (DTO/VO 等) 配置
  • C#环境下MAC地址获取方法解析
  • (k8s)Kubernetes 从0到1容器编排之旅
  • Rust Web开发框架对比:Warp与Actix-web
  • F12抓包12:Performance(性能)前端性能分析
  • 数据结构(Day13)
  • 链表的快速排序(C/C++实现)
  • css总结(记录一下...)
  • SpringBoot 处理 @KafkaListener 消息
  • Spring Boot-API版本控制问题
  • Git 提取和拉取的区别在哪
  • 【数据结构与算法 | 每日一题 | 力扣篇】力扣2390, 2848