CentOS7安装PostgreSQL15以及PostGIS3.3

 

安装Postgresql

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libzstd-1.5.5-1.el7.x86_64.rpm
yum -y install postgresql15-server

安装postgis

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install postgis33_15

初始化数据库

/usr/pgsql-15/bin/postgresql-15-setup initdb

启动数据库

systemctl enable postgresql-15
systemctl start postgresql-15

PostgreSQL配置与管理

(1)修改用户名密码

[root@VM-16-10-centos ~]# su - postgres
Last login: Mon Dec 25 10:53:16 CST 2023 on pts/0
-bash-4.2$ psql -U postgres
psql (15.5)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'postgres';

(2)配置postgresql.conf,将listen_addresses = '*'。(注意前面的#要取消)

[root@VM-16-10-centos data]# cd /var/lib/pgsql/15/data
[root@VM-16-10-centos data]# vim postgresql.conf
# - Connection Settings -
 
listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp'  # comma-separated list of directories
                                        # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                        # (change requires restart)
#bonjour = off                          # advertise server via Bonjour
                                        # (change requires restart)
#bonjour_name = ''                      # defaults to the computer name
                                        # (change requires restart)

(3)配置pg_hba.conf,后面新增两行远程连接配置。配置完成之后需要重启postgres。

[root@VM-16-10-centos data]# vim pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD
 
# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             127.0.0.1/32            ident
host    all             all             0.0.0.0/0               md5

连接验证

 

参考链接:

https://blog.csdn.net/mxy2572185/article/details/135155930

https://www.postgresql.org/download/linux/redhat/

posted @ 2024-05-28 10:47  粒子先生  阅读(220)  评论(0编辑  收藏  举报