阅读背景:

如何将nodejs应用程序部署到谷歌云?

来源:互联网 

I'm trying to deploy a nodejs application to google cloud, I've posted several SO questions about the errors I've been getting and how to fix them. Let me illustrate my endeavours...

我正在尝试将一个nodejs应用程序部署到谷歌云,我已经发布了几个关于我一直在收到的错误以及如何解决它们的问题。让我说明我的努力......

problem 1) I tried following the tutorial, the hello world app deployment. When I entered the command to deploy,

问题1)我尝试了教程,hello world app部署。当我输入命令进行部署时,

$ gcloud preview app deploy app.yaml --set-default

It gave me an error saying managed vms aren't available for your application's region. I contacted someone from Google, a technical support representative from google, said his name was Ling, and he said he "wasn't aware managed vms weren't supported in India" and he wanted me to point out where I found that information. So I sent him this, note one of the answers. OK.....

它给了我一个错误,说管理的vms不适用于您的应用程序的区域。我联系了来自Google的技术支持代表谷歌的人,他说他的名字叫Ling,他说他“不知道托管的vm​​s在印度不受支持”,他希望我指出我在哪里找到这些信息。所以我给他发了这个,请注意其中一个答案。好.....

problem 2) So, I was stuck, didn't really know what to do. Searched "how to deploy nodejs app on google cloud" and found a video in which a google developer informed me that there are "two main ways to run your application in the cloud, infrastructure as a service and platform as a service". Running it on app engine was the platform as a service, and that was off the list so I went with my only remaining option. There is a tutorial, the bookshelf app tutorial, also by google, and the last part describes how to run your application on the compute engine. I tried to go through the tutorial, but when I entered the command

问题2)所以,我被卡住了,不知道该怎么做。搜索了“如何在谷歌云上部署nodejs应用程序”,并发现了一个视频,其中谷歌开发人员告诉我“有两种主要方式在云中运行您的应用程序,基础架构即服务和平台即服务”。在应用程序引擎上运行它是平台即服务,这是不在列表中所以我选择了我唯一剩下的选项。有一个教程,书架应用教程,也是谷歌,最后一部分描述了如何在计算引擎上运行你的应用程序。我试图完成教程,但是当我输入命令时

git push cloud 7-gce:master

to push my code to the repository, it's asking me for my username and password, It never mentioned that in the tutorial, I don't know what to enter. I found this question but I'm not sure it applies to my situation. So next I went through some tutorials suggested by Zachary Newman, and I wasn't able to follow the tutorial where they use the ubuntu because when they tell you to hello.js file, it's really weird because I had to ssh into the ubuntu image vm I created and everything was really slow, I'm not familiar with commands on linux so I had to look up how to "save and exit" after creating the hello.js file. I got the "web server" to run, it's the reverse proxy nginx server, but since I don't know what the APP_PRIVATE_IP_ADDRESS is, when I accessed the page, I could see the nginx page but not the "hello world" message that's supposed to display. Please see the Prerequisites heading to see what the tutorial was trying to teach me. OK....

将我的代码推送到存储库,它要求我输入我的用户名和密码,它从未在教程中提到过,我不知道要输入什么。我发现了这个问题,但我不确定它是否适用于我的情况。接下来我接受了Zachary Newman建议的一些教程,我无法按照他们使用ubuntu的教程,因为当他们告诉你hello.js文件时,它真的很奇怪,因为我不得不ssh到ubuntu图像vm我创建了,一切都很慢,我不熟悉linux上的命令所以我必须在创建hello.js文件后查找如何“保存并退出”。我得到了“web服务器”来运行,它是反向代理nginx服务器,但由于我不知道APP_PRIVATE_IP_ADDRESS是什么,当我访问页面时,我可以看到nginx页面而不是“hello world”消息应该显示。请参阅先决条件标题以查看教程试图教我的内容。好....

problem 3) On the google developers console, once you log in, there is a navigation section on the left, there is a link to the "Cloud Launcher". In there I found a link to create a Virtual Machine with nodejs installed, it's created by Bitnami. I clicked it and my vm was running, I went to the external ip address provided, and saw a Congratulations (ugh...) page by Bitnami. I didn't really know what to do from there, so I posted another SO question. A bitnami developer told me I "need to copy your files to the remote repository, create the configuration files and after that you have to include that configuration in the configuration of Apache to serve the application". How?!?! He just posted a link as well to a bitnami wiki page. I used filezilla to connect to my vm, and I tried to upload my application files to the vm. I was able to upload everything except the node modules (they were taking too long to upload and for some reason the ftp client kept loosing the connection with the server after 10 minutes or so of uploading). So I thought I would just ssh into the instance and try to npm install my dependencies. But it gave me more errors...

