postgresql repmgr setup

一.soft requires(Master/Slave)

OS: CentOS Linux release 7.3.1611 (Core) X64

1.disabled SELINUX

# more /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of three two values:

#     targeted - Targeted processes are protected,

#     minimum - Modification of targeted policy. Only selected processes are protected.

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

2.disabled firewall

systemctl disable firewalld.service

3.install pg repository rpm

pgdg-centos10-10-1.noarch.rpm

https://yum.postgresql.org/repopackages.php

4.install repmgr repository rpm

yum install http://packages.2ndquadrant.com/repmgr/yum-repo-rpms/repmgr-rhel-1.0-1.noarch.rpm

5.install repmgr

# yum install -y repmgr10

# chown postgres.postgres -R /etc/repmgr/10/

# systemctl enable repmgr10.service

6.set postgres user pwd and pg path

### pgdata ###

# mkdir /pgdata10

# chown postgres.postgres /pgdata10/

### pg password ###

# passwd postgres

### pg PATH ###

# su - postgres

-bash-4.2$ vi .bash_profile

[ -f /etc/profile ] && source /etc/profile

PATH=/usr/pgsql-10/bin:$PATH

export PATH

PGDATA=/var/lib/pgsql/10/data

export PGDATA

# If you want to customize your settings,

# Use the file below. This is not overridden

# by the RPMS.

[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile

~

### set pg boot ###

# systemctl enable postgresql-10

# vi /usr/lib/systemd/system/postgresql-10.service

# Location of database directory

Environment=PGDATA=/pgdata10/

二、hostname and ssh

1.set hostname

master

hostnamectl set-hostname ‘pgdb1‘

[[email protected] ~]# more /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.3.226    pgdb1

172.16.3.228    pgdb2

slave

hostnamectl set-hostname ‘pgdb2‘

[[email protected] ~]# more /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.3.226    pgdb1

172.16.3.228    pgdb2

[[email protected] ~]#

2.ssh

master

[[email protected] ~]# su - postgres

Last login: Mon Sep  4 10:32:25 CST 2017 on pts/0

-bash-4.2$

-bash-4.2$

-bash-4.2$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/var/lib/pgsql/.ssh/id_rsa):

Created directory ‘/var/lib/pgsql/.ssh‘.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /var/lib/pgsql/.ssh/id_rsa.

Your public key has been saved in /var/lib/pgsql/.ssh/id_rsa.pub.

The key fingerprint is:

22:84:86:c4:2a:1e:d2:3b:9e:86:b6:1c:72:d5:d2:32 [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

|..               |

|.o .             |

|o.o .            |

|+o.. o           |

|+ ..E + S        |

| .o. = .         |

|.+.o             |

|+o=              |

|.+.              |

+-----------------+

-bash-4.2$

-bash-4.2$ ssh-copy-id [email protected]

The authenticity of host ‘pgdb2 (172.16.3.228)‘ can‘t be established.

ECDSA key fingerprint is c1:b4:f8:21:7e:3f:81:e4:e9:e8:93:43:d5:8e:0f:0e.

Are you sure you want to continue connecting (yes/no)? yes

/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]‘s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh ‘[email protected]‘"

and check to make sure that only the key(s) you wanted were added.

-bash-4.2$

-bash-4.2$

-bash-4.2$ ssh pgdb2 date

Mon Sep  4 10:55:40 CST 2017

-bash-4.2$

Slave

[[email protected] ~]# su - postgres

Last login: Mon Sep  4 10:32:25 CST 2017 on pts/0

-bash-4.2$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/var/lib/pgsql/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /var/lib/pgsql/.ssh/id_rsa.

Your public key has been saved in /var/lib/pgsql/.ssh/id_rsa.pub.

The key fingerprint is:

38:9b:0b:38:9a:ef:ae:75:e5:74:a9:3d:cc:3c:53:05 [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

|          E      |

|           .     |

|            .    |

|       . . .     |

|      = S .      |

|   . + @ .       |

|  + o = O        |

| + o . . +       |

|+=+   .          |

+-----------------+

-bash-4.2$

-bash-4.2$

-bash-4.2$ ssh-copy-id [email protected]

The authenticity of host ‘pgdb1 (172.16.3.226)‘ can‘t be established.

ECDSA key fingerprint is c1:b4:f8:21:7e:3f:81:e4:e9:e8:93:43:d5:8e:0f:0e.

Are you sure you want to continue connecting (yes/no)? yes

/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]‘s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh ‘[email protected]‘"

and check to make sure that only the key(s) you wanted were added.

-bash-4.2$

-bash-4.2$

-bash-4.2$

-bash-4.2$ ssh pgdb1 date

Mon Sep  4 10:56:33 CST 2017

-bash-4.2$

三、setting repmgr

1.Master

1).init pgdata

[[email protected] ~]# su - postgres

Last login: Mon Sep  4 11:02:33 CST 2017 on pts/0

-bash-4.2$

-bash-4.2$ initdb -D /pgdata10/

