安装postgresql数据库的两种方法

10 篇文章 4 订阅

YUM源安装

我们先用yum源将postgresql安装,如果没有就用yum clean all命令更新yum源,还是没有的话就到网上去下载安装包,然后再将安装包发送给虚拟机就好了,我现在先弄yum安装,下载安装的在下面,还请自行跳过。

安装命令:yum install -y *postgresql*

[root@localhost ~]# yum install -y *postgresql*
BaseOS                                                                                                                                                                             2.0 MB/s | 3.9 kB     00:00    
AppStream                                                                                                                                                                          2.3 MB/s | 4.3 kB     00:00    
Dependencies resolved.
===================================================================================================================================================================================================================
 Package                                                   Architecture                         Version                                                              Repository                               Size
…………                                      

Complete!

下载安装

我给大家准备好了资源,大家可以用我的,也可以用自己的。

百度网盘:

链接:https://pan.baidu.com/s/1ZfT5ZbcIJdDGpE0xBXV07A
提取码:4444

下载好后就找的它的位置,我的是D盘。

我们要确保两者网络的连通性,在主机里用win键+R键打开允许,输入cmd。

然后就是ping一下虚拟机的ip地址,ping通了后就将文件发送给虚拟机。

如果ping不通或想要知道语法格式的可以看一下《安装tomcat的详细步骤》这里面有ping不通的解决方法和scp的语法格式。

C:\Users\lenovo>ping 20.20.20.24

正在 Ping 20.20.20.24 具有 32 字节的数据:
来自 20.20.20.24 的回复: 字节=32 时间<1ms TTL=64
来自 20.20.20.24 的回复: 字节=32 时间<1ms TTL=64
来自 20.20.20.24 的回复: 字节=32 时间<1ms TTL=64

20.20.20.24 的 Ping 统计信息:
    数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms
Control-C
^C

C:\Users\lenovo>d:
D:\>dir
 驱动器 D 中的卷没有标签。
 卷的序列号是 5C1C-6DEA

 D:\ 的目录

2021/08/09  12:36    <DIR>          2345Downloads
2022/10/04  09:30        10,577,344 apache-tomcat-8.5.78.tar.gz
2021/11/04  15:55    <DIR>          ensp
2021/08/28  10:11    <DIR>          ESXI-6.7.0-
2021/05/23  16:21    <DIR>          GameDownload
2022/10/03  19:46    <DIR>          kinsttemp
2021/08/10  10:48    <DIR>          KuGou
2022/10/05  14:53        28,988,974 postgresql-14.5.tar.gz
2021/07/07  08:58    <DIR>          QMDownload
2021/10/22  11:39    <DIR>          SogouInput
2022/06/25  09:03    <DIR>          vm虚拟机
2021/08/31  16:40    <DIR>          WdGame
2022/10/03  19:49    <DIR>          向日葵
2022/07/15  20:22    <DIR>          浏览器下载
2021/03/12  14:13    <DIR>          驱动
               2 个文件     39,566,318 字节
              13 个目录 133,157,396,480 可用字节

D:\>scp postgresql-14.5.tar.gz root@20.20.20.24:/usr/local
root@20.20.20.24's password:
postgresql-14.5.tar.gz                                                                100%   28MB  69.3MB/s   00:00

上传之后我们就来到虚拟机里查看一波,我们是将它放/usr/local目录里的,我们就来到/usr/local目录里用ls命令查看postgresql-14.5.tar.gz安装包,确定无误后就将它压缩。

[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  postgresql-14.5.tar.gz  sbin  share  src
[root@localhost local]# tar -zxvf postgresql-14.5.tar.gz 
postgresql-14.5/
postgresql-14.5/.dir-locals.el
postgresql-14.5/contrib/
postgresql-14.5/contrib/tcn/
postgresql-14.5/contrib/tcn/tcn.control
postgresql-14.5/contrib/tcn/Makefile
postgresql-14.5/contrib/tcn/tcn.c
postgresql-14.5/contrib/tcn/tcn--1.0.sql
postgresql-14.5/contrib/sslinfo/
postgresql-14.5/contrib/sslinfo/sslinfo--1.0--1.1.sql
postgresql-14.5/contrib/sslinfo/sslinfo.control
postgresql-14.5/contrib/sslinfo/sslinfo.c
postgresql-14.5/contrib/sslinfo/Makefile
……

压缩完后我们还要做一些准备工作,首先就是创建一个普通用户pp,然后设置密码,弄好后就来创建一个文件夹做为postgresql的安装路径,还有postgresql的日志,但不过我们可以改一下压缩好后的文件夹的名字,也可以不改

[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  postgresql-14.5  postgresql-14.5.tar.gz  sbin  share  src
[root@localhost local]# mv postgresql-14.5 postgersql   #修改压缩后的文件夹的名字
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  postgersql  postgresql-14.5.tar.gz  sbin  share  src
[root@localhost local]# useradd pp   #创建pp用户
[root@localhost local]# passwd pp    #设置pp用户的密码
Changing password for user pp.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost local]# mkdir -p /opt/pgsql/data     #创建安装路径
[root@localhost local]# chown pp /opt/pgsql/data     #给予pp用户的权利
[root@localhost local]# touch /opt/pgsql/pgsql.log    #创建日志
[root@localhost local]# chown pp /opt/pgsql/pgsql.log 

现在就可以用命令安装了,先进入解压好的文件夹里,然后查看configure文件,然后安装,安装命令:

命令:./configure --prefix=/opt/pgsql/    #注意前面有一个点,那个点不能少,还有是两个-,不是一个-。

语法格式:./configure --prefix=安装路径

[root@localhost local]# cd postgersql/
[root@localhost postgersql]# ls
aclocal.m4  config  configure  configure.ac  contrib  COPYRIGHT  doc  GNUmakefile.in  HISTORY  INSTALL  Makefile  README  src
[root@localhost postgersql]# ./configure --prefix=/opt/pgsql/
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
……

然后切换用户pp,初始化postgresql数据库,中间还会跳出一个要求输入administrator管理员的密码界面,这个不用慌,直接输入密码就好了,如图:

这个就是认证要求,意思是该软件不是来自可信任的来源,请不要安装此包,除非您确定这样做是安全的。然后就是输入管理员的密码,输入之后回车就行。

[root@localhost postgersql]# su - pp
[pp@localhost ~]$ pg_ctl -D /opt/pgsql/data -l /opt/pgsql/pgsql.log strat
bash: pg_ctl: command not found...
Install package 'postgresql-server' to provide command 'pg_ctl'? [N/y] y


 * Waiting in queue... 
 * Loading list of packages.... 
The following packages have to be installed:
 libpq-13.5-1.el8.x86_64	PostgreSQL client library
 postgresql-10.19-1.module+el8.6.0+802+f92d3c38.x86_64	PostgreSQL client programs
 postgresql-server-10.19-1.module+el8.6.0+802+f92d3c38.x86_64	The programs needed to create and run a PostgreSQL server
Proceed with changes? [N/y] y


 * Waiting in queue... 
 * Waiting for authentication... 
 * Waiting in queue... 
 * Loading list of packages.... 
 * Requesting data... 
 * Testing changes... 
 * Installing packages... 
pg_ctl: unrecognized operation mode "strat"
Try "pg_ctl --help" for more information.

好了这个就安装好了。

有什么不懂疑惑的就评论私信我,看到百分百会回的!

玩linux和Windows的小伙伴可以私信我要资源,我都会尽力搞干货发给大家的。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值