设为首页 收藏本站
查看: 1104|回复: 0

[经验分享] nodejs 0.9.0在Centos6.3下的安装

[复制链接]

尚未签到

发表于 2017-2-22 09:05:26 | 显示全部楼层 |阅读模式
  1.确保安装了GUN make
    [iyunv@localhost node-v0.9.0]# rpm -qa|grep make
    makebootfat-1.4-10.el6.x86_64

    #显示没有安装。
    安装后:
    [iyunv@localhost node-v0.9.0]# yum -y install make
    ......
    ......
    [iyunv@localhost node-v0.9.0]# rpm -qa|grep make
    makebootfat-1.4-10.el6.x86_64
    make-3.81-19.el6.x86_64

2.确保安装了gcc,gcc-c++,ncurses-devel,openssl-devel
  1)gcc安装:
安装前:
    [iyunv@localhost ~]# gcc -v
    -bash: gcc: command not found
    [iyunv@localhost node-v0.9.0]# rpm -qa|grep gcc
    libgcc-4.4.6-3.el6.x86_64

安装后:
    [iyunv@localhost node-v0.9.0]# yum -y install gcc
    ......
    ......
    [iyunv@localhost node-v0.9.0]# rpm -qa|grep gcc
    libgcc-4.4.6-3.el6.x86_64
    gcc-4.4.6-3.el6.x86_64
    [iyunv@localhost node-v0.9.0]# gcc -v
    使用内建 specs。
    目标:x86_64-redhat-linux
    配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
    线程模型:posix
    gcc 版本 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
  2)gcc-c++安装:
安装前:
    [iyunv@localhost node-v0.9.0]# rpm -qa|grep gcc-c++
  
安装后:
    [iyunv@localhost node-v0.9.0]# yum -y install gcc-c++
    ......
    ......
    [iyunv@localhost node-v0.9.0]# rpm -qa|grep gcc-c++
    gcc-c++-4.4.6-3.el6.x86_64
   
  3)安装openssl-devel
    openssl-devel:
    用于ssl(这个就是在网络层的一个加密连接)的一些操作,比如ssl的证书验证之类的
安装前:
    [iyunv@localhost node-v0.9.0]# rpm -qa|grep openssl-devel

安装后:
    [iyunv@localhost node-v0.9.0]# yum -y install openssl-devel
    ......
    ......
    [iyunv@localhost node-v0.9.0]# rpm -qa|grep openssl-devel
    openssl-devel-1.0.0-20.el6_2.5.x86_64

  4)确保安装了python   
    [iyunv@localhost node-v0.9.0]# python
    Python 2.6.6 (r266:84292, Dec  7 2011, 20:48:22)
    [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
   
3.安装node
  1).下载nodejs到本地并解压缩
  [iyunv@localhost node]# wget http://nodejs.org/dist/v0.9.0/node-v0.9.0.tar.gz
  [iyunv@localhost node]# tar zxvf node-v0.9.0.tar.gz

  2).进入到该目录编译和安装
  [iyunv@localhost node-v0.9.0]# cd node-v0.9.0
  [iyunv@localhost node-v0.9.0]# ./configure --prefix=/usr/local/node/0.9.0
  这里安装在了/usr/local/node/0.9.0目录下
  [iyunv@localhost node-v0.9.0]# make
  [iyunv@localhost node-v0.9.0]# make install
 
  3).配置NODE_HOME
  [iyunv@localhost node-v0.9.0]# vi /etc/profile
  在export PATH USER 。。。一行的上面添加如下内容,并将NODE_HOME/bin设置到系统path中
  #set for nodejs
  export NODE_HOME=/usr/local/node/0.9.0
  export PATH=$NODE_HOME/bin:$PATH
 
  保存退出后执行如下命令,使刚才的配置生效
  [iyunv@localhost node-v0.9.0]# source /etc/profile
 
  执行node -help命令验证设置成功
  [iyunv@localhost node-v0.9.0]# node -help
  Usage:
    shell [options] -e string
      execute string in V8
      ......
      ......
     
  至此安装设置完毕。
 
4.运行一个简单的node应用程序
  [lify@localhost studyfile]$ vi app.js
  输入如下内容
  var http = require('http');
  http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, World!\n');
  }).listen(8080, '127.0.0.1');
  console.log('Server running at http://127.0.0.1:8080');
 
  执行如下命令
  [lify@localhost studyfile]$ node app.js
  Server running at http://127.0.0.1:8080
 
  在浏览器中输入http://127.0.0.1:8080/,会有下面的输出:
  Hello, World!
 
5.Node服务在后台运行
  有多重方式可以实现该功能,这里以forever为例进行介绍
  1)安装forever
  [iyunv@localhost bin]# npm install -g forever
 
  2)创建启动脚本
  [iyunv@localhost bin]# vi /etc/init.d/node
 
  编辑node文件,下面以开机自动启动上面演示的app.js为例,输入如下内容
  #! /bin/sh -e
  set -e
  PATH=/usr/local/node/0.9.0/bin:/bin:/usr/bin:/sbin:/usr/sbin
  DAEMON=/home/lify/program/node/studyfile/app.js
  case "$1" in
  start) forever start $DAEMON ;;
  stop) forever stop $DAEMON ;;
  force-reload|restart)
  forever restart $DAEMON ;;
  *) echo "Usage: /etc/init.d/node {start|stop|restart|force-reload}"
  exit 1
  ;;
  esac
  exit 0
 
  2)增加对该文件的执行权限
  [iyunv@localhost bin]# chmod u+x /etc/init.d/node
 
  3)启动服务
  [iyunv@localhost bin]# service node start
  info:    Forever processing file: /home/lify/program/node/studyfile/app.js
 
  用forever查看运行状态
  [iyunv@localhost bin]# forever list
  info:    Forever processes running
  data:        uid  command                        script                                   forever pid   logfile                 uptime
  data:    [0] gOgC /usr/local/node/0.9.0/bin/node /home/lify/program/node/studyfile/app.js 21035   21037 /root/.forever/gOgC.log 0:0:0:18.71
  通过进程查看node运行状态
  [iyunv@localhost bin]# ps ax | grep node
  21035 ?        Ssl    0:00 /usr/local/node/0.9.0/bin/node /usr/local/node/0.9.0/lib/node_modules/forever/bin/monitor /home/lify/program/node/studyfile/app.js
  21037 ?        Sl     0:00 /usr/local/node/0.9.0/bin/node /home/lify/program/node/studyfile/app.js
  21053 pts/0    S+     0:00 grep node
 
  停止node服务
  [iyunv@localhost bin]# service node stop
 
  用forever查看运行状态
  [iyunv@localhost bin]# forever list
  info:    No forever processes running
  通过进程查看node运行状态
  [iyunv@localhost bin]# ps ax | grep node
  21072 pts/0    S+     0:00 grep node

  node的安装介绍完毕


 

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-345471-1-1.html 上篇帖子: NodeJS框架express的路径映射(路由)功能及控制 下篇帖子: node-yesdb:一个nodejs的bitcask k-v数据库的实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表