Centos 7.2 Node.js 安装
2016-05-11 14:10
411 查看
Add some useful external repositories to install useful softwares. | |
[1] | Install a plugin to add priorities to each installed repositories. |
[root@dlp ~]# yum -y install yum-plugin-priorities # set [priority=1] to official repository [root@dlp ~]#sed -i -e "s/\]$/\]\npriority=1/g" /etc/yum.repos.d/CentOS-Base.repo |
[2] | Add EPEL Repository which is provided from Fedora project. |
[root@dlp ~]# yum -y install epel-release # set [priority=5] [root@dlp ~]#sed -i -e "s/\]$/\]\npriority=5/g" /etc/yum.repos.d/epel.repo # for another way, change to [enabled=0] and use it only when needed [root@dlp ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo # if [enabled=0], input a command to use the repository [root@dlp ~]# yum --enablerepo=epel install [Package] |
[3] | Add RPMforge Repository which provides many useful packages. |
yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
# set [priority=10]
[root@dlp ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/rpmforge.repo
# for another way, change to [enabled=0] and use it only when needed
[root@dlp ~]# sed -i -e "s/enabled = 1/enabled = 0/g" /etc/yum.repos.d/rpmforge.repo
# if [enabled=0], input a command to use the repository
[root@dlp ~]#
yum --enablerepo=rpmforge install [Package]
[root@www ~]#
yum --enablerepo=epel -y install nodejs npm
[2] | Create a test tool. It's possible to do it as a common user. |
[cent@www ~]$ vi helloworld.jsvar http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1'); console.log('listening on http://127.0.0.1:1337/'); # run server [cent@www ~]$ node helloworld.js & # verify (it's OK if following reply is back ) [cent@www ~]$ curl http://127.0.0.1:1337/ Hello World |
[3] | Install Socket.IO and create a test apprication with using WebSocket. |
[cent@www ~]$ npm install socket.io express [cent@www ~]$ vi chat.js var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection', function(socket){ socket.on('chat message', function(msg){ io.emit('chat message', msg); }); }); http.listen(1337, function(){ console.log('listening on *:1337'); }); [cent@www ~]$ vi index.html <!DOCTYPE html> <html> <head> <title>WebSocket Chat</title> </head> <body> <form action=""> <input id="sendmsg" autocomplete="off" /><button>Send</button> </form> <ul id="messages" style="list-style-type: decimal; font-size: 16px; font-family: Arial;"></ul> <script src="/socket.io/socket.io.js"></script> <script src="http://code.jquery.com/jquery.min.js"></script> <script> var socket = io(); $('form').submit(function(){ socket.emit('chat message', $('#sendmsg').val()); $('#sendmsg').val(''); return false; }); socket.on('chat message', function(msg){ $('#messages').append($('<li style="margin-bottom: 5px;">').text(msg)); }); </script> </body> </html> [cent@www ~]$ node chat.js listening on *:1337 |
Access to "http://(server's hostname or IP address):1337/" from a Client computer to make sure sample app works normally. |
相关文章推荐
- OpenStack一键安装for CentOS
- Centos 7.2 PHP 7.0 安装
- 防火墙之 iptables详解
- Centos 7.2 JDK8 安装
- Azure File 服务(4): Linux上使用
- RHEL7安装、ip修改、关防火墙、关selinux、配置yum源
- Linux安装-gedit
- Linux Pthread fork 探究
- Linux下which、whereis、locate、find 命令的区别
- 【Linux进阶】CentOS安装MySQL数据库
- linux打补丁和git打patch方法
- 制作centos6.5 镜像,安装cloud-init 支持openstack 密码注入
- linux之scp命令学习
- Linux常见问题
- linux修改默认时区
- linux下IPTABLES配置详解
- Linux文件系统损坏导致的数据库危机
- U盘安装CENTOS
- Linux常用命令汇总--mkdir
- Linux C下链队列的实现