pg配置国内数据源安装

步骤一:# 备份现有的 yum 源配置文件

复制代码
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

步骤二:#配置清华源

复制代码
sudo tee /etc/yum.repos.d/CentOS-Base.repo << 'EOF'
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-7
EOF

步骤三:清理并重建 yum 缓存

复制代码
# 清理所有 yum 缓存
sudo yum clean all
sudo rm -rf /var/cache/yum

# 重建 yum 缓存
sudo yum makecache

# 测试 yum 是否正常工作
sudo yum check-update

步骤四:安装 PostgreSQL 15

复制代码
# 1. 添加 PostgreSQL 官方仓库
sudo tee /etc/yum.repos.d/pgdg.repo << 'EOF'
[pgdg15]
name=PostgreSQL 15 for RHEL/CentOS 7 - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-7-$basearch
enabled=1
gpgcheck=1
gpgkey=https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG-15
EOF

# 2. 更新缓存并安装
sudo yum makecache
sudo yum install -y postgresql15-server postgresql15-contrib

# 如果上面的官方源下载慢,可以使用国内镜像
sudo sed -i 's|https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-7-$basearch|https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/15/redhat/rhel-7-$basearch|g' /etc/yum.repos.d/pgdg.repo

步骤五:初始化和配置 PostgreSQL

复制代码
# 1. 初始化数据库
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb

# 2. 启动 PostgreSQL 服务
sudo systemctl start postgresql-15

# 3. 设置开机自启
sudo systemctl enable postgresql-15

# 4. 查看服务状态
sudo systemctl status postgresql-15

# 5. 修改 postgres 用户密码
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'YourNewPassword123';"

# 6. 允许远程连接(可选)
# 修改配置文件
sudo vi /var/lib/pgsql/15/data/postgresql.conf
# 找到 listen_addresses,修改为:listen_addresses = '*'

# 修改认证配置
sudo vi /var/lib/pgsql/15/data/pg_hba.conf
# 在文件末尾添加:
# host    all             all             0.0.0.0/0               md5

# 7. 重启 PostgreSQL 使配置生效
sudo systemctl restart postgresql-15

# 8. 配置防火墙(如果需要)
sudo firewall-cmd --permanent --add-port=5432/tcp
sudo firewall-cmd --reload

验证安装

复制代码
# 检查 PostgreSQL 版本
sudo -u postgres psql --version

# 登录 PostgreSQL
sudo -u postgres psql

# 在 psql 命令行中执行:
\conninfo
\l  # 列出数据库
\q  # 退出
相关推荐
草莓熊Lotso20 小时前
Linux 文件描述符与重定向实战:从原理到 minishell 实现
android·linux·运维·服务器·数据库·c++·人工智能
历程里程碑20 小时前
Linux22 文件系统
linux·运维·c语言·开发语言·数据结构·c++·算法
岳麓丹枫00121 小时前
PostgreSQL 中 pg_wal 目录里的 .ready .done .history 文件的生命周期
数据库·postgresql
寻星探路1 天前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑
java·开发语言·网络·python·http·ai·https
ValhallaCoder1 天前
hot100-二叉树I
数据结构·python·算法·二叉树
wdfk_prog1 天前
[Linux]学习笔记系列 -- [drivers][input]input
linux·笔记·学习
数据知道1 天前
PostgreSQL 核心原理:如何利用多核 CPU 加速大数据量扫描(并行查询)
数据库·postgresql
盟接之桥1 天前
盟接之桥说制造:引流品 × 利润品,全球电商平台高效产品组合策略(供讨论)
大数据·linux·服务器·网络·人工智能·制造
猫头虎1 天前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
忆~遂愿1 天前
ops-cv 算子库深度解析:面向视觉任务的硬件优化与数据布局(NCHW/NHWC)策略
java·大数据·linux·人工智能