Postgresql+Keepalived高可用方案

一、变更计划与方案

1.1 概述
现有postgresql数据库为单一数据库,没有备份数据,为保证数据安全正常运行,现将给定的3台服务器,组成一个1主2从的高可用架构。
1.2 基本信息

主机名 IP地址 服务器角色 系统信息 数据库目录
72_123 192.168.247.123 Postgresql主节点 Red Hat7.7 /data
72_124 192.168.247.124 Postgresql从节点 Red Hat7.7 /data
72_125 192.168.247.125 Postgresql从节点 Red Hat7.7 /data

1.3实施计划
先将247.124和247.125设置为247.123的从库,然后安装Keepalived 高可用组件,搭建高可用架构

二、实施方案

2.1 各节点安装postgres (root用户)
准备postgresql-11-10.tar.gz软件包
https://www.postgresql.org/ftp/source/v11.10/
安装相关依赖包

yum -y install readline readline-devel zlib zlib-devel

配置hosts文件

cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.247.123  master
192.168.247.124 slave1
192.168.247.125 slave2

关闭防火墙,SELINUX

systemctl stop firewalld
systemctl enable firewalld

setenforce 0
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

创建用户、安装目录、数据库目录

useradd  postgres
password postgres

mkdir /opt/pg11/
mkdir /data/
chown -R postgres:postgres /opt/pg11/
chown -R postgres:postgres /data/

解压并编译安装

tar -xvf postgresql-11.10.tar.gz 
cd postgresql-11.10/
./configure --prefix=/opt/pg11/
make world
make install-word

设置环境变量

su - postgres
vim .bashrc
export LD_LIBRARY_PATH=/opt/pg11/lib
export PGDATA=/data/
export PGHOME=/opt/pg11/
export PATH=$PATH:/opt/pg11/bin/

初始化数据库

/opt/pg11/bin/initdb -D /data/   

修改配置文件(参数值根据服务器配置填写)

listen_addresses = '*' 
port = 5432 
max_connections = 100 
shared_buffers = 128MB
dynamic_shared_memory_type = posix 
wal_level = replica 
max_wal_size = 1GB  
min_wal_size = 80MB
track_commit_timestamp = on    
log_timezone = '
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值