1、安装 PostgreSQL
使用以下命令安装 PostgreSQL:
sudo yum install postgresql-server postgresql-contrib
2、初始化数据库
执行以下命令来初始化 PostgreSQL 数据库:
sudo postgresql-setup initdb
3、启动 PostgreSQL 服务
启动 PostgreSQL 服务 && 设置 PostgreSQL 在系统启动时自动启动
sudo systemctl start postgresql sudo systemctl enable postgresql
4、配置访问权限
默认情况下,PostgreSQL 配置为仅本地访问。如果你需要从其他机器访问 PostgreSQL 数据库,需要编辑 PostgreSQL 配置文件。
打开 PostgreSQL 主配置文件 postgresql.conf
:
sudo vim /var/lib/pgsql/data/postgresql.conf
找到 listen_addresses
配置项,将其设置为 '*'
,允许所有地址的连接:
listen_addresses = '*'
打开 pg_hba.conf
文件,该文件用于配置客户端认证方式:
sudo vim /var/lib/pgsql/data/pg_hba.conf
在文件末尾添加一行,允许所有地址以密码方式连接:
host all all 0.0.0.0/0 md5
重启服务
sudo systemctl restart postgresql
5、设置 PostgreSQL 密码
sudo -u postgres psql postgres=# ALTER USER postgres WITH PASSWORD '123123';
6、连接报错
psql: FATAL: password authentication failed for user "postgres"
PostgresQL 连接时的默认认证方式为 peer,PostgresQL 会从操作系统内核中获取当前的用户名(SSH的登录用户)并且作为允许连接的用户名进行认证,这种方式仅仅适用于本地连接
修改pg_hba.conf ,将认证方式改为md5
- CentOS PostgreSQL CentOS7postgresql centos7 postgis centos postgresql postgis centos7 centos postgresql centos7 centos yum postgresql源码centos7 centos postgresql centos7 centos sde postgresql postgis3 centos7 postgis centos postgresql centos7 centos7 postgresql centos7 centos 11 postgresql centos7教程centos