问题3)在谷歌开发者控制台上,一旦你登录,左侧有一个导航部分,有一个指向“云启动器”的链接。在那里,我找到了一个链接,用于创建安装了nodejs的虚拟机,它由Bitnami创建。我点击它,我的vm正在运行,我去了提供的外部IP地址,并看到Bitnami的祝贺(呃...)页面。我真的不知道该怎么做,所以我发布了另一个SO问题。 bitnami开发人员告诉我,我“需要将您的文件复制到远程存储库,创建配置文件,之后您必须将该配置包含在Apache的配置中以服务应用程序”。怎么样?!?!他刚刚发布了一个链接到bitnami wiki页面。我使用filezilla连接到我的虚拟机,我尝试将我的应用程序文件上传到虚拟机。我能够上传除节点模块之外的所有内容(它们上传时间太长,并且由于某种原因,ftp客户端在上传10分钟左右后仍然失去与服务器的连接)。所以我想我会ssh到实例并尝试npm安装我的依赖项。但它给了我更多错误......

problem 4) I don't know why this post was put on hold, but I found this. I can't find the exact page right now but I read somewhere in the google docs that we can't ssh into an instance as root/administrator by design, and that we have to perform some advanced configuration in order to be able to do this. THE PROBLEM is that I can't install the dependencies unless I ssh in as an administrator....:'( So I just uploaded my node modules with filezilla. Everything looks good to go, I ssh into my instance and I cd into my application directory and enter the command

问题4)我不知道为什么这个帖子被搁置,但我发现了这个。我现在找不到确切的页面,但是我在谷歌文档的某个地方读到我们不能按照设计的root / administrator进入实例,并且我们必须执行一些高级配置才能够做到这个。问题是我不能安装依赖项,除非我作为管理员ssh进入....:'(所以我只是用filezilla上传我的节点模块。一切看起来不错,我ssh到我的实例,我进入我的应用程序目录并输入命令

node app.js

and almost as if to taunt me, it console logs out "connected to mongo...." and "Listening on port 3000.....". I get so excited, I think it's working.....

几乎就像嘲笑我一样,它控制台注销“连接到mongo ....”和“侦听端口3000 .....”。我很兴奋,我觉得它很有效......

problem 4) The server never really started running I think, it wasn't able to connect to the mongodb database (another instance) that I was running, this was the command to connect to the mongodb instance in my app.js file

问题4)服务器从未真正开始运行我认为,它无法连接到我正在运行的mongodb数据库(另一个实例),这是连接到我的app.js文件中的mongodb实例的命令

mongoose.connect('mongodb://****/myappdatabase');

where the **** indicates the external IP of my mongodb instances. After about 5 minutes, I get an error on the ssh browser

其中****表示我的mongodb实例的外部IP。大约5分钟后,我在ssh浏览器上收到错误

Error: connect ETIMEDOUT ****:27017

BUT WHO HAS TIME TO READ ALL OF THIS RIGHT?

但是,他有时间阅读所有这些权利吗?

I'm not a developer, I don't have much experience with programming (close to zero actually). I'm a hobbyist. I picked up a book on c programming by stephen g. kochan about 5 or 6 months ago, and since then, I've just been following tutorials on the internet, a programming in java book, and some reference material. I wanted to create a website.

我不是开发人员,我没有太多的编程经验(实际上接近于零)。我是一个业余爱好者。我拿了一本关于stephen g的c编程的书。 kochan大约5或6个月前,从那以后,我一直在关注互联网上的教程,java书籍编程和一些参考资料。我想创建一个网站。

I learned some html, css, javascript and jquery off of w3schools and went through some tutorials on creating a basic node server and serving some html pages, that's literally all my application does. That's all I want it to do.

我从w3schools学到了一些html,css,javascript和jquery,并经历了一些关于创建基本节点服务器和提供一些html页面的教程,这实际上就是我所有的应用程序。这就是我想要它做的一切。

I used the express framework for node, and mongoose to connect to my mongodb running locally. Socket.io for a little bit of networking. I created the website for fun and I would really like to host it and share it with my friends, I made it this far, it would be really embarrassing to quit now because I can't host the website. I went through a lot more than what I posted on this question by the way.

我使用了node的express框架,并使用mongoose连接到我在本地运行的mongodb。 Socket.io有点网络化。我创建了网站以获得乐趣,我真的想主持它并与我的朋友分享,我做到了这一点,现在退出真的很尴尬,因为我无法主持网站。顺便说一句,我经历的事情比我在这个问题上发布的要多得多。

Now I would really appreciate some help, even some guidance as to what I need to know, maybe books I should read or documentation I should go through to become more familiar with website hosting would be great. I am going to offer this question up for a bounty in 2 days but until then, if there is anyone that went through this and would like to help for no personal gain of their own, your saving my life. I've been going at this for about 4 days with no luck. Thanks and let me know if there is anything you would like to know about my application. I mean seriously, how hard could it be, I'm doing something (or everything) terribly wrong.

现在我真的很感激一些帮助,甚至一些关于我需要知道的指导,也许我应该阅读的书籍或者我应该通过的文档来更熟悉网站托管会很棒。我将在2天内提出这个问题以获得赏金,但在此之前,如果有人经历过这个并希望帮助他们自己没有个人利益,那么你将拯救我的生命。我已经在这里待了大约4天而没有运气。谢谢,如果您有任何关于我的申请的信息,请告诉我。我的意思是认真的,它有多难,我做某事(或一切)都非常错误。

