Ensure that python is installed. Most installation failures are caused by the low Python version. Before installation, upgrade python to http://www.tomtalk.net/wiki/python.
[Root @ SNDA-192-168-15-161 ~] # Python-V
Python 2.7.3
Start installation:
1) download nodejs to the local device and decompress it.
[Root @ SNDA-192-168-15-161 node] # wget http://nodejs.org/dist/v0.9.0/node-v0.9.0.tar.gz
[Root @ SNDA-192-168-15-161 node] # tar zxvf node-v0.9.0.tar.gz
2). Go to the directory to compile and install
[Root @ SNDA-192-168-15-161 node-v0.9.0] # cd node-v0.9.0
[Root @ SNDA-192-168-15-161 node-v0.9.0] #./configure -- prefix =/usr/local/node/0.9.0
It is installed in the/usr/local/node/0.9.0 directory.
[Root @ SNDA-192-168-15-161] # Make
[Root @ SNDA-192-168-15-161] # make install
3) Configure node_home
[Root @ SNDA-192-168-15-161] # vi/etc/profile
In export path user... Add the following content to the line and set node_home/bin to the system path.
# Set for nodejs
Export node_home =/usr/local/node/0.9.0
Export Path = $ node_home/bin: $ path
Save and exit, and execute the following command to make the configuration take effect.
[Root @ SNDA-192-168-15-161] # source/etc/profile
Run the node-H command to verify that the setting is successful.
[root @ SNDA-192-168-15-161 ~] # Node-H
usage: node [Options] [-E script | script. js] [arguments]
node debug script. js [arguments]
options:
-V, -- version print node's version
-E, -- eval script evaluate script
-P, -- Print print result of -- eval
-I, -- Interactive always enter the repl even if stdin
does not appear to be a terminal
-- no-deprecation silence deprecation warnings
-- Trace-deprecation show stack traces on deprecations
-- v8-options print V8 command line options
-- Max-Stack-size = Val Set max V8 stack size (bytes)
Environment variables:
Node_path ':'-separated list of directories
Prefixed to the module search path.
Node_module_contexts set to 1 to load modules in their own
Global contexts.
Node_disable_colors set to 1 to disable colors in the repl
Documentation can be found at a http://nodejs.org/
So far, the installation and configuration are complete.
Run a simple node ApplicationProgram+ Socket. Io, the socket. Io module must be installed first.
[Root @ SNDA-192-168-15-161 ~] # NPM install socket. Io
[Root @ SNDA-192-168-15-161 ~] # Vi app. js
VaR HTTP = require ('http ');
VaR IO = require ('socket. Io ');
VaR Server = http. createserver (function (req, Res ){
Res. writehead (200, {'content-type': 'text/plain '});
Res. End ('Hello World ');
});
Server. Listen (process. argv [2]);
VaR socket = Io. Listen (server );
Socket. On ('connection', function (client ){
Console. Log ('client has connected ');
Client. On ('message', function (){});
});
[Root @ SNDA-192-168-15-161 ~] # Nodejs./APP. js 8001 &
[Root @ SNDA-192-168-15-161 ~] # Nodejs./APP. js 8002 &
[Root @ SNDA-192-168-15-161 ~] # Nodejs./APP. js 8003 &
[Root @ SNDA-192-168-15-161 ~] # Nodejs./APP. js 8004 &
For more details, refer to the example on the socket. Io official website.
Perfect Combination of websocket and node. js
http://wanshuiqianshan.iteye.com/blog/1618498