在openshift上将远程django应用程序连接到postgresql

时间:2013-06-10 05:37:55

标签: django postgresql heroku openshift

我有一个在VPS上运行的django应用程序。我只想将它连接到我在redhat上的openshift上安装的postgresql实例。在数据库设置的我的设置文件中,我已经输入以下内容 -

########## DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'sdf',
        'USER': 'asdfsfpbb6c',
        'PASSWORD': 'dsfgsdgs1sbdeU',
        'HOST': '',
        'PORT': '',
    }
}

The trouble now is the HOST and PORT are 127.4.57.130 and 5432. 

要在本地访问它,我总是可以进行端口转发,但是如果我想从另一个网络服务器访问数据库怎么办?比如一个VPS?我怎样才能做到这一点?

stormydude@ubuntu:~$ rhc port-forward <app_name>
Checking available ports ... done
Forwarding ports ...
Address already in use - bind(2) while forwarding port 5432. Trying local port 5433

To connect to a service running on OpenShift, use the Local address

Service    Local               OpenShift
---------- -------------- ---- -----------------
postgresql 127.0.0.1:5433  =>  127.4.57.130:5432
python     127.0.0.1:8080  =>  127.4.57.129:8080

Press CTRL-C to terminate port forwarding

另外,如果我的服务器在heroku上,是否有办法,我可以在openshift上连接到数据库服务器?

2 个答案:

答案 0 :(得分:1)

您可以从OpenShift向另一台服务器转发反向端口,也可以从服务器向前移植到OpenShift服务器 - 但没有直接的数据库访问权限。直接访问需要将您的数据库暴露给外部世界,并且通常被认为是不良安全实践

答案 1 :(得分:1)

使用此博客通过Red Hat命令行工具(rhc)设置端口转发

https://www.openshift.com/blogs/getting-started-with-port-forwarding-on-openshift

或者您可以手动运行:ssh -N -L $ YOUMACHINE_INTERNAL_IP:3306:$ OPENSHIFT_REMOTE_INTERNAL_IP:3306 {appName} - {namespace} @ rhcloud.com

将OPENSHIFT_REMOTE_INTERNAL_IP替换为127 ... * ip地址

示例:

ssh -N -L 10.11.22.213:3306:127.4.139.121:3306 test-testing@rhcloud.com

相关问题