一、变更计划与方案
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 = '