外部postgresqlからlocalhostにポートを渡す

外部postgresqlからlocalhostにポートを渡す

アプリケーションサーバーの外部でホストされている複数のデータベースがあります。たとえば、次のようになります。データベースインスタンス:

192.168.178.21:5432
192.168.178.22:5432
192.168.178.23:5432

アプリケーションサーバー:192.168.178.11

ここで、外部データベースをポート5431-5433に渡し、psqlを使用してlocalhostに接続できるようにしたいと思います。

psql -h 127.0.0.1 -p 5432 -U <user> -d <db>

私は得る:

psql: could not connect to server: Connection refused
        Is the server running on host "127.0.0.1" and accepting
        TCP/IP connections on port 5432?

このサーバーのサービスは、localhostへの接続のみを許可します。それ以外の場合、そのポートはSSHを介して転送されます。

ファイアウォール迷彩を試しました。

firewall-cmd --zone=internal --add-masquerade --permanent
firewall-cmd --zone=internal --add-forward-port=port=5432:proto=tcp:toport=5432:toaddr=192.168.178.22 --permanent
firewall-cmd --reload

どんなアイデアがありますか? (CentOS、Fedora、Redhatの紹介など、いくつかのマニュアルを集めました)

編集:そのサーバーはPostgresポートのみを開いており、他に何もありません。私は次のpostgresql認識ゲートウェイを使用しようとします。シャキッとしたエージェント

ベストアンサー1

postgresqlがどのように機能するかによって異なります。pg_hba.confpostgresql サーバーがリストされた IP アドレスを受信するかどうかを設定します。

そうでなく、これらのサーバーにSSHで接続できる場合は、-Lssh(1)の例でSSHポート転送オプションを使用できます。

ssh [email protected] -L 5431:localhost:5432 -f
ssh [email protected] -L 5432:localhost:5432 -f
ssh [email protected] -L 5433:localhost:5432 -f

次の方法で同じ効果が得られます。~/.ssh/config

Host db1
        Hostname 192.168.178.21
        LocalForward            localhost:5431 localhost:5432

Host db2
        Hostname 192.168.178.22
        LocalForward            localhost:5432 localhost:5432

Host db3
        Hostname 192.168.178.23
        LocalForward            localhost:5433 localhost:5432

それから

ssh -f db1
ssh -f db2
ssh -f db3

おすすめ記事