复制 PostgreSQL 斯拉夫语多
zh:复制 PostgreSQL 斯拉夫语多
en:Replication PostgreSQL Slavic multi
he:שכפול מרובה PostgreSQL סלאבית
ro:Replicare PostgreSQL slave multi
ru:Multi PostgreSQL славянских репликации
pl:Replikacja wielu słowiańskich PostgreSQL
ja:レプリケーション PostgreSQL スラブ マルチ
ar:النسخ المتماثل السلافية كيو متعدد
de:Replikation PostgreSQL slawischen multi
nl:Replicatie PostgreSQL Slavische multi
it:Replica PostgreSQL slavo multi
pt:Replicação PostgreSQL eslavo multi
es:Replicación multi de PostgreSQL Slavic
fr:Replication PostgreSQL multi slaves
这篇文章是从由软件进行自动翻译。你可以看到这篇文章的源代码
介绍 | ! _ 此页处理异步 PostgreSQL 执行流与一个主节点和两个奴隶的复制。我们斯拉夫语将作为热备用配置,即是说,它将可能运行查询 | ! _ 只读 | ! _ 就这些了。
这种放置上下文 | ! _ 我们有 | ! _ Debian 服务器 | ! _ 最后更新 | ! _ | ! _ 就是我们的主人 | ! _ | ! _ 将一个奴隶 | ! _ | ! _ 将第二个奴隶 | ! _ 指定命令将执行 root 时他们前面 | ! _ 以及 系统用户当他们前面的是 | ! _ PostgreSQL 和预配置的三台服务器的安装 | ! _ 在此部分中的所有命令都都必须在每台服务器上完成。 (作为第一步,它建议要有一个文件 | ! _ 填充的每个服务器,这样比赛 | ! _ 通过调整与您自己的服务器的主机名和 ip 地址 | ! _ 添加存款 APT PostgreSQL | ! _ 我们导入公钥的这笔存款 | ! _ 更新缓存 APT 考虑存款 | ! _ 安装包 ql | ! _ 安装最新的稳定版本是 | ! _ 在撰写这些行 | ! _ 我们定义一个密码 | ! _ 他的选择但安全 | ! _ 并生成 ssh 密钥对 | ! _ 没有密码 | ! _ 为系统 用户 | ! _ 我们复制用户 从与每个服务器公共 ssh 密钥 | ! _ 以来的第一个服务器 | ! _ Postgres | ! _ 在我们的案例 | ! _ 对第二个 | ! _ Postgres | ! _ 对我们来说 | ! _ 和 troisiseme | ! _ Postgres | ! _ 从第二到第一和第三个服务器 | ! _ 从第三到第一和第二个服务器 | ! _ 主配置 | ! _ 只有在母版上做 | ! _ Postgres | ! _ 在我们的案例 | ! _ 它将创建角色 | ! _ 复制用户 | ! _ 注意 | ! _ 它定义的连接限制 | ! _ 因为我们有 | ! _ 斯拉夫语 | ! _ 编辑主要 ql 配置文件 | ! _ 若要配置下面的指令 | ! _ 注意 | ! _ 我们启用存档到我们第二个服务器 | ! _ 自定义您的服务器 ip 地址 | ! _ 为更多的预防措施。我们还定义参数 hot_standby,忽略在主机上,在那里应该降级,奴隶在将来的井。) 现在编辑 postgresql 身份验证文件 | ! _ 若要添加我们复制用户的权限,从我们斯拉夫语或以下行在文件末尾连接 | ! _ 请调整此线根据您复制和网络的用户的名称 | ! _ 或各自的 ip 地址 | ! _ 你斯拉夫语的 | ! _ 它重新启动时要考虑到我们的配置的 postgresql 服务 | ! _ 在根 | ! _ 这将确保该服务已正确启动 | ! _ 斯拉夫人配置 | ! _ 在第一个奴隶 | ! _ 我们开始停止 postgresql 服务 | ! _ 编辑主要 postgresql 配置文件 | ! _ 要配置相同的准则作为主人,由裁缝不仅仅是 ip 第一个奴隶的第二个奴隶在命令 rsync 进行存档或 | ! _ 现在编辑 postgresql 身份验证文件 | ! _ 若要添加我们复制用户的权限,从我们其他服务器连接 | ! _ 这将用时预期这个奴隶晋升大师 | ! _ 注意 | ! _ 带有这种配置类似于我们的主人,这将允许容易促进这个奴隶作为大师以备不时之需。
下面的操作,用户身份登录系统 postgres | ! _ 我们创建的主档案沃尔玛的目标目录 | ! _ 它将移除 postgresql 的数据目录 | ! _ 它使基准备份 | ! _ 自定义的 ip,你的主人和你复制用户的名称 | ! _ 你会问你复制用户的密码 | ! _ 它通过创建文件配置复制 | ! _ 使用以下参数 | ! _ 注意 | ! _ 触发文件是我们创建当我们想要他停止复制的奴隶和将开始接受条目的文件 — — 当你想要促进作为主节点。提升时崩溃的她的主人的奴隶之前, 确保初始主机不会上升,避免腐败。 :
我们返回根和启动服务 | ! _ 这将确保服务已正确启动 | ! _ 如果它将连接到我们的主,我们已经可以检查我们的主和第一个奴隶之间的复制是功能 | ! _ 它将连接到我们的主和它连接在系统 postgres 用户 | ! _ 然后将连接到 postgresql | ! _ 它使扩展的显示和我们检查我们的复制 | ! _ 我们与我们的第一个奴隶的异步流复制做的很好。这一阶段都有一个主复制 | ! _ 经典的奴隶 | ! _ 一个单一的奴隶异步流 | ! _ 关于第二个奴隶 | ! _ 我们 Redid 一样做上第一个奴隶显然适应其主机名中的文件 recovery.conf 和 ip 地址在命令中的存档在主配置文件,如果你还想要启用存档在这第二个奴隶。 3 验证和测试的我们多掌握复制斯拉夫语 | ! _ 它将连接到主和它登录用户 postgres | ! _ 然后将连接到 postgresql | ! _ 它使扩展的显示和我们检查我们的复制 | ! _ 所以那里好我们 | ! _ 我们两个的斯拉夫服务器复制 | ! _ Postgres | ! _ 和 postgres | ! _ 仍连接到主机上的 postgresql,它会创建一个数据基地 | ! _ | ! _ | ! _ 它检查数据库以及在复制我们 | ! _ 斯拉夫语 | ! _ 我们在我们的主人创建的数据库是如此好自动复制到我们两个的斯拉夫语。 8 (若要删除,自从掌握) :
Postgres01 (10.1.1.75) :
Postgres02 (10.1.1.90) :
Postgres03 (10.1.1.199) :
"#" "$".
/etc/hosts () :
# cat /etc/hosts 127.0.0.1 localhost 10.1.1.75 postgres01 10.1.1.90 postgres02 10.1.1.199 postgres03
:
# echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" > /etc/apt/sources.list.d/postgres.list
:
# gpg --keyserver pgpkeys.mit.edu --recv-key 7FCC7D46ACCC4CF8 && gpg -a --export 7FCC7D46ACCC4CF8 | apt-key add -
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key ACCC4CF8 from hkp server pgpkeys.mit.edu
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key ACCC4CF8: public key "PostgreSQL Debian Repository" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK
:
# apt-get update
( 9.5 ) :
# apt-get install postgresql
() () :
# passwd postgres
# su - postgres
$ ssh-keygen
:
(postgres01 ) (postgres02 ) (postgres03) :
root@postgres01:~# su - postgres
postgres@postgres01:~$ ssh-copy-id postgres02
postgres@postgres01:~$ ssh-copy-id postgres03
:
root@postgres02:~# su - postgres
postgres@postgres02:~$ ssh-copy-id postgres01
postgres@postgres02:~$ ssh-copy-id postgres03
:
root@postgres03:~# su - postgres
postgres@postgres03:~$ ssh-copy-id postgres01
postgres@postgres03:~$ ssh-copy-id postgres02
(postgres01 ) :
/ :
# su - postgres
$ psql -c "CREATE USER repuser REPLICATION LOGIN CONNECTION LIMIT 2 ENCRYPTED PASSWORD '<mot de passe repuser>';"
: 2 2
/etc/postgresql/9.5/main/postgresql.conf :
listen_addresses = '*'
wal_level = hot_standby
archive_mode = on
archive_command = 'rsync -av %p postgres@<ip du premier slave>:/var/lib/postgresql/wal_archive/%f'
max_wal_senders = 2
wal_keep_segments = 256
hot_standby = on
: ()
/etc/postgresql/9.5/main/pg_hba.conf :
hostssl replication repuser <ip du réseau de vos serveurs>/24 md5
()
() :
# systemctl restart postgresql
:
root@postgres01:~# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
Active: active (exited) since Thu 2016-06-02 12:06:28 CEST; 22s ago
Process: 77056 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 77056 (code=exited, status=0/SUCCESS)
root@postgres01:~# ps -u postgres u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
postgres 77038 0.0 4.4 227300 21836 ? S 12:06 0:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.
postgres 77040 0.0 0.8 227300 4160 ? Ss 12:06 0:00 postgres: checkpointer process
postgres 77041 0.0 1.0 227300 4968 ? Ss 12:06 0:00 postgres: writer process
postgres 77042 0.0 1.7 227300 8776 ? Ss 12:06 0:00 postgres: wal writer process
postgres 77043 0.0 1.3 227728 6708 ? Ss 12:06 0:00 postgres: autovacuum launcher process
postgres 77044 0.0 0.6 82244 3392 ? Ss 12:06 0:00 postgres: archiver process
postgres 77045 0.0 0.8 82244 4244 ? Ss 12:06 0:00 postgres: stats collector process
:
# systemctl stop postgresql
/etc/postgresql/9.5/main/postgresql.conf :
listen_addresses = '*'
wal_level = hot_standby
archive_mode = on
archive_command = 'rsync -av %p postgres@<ip du second slave>:/var/lib/postgresql/wal_archive/%f'
max_wal_senders = 2
wal_keep_segments = 256
hot_standby = on
/etc/postgresql/9.5/main/pg_hba.conf () :
hostssl replication repuser <ip du réseau de vos serveurs>/24 md5
:
:
# su – postgres
:
$ mkdir /var/lib/postgresql/wal_archive
:
$ rm -rf /var/lib/postgresql/9.5/main
() :
$ pg_basebackup -h <ip de votre master> -D /var/lib/postgresql/9.5/main -U repuser -v -P --xlog
/var/lib/postgresql/9.5/main/recovery.conf :
standby_mode = on
primary_conninfo = 'host=<ip de votre master> port=5432 user=repuser password=<mot de passe de repuser> sslmode=require application_name=<hostname de votre slave>'
trigger_file = '/var/lib/postgresql/9.5/postgres.trigger'
:
:
# systemctl start postgresql
:
# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
Active: active (exited) since Thu 2016-06-02 12:53:42 CEST; 1min 6s ago
Process: 8894 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 8894 (code=exited, status=0/SUCCESS)
# ps -u postgres u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
postgres 8878 0.0 4.4 227308 21892 ? S 12:53 0:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.
postgres 8879 0.0 1.1 227376 5700 ? Ss 12:53 0:00 postgres: startup process recovering 00000001000000000000000
postgres 8880 0.0 0.8 227308 4140 ? Ss 12:53 0:00 postgres: checkpointer process
postgres 8881 0.0 1.0 227308 5236 ? Ss 12:53 0:00 postgres: writer process
postgres 8882 0.0 0.6 82252 3316 ? Ss 12:53 0:00 postgres: stats collector process
postgres 8883 0.0 1.7 238064 8520 ? Ss 12:53 0:00 postgres: wal receiver process streaming 0/30003E0
:
:
# su - postgres
:
$ psql
:
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 78879
usesysid | 16384
usename | repuser
application_name | postgres02
client_addr | 10.1.1.90
client_hostname |
client_port | 49009
backend_start | 2016-06-02 12:53:36.641823+02
backend_xmin |
state | streaming
sent_CRElocation | 0/30004C0
write_location | 0/30004C0
flush_location | 0/30004C0
replay_location | 0/30004C0
sync_priority | 0
sync_state | async
/ ()
:
# su – postgres
:
$ psql
:
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 78879
usesysid | 16384
usename | repuser
application_name | postgres02
client_addr | 10.1.1.90
client_hostname |
client_port | 49009
backend_start | 2016-06-02 12:53:36.641823+02
backend_xmin |
state | streaming
sent_location | 0/5000140
write_location | 0/5000140
flush_location | 0/5000140
replay_location | 0/5000140
sync_priority | 0
sync_state | async
-[ RECORD 2 ]----+------------------------------
pid | 82725
usesysid | 16384
usename | repuser
application_name | postgres03
client_addr | 10.1.1.199
client_hostname |
client_port | 51754
backend_start | 2016-06-02 14:31:43.759683+02
backend_xmin |
state | streaming
sent_location | 0/5000140
write_location | 0/5000140
flush_location | 0/5000140
replay_location | 0/5000140
sync_priority | 0
sync_state | async
2 (postgres02 03).
(ex : checkrep) :
postgres=# CREATE DATABASE checkrep;
2 :
root@postgres02:~# su - postgres
postgres@postgres02:~$ psql
psql (9.5.3)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
checkrep | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
root@postgres03:~# su - postgres
postgres@postgres03:~$ psql
psql (9.5.3)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
checkrep | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
:
postgres=# DROP DATABASE checkrep;
开启评论自动刷新