栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Centos 7 在线安装 PostgreSQL 12

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Centos 7 在线安装 PostgreSQL 12

目录
    • 一、数据库安装
    • 二、配置防火墙
    • 三、初始化用户名和密码
    • 四、修改配置文件,配置远程访问
    • 五、重启服务
    • 六、连接测试

一、数据库安装

官网地址:https://www.postgresql.org/download/linux/redhat/

1.1 安装存储库RPM文件

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

1.2 安装PostgreSQL

yum install -y postgresql12-contrib postgresql12-server

1.3 验证是否安装成功

rpm -aq | grep postgres

1.4 初始化数据库

/usr/pgsql-12/bin/postgresql-12-setup initdb

1.5 设置开机自启动,启动PostgreSQL服务

systemctl enable postgresql-12
systemctl start postgresql-12
二、配置防火墙
# 查询5432端口是否开放
firewall-cmd --query-port=5432/tcp
# 开放5432端口(5432为PostgreSQL端口)
firewall-cmd --zone=public --add-port=5432/tcp --permanent
# 重启
firewall-cmd --reload
# 查看防火墙是否放行5432端口
firewall-cmd --zone=public --list-ports
三、初始化用户名和密码
# 切换用户,执行后提示符会变为'-bash-4.2$'
su - postgres
# 登录数据库,执行后提示符变为 'postgres=#'
psql -U postgres
# 设置密码,设置postgres用户密码为postgres
ALTER USER postgres WITH PASSWORD 'postgres';
ALTER USER postgres WITH PASSWORD '密码';
# 退出数据库
q
# 备注其他:列出所有库l  列出所有用户du 列出库下所有表d
# 登出
exit
四、修改配置文件,配置远程访问


4.1 修改监听postgresql.conf

vim /var/lib/pgsql/12/data/postgresql.conf
# 修改如下内容:
#listen_addresses = 'localhost'  为  listen_addresses='*'


4.2 修改pg_hba.conf

vim /var/lib/pgsql/12/data/pg_hba.conf
# 修改如下内容,信任指定服务器连接
# 如果想允许所有IPv4地址,则加入一行host all all 0.0.0.0/0 md5。IPv6方法类似。
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               md5

五、重启服务

切换到root用户,重启postgresql服务

systemctl restart postgresql-12
六、连接测试

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/276943.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号