美文网首页
阿里云CentOS 8安装PostgreSQL并开启远程访问

阿里云CentOS 8安装PostgreSQL并开启远程访问

作者: 山哥Samuel | 来源:发表于2020-07-16 23:21 被阅读0次

1. Install PostgreSQL on CentOS 8

yum install postgresql-server postgresql-contrib

2. 初始化数据库

postgresql-setup initdb

3. 启动 DB

systemctl start postgresql

4. (Optional) Enable PostgreSQL

systemctl enable postgresql

5. 设置远程访问

su postgres
psql

# 查看配置文件位置
postgres=# show config_file;
             config_file             
-------------------------------------
 /var/lib/pgsql/data/postgresql.conf
(1 row)

postgres=# show hba_file;
            hba_file             
---------------------------------
 /var/lib/pgsql/data/pg_hba.conf
(1 row)

添加配置

# vi /var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'

# /var/lib/pgsql/data/pg_hba.conf
host    all             all             0.0.0.0/0               md5
host    all             all             ::/0                    md5

6. 重启数据库

systemctl restart postgresql

7. 开放防火墙

firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reload

8. 开放安全组的端口访问

相关文章

网友评论

      本文标题:阿里云CentOS 8安装PostgreSQL并开启远程访问

      本文链接:https://www.haomeiwen.com/subject/nbmgchtx.html