The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".

The default database encoding has accordingly been set to "UTF8".

The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /pgdata10 ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

selecting dynamic shared memory implementation ... posix

creating configuration files ... ok

running bootstrap script ... ok

performing post-bootstrap initialization ... ok

syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the option -A, or

--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

pg_ctl -D /pgdata10/ -l logfile start

-bash-4.2$

2.Configure The Postgresql.Conf

-bash-4.2$ cd /pgdata10/

-bash-4.2$ vi postgresql.conf

#max_wal_senders = 10

wal_keep_segments = 5000

wal_level = logical

#full_page_writes = on

#max_replication_slots = 10

#hot_standby = on

# - Archiving -

archive_mode = on               # enables archiving; off, on, or always

# (change requires restart)

archive_command = ‘cd .‘                # command to use to archive a logfile segment

shared_preload_libraries = ‘repmgr_funcs‘

log_min_duration_statement = 1000

log_checkpoints = on

log_connections = on

log_disconnections = on

log_line_prefix = ‘%t [%p]: [%l-1] user=%u,db=%d,client=%h ‘

log_lock_waits = on                     # log lock waits >= deadlock_timeout

#log_statement = ‘none‘                 # none, ddl, mod, all

#log_replication_commands = off

log_temp_files = 0

log_autovacuum_min_duration = 0

3.pg_hba.conf

vi pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only

local   all             all                                     trust

# IPv4 local connections:

host    all             all             127.0.0.1/32            trust

host    repmgr          repmgr          172.16.3.0/16           trust

host    all             all             0/0                     md5

# IPv6 local connections:

host    all             all             ::1/128                 trust

# Allow replication connections from localhost, by a user with the

# replication privilege.

local   replication     all                                     trust

local   replication     repmgr                                  trust

host    replication     all             127.0.0.1/32            trust

host    replication     all             ::1/128                 trust

"pg_hba.conf" 97L, 4791C written

### start pg boot ###

# systemctl start postgresql-10

4. Repmgr.Conf

master

# su - postgres

$ vi /etc/repmgr/10/repmgr.conf

cluster=pgcluster

node=1          # a unique integer

node_name=node1

conninfo=‘host=pgdb1 dbname=repmgr user=repmgr‘

#use_replication_slots=0

#loglevel=NOTICE

#logfacility=STDERR

logfile=‘/var/log/repmgr/repmgr-10.log‘

master_response_timeout=30

#reconnect_attempts=6

#reconnect_interval=10

#failover=manual

#priority=100

promote_command=‘/usr/pgsql-10/bin/repmgr standby promote -f /etc/repmgr/10/repmgr.conf‘

follow_command=‘/usr/pgsql-10/bin/repmgr standby follow -f /etc/repmgr/10/repmgr.conf‘

slave

cluster=pgcluster

node=2           # a unique integer

node_name=node2

conninfo=‘host=pgdb2 dbname=repmgr user=repmgr‘

#use_replication_slots=0

#loglevel=NOTICE

#logfacility=STDERR

logfile=‘/var/log/repmgr/repmgr-10.log‘

master_response_timeout=30

#reconnect_attempts=6

#reconnect_interval=10

#failover=manual

#priority=100

promote_command=‘/usr/pgsql-10/bin/repmgr standby promote -f /etc/repmgr/10/repmgr.conf‘

follow_command=‘/usr/pgsql-10/bin/repmgr standby follow -f /etc/repmgr/10/repmgr.conf‘

5.master

-bash-4.2$ createuser -s repmgr

-bash-4.2$ createdb repmgr -O repmgr

register master

-bash-4.2$ repmgr -f /etc/repmgr/10/repmgr.conf master register

NOTICE: master node correctly registered for cluster ‘pgcluster‘ with id 1 (conninfo: host=pgdb1 dbname=repmgr user=repmgr)

-bash-4.2$

slave

-bash-4.2$ repmgr -f /etc/repmgr/10/repmgr.conf -h pgdb1 -d repmgr -U repmgr -D /pgdata10/ --force standby clone

NOTICE: destination directory ‘/pgdata10/‘ provided

NOTICE: starting backup (using pg_basebackup)...

HINT: this may take some time; consider using the -c/--fast-checkpoint option

NOTICE: standby clone (using pg_basebackup) complete

NOTICE: you can now start your PostgreSQL server

HINT: for example : pg_ctl -D /pgdata10/ start

HINT: After starting the server, you need to register this standby with "repmgr standby register"

-bash-4.2$

start server

[[email protected] ~]# systemctl start postgresql-10.service

register standby

[[email protected] pgdata10]# su - postgres

Last login: Mon Sep  4 11:51:11 CST 2017 on pts/1

-bash-4.2$

-bash-4.2$

-bash-4.2$ repmgr -f /etc/repmgr/10/repmgr.conf standby register

NOTICE: standby node correctly registered for cluster pgcluster with id 2 (conninfo: host=pgdb2 dbname=repmgr user=repmgr)

