Install nodejs and websocket in centos

Source: Internet
Author: User
Tags node server
Software Environment: VitrualBoxCentOS6.4NodeJSv0.12.5 installation process: Step 1. confirm that the server has nodejs compilation and dependent software. if not, run the following command to install the software. [Root @ **** node-v0.12.5] # yum-yinstallgccgcc-c ++ openssl-develSte

Software environment:

VitrualBox

CentOS 1, 6.4

NodeJS v0.12.5

Installation process:

Step 1. confirm that the server has nodejs compilation and dependent software. if not, run the following command to install nodejs.

[Root @ **** node-v0.12.5] # yum-y install gcc-c ++ openssl-devel

Step 2. download and decompress the Node. js source code package.

[Root @ **** node-v0.12.5] # wget http://nodejs.org/dist/v0.12.5/node-v0.12.5.tar.gz

[Root @ **** node-v0.12.5] # tar zxvf node-v0.12.5.tar.gz

[Root @ **** node-v0.12.5] # cd node-v0.12.5

Step 3. configure, compile, and install.

[Root @ **** node-v0.12.5] #./configure -- prefix =/usr/local/node

[Root @ ***** node-v0.12.5] # make & make install

Will last 3-4 min ....

Step 4. configure the Node environment

[Root @ **** node-v0.12.5] # vi/etc/profile

 

# Set nodejs env

Export NODE_HOME =/usr/local/node

Export PATH = $ NODE_HOME/bin: $ PATH

Export NODE_PATH = $ NODE_HOME/lib/node_modules: $ PATH

 

[Root @ **** node-v0.12.5] # source/etc/profile -- restart takes effect

Step 5. test whether the installation is successful

[Root @ **** node-v0.12.5] # node-v

V0.12.5

If the NodeJS version number is displayed, it indicates OK.

Step 6. Hello World for NodeJS

[Root @ **** node-v0.12.5] # node

> Console. log ("Hello NodeJS, I'm ***");

Hello NodeJS, I'm ****

Undefined

>

Output: Hello NodeJS, I'm ***

Step 7. install the SocketLog Google browser plug-in

  • Chrome plug-in installation: https://github.com/luofei614/SocketLog download after the root directory chrome. crx

  • (If you cannot access this page normally, you can install it manually)

  • Directory structure:

  • The chrome directory is the source code of the chrome plug-in.

  • Chrome. the crx file is the installation package of the chrome plug-in. if you cannot install it from the chrome app store, you can manually install it. enter and open chrome: // extensions/in the address bar of the browser, and then set chrome. drag crx to install it.

  • SocketLog. class. php in the php directory is the class library for sending logs. when sending logs, we need to load this class library and then call the slog function.

Step 8. install the Websocket and SocketLog plug-ins

[Root @ ****** local] # npm install websocket

Step 9. install npm install-g socketlog-server on the server and run socketlog-server to start the service. A local websocket service will be started, and the listening port is 1229. If you want to run socketlog-server>/dev/null in the service background &

If nohup indicates nohup: ignoring input and redirecting stderr to stdout, change the preceding command to nohup node server/index. js>/dev/null 2> & 1 & this is okay

Step 10. check whether 1229 and 1116 are occupied.

Step 11. check whether the connection is successful and the light turns blue.

If no IP address is correct or not, enter the IP address of the virtual machine. the SocketLog plug-in must be the latest version. if the current version is 2.0.0 or not, check whether Port 1229 and Port 1116 are enabled.

[Root @ ****** local] # cat/etc/sysconfig/iptables

If no, use vi/etc/sysconfig/iptables.

-A input-m state -- state NEW-m tcp-p tcp -- dport 1116-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 1229-j ACCEPT

Run the following command to restart iptables: service iptables restart.

At this time, the rocket was lit up, and then it was okay to write code for testing.

Step 11. the code is as follows:

Include 'etetlog-master/php/SocketLog. class. php ';

Slog (array (

'Host' => 'localhost', // websocket server address, default: localhost

'Port' => '123', // websocket server port. the default port is 1229.

'Optimize' => false, // whether optimization-friendly parameters are displayed. the default value is false if the running time and memory consumption are used.

'Show _ included_files '=> false, // whether to display the files loaded by the current program. The default value is false.

'Error _ handler' => false, // whether to take over the program error. The program error is displayed on the console. the default value is false.

'Force _ client_id '=> '', // logs are forcibly recorded to the configured client_id. the default value is wjh_zfH5NbLn.

'Allow _ client_ids '=> array () /// restrict the client_id allowed to read logs. the default value is null, indicating that all users can obtain logs. Wjh_zfH5NbLn

), 'Set _ config ');

Slog ('etetlog success ');

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.