Centos7 Yum源安装postgresql (在线安装)

Centos7 Yum安装postgresql 13

一:PostgreSQ官网下载地址

https://www.postgresql.org/download/
选择你需要下载的环境
第一个选择的是系统,第二个是选择你环境的发行版本。
这里我们系统以Linux中的Centos为例,所以这里我们选择的是Red Hat/Centos

选择你的系统环境
1.为选择需要安装的Postgresql版本,选择13,默认就会安装13下面最新的版本。
2.选择你系统版本号
3.选择系统的架构(一般都是默认的,且Centos系统都是x86架构)
4.就是查找出来,对应你选择的系统版本安装Postgresql需要执行的命令

下面是查询出来安装postgresql的命令,将下面的命令一一执行即可完成postgresql的安装。
下面带有# 号的为注释,不需要在系统中执行。

二:安装 postgresql-13

# Install the repository RPM:这里的意思是“安装存储库RPM”
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
 
# Install PostgreSQL:这里的意思是“安装PostgreSQL”
sudo yum install -y postgresql13-server
 
# Optionally initialize the database and enable automatic start:这里的意思是 “初始化数据库并设置为开机自动启动”
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13

postgresql在安装时默认添加用户postgres

su - postgres
psql


我们来设置密码后再退出

postgres=# ALTER USER postgres WITH PASSWORD '所需要设置的密码';
ALTER ROLE
postgres=# \q

三:配置postgresql-13

配置远程连接,需要设置pg_hba.conf

vim /var/lib/pgsql/13/data/pg_hba.conf

把local和host那三行内容给注释掉,在下面自己配置一条

host    all             all              0.0.0.0/0               md5


wq 保存退出
配置远程连接的地址和端口号

vim /var/lib/pgsql/13/data/postgresql.conf

放开listen_addresses和port的注释并把listen_addresses后的localhost改成*

wq保存退出
查看postgresql是否已经在运行

[root@lizhiqi ~]# ps -ef | grep postgresql
root     16271 16205  0 12:49 pts/0    00:00:00 grep --color=auto postgresql
[root@lizhiqi ~]#

在服务器上放行postgresql 的端口

添加指定需要开放的端口:
firewall-cmd --add-port=5432/tcp --permanent
重新载入添加的端口:
firewall-cmd --reload
查询指定端口是否开启成功:
firewall-cmd --query-port=5432/tcp

重启服务:

systemctl restart postgresql-13


启动postgresql命令

systemctl start postgresql

查看postgresql运行状态命令

systemctl status postgresql
ALTER USER postgres WITH PASSWORD 'postgres';
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值