-bash-4.2$

master/slave

start repmgr10.service

# systemctl start repmgr10.service

master

su - postgres

-bash-4.2$ repmgr -f /etc/repmgr/10/repmgr.conf cluster show

Role      | Name  | Upstream | Connection String

----------+-------|----------|-------------------------------------

* master  | node1 |          | host=pgdb1 dbname=repmgr user=repmgr

standby | node2 | node1    | host=pgdb2 dbname=repmgr user=repmgr

-bash-4.2$

时间: 2024-11-06 22:49:11

postgresql repmgr setup的相关文章

通过EDB-Mtk工具从Oracle向PostgreSQL迁移数据

一. 参考资料 postgresql-10-US.pdf Postgres_Plus_Migration_Guide.pdf www.postgresql.org www.enterprisedb.com *由于技术更新很快,请注意本文的时效性. 二. 环境说明 源数据库:Oracle 12cR2下的一个pdb,服务名aegisdb 目标数据库:postgresql-10.1 三. 准备迁移工具 工具名称: EDB Migration Toolkit(EDB MTK) EDB MTK可以通过Po

Confluence 6 新安装配置数据库字符集编码

Confluence 和你的数据库必须配置使用相同的字符集. Confluence 使用 UTF-8 字符集编码,所以你的数据库也必须配置为使用 UTF-8 (或者与 UTF-8 相同的编码,例如在 Oracle 中使用的 AL32UTF8 编码). 当你在第一次安装 Confluence 的时候,你需要考虑下面的的几个位置配置使用不同的字符集: 当你创建数据库的时候. 当你使用 JDBC 字符串连接数据库时候配置的连接字符串,或者是你使用的数据源(如果你在安装 Confluence 的时候使用

Confluence 6 配置一个数据源连接

这个指南指导你如何配置使用 JNDI 数据源来连接到你的数据库.使用这个类型的连接,Confluence 将会询问应用服务器(Tomcat)中你配置的连接信息. 如果你希望使用 JDBC 的数据库连接方式,请参考下面的指南: Database Setup for PostgreSQL Database Setup for SQL Server Database Setup For MySQL Database Setup for Oracle JDBC 直接连接 Confluence 到数据库为

seam2.2根据已有数据库(postgresql)生成项目

首先呢,这是我向同哥请教的一个文题,然后同哥把整个过程给我解答了一遍,谢谢同哥的乃森及引针啦---- seam2.2根据已有数据库(postgresql)生成项目 一,建数据库 进入pgAdmin新建一个数据库然后用eclipse的插件ErMaster导出sql或者是自己手写sql新建数据表 ,这里新建了一个名为test的数据库 里面有两个表,member和department,为多对一的关系,注意不要忘了设置主键 二,进入seam目录运行 ./seam setup ./seam create-

CentOS 7 安装 PostgreSQL

参考:http://blog.csdn.net/lk10207160511/article/details/50359549##1 1.检查本机是否安装 PostgreSQL $ sudo rpm -aq | grep postgresql 2.从仓库中安装 PostgresSQL 搜索包名: $ yum search postgresql 列出包名,例如可能有: postgresql.i686 : PostgreSQL client programspostgresql.x86_64 : Po

UBUNTU下使用PostgreSql.和nginx安装postfixAdmin2.92版

本文为在Ubuntu14.04中使用PostgreSql和Nginx安装PostfixAdmin2.92版的记录. <! –more– > 需要安装的包 记忆有些模糊,大概列一下: postfix,PostgreSql,postfix-pgsql,php5-pgsql,nginx,php5-fpm,这些包可以通过Ubuntu的包管理安装. 准备工作 需要配置nginx支持php,方法见另外的文. 需要建立PostfixAdmi使用的PostgreSql数据库和数据库用户,并配置可以通过网络登录

PostgreSQL与RPM

如何查看使用PostgreSQL的RPM包安装后的文件目录及相关路径(PostgreSQLRPM的spec文件已经帮我们创建好了postgres用户及postgres组). 查看RPM文档信息:/usr/share/doc/rpm-4.11.1 RPM数据库文件:file /var/lib/rpm/* |grep Berkeley [[email protected] soft_bak]# rpm -qpl postgresql94-9.4.5-1PGDG.rhel7.x86_64.rpm /u

Avoiding PostgreSQL database corruption

TL;DR: Don't ever set fsync=off, don't kill -9 the postmaster then deletepostmaster.pid, don't run PostgreSQL on network file systems. Reports of database corruption on the PostgreSQL mailing list are uncommon, but hardly rare. While a few data corru

Pacemaker+Corosync搭建PostgreSQL集群

https://my.oschina.net/aven92/blog/518928 · PostgreSQL中国社区: http://postgres.cn/index.php/home · PostgreSQL专业1群: 3336901(已满) · PostgreSQL专业2群: 100910388 · PostgreSQL专业3群: 150657323 一.环境 $ cat /etc/redhat-release  CentOS Linux release 7.0.1406 (Core)