首页
找靠谱产品
找解决方案
找靠谱公司
找案例
找对的人
专家智库
悬赏任务
SAAS
ToB门户
了解全球最新的ToB事件
论坛
潜水/灌水快乐,沉淀知识,认识更多同行。
ToB圈子
加入IT圈,遇到更多同好之人。
微博
Follow
记录
Doing
博客
Blog
文库
业界最专业的IT文库,上传资料也可以赚钱
下载
分享
Share
排行榜
Ranklist
相册
Album
应用中心
qidao123.com ToB IT社区-企服评测·应用市场
»
论坛
›
数据库
›
Mysql
›
CentOS7 安装 PostgreSQL
返回列表
发新帖
CentOS7 安装 PostgreSQL
[复制链接]
发表于 2025-3-20 18:35:14
|
显示全部楼层
|
阅读模式
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要
登录
才可以下载或查看,没有账号?
立即注册
×
一、CentOS7 编译安装 PostgreSQL-12.22
PostgreSQL-12.22 及 PostgreSQL-14.15
版本
的安装流程均遵照下文所述步骤
1. 编译安装
su root
复制
代码
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake # 安装 PostgreSQL 的依赖包
wget https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.gz
tar -zxvf postgresql-12.22.tar.gz
cd postgresql-12.22
./configure --prefix=/usr/local/postgresql-12.22 # 指明安装路径为 `/usr/local/postgresql-12.22`
make -j$(nproc) && make install # 使用 $(nproc) 获取系统的CPU核心数,实现 make 任务的加速执行
复制
代码
2. 创建 postgres 用户
su root
复制
代码
groupadd postgres
useradd postgres -g postgres
passwd postgres
id postgres
cd /usr/local/postgresql-12.22
mkdir data log
chown -R postgres:postgres /usr/local/postgresql-12.22
chmod -R 700 /usr/local/postgresql-12.22
复制代码
3. 利用 postgres 用户管理 PostgreSQL
su postgres
复制代码
# 初始化
/usr/local/postgresql-12.22/bin/initdb /usr/local/postgresql-12.22/data
# 修改
配置
文件
vim /usr/local/postgresql-12.22/data/postgresql.conf
listen_addresses = '*'
port = 5432
vim /usr/local/postgresql-12.22/data/pg_hba.conf
host all all 0.0.0.0/0 md5 # 设置使用任意ip登录
数据库
需要使用基于 md5
加密
策略验证用户身份
# 管理服务:开启、重启、重新加载
配置
文件、查看状态、停止
/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt start
/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt restart
/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt reload
/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt status
/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt stop
# 使用 psql 客户端登录
数据库
/usr/local/postgresql-12.22/bin/psql -h 127.0.0.1 -p 5432 -d postgres -U postgres
/usr/local/postgresql-12.22/bin/psql -h 12.12.12.12 -p 5432 -d postgres -U postgres
# 修改
数据库
中 postgres 用户的密码
select usename, passwd from pg_shadow;
alter user postgres with password 'postgres123456';
复制代码
4.
配置
systemctl 工具管理服务
在配置 systemctl 文件时,由于 systemctl 命令仅限 root 用户利用,而 PostgreSQL 的二进制文件要求以 postgres 用户身份执行,因此必须明确指定服务以 postgres 用户权限运行
su root
复制代码
vim /etc/systemd/system/postgresql-12.22.service
复制代码
[Unit]
Description=PostgreSQL 12.22
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
ExecStart=/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt start
[Install]
WantedBy=multi-user.target
复制代码
systemctl daemon-reload
systemctl start postgresql-12.22.service
systemctl restart postgresql-12.22.service
systemctl status postgresql-12.22.service
systemctl enable postgresql-12.22.service
systemctl stop postgresql-12.22.service
reboot
复制代码
5. 远程连接测试
至此编译安装 PostgreSQL 完成
6. 直接将安装目次复制到另一台机器
将安装目次打包
su root
tar -zcvf postgresql-12.22.tar.gz postgresql-12.22
复制代码
将安装目次的压缩包上传到另一台
服务器
su root
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmakegroupadd postgresuseradd postgres -g postgrespasswd postgresid postgrestar -zxvf postgresql-12.22.tar.gzchmod -R 700 /usr/local/postgresql-12.22chown -R postgres:postgres /usr/local/postgresql-12.22
复制代码
su postgres
/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt start/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt status/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt stop
复制代码
开机自启
su root
vim /etc/systemd/system/postgresql-12.22.service
复制代码
[Unit]
Description=PostgreSQL 12.22
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
ExecStart=/usr/local/postgresql-12.22/bin/pg_ctl -D /usr/local/postgresql-12.22/data -l /usr/local/postgresql-12.22/log/log.txt start
[Install]
WantedBy=multi-user.target
复制代码
systemctl daemon-reload
systemctl start postgresql-12.22.service
systemctl restart postgresql-12.22.service
systemctl status postgresql-12.22.service
systemctl enable postgresql-12.22.service
systemctl stop postgresql-12.22.service
reboot
复制代码
二、CentOS7 利用 yum 工具安装 PostgreSQL-14
官网
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql14-server
/usr/pgsql-14/bin/postgresql-14-setup initdb
systemctl enable postgresql-14
systemctl start postgresql-14
systemctl status postgresql-14
systemctl stop postgresql-14
复制代码
利用 yum 安装 PostgreSQL时
自动创建 postgres 用户
数据目次 data 位于 /var/lib/pgsql/14/data
二进制可执行文件目次 bin 位于 /usr/pgsql-14/bin
三、利用 rpm 离线安装 PostgreSQL-14
进入官网,下载所必要的 rpm 包到
服务器
,必要保证各个软件包的小
版本
保持一致,同时利用 rpm 离线安装必要提前下载所需依赖包的 rpm 软件包
安装时必要按照如下顺序【这里的软件包大概不全,可先执行命令安装,安装提示找缺少的 rpm 包安装即可】
libicu-50.2-4.el7_7.x86_64.rpm
libxslt-1.1.28-6.el7.x86_64.rpm
postgresql14-libs-14.15-1PGDG.rhel7.x86_64.rpm
postgresql14-14.15-1PGDG.rhel7.x86_64.rpm
postgresql14-server-14.15-1PGDG.rhel7.x86_64.rpm
postgresql14-contrib-14.15-1PGDG.rhel7.x86_64.rpm
安装完成后
自动创建 postgres 用户
数据目次 data 位于 /var/lib/pgsql/14/data
二进制可执行文件目次 bin 位于 /usr/pgsql-14/bin
rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm
rpm -ivh libxslt-1.1.28-6.el7.x86_64.rpm
rpm -ivh postgresql14-libs-14.15-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql14-14.15-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql14-server-14.15-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql14-contrib-14.15-1PGDG.rhel7.x86_64.rpm
复制代码
/usr/pgsql-14/bin/postgresql-14-setup initdb
systemctl enable postgresql-14
systemctl start postgresql-14
systemctl status postgresql-14
systemctl stop postgresql-14
复制代码
sql14-contrib-14.15-1PGDG.rhel7.x86_64.rpm
```sh/usr/pgsql-14/bin/postgresql-14-setup initdb
systemctl enable postgresql-14
systemctl start postgresql-14
systemctl status postgresql-14
systemctl stop postgresql-14
复制代码
回复
使用道具
举报
返回列表
浏览过的版块
DevOps与敏捷开发
物联网
前端开发
网络安全
Oracle
开源技术
SQL-Server
数据仓库与分析
分布式数据库
Java
天津储鑫盛钢材现货供应商
+ 我要发帖
登录后关闭弹窗
登录参与点评抽奖 加入IT实名职场社区
去登录
微信订阅号
微信服务号
微信客服(加群)
H5
小程序
快速回复
返回顶部
返回列表