centOS下安装nodejs小结以及守护进程使用与结束
2017-03-15 15:01
651 查看
/*
* 备注:错误步骤:1~4,直接进行步骤5即可
*/
1. 首先需要下载node安装包,可以在
* 备注:错误步骤:1~4,直接进行步骤5即可
*/
1. 首先需要下载node安装包,可以在
https://nodejs.org/dist/中查找最新的安装包地址,使用
wget https://nodejs.org/dist/v4.5.0/node-v4.5.0.tar.gz[/code]
提示ERROR: certificate common name `*.nodejs.org' doesn't match requested host name `nodejs.org'. To connect to nodejs.org insecurely, use `--no-check-certificate'.
是因为该网址所使用的协议是https协议,因此加上了--no-check-certificate参数wget --no-check-certificate https://nodejs.org/dist/v4.5.0/node-v4.5.0.tar.gz[/code]
成功下载
2. 嗯,上述方法需要安装 gcc 与 gcc-c++,因此使用yum -y groupinstall "Development Tools"
对上面两者进行了安装
3. 将安装包进行解压,使用tar -xf node-v4.5.0.tar.gz
然后发现当前文件夹下多出了一个解压后的文件夹
4. 接下来进入该目录,使用make对其进行编译,此时出错,显示的错误内容为:In file included from ../deps/v8/src/v8.h:29, from ../deps/v8/src/accessors.cc:5: ../deps/v8/include/v8.h: In constructor 'v8::MaybeLocal<T>::MaybeLocal()': ../deps/v8/include/v8.h:353: error: 'nullptr' was not declared in this scope ../deps/v8/include/v8.h: In member function 'bool v8::MaybeLocal<T>::IsEmpty() const': ../deps/v8/include/v8.h:360: error: 'nullptr' was not declared in this scope ../deps/v8/include/v8.h: In member function 'bool v8::MaybeLocal<T>::ToLocal(v8::Local<S>*) const': ../deps/v8/include/v8.h:364: error: 'nullptr' was not declared in this scope ../deps/v8/include/v8.h: In member function 'bool v8::WeakCallbackInfo<T>::IsFirstPass() const': ../deps/v8/include/v8.h:430: error: 'nullptr' was not declared in this scope ../deps/v8/include/v8.h: At global scope: ../deps/v8/include/v8.h:469: error: expected unqualified-id before 'using' ../deps/v8/include/v8.h: In constructor 'v8::Global<T>::Global()': ../deps/v8/include/v8.h:790: error: 'nullptr' was not declared in this sc
经检查,应该是gcc与gcc-c++版本问题,所以对其进行更新也许可以解决。
5. 之后并没有继续上述方法。而是查到了使用sudo yum install -y nodejs
可以成功安装nodejs,使用版本测试查看版本node -v
显示为v0.10.48
表示成功安装
在node安装成功之后,写一个常用的http模块程序:server.js1 var http = require('http'); 2 var server = http.createServer(function(req, res){ 3 res.writeHeader(200, { 4 'Content-Type': 'text/plain; charset=utf-8' 5 }); 6 res.end('Hello World'); 7 }); 8 server.listen(8888); // 监听8888端口,其他如apache服务器默认为80端口
在使用node server.js
之后,发现可以访问云服务器ip地址的8888端口,界面输出Hello World字样。
但是有个问题,如果将所使用的shell关闭了以后,该页面就访问不到了,因此查找解决方法,发现需要“守护进程”
在查找过程中,发现阮一峰大神的这篇博客中有提到这一点:可以使用node sever.js &
在后面加一个&使该进程变为后台任务,是最简单的方法,但是当server.js修改的时候需要重新启动server.js,并不能自动监测该文件的变化,因此可以看博客中的几个方法。
其中,使用linux中的 nohup方法加指令来使命令后台运行,较为简单。
另外,如果需要结束后台任务,需要kill命令// 首选需要查找运行在8888端口上的进程id sudo lsof -i:8888 // 然后使用这个命令杀死进程 sudo kill -9 24841
相关文章推荐
- centOS下安装nodejs小结以及守护进程使用与结束
- centos安装supervisor守护进程与简单配置使用
- linux(centos 64位)nodejs 安装 forever 进程守护
- centos安装supervisor守护进程与简单配置使用
- Linux(centos6.0)下安装Node.js以及使用
- LR监控服务器以及在服务器上安装rstatd守护进程
- Centos中安装.SSH安装,配置以及使用
- Linux(centos6.0)下安装Node.js以及使用
- Linux使用错误小结(CentOS)- vim安装问题: Error: Nothing to do
- centos 6上安装使用saltstack以及基础管理-二(接上次)
- node.js应用后台守护进程管理器Forever安装和使用实例
- CentOS 5.5 使用 EPEL 和 RPMForge 软件库,以及 yum 安装 LNMP
- INNO安装卸载自动结束进程插件使用
- INNO安装卸载自动结束进程插件使用
- 在centos使用rpm包的方式安装mysql,以及更改root密码
- 使用nodejs实现守护进程
- (转)守护进程原理分析以及linux下的daemon函数使用
- CentOS 6.2 使用第三方yum源安装更多rpm软件包以及centos系统的若干问题
- Linux(centos6.0)下安装Node.js以及使用
- CentOS 6.2使用yum安装LAMP以及phpMyadmin详解