IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    如何在 CentOS 中部署远程 PostgreSQL

    Jsun Dot LOL发表于 2022-01-27 00:00:00
    love 0

    安装

    查找可用的 PostgreSQL 版本

    dnf module list postgresql
    

    安装

    sudo dnf module enable postgresql:12
    

    安装其他依赖

    sudo dnf install postgresql-server
    

    初始化

    sudo postgresql-setup --initdb
    

    启动服务

    启动

    sudo systemctl start postgresql
    

    设置为服务 (开机自启动)

    sudo systemctl enable postgresql
    

    创建用户

    登录 PostgreSQL 默认用户并创建用户

    sudo -u postgres createuser --interactive
    

    设置用户密码

    使用数据库管理员账户登录 psql 命令行

    sudo -u postgres psql
    

    设置密码(psql 中输入)

    \password <用户名>
    

    退出 psql

    \q
    

    允许远程连接

    找到 postgresql.conf 和 pg_hba.conf

    一般在/var/lib/pgsql/data中 地址可能稍有出入

    postgresql.conf

    开启远程连接和设置端口

    listen_addresses = '*'
    port = <端口>
    

    pg_hba.conf

    允许远程访问

    host all all 0.0.0.0/0 md5
    

    重启服务

    sudo systemctl reload postgresql
    

    备注

    如果安全组开端口了还是访问不了, 多半是内置的 iptables 把端口 ban 了

    iptables -I INPUT -p tcp -m tcp --dport <端口> -j ACCEPT
    

    参考

    How To Install and Use PostgreSQL on CentOS 8 | DigitalOcean

    Configure PostgreSQL to allow remote connection | BigBinary Blog

    FATAL: password authentication failed for user "postgres" (postgresql 11 with pgAdmin 4) - Stack Overflow

    php - connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host - Database Administrators Stack Exchange

    Allow web traffic in iptables software firewall -



沪ICP备19023445号-2号
友情链接