Cenots7 离线安装部署PostgreSQL 的详细过程(centos7离线安装依赖包)不要告诉别人

随心笔谈11个月前发布 admin
106 0



目录1 PostgreSQL源码包下载并复制1.1PostgreSQL源码包下载:1.2复制源码包至服务器2基于PostgreSQL源码安装2.1解压缩源码2.2检查环境 指定安装路径2.3编译2.4安装3.postgresql的配置3.1创建用户和组3.2创建数据库库文件存储目录、给postgres赋予权限3.3初始化数据库目录3.4启动停止postgres14.53.4.1启动3.4.2停止3.4.3权限不足的解决方法3.4.4修改管理员密码3.5开启远程访问3.5.1开启远程访问3.5.2配置认证方式3.5.3测试连接

访问PostgreSQL官网

选择所需版本进行下载,本次下载安装版本为v14.5

使用SSH终端工具,远程连接服务器,并使用终端工具提供的上传工具,把postgresql-14.5.tar.gz 上传至服务器/usr/local/postgres14.5/src 文件夹下

建目录文件夹的命令

[root@localhost local]# mkdir -p /usr/local/postgres14.5/src

切换到源码目录

[root@localhost local]# cd /usr/local/postgres14.5/src

解压gz

[root@localhost src]# gunzip postgresql-14.5.tar.gz

解压tar

[root@localhost src]# tar -xf postgresql-14.5.tar

检查环境,指定安装目录和服务端口

[root@localhost postgresql-14.5]# https://www.jb51.net/article/configure –prefix=/usr/local/pgsql-14.5 –with-pgport=5435

注意:使用configure脚本检查,无错误或警告提示方可进行下一步编译操作,若有错误或警告提示需根据提示进行相关操作。

[root@localhost postgresql-14.5]# make

[root@localhost postgresql-14.5]# make install

安装位置在2.2 由 –prefix=/usr/local/pgsql-14.5中指定

提示:在本文档的描述的安装过程前,系统已经安装有其它版本的PostgreSQL,本次安装非升级安装。

创建组

[root@localhost ~]# groupadd postgres

创建用户并加入组

[root@localhost pgsql-14.5]#useradd -g postgres postgres

创建数据库库文件存储目录data

[root@localhost DISK-8T]# mkdir -p /run/media/postgres/data

data目录授权给postgres.postgres

[root@localhost DISK-8T]# chown postgres.postgres /run/media/postgres/data

切换用户

[root@localhost bin]# su – postgres

初始化数据 -D指定初始化创建的数据库的文件路径

-bash-4.2$ /usr/local/pgsql-14.5/bin/initdb -D /run/media/postgres/data

提示:红框中标注为postgres14.5的启动方式

/usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile start

3.4.1启动

切换用户 PG是禁止使用超级管理员来运行该命令的

[root@localhost lib]# su postgres

启动数据库

-bash-4.2$ /usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile start

3.4.2停止

切换到postgres用户

[root@localhost pgsql]# su – postgres

上一次登录:三 10月 19 13:31:02 CST 2022pts/0 上

-bash-4.2$ /usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile stop

3.4.3权限不足的解决方法

切换到postgres用户,运行数据库启动命令报logfile: 权限不够,可按下列方法解决:

编辑sudoers配置文件 ,按下图红框所示,给postgres用户添加提升权限的配置

[root@localhost bin]# vi /etc/sudoers

3.4.4修改管理员密码

说明:因服务器存在多个版本的PG,因此先在/ usr / bin中创建一个postgre14.5版本对应的psql链接

[root@localhost psql]# ln -s /usr/local/pgsql-14.5/bin/psql /usr/bin/psql145

切换用户

[root@localhost psql]# su – postgres

上一次登录:三 10月 19 14:08:33 CST 2022pts/0 上

运行postgre14.5 对应的psql

-bash-4.2$ psql145

psql145 (14.5)

Type “help” for help.

postgres=#

修改管理员密码

\q再exit退出

postgres=# alter role postgres with password ‘123’;

3.5.1开启远程访问

切换到数据库目录

[root@localhost pgsql]# cd /run/media/postgres/data

修改postgresql.conf 配置文件,开启远程访问

把listen_addresses=’localhost’,修改成 listen_addresses=’*’

可在此文件中修改服务端口

[root@localhost postgre14.5Data]# vi postgresql.conf

3.5.2配置认证方式

修改pg_hba.conf 添加远程访问的认证方式

未尾添加 host all all 0.0.0.0/0 md5

[root@localhost postgre14.5Data]# vi pg_hba.conf

3.5.3测试连接

使用Navicat测试数据库连接

到此这篇关于Cenots7 离线安装部署PostgreSQL 的文章就介绍到这了,更多相关PostgreSQL 离线安装部署内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:postgresql数据库安装部署搭建主从节点的详细过程(业务库)CentOS7使用yum安装PostgreSQL和PostGIS的方法CentOS7 安装 PostgreSQL11的方法步骤

© 版权声明

相关文章