1 个解决方案

#1


8  

Wow dude. I thought about flagging this, but you appear to genuinely want to learn to program and need help. And experienced coders teaching novice coders is what this site is all about. So, here we go.

哇老兄。我想过这样做,但你似乎真的想学习编程并需要帮助。经验丰富的编程员教授新手编码器就是这个网站的全部内容。所以,我们走了。

First and foremost, Linux is your friend. Learn it. Use it. I don’t use Ubuntu, but you should. Use 14.04 because it’s a forgiving disto and comes cram-packed with things you need when you’re just learning.

首先,Linux是你的朋友。学习它。用它。我不使用Ubuntu,但你应该这样做。使用14.04,因为它是一个宽容的东西,并且当你刚刚学习时,它会挤满你需要的东西。

Time to address your questions:

是时候解决你的问题:

Problem 1: you are using a gcloud preview product. Those are awesome, but not for beginners because you don’t know what you’re doing. Just stand up an Ubuntu instance on an n1-standard and rock it. No bells. No whistles. Learn Ubuntu linux with the same passion that you taught yourself how to program a web site.

问题1:您正在使用gcloud预览产品。那些很棒,但不适合初学者,因为你不知道你在做什么。只需在n1标准上建立一个Ubuntu实例并摇滚吧。没有钟声。没有口哨。学习Ubuntu linux与您自学的如何编写网站的热情相同。

Problem 2: Don’t use git. I use git every day and it’s awesome, but you have a long way to go and git is hella confusing. Take your workspace, tar/gzip it and just ssh the whole shebang to cloud. Then unzip it and you’ll have your whole code right there on your server. Caveat: never do this professionally. But for someone just learning … small bites dude … small bites.

问题2:不要使用git。我每天都使用git而且很棒,但是你还有很长的路要走,git让hella感到困惑。拿你的工作区,tar / gzip它,然后把整个shebang ssh到云端。然后解压缩它,您将在服务器上拥有整个代码。警告:从不专业。但是对于刚学习的人来说......小咬人......小咬。

Problem 3: Don’t use Bitnami pre-built images. It robs you of the opportunity learning how to do this from scratch and that is an invaluable experience. Here are two commands you must learn:

问题3:不要使用Bitnami预建图像。它剥夺了您从头开始学习如何做到这一点的机会,这是一次非常宝贵的经历。以下是您必须学习的两个命令:

apt-get update
apt-get install <insert thing you want to install>

That’s it. Not rocket science and you will discover the power of package management on linux.

而已。不是火箭科学,你会发现Linux上的包管理的力量。

Problem 4: You are over-thinking this. For real, learn apt-get. It will get you so far, you’ll curse yourself for not using it earlier. apt-get node. apt-get mongo. And slam it all on one instance. Is that what I do professionally? Hell no. But it’s all about baby steps when you combine dev-ops with programming and you need to take those steps.

问题4:你过分思考这个问题。真实的,学习apt-get。它会让你到目前为止,你会诅咒自己之前没有使用它。 apt-get节点。 apt-get mongo。并在一个实例上猛烈抨击。那是我的职业吗?一定不行。但是当你将dev-ops与编程结合起来并且你需要采取这些步骤时,所有这些都与宝贝步骤有关。

Errata: You wanted someone to recommend a book or a website or guidance. All you need to know is already on Ubuntu. They are called man pages. It’s short for manual. You can buy all the books in the world off Amazon and watch infinite youtube pages. It won’t compare to simply maning commands. You gotta trust me on this.

勘误表:您希望有人推荐书籍,网站或指南。您需要知道的只是Ubuntu。它们被称为手册页。这是手动的简称。您可以在亚马逊上购买世界上所有的书籍,并观看无限的YouTube页面。它不会与简单的maning命令相比。你必须相信我。

In summary: Just create an Ubuntu instance. tar and gzip all your code and scp it to your instance. Learn apt-get and for real, you are set. You will totally destroy your instance many times. So just delete it, re-create it, and keep starting over. Each time, you will be wiser and smarter than the time before. I tutor novice developers all the time. You gotta start small and work your way up. Eventually you’ll understand why you’d want to use git. Why you want to scale. Why LXC is amazing. Why GCE’s managed instance and VMs are crazy baller, and why scripting your deployment is a best practice. But first you have to understand how to build an instance and get your code there in any way possible. You’ll grow from there. Good luck, buddy.

总结:只需创建一个Ubuntu实例。 tar和gzip你的所有代码并将其scp到你的实例。学习apt-get和真实,你就定了。你将完全摧毁你的实例多次。所以只需删除它,重新创建它,并继续重新开始。每一次,你都会比以前更聪明,更聪明。我一直在指导新手开发人员。你必须从小做起,然后继续努力。最终你会明白你为什么要使用git。为什么要缩放。为什么LXC太棒了。为什么GCE的托管实例和虚拟机是疯狂的,以及为什么编写部署脚本是最佳做法。但首先,您必须了解如何构建实例并以任何可能的方式获取代码。你会从那里成长。祝你好运,伙计。


分享到: