CentOS7离线压缩包安装PostgreSQL

CentOS7离线压缩包安装PostgreSQL

1 下载压缩包

官方地址
注:本文使用的是17.2版本

2 安装依赖

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
yum install -y libicu libicu-devel

3 解压

tar -zxvf postgresql-17.2.tar.gz
cd postgresql-17.2

4 编译postgresql源码

./configure --prefix=/opt/pgsql/postgresql172

4.1 可能出现的问题

  1. configure: error: no acceptable C compiler found in $PATH
sudo yum install gcc-c++
  1. configure: error: ICU library not found If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn’t looking in the proper directory. Use --without-icu to disable ICU support.
sudo yum install libicu-devel
  1. configure: error: bison not found
yum install bison
  1. configure: error: flex not found
yum install flex
  1. configure: error: readline library not found
yum install readline-devel
  1. configure: error: zlib library not found
yum install zlib-devel

5 源码编译安装

make
make install

6 创建用户组、用户

groupadd postgres
useradd -g postgres postgres

7 创建数据主目录

cd /opt/pgsql/postgresql172
mkdir data
chown postgres:postgres data

8 配置环境变量

cd /home/postgres/
ls -la
vi .bash_profile

在最后面添加:
export PGHOME=/opt/pgsql/postgresql172
export PGDATA=$PGHOME/data
export PATH=$PATH:$HOME/bin:$PGHOME/bin

9 应用环境变量

source .bash_profile

10 初使化数据库

su - postgres
initdb

11 配置服务

cd /opt/pgsql/postgresql172/data
vi postgresql.conf

修改:
listen_address = ‘*’
port = 5432
max_connections = 100

vi pg_hba.conf

添加一行:
# IPv4 local connections:
host all all 0.0.0.0/0 trust
host all all 127.0.0.1/32 trust

12 设置开机自启动

su root
cd /home/postgresql-17.2/contrib/start-scripts
chmod a+x linux
cp linux /etc/init.d/postgresql172
vi /etc/init.d/postgresql172

修改:
prefix = /opt/pgsql/postgresql172
PGDATA=“/opt/pgsql/postgresql172/data”

chkconfig --add postgresql172
chkconfig

13 设置防火墙

yum -y install firewalld
systemctl start firewalld
systemctl status firewalld
firewall-cmd --permanent --zone=public --add-service=postgresql
firewall-cmd --reload

14 启动数据库服务

service postgresql start
ps -ef | grep postgres
su - postgres
psql
# 修改密码
ALTER USER postgres WITH PASSWORD 'admin@123';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Winemonk

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值