简体   繁体   English

流星:部署到Amazon EC2

[英]Meteor: Deploying to Amazon EC2

I am reading about Deploying to EC2 . 我正在阅读有关部署到EC2的信息 The final step looks like this, where I put the bundle folder outside of my meteor project 最后一步是这样的,我将bundle文件夹放在流星项目之外

PORT=80 MONGO_URL=mongodb://localhost:27017/sidebar
ROOT_URL=http://ec2-23-20-113-59.compute-1.amazonaws.com/
sudo node ../bundle/main.js

where I replace the ROOT_URL with the public DNS shown in my AWS console. 在这里,我用AWS控制台中显示的公共DNS替换了ROOT_URL。 I am not quite sure what to use for MONGO_URL, so I start the meteor via the command 我不太确定该如何使用MONGO_URL,因此我通过以下命令启动流星

meteor

to see what the mongodb address meteor uses, which turns out to be 看看流星使用的mongodb地址是什么

mongodb://127.0.0.1:3002/meteor

But for the node app to be able to connect to mongodb, I have to keep the meteor app running. 但是为了使节点应用程序能够连接到mongodb,我必须保持流星应用程序运行。 When it seems to be working, with the console showing 当它似乎可以正常工作时,控制台显示

listening

I try to access the site using the public DNS, but it doesn't work. 我尝试使用公共DNS访问该站点,但是它不起作用。 So I don't know what to do next. 所以我不知道下一步该怎么做。

You need to start your own instance of mongodb. 您需要启动自己的mongodb实例。 What you are seeing when running your project using the meteor command is just the in-place mongo db that meteor provides you with for development. 使用meteor命令运行项目时所看到的只是流星为您提供的用于开发的就地mongo数据库。 In production you just start your own mongodb (install it via your linux package manager) and then set your MONGO_URL to that -- you can use the local IP for that. 在生产中,您只需启动自己的mongodb(通过linux程序包管理器安装它),然后将MONGO_URL设置MONGO_URL即可—您可以使用本地IP。

On Ubuntu on AWS, for instance, if you installed mongodb using apt-get install mongodb , it will run on this URL: MONGO_URL='mongodb://localhost:27017/yourdbname' . 例如,在AWS的Ubuntu上,如果您使用apt-get install mongodb ,它将在以下URL上运行: MONGO_URL='mongodb://localhost:27017/yourdbname' If you use a separate AWS instance to run the db then you'll just replace localhost with the IP of that instance. 如果您使用单独的AWS实例运行数据库,则只需将localhost替换为该实例的IP。

BTW: you should avoid running anything as root, incl. 顺便说一句:您应该避免以root身份运行任何东西,包括。 your bundled app. 您捆绑的应用。 I'm assuming you are doing that only in order to be able to bind to port 80. A perhaps safer way of doing so is to allow your user to bind to that port also using the following command prior to invoking node: 我假设您这样做只是为了能够绑定到端口80。这样做的一种更安全的方法是允许用户在调用节点之前也使用以下命令将其绑定到该端口:

sudo setcap 'cap_net_bind_service=+ep' /usr/bin/nodejs

Update: The easiest way to set these environment variables is to just use env : 更新:设置这些环境变量的最简单方法是只使用env

sudo env PORT=80 MONGO_URL=mongodb://localhost:27017/sidebar ROOT_URL=http://ec2-23-20-113-59.compute-1.amazonaws.com/ node ../bundle/main.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM