如何从两个Openshift应用程序访问MongoDB数据库? [英] How do you access a MongoDB database from two Openshift apps?

查看:101
本文介绍了如何从两个Openshift应用程序访问MongoDB数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从2个Openshift应用程序访问我的MongoDB数据库-一个应用程序是通过浏览器的交互式数据库维护应用程序,另一个是通过Openshift应用程序在移动设备上运行的主要Web应用程序.正如我在Openshift中看到的那样,MongoDB设置在特定应用程序的文件夹空间中,而不是独立于该空间.

I want to be able to access my MongoDB database from 2 Openshift apps- one app is an interactive database maintenance app via the browser, the other is the principle web application which runs on mobile devices via an Openshift app. As I see it in Openshift, MongoDB gets set up within a particular app's folder space, not independent of that space.

完成对数据库的多个应用程序访问的方法是什么?

What would be the method to accomplish this multiple app access to the database ?

这不是理想的选择,但我是将两个Openshift应用程序的功能合并为一个的唯一选择吗?那感觉就像是一盘烂意大利面.

It's not ideal but is my only choice to merge the functionality of both Openshift apps into one ? That's tastes like a bad plate of spaghetti.

推荐答案

2018更新:这适用于Openshift2.版本3有很大的不同,但是Linux和扩展的通用规则适用,详细信息已过时

尽管@MartinB的回答是及时和正确的,但这只是一个链接,所以让我在这里输入要点.

Although @MartinB answer was timely and correct, it's just a link, so let me put the essentials here.

假设已经完成了设置非共享数据库的操作,则需要找到它的主机和端口.您可以ssh到您的应用程序(带有数据库的应用程序)或使用rhc:

Assuming that setting up a non-shared DB is already done, you need to find it's host and port. You can ssh to your app (the one with the DB) or use the rhc:

rhc ssh -a appwithdb
env | grep MONGODB 

env带来所有环境变量,并且grep过滤它们以仅显示与Mongo相关的变量.您应该会看到类似

env brings all the environment variables, and grep filters them to show only Mongo-related ones. You should see something like:

OPENSHIFT_MONGODB_DB_HOST=xxxxx-yyyyy.apps.osecloud.com
OPENSHIFT_MONGODB_DB_PORT=zzzzz

xxxxx is the ID of the gear that Mongo sits on
yyyyy is your domain/namespace
zzzzz is MongoDB port

现在,您可以使用它们在Openshift环境中的任何位置创建到数据库的连接.另一个应用程序必须使用xxxxx-yyyyy:zzzzz URL.您可以将它们存储在自定义变量中,以简化维护.

Now, you can use these to create a connection to the DB from anywhere in your Openshift environment. Another application has to use the xxxxx-yyyyy:zzzzz URL. You can store them in custom variables to make maintenance easier.

$ rhc env-set \
MYOWN_DB_HOST=xxxxx-yyyyy \
MYOWN_DB_PORT=zzzzz \
MYOWN_DB_PASSWORD=****** \
MYOWN_DB_USERNAME=admin..... \
MYOWN_DB_NAME=dbname...

然后使用环境变量代替标准变量.请记住,当数据库移开时它们不会自动更新.

And then use the environment variables instead of the standard ones. Just remember they don't get updated automatically when the DB moves away.

这篇关于如何从两个Openshift应用程序访问MongoDB数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