データベースサーバー側の設定
PostgreSQLの設定を行う。
(1).外部接続を有効にする
$ vim /var/lib/postgresql/8.4/data/postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on;
listen_addresses = '*' # what IP address(es) to listen on;
※まずは、誰でもOKで。
(2).動いているサービスを止めていく(port 5432にアクセスしているもの)
a). crontabの停止
$ crontab -u postgres -e
$ /etc/init.d/cron restart
で動いているスケジュールを消す。
b).mod-pythonの停止
$ sudo vim /etc/apache2/sites-enabled/000-default
# <Location "/uki2/">
# Options Indexes FollowSymLinks MultiViews
# AllowOverride None
# Order allow,deny
# allow from all
# SetHandler python-program
# PythonPath "['/var/django','/var/django/uki2'] + sys.path"
# PythonHandler django.core.handlers.modpython
# SetEnv DJANGO_SETTINGS_MODULE uki2.settings
# PythonOption django.root /uki2
# PythonDebug On
# </Location>
c).ポートへのアクセスがないことを確認
$ pg_ctl stop
$ lsof | grep 5432
何もでなければOK
d).確認
$ netstat -ln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
ココを参照。
この状態では接続確認すると以下の通り拒否される
psql -h 184.12.233.77
psql: could not connect to server: Connection refused
Is the server running on host "184.12.233.77" and accepting
TCP/IP connections on port 5432?
./etc/postgresql/8.4/main/postgresql.conf
./var/lib/postgresql/8.4/data/postgresql.conf
両方のpostgresql.confを編集してみると以下の通りエラーが変わった
psql -h 184.12.233.77
psql: FATAL: no pg_hba.conf entry for host "184.88.211.174", user "postgres", database "postgres", SSL on
FATAL: no pg_hba.conf entry for host "184.88.211.174", user "postgres", database "postgres", SSL off
次の対応をしてみた
$ vim /var/lib/postgresql/8.4/data/postgresql.conf
ssl = false
でも変わらない。
まずは接続確認のためポートを限定せずすべてのポートで実験してみる。
$ vim /var/lib/postgresql/8.4/data/pg_hba.conf
# IPv4 local connections:
host all all 127.0.0.1/32 trust
#host all all 184.73.211.174 trust
host all all 0.0.0.0/0 trust
接続確認
$ psql -h ***.***.***.*** -U username -q dbname
Password for user username
接続できた。
参考サイト