javascript 在我的服务器上安装/设置 Socket.IO
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4410214/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing/setting up Socket.IO on my server
提问by wilsonpage
Ok so I have read through the Socket.IO docs and I am still a little unsure of a couple of points:
好的,所以我已经通读了 Socket.IO 文档,但我仍然有点不确定几点:
The documentation says...
文档说...
To run the demo, execute the following:
要运行演示,请执行以下操作:
git clone git://github.com/LearnBoost/Socket.IO-node.git socket.io
cd socket.io/example/
sudo node server.js
Now I don't know what this means at all! I think it may be command line interface. I of course have access to this on my localhost, but my online hosting package is a shared LAMP setup. Meaning I don't have access to the root command line (i think).
现在我根本不知道这意味着什么!我认为这可能是命令行界面。我当然可以在我的本地主机上访问它,但我的在线托管包是一个共享的 LAMP 设置。这意味着我无权访问根命令行(我认为)。
How do I actually setup socket.IO, is it impossible on my shared server package?
我如何实际设置 socket.IO,在我的共享服务器包上是不可能的吗?
Appreciate any help...
感谢任何帮助...
W.
W.
回答by kanaka
If you aren't familiar with node.js or with basic command line usage then I would suggest that you use a hosted WebSockets solution like pusherapp. Trying to learn WebSockets, and Node.js, and the Linux command line all at once is going to lead to a lot of frustration. Take a look a pusherapp's quick start guide, it's very easy to get started. You can have 5 simultaneous connections with a single application for free (I'm not affiliated with pusherapp).
如果您不熟悉 node.js 或基本命令行用法,那么我建议您使用托管 WebSockets 解决方案,例如pusherapp。尝试同时学习 WebSockets、Node.js 和 Linux 命令行会导致很多挫折。看一看pusherapp的快速入门指南,上手很容易。您可以免费与一个应用程序同时建立 5 个连接(我不隶属于 pusherapp)。
Updated(with inline answers to questions):
更新(带有问题的内嵌答案):
If you are going to go the direction of running a Socket.IO application:
如果您打算运行 Socket.IO 应用程序的方向:
You don't technically need git since you can download node.js and Socket.IO from their respective download links on github.
You don't actually need a LAMP server to use Socket.IO. By default Socket.IO functions as a simple webserver in addition to a WebSockets server. If you want server side scripting then you might want Apache with mod_php, mod_python, etc.
You don't technically need a dedicated server or even root access. You do need a system where you can have long running process. And if you want the service to start automatically when the system is rebooted, you probably want to add a startup file to /etc/init.d, /etc/rc.d which will require root access. Both node.js and Socket.IO can be installed and run from a normal home directory. If you want to run Socket.IO on a standard port like 80 or 443 then you will need to run it with root privilege.
Node.JS scales quite well so Socket.IO will probably scale pretty well too.
It's not a simple matter to get everything setup and working, but if your goal is a free solution for web serving+WebSockets then Socket.IO is probably is good route to at least explore if you are brave.
您在技术上不需要 git,因为您可以从 github 上各自的下载链接下载 node.js 和 Socket.IO。
您实际上并不需要 LAMP 服务器来使用 Socket.IO。默认情况下,除了 WebSockets 服务器之外,Socket.IO 还充当一个简单的 Web 服务器。如果您需要服务器端脚本,那么您可能需要带有 mod_php、mod_python 等的 Apache。
从技术上讲,您不需要专用服务器,甚至不需要 root 访问权限。您确实需要一个可以长时间运行进程的系统。如果您希望服务在系统重新启动时自动启动,您可能需要将启动文件添加到 /etc/init.d、/etc/rc.d 中,这将需要 root 访问权限。node.js 和 Socket.IO 都可以从普通的主目录安装和运行。如果您想在 80 或 443 等标准端口上运行 Socket.IO,则需要以 root 权限运行它。
Node.JS 的伸缩性很好,所以 Socket.IO 也可能伸缩性很好。
设置和运行所有内容并不是一件简单的事情,但是如果您的目标是 Web 服务+WebSockets 的免费解决方案,那么 Socket.IO 可能是至少探索的好途径,如果您有勇气的话。
回答by profitphp
First you'll have to determine if your host supports SSH. Sometimes they don't by default on shared hosting, but if you ask they can turn it on. If it does you'll use some sort of SSH client to connect to it. Putty for windows is the most common. Then you'll use git, which is a source control program. Which you'll probably have to install on your host, which may or may not be allowed. If you can, this can be accomplished a number of ways, you'll want to read the git documentation, it will depend largely on what linux distribution you're running. CD is change directory, basic command line stuff. sudo on the last line is telling the system to run the command as root, which it will ask you the password for, which you may not have access to on your host. Sounds like you're gonna have an uphill battle on shared hosting. You may want to opt for a VPS instead.
首先,您必须确定您的主机是否支持 SSH。有时他们默认情况下不会在共享主机上,但如果你问他们可以打开它。如果是,您将使用某种 SSH 客户端连接到它。窗户用腻子是最常见的。然后您将使用 git,这是一个源代码控制程序。您可能必须在主机上安装它,这可能会或可能不会被允许。如果可以,这可以通过多种方式完成,您需要阅读 git 文档,这在很大程度上取决于您正在运行的 Linux 发行版。CD 是更改目录,基本的命令行东西。最后一行的 sudo 告诉系统以 root 身份运行命令,它会询问您的密码,您可能无法在主机上访问该密码。听起来像你' 将在共享主机上进行一场艰苦的战斗。您可能想改用 VPS。
回答by Daniel J. Pritchett
If your shared host is a LAMP system with no command line access you're not going to get very far with Socket.IO. The instructions you posted assume you have command line access and that you've installed the node.js runtime on your system.
如果您的共享主机是一个没有命令行访问权限的 LAMP 系统,那么使用 Socket.IO 就不会走得太远。您发布的说明假定您具有命令行访问权限,并且您已在系统上安装了 node.js 运行时。
If you really want to try this I recommend you get a VPS of your own (I use prgmr.com) to test it out. For what it's worth I found the Socket.IO platform pretty nice to use once I got it up and running.
如果您真的想尝试此操作,我建议您使用自己的 VPS(我使用 prgmr.com)进行测试。就其价值而言,我发现 Socket.IO 平台一旦启动并运行就非常好用。

