Centos7安装PostgresSQL

Centos7安装PostgresSQL

  • 更新系统
sudo yum update -y
  • 添加PostgreSQL Yum存储库
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  • 安装PostgreSQL Server和客户端软件包
sudo yum install -y postgresql13-server postgresql13
  • 查看安裝是否完成
sudo rpm -qi postgresql13-server

image-20210114133718074

  • 初始化数据库
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
# 停止数据库
sudo systemctl stop postgresql-13
  • 数据库初始化完成后,可以通过修改数据文件目录的postgresql.conf配置文件来达到设置postgresql侦听端口的目的
vim /var/lib/pgsql/13/data/postgresql.conf

listen_addresses = '*'    
  • 允许远程访问
vim /var/lib/pgsql/13/data/pg_hba.conf

修改postgres密码

su postgres 

psql 

alter user postgres with password 'postgres';

修改后的内容如下:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0                 md5
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
  • 修改用户密码
  #登陆postgresql
  sudo -u postgres psql
  
  #修改i登陆postgresql密码
  alter user postgres with password 'postgres';
  • 开放防火墙
firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reload
# 查看是否开放
firewall-cmd --query-port=5432/tcp

安装PostGIS

  • 将EPEL存储库添加到CentOS 7

EPEL存储库中有许多依赖项,运行以下命令在CentOS 7计算机中安装epel存储库:

sudo yum -y install epel-release
  • 安装PostGIS
sudo yum -y install postgis31_13

猜你喜欢

转载自blog.csdn.net/qq_36213352/article/details/117856659