pgAdmin遠端連線阿里雲主機的PostgreSQL-9.5
阿新 • • 發佈:2019-01-23
主機:阿里雲學生機
作業系統:centos7.2
軟體版本:
PostgreSQL-9.5
pgAdmin 3
在雲主機和本地電腦上安裝完postgreSQL和pgAdmin的過程就不再贅述,下面只用來討論遠端連線的這一部分內容。
要想pgAdmin遠端連線到postgreSQL首先要滿足幾個條件:
1.postgresql允許遠端的地址連線到自己
2.信任伺服器連線
3.防火牆要允許
1.信任所有ip的主機
/var/lib/pgsql/9.5/data/ 用vi 或者 vim命令編輯 pg_hba.conf
修改前
<pre name="code" class="plain"># 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 ident # IPv6 local connections: host all all ::1/128 ident # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer #host replication postgres 127.0.0.1/32 ident #host replication postgres ::1/128 ident
修改後
<pre name="code" class="plain"># TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust host all all 0.0.0.0/0 trust
2.允許連線到資料庫 vim /var/lib/pgsql/9.5/data/postgresql.conf 找到被註釋掉的 去掉註釋,並把localhost改為 * 意思是受所有主機連線到資料庫,當然你也可以改成你的ip。不過由於我們的IP地址都是動態獲取的,而且大多數情況下我們都是出於區域網之中,所以並不容易知道自己所在主機的公網ip,所以說改成 * 允許所有主機連線即可。<pre name="code" class="plain">#------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - listen_addresses = '*' <span> </span># what IP address(es) to listen on; listen-address='localhost' # 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)
3.設定防火牆,由於防火牆已經內建了postgreSQL服務,所以我們只需要開放服務即可firewall-cmd --add-service=postgresql --permanent 開放postgresql服務 firewall-cmd --reload 過載防火牆
4.重啟防火牆 總結:這是一個比較簡單的過程,實際操作過程中可能會出錯,不過這些錯誤都不是什麼大問題,畢竟誰沒有踩過幾個坑呢。 以上內容僅限於記錄日常所學,如有錯誤或者表述不清的地方歡迎大家指正!