admin管理员组

文章数量:1130349

系统版本centos7.9
postgresql版本13.4
repmgr版本5.2.1
主机:192.168.101.132 node1
备机:192.168.101.133 node2

1、安装repmgr(主备库都要安装)

[root@node1 ~]# tar -zxvf repmgr-5.2.1.tar.gz 
[root@node1 ~]# cd repmgr-5.2.1
[root@node1 repmgr-5.2.1]# ./configure --prefix=/home/postgresql
//这里编译会报错,因为没有flex
[root@node1 repmgr-5.2.1]# yum install -y flex
//安装之后在执行上述编译
[root@node1 repmgr-5.2.1]# make && make install

2、主库配置

2.1、基本信息

[root@node1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.101.132 node1
192.168.101.133 node2
[root@node1 ~]# cat /etc/profile
... ...
unset i
unset -f pathmunge
PATH=$PATH:/home/postgresql/bin
[root@node1 ~]# su - postgres
Last login: Wed Sep 22 17:19:08 CST 2021 on pts/0
[postgres@node1 ~]$ pwd
/home/postgres
[postgres@node1 ~]$ cat .pgpass 
192.168.101.132:5432:repmgr:repmgr:repmgr
192.168.101.133:5432:repmgr:repmgr:repmgr
[postgres@node1 ~]$ cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

PGHOME=/home/postgresql

export PGHOME

PGDATA=$PGHOME/data

export PGDATA

PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin

export PATH
[postgres@node1 ~]$ vim /home/postgresql/data/postgresql.conf
unix_socket_directories='/home/postgresql/data'
wal_log_hints = on
archive_mode = on
archive_command = 'arch.sh %f %p' 
#archive_command = 'test ! -f /home/postgres/pgarch/%f && cp %p /home/postgres/pgarch/%f'

//arch.sh脚本位置及内容
[postgres@node1 pgdata]$ pwd
/home/postgres/pgdata
[postgres@node1 pgdata]$ ll
total 4
drwxrwxr-x. 2 postgres postgres   6 Sep 23 11:15 arch
-rw-rw-r--. 1 postgres postgres 178 Sep 23 11:13 arch.sh
[postgres@node1 pgdata]$ cat arch.sh //删除7天内的归档日志。
test ! -f /home/postgresql/pgdata/arch/$1 && cp --preserve=timestamps $2 /home/postgresql/pgdata/arch/$1 ; find /home/postgresql/pgdata/arch/ -type f -mtime +7 -exec rm -f {} \;

//创建复制用户
[postgres@node1 ~]$ createuser -s -P repmgr  //-P设置密码,与用户名一样即可,并且对应上述.pgpass文件中的配置信息
[postgres@node1 ~]$ createdb repmgr -O repmgr
[postgres@node1 ~]$ vim /home/postgr

系统版本centos7.9
postgresql版本13.4
repmgr版本5.2.1
主机:192.168.101.132 node1
备机:192.168.101.133 node2

1、安装repmgr(主备库都要安装)

[root@node1 ~]# tar -zxvf repmgr-5.2.1.tar.gz 
[root@node1 ~]# cd repmgr-5.2.1
[root@node1 repmgr-5.2.1]# ./configure --prefix=/home/postgresql
//这里编译会报错,因为没有flex
[root@node1 repmgr-5.2.1]# yum install -y flex
//安装之后在执行上述编译
[root@node1 repmgr-5.2.1]# make && make install

2、主库配置

2.1、基本信息

[root@node1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.101.132 node1
192.168.101.133 node2
[root@node1 ~]# cat /etc/profile
... ...
unset i
unset -f pathmunge
PATH=$PATH:/home/postgresql/bin
[root@node1 ~]# su - postgres
Last login: Wed Sep 22 17:19:08 CST 2021 on pts/0
[postgres@node1 ~]$ pwd
/home/postgres
[postgres@node1 ~]$ cat .pgpass 
192.168.101.132:5432:repmgr:repmgr:repmgr
192.168.101.133:5432:repmgr:repmgr:repmgr
[postgres@node1 ~]$ cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

PGHOME=/home/postgresql

export PGHOME

PGDATA=$PGHOME/data

export PGDATA

PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin

export PATH
[postgres@node1 ~]$ vim /home/postgresql/data/postgresql.conf
unix_socket_directories='/home/postgresql/data'
wal_log_hints = on
archive_mode = on
archive_command = 'arch.sh %f %p' 
#archive_command = 'test ! -f /home/postgres/pgarch/%f && cp %p /home/postgres/pgarch/%f'

//arch.sh脚本位置及内容
[postgres@node1 pgdata]$ pwd
/home/postgres/pgdata
[postgres@node1 pgdata]$ ll
total 4
drwxrwxr-x. 2 postgres postgres   6 Sep 23 11:15 arch
-rw-rw-r--. 1 postgres postgres 178 Sep 23 11:13 arch.sh
[postgres@node1 pgdata]$ cat arch.sh //删除7天内的归档日志。
test ! -f /home/postgresql/pgdata/arch/$1 && cp --preserve=timestamps $2 /home/postgresql/pgdata/arch/$1 ; find /home/postgresql/pgdata/arch/ -type f -mtime +7 -exec rm -f {} \;

//创建复制用户
[postgres@node1 ~]$ createuser -s -P repmgr  //-P设置密码,与用户名一样即可,并且对应上述.pgpass文件中的配置信息
[postgres@node1 ~]$ createdb repmgr -O repmgr
[postgres@node1 ~]$ vim /home/postgr

本文标签: repmgrpg库主备