赞
踩
# 创建repo镜像源文件
touch /etc/yum.repos.d/pgsql12.repo
# 编辑配置文件
vi /etc/yum.repos.d/pgsql12.repo
[pgdg12]
name=PostgreSQL 12 for RHEL/CentOS $releasever - $basearch
baseurl=https://mirrors.aliyun.com/postgresql/repos/yum/12/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/postgresql/repos/yum/RPM-GPG-KEY-PGDG
repo_gpgcheck = 1
# 更新yum缓存
yum makecache
# 安装postgresql12-server
yum install postgresql12-server
# 编辑服务配置 修改数据库目录位置
# Environment=PGDATA=/opt/pgsql/12/data
vi /usr/lib/systemd/system/postgresql-12.service
# 初始化数据库
/usr/pgsql-12/bin/postgresql-12-setup initdb
# 修改配置文件 允许来自任何主机的连接
# listen_addresses = '*'
vi /opt/pgsql/12/data/postgresql.conf
# 修改配置文件 授权主机密码连接
# host all all 0.0.0.0/0 md5
vi /opt/pgsql/12/data/pg_hba.conf
# 启动服务
systemctl start postgresql-12.service
# 开机自动启动
systemctl enable postgresql-12.service
# 切换到postgres用户
su -l postgres
# 登录pg数据库
psql
# 设置postgres密码
\password postgres
# 放行postgresql服务
firewall-cmd --zone=public --add-service=postgresql --permanent
# 重载防火墙
firewall-cmd --reload
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。