10

Amazon ec2 インスタンスを開始し、postgresql 9.1 をその上にインストールしました。次に、Security Group: quicklaunch-1 (there was one moredefault` に移動し、変更していません)、5432 TCP ポートを開きました。テーブルは次のようになります。

(Service)   Source  Action
22        0.0.0.0/0         Delete
5432      0.0.0.0/32    Delete
5433      0.0.0.0/32    Delete
6432      0.0.0.0/32    Delete

データベースとユーザーを作成しました。私/etc/postgresql/9.1/main/pg_hba.confはこのように見えます:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             0.0.0.0/0               md5
host    db_name         user_name       0.0.0.0/0               md5

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
host    replication     postgres        127.0.0.1/32            md5
host    replication     postgres        ::1/128                 md5

/etc/postgresql/9.1/main/postgresql.confは次のようになります。

# - Connection Settings -
listen_addresses = '*'
#listen_addresses = 'localhost'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost', '*' = all
                                        # (change requires restart)
port = 5432                             # (change requires restart)

次に、次のようにリモート マシンに接続しようとします。

psql -h ec2-xxx-xx-xxx-xxx.compute-1.amazonaws.com -d <database_name> -U <username>

ここで、ec2-xxx-xx-xxx-xxx.compute-1.amazonaws.comは私のパブリック DNSです。

上記のコマンドを実行しても接続されません。どうすれば接続できますか?

4

3 に答える 3

11

この表では:

5432      0.0.0.0/32    Delete
5433      0.0.0.0/32    Delete
6432      0.0.0.0/32    Delete 

CIDR は、IP を許可していないように見えます。代わりに、ポート 22 (ssh) のようにすべきではありません0.0.0.0/0か?

于 2013-01-27T13:51:11.110 に答える
5

この問題の解決策を見つけました。2 つのことが必要です。

  1. テキスト エディタを使用して pg_hba.conf を変更します。host all all 127.0.0.1/0 md5 という行を見つけます。そのすぐ下に、次の新しい行を追加します: host all all 0.0.0.0/0 md5

  2. PostgreSQL postgresql.conf ファイルの編集:

    テキスト エディタを使用して、postgresql.conf を変更します。#listen_addresses = 'localhost' で始まる行を見つけます。# を削除して行のコメントを解除し、localhost を に変更し*ます。行は次のようになります: listen_addresses = '*' # what IP address(es) to listen on;.

Postgreサービスを再起動するだけで接続されます

于 2015-09-05T12:40:25.053 に答える