postgresql集群规划

xiaoxiao2021-02-28  54

1 私有IP规划

2台服务做主备,私有IP单独划分网段,加上网络地址和广播地址,至少需要4个ip. PostgreSQL配置pg_hba.conf免密码登录时需要用到网络地址,同时划分较小的子网保证安全性,方便服务器之间的配置管理. 示例采用192.168.1.200/29网段计算.

1.1 网段实际使用数量计算方法

2^(32-29) - 2(网络地址和广播地址) = 6(网络地址个数)

1.2 转换IP

--转换192.168.1.200 select cast( --pg十进制时没有无符号32位整数,因此要转换为bigint (cast(192 as bit(32)) << 24) | (cast(168 as bit(32)) << 16) | (cast(1 as bit(32)) << 8) | (cast(200 as bit(32))) as bigint), --二进制 (cast(192 as bit(32)) << 24) | (cast(168 as bit(32)) << 16) | (cast(1 as bit(32)) << 8) | (cast(200 as bit(32))) --输出结果为 --3232235976,11000000101010000000000111001000 --反算回来 select (3232235976>>24)&255 ,(3232235976 >>16)&255,(3232235976 >>8)&255,(3232235976)&255

1.3 计算网络地址

计划的私有网段是192.168.1.200/29,计算网络地址方法为

--计算起始网段,取ip的最后一段,本例中为200 select 200 >>(32-29)<<(32-29) --200,符合预计 select 191 >>(32-29)<<(32-29) --184(191的起网络地址是184)

1.4 计算掩码

计划的私有网段是192.168.1.200/29,计算掩码方法为

--计算起始网段,取ip的最后一段,本例中为200 select cast((cast(255 as bit(8)) << (32-29)) as int) --248(因此得到掩码为255.255.255.248)

1.5 计算可用的ip段

注意可用IP段必须去除第一个网络地址和最后一个广播地址,因此在本例中实际可用的ip地址是6个.

#200网段时可用的ip段 11001000-11001111 200 207 #191网段时可用的ip段10111000‬-10111111 184 191

因此192.168.1.200/29的可用ip为8个,分别是:

192 168 1 200 11000000 10101000 00000001 11001000 #当前网段的网络地址,不能使用 --- 192 168 1 201 11000000 10101000 00000001 11001001 --- 192 168 1 202 11000000 10101000 00000001 11001010 --- 192 168 1 203 11000000 10101000 00000001 11001011 --- 192 168 1 204 11000000 10101000 00000001 11001100 --- 192 168 1 205 11000000 10101000 00000001 11001101 --- 192 168 1 206 11000000 10101000 00000001 11001110 --- 192 168 1 207 11000000 10101000 00000001 11001111 #当前网段的广播地址,不能使用 ---

最后得到结果

#网络地址个数计算方式 IP段范围 192.168.1.200-208 网络地址 192.168.1.200 广播地址 192.168.1.208 掩码 255.255.255.248 主机范围 192.168.1.201 - 192.168.1.206

2 主机规划

最多可以支持的主机

主机名IP用途192.168.1.201虚拟ip,对外提供服务pgser01192.168.1.202PostgreSQL masterpgser02192.168.1.203PostgreSQL slave 1pgser03192.168.1.204PostgreSQL slave 2pgser04192.168.1.205PostgreSQL slave 3pgser05192.168.1.206PostgreSQL slave 4

实际需要的主机

主机名IP用途192.168.1.201虚拟ip,对外提供服务pgser01192.168.1.202PostgreSQL masterpgser02192.168.1.203PostgreSQL slave 1

3 配置pg_hba

服务器安装好后,配置pg_hba.conf,服务器之间使用免密码登录.

vim /data/pgdata/pg_hba.conf

添加以下内容

host replication repl 192.168.1.200/29 trust #允许ip为192.168.1.200-206的服务器使用流复制,repl为pg流复制的用户名 host all all 192.168.1.200/29 trust #服务器之间相互信任,不需要登录密码 host all all 0.0.0.0/0 md5 #其它主机需要密码

为提升系统安全性,数据库尽量不要使用postgres用户,单独创建一个用户(用户名为repl,具有replication login connection权限,最多允许3个并发连接,可以根据实际情况加大)用于流复制.

create user repl replication login connection limit 3 encrypted password '!@#$%^';
转载请注明原文地址: https://www.6miu.com/read-2625256.html

最新回复(0)