2021-02-23 postgresql11.7 离线主从安装, 并安装pgpool使用虚拟ip

该博客详细介绍了如何在CentOS 7.5环境下,离线安装PostgreSQL 11.7主从服务器,并通过pgpool配置虚拟IP实现主从切换和负载均衡。内容包括环境准备、RPM包安装、数据库集群初始化、pg_hba.conf和postgresql.conf的修改、主从同步、pgpool安装及配置,以及pgpool的启动与测试。
摘要由CSDN通过智能技术生成

postgresql11.7 离线主从安装, 并安装pgpool使用虚拟ip

PG官方下载地址:https://yum.postgresql.org/rpmchart/

离线下载教程地址https://blog.csdn.net/semian7633/article/details/106266935

1.环境准备

1.1软件

  • Centos7.5
  • PostgreSQL11.7
主机名 ip 主从 备注
node149 192.168.73.149  
node150 192.168.73.150  
vip 192.168.73.111 (虚拟ip)  

首先做好 两台服务器的主机互信

1.2 安装rpm包

[root@node149 pg11.7]# ll
总用量 7512
-rw-r--r-- 1 root root 1731368 7月   6 11:38 postgresql11-11.7-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root  621740 7月   6 11:38 postgresql11-contrib-11.7-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root  369976 7月   6 11:38 postgresql11-libs-11.7-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 4963356 7月   6 11:38 postgresql11-server-11.7-1PGDG.rhel7.x86_64.rpm
[root@node149 pg11.7]# rpm -ivh postgresql11-11.7-1PGDG.rhel7.x86_64.rpm
警告:postgresql11-11.7-1PGDG.rhel7.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 442df0f8: NOKEY
准备中...                          ################################# [100%]
        软件包 postgresql11-11.7-1PGDG.rhel7.x86_64 已经安装
[root@node149 pg11.7]# rpm -ivh  postgresql11-contrib-11.7-1PGDG.rhel7.x86_64.rpm
警告:postgresql11-contrib-11.7-1PGDG.rhel7.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 442df0f8: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:postgresql11-contrib-11.7-1PGDG.r################################# [100%]
[root@node149 pg11.7]# rpm -ivh postgresql11-libs-11.7-1PGDG.rhel7.x86_64.rpm
警告:postgresql11-libs-11.7-1PGDG.rhel7.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 442df0f8: NOKEY
准备中...                          ################################# [100%]
        软件包 postgresql11-libs-11.7-1PGDG.rhel7.x86_64 已经安装
[root@node149 pg11.7]# rpm -ivh postgresql11-server-11.7-1PGDG.rhel7.x86_64.rpm
警告:postgresql11-server-11.7-1PGDG.rhel7.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 442df0f8: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:postgresql11-server-11.7-1PGDG.rh################################# [100%]
[root@node149 pg11.7]# rpm -ivh postgresql11-devel-11.7-1PGDG.rhel7.x86_64.rpm
警告:postgresql11-devel-11.7-1PGDG.rhel7.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 442df0f8: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:postgresql11-devel-11.7-1PGDG.rhe################################# [100%]


在/etc/pfofile 下面设置环境变量

export PGHOME=/usr/pgsql-11
export PGDATA=/var/lib/pgsql/11/data/
export PATH=$PGHOME/bin:$PATH

初始化数据库集群,这个集群是指单机下的数据库集合,初始化后存在两个自带的数据库postgres和template1

[root@node149 opt]# chown -R postgres:postgres /usr/pgsql-11/
[root@node149 opt]# su - postgres
上一次登录:一 7月  6 14:06:12 CST 2020pts/3 上
-bash-4.2$  initdb -k -D /usr/pgsql-11/data
属于此数据库系统的文件宿主为用户 "postgres".
此用户也必须为服务器进程的宿主.
数据库簇将使用本地化语言 "zh_CN.UTF-8"进行初始化.
默认的数据库编码已经相应的设置为 "UTF8".
initdb: 无法为本地化语言环境"zh_CN.UTF-8"找到合适的文本搜索配置
缺省的文本搜索配置将会被设置到"simple"

禁止为数据页生成校验和.

创建目录 /usr/pgsql-11/data ... 成功
正在创建子目录 ... 成功
选择默认最大联接数 (max_connections) ... 100
选择默认共享缓冲区大小 (shared_buffers) ... 128MB
selecting default timezone ... Asia/Shanghai
选择动态共享内存实现 ......posix
创建配置文件 ... 成功
正在运行自举脚本 ...成功
正在执行自举后初始化 ...成功
同步数据到磁盘...成功

警告:为本地连接启动了 "trust" 认证.
你可以通过编辑 pg_hba.conf 更改或你下次
执行 initdb 时使用 -A或者--auth-local和--auth-host选项.

成功。您现在可以用下面的命令开启数据库服务器:

    pg_ctl -D /usr/pgsql-11/data -l logfile start

-bash-4.2$

修改postgresql.conf文件

listen_addresses = '*'
port = 15042
log_directory = '/usr/pgsql-11/log' # 这个文件夹不存在则新建

