zoukankan      html  css  js  c++  java
  • pgAdmin的Desktop Mode设置允许远程访问

    有时候因为一些安全设置或权限问题,不允许用户直接访问PostgreSQL数据库,但是Support系统的用户必须要访问数据库. 那怎么办呢? 在一台可以访问PostgreSQL的服务器上安装pgAdmin,然后让用户使用浏览器远程访问pgAdmin,访问PostgreSQL数据库, 那么pgAdmin如何设置允许远程访问呢?其实pgAdmin有Desktop Mode和Server Mode两种模式,对于Server Mode的话,这个根本不是问题。

     

    下面介绍Desktop Mode的pgAdmin如何允许远程访问,这个是在对pgAdmin这个工具不熟悉的情况下的一个尝试。很多时候,我们都像一个蹒跚学步的小孩一样,需要时间和尝试才会熟练的掌握一款工具!过程中总有磕磕碰碰。

     

    下面测试环境为Windows Server 2019 Datacenter版本,在pgAdmin的安装目录,例如,C:Program FilespgAdmin 4v4web目录下(这里是默认安装,根据实际情况找到安装目录)config.py文件, 找到DEFAULT_SERVER参数,将其值修改为'0.0.0.0'后

     

    # This option allows the user to host the application on a LAN
    # Default hosting is on localhost (DEFAULT_SERVER='localhost').
    # To host pgAdmin4 over LAN set DEFAULT_SERVER='0.0.0.0' (or a specific
    # adaptor address.
    #
    # NOTE: This is NOT recommended for production use, only for debugging
    # or testing. Production installations should be run as a WSGI application
    # behind Apache HTTPD.
    DEFAULT_SERVER = '0.0.0.0'
     
    # The default port on which the app server will listen if not set in the
    # environment by the runtime
    DEFAULT_SERVER_PORT = 5050

     

     

    退出并重新启动pgAdmin后,找到右下角pgAdmin的图标,选择Copy server URL,就可以在远程服务器使用类似下面的URL链接访问pgAdmin了。

     

    clip_image001

     

    http://192.168.103.63:52846/?key=33962ea5-6319-4659-bdfa-6b9b233e6eb9

     

     

    测试过程中发现,启用远程访问pgAdmin后,不需要输入master密码了。后面查看官方文档才知道,一般而言只有destop mode才有master password,但是修改参数DEFAULT_SERVER = '0.0.0.0'后,只有本机第一次登录paAdmin才会需要master密码,而其他用户通过浏览器远程访问paAdmin的话,不需要输入master密码了。取而代之的是一长串key:33962ea5-6319-4659-bdfa-6b9b233e6eb9  当然这个key是变化的。每次重启pgAdmin后就会重新生成一长串Key。

     

    ##########################################################################
     
    # Master password is used to encrypt/decrypt saved server passwords
     
    # Applicable for desktop mode only
     
    ##########################################################################
     
    MASTER_PASSWORD_REQUIRED = True

     

     

     

    clip_image002

     

    虽然通过key这种方式也能达到一定的安全性,例如,如果你不知道key,使用下面链接是访问不了系统的。

     

    http://192.168.103.63:52846//browser/

     

    它会提示下面错误信息,使用上面带key的URL链接访问过后,上面这种链接才能正常访问。总之安全总是相对的。对于Desktop Mode的pgAdmin还是不建议开启远程访问。

     

    Unauthorized
     
    The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.

     

     

     

    参考资料:

     

        https://www.pgadmin.org/faq/#2

        https://www.pgadmin.org/docs/pgadmin4/development/server_deployment.html

  • 相关阅读:
    使用Visual Studio 2010来部署Windows应用程序
    如何显示一个非激活窗体
    构建ASP.NET网站十大必备工具(2)
    在Azure中创建一个“Hello World”应用程序
    轻松搞定VS2010 和旧版本服务器一起使用的问题
    Sql注入与转义
    小数型 Float(M,D),decimal(M,D)
    MySQL SQL语句
    作业综合练习配置+自定义函数设置
    作业综合练习初始化工作
  • 原文地址:https://www.cnblogs.com/kerrycode/p/14107412.html
Copyright © 2011-2022 走看看