改pg_hba.conf文件,增加

host all smoke 0.0.0.0/0 trust

启动postgresql服务

[root@node149 pg11.7]# chown -R postgres:postgres /var/run/postgresql
-bash-4.2$ pg_ctl -D /usr/pgsql-11/data -l /usr/pgsql-11/log/pgsql.log start

在可以联网的服务器上在/etc/yum.repos.d 放入一下文件,文件在附件

[root@node149 postgis]# ll /etc/yum.repos.d/
总用量 24
-rw-r--r-- 1 root root 2523 7月   2 11:18 CentOS-Base.repo
-rw-r--r-- 1 root root 1050 9月  18 2019 epel.repo
-rw-r--r-- 1 root root 1149 9月  18 2019 epel-testing.repo
-rw-r--r-- 1 root root 9154 4月  27 18:40 pgdg-redhat-all.repo
[root@node149 postgis]#

安装这些外部的依赖包

[root@node149 postgis]# ll
总用量 19452
-rw-r--r--  1 root root  173480 4月   4 04:49 boost-serialization-1.53.0-28.el7.x86_64.rpm
-rw-r--r--  1 root root  540436 10月  2 2017 cfitsio-3.370-10.el7.x86_64.rpm
-rw-r--r--  1 root root  259816 9月  30 2019 CGAL-4.7-1.rhel7.1.x86_64.rpm
-rw-r--r--  1 root root   64540 7月  10 2014 CharLS-1.0-5.el7.x86_64.rpm
-rw-r--r--  1 root root   32938 2月  23 2018 freexl-1.0.5-1.el7.x86_64.rpm
-rw-r--r--  1 root root 7414676 5月   5 18:22 gdal30-libs-3.0.4-4.rhel7.x86_64.rpm
-rw-r--r--  1 root root  605872 5月   1 20:27 geos38-3.8.1-2.rhel7.x86_64.rpm
-rw-r--r--  1 root root 1671708 5月   9 2019 hdf5-1.8.12-11.el7.x86_64.rpm
-rw-r--r--  1 root root   34814 2月  12 2019 libaec-1.0.4-1.el7.x86_64.rpm
-rw-r--r--  1 root root  433272 7月  19 2014 libdap-3.13.1-2.el7.x86_64.rpm
-rw-r--r--  1 root root   96004 5月   4 22:17 libgeotiff16-1.6.0-1.rhel7.x86_64.rpm
-rw-r--r--  1 root root  307596 8月  23 2019 libgfortran-4.8.5-39.el7.x86_64.rpm
-rw-r--r--  1 root root   32864 2月   5 2014 libgta-1.0.4-1.el7.x86_64.rpm
-rw-r--r--  1 root root  194380 8月  23 2019 libquadmath-4.8.5-39.el7.x86_64.rpm
-rw-r--r--  1 root root  200876 7月   4 2014 mesa-libGLU-9.0.0-4.el7.x86_64.rpm
-rw-r--r--  1 root root  709772 12月 13 2015 netcdf-4.3.3.1-5.el7.x86_64.rpm
-rw-r--r--  1 root root  223692 9月  30 2019 ogdi41-4.1.0-2.rhel7.x86_64.rpm
-rw-r--r--  1 root root  156596 2月  20 00:18 openjpeg2-2.3.1-3.el7_7.x86_64.rpm
-rw-r--r--  1 root root  199736 7月   4 2014 perl-DBD-Pg-2.19.3-4.el7.x86_64.rpm
-rw-r--r--  1 root root   86328 4月   4 05:04 perl-version-0.99.07-6.el7.x86_64.rpm
drwxr-xr-x  2 root root     154 7月   6 15:59 postgis23
-rw-r--r--  1 root root 2121432 5月   4 20:49 proj70-7.0.1-1.rhel7.x86_64.rpm
-rw-r--r--  1 root root   28600 11月 21 2016 protobuf-c-1.0.2-3.el7.x86_64.rpm
-rw-r--r--  1 root root   14796 9月  30 2019 SFCGAL-1.3.1-2.rhel7.x86_64.rpm
-rw-r--r--  1 root root 1731116 9月  30 2019 SFCGAL-libs-1.3.1-2.rhel7.x86_64.rpm
-rw-r--r--  1 root root  638488 2月   7 01:31 sqlite33-3.30.1-1.rhel7.x86_64.rpm
-rw-r--r--  1 root root  562264 2月   7 01:31 sqlite33-libs-3.30.1-1.rhel7.x86_64.rpm
-rw-r--r--  1 root root  423152 8月  23 2019 unixODBC-2.3.1-14.el7.x86_64.rpm
-rw-r--r--  1 root root  899740 3月   5 01:04 xerces-c-3.1.1-10.el7_7.x86_64.rpm
drwxr-xr-x 12 root root     174 7月   6 16:57 yilai
[root@node149 postgis]#

创建数据库replica

-bash-4.2$ createdb -h localhost -p 15432 gisdb  #创建gisdb的数据库
-bash-4.2$ psql -h localhost -p 15432 -d gisdb  #连接gisdb数据库
ps
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值