ubuntu 下安装nodejs以及pm2
ubuntu 12.04服务器可以使用apt-get方式安装Node JS,但是,安装完后的版本为v0.6.12的版本,如果我们想要使用新一点的版本需要做如下配置:
|
1
2
3
4
|
apt-get install python-software-propertiesapt-add-repository ppa:chris-lea/node.jsapt-get updateapt-get install nodejs |
安装完成后可以检查一下版本,使用如下命令可以查看:
|
1
2
|
root@test:#node -vv0.10.28 |
接下来我们需要安装pm2这个软件
首先我们需要安装一个npm的软件,具体命令如下:
|
1
2
|
apt-get install npmnpm -v |
安装完成,我们就可以安装pm2这个软件,使用如下命令安装:
|
1
|
root@test:# npm install -g pm2 |
在shell中输入pm,使用table补全,如果能出现pm2,说明已经正常安装。
现在我们可以使用PM2命令来启动node
输入如下命令,启动我们的app.js
|
1
|
pm2 start app.js |
那我们如何让pm2在开机的时候自动运行我们的程序呢?或者说我们想要启动,停止或者重启的时候用什么命令呢?我们可以做如下操作:
|
1
|
sudo env PATH=$PATH:/usr/local/bin pm2 startup app.js -u safeuser #(你启动node的用户) |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
addam@AYZ:/web/webtest$ sudo env PATH=$PATH:/usr/local/bin pm2 startup app.jsPM2 Generating system init script in /etc/init.d/pm2-init.shPM2 Making script booting at startup...PM2 -ubuntu- Using the command chmod +x /etc/init.d/pm2-init.sh; update-rc.d pm2-init.sh defaults Adding system startup for /etc/init.d/pm2-init.sh ... /etc/rc0.d/K20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc1.d/K20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc6.d/K20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc2.d/S20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc3.d/S20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc4.d/S20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc5.d/S20pm2-init.sh -> ../init.d/pm2-init.shPM2 Done. |
这样我们就可以使用/etc/init.d/pm2-init.sh start|stop|restart 命令来启动关闭和重启我们的程序了,而且开机的时候也会自动启动,如果你使用kill来杀死这个进程,当你再次使用原来的pm2 start app.js 来启动的时候,会发现报错,无法找到套接字等问题。所以,使用这样平滑的方式启动停止,对我们的程序有很大的好处。
PM2的主要功能:
Main features
Built-in load balancer (using the native cluster module)
Script daemonization
0s downtime reload for Node apps
Generate SystemV/SystemD startup scripts (Ubuntu, Centos...)
Pause unstable process (avoid infinite loop)
Restart on file change with
--watchMonitoring in console
PM2地址:https://github.com/Unitech/pm2
参考文献:https://www.digitalocean.com/community/articles/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps
ubuntu 下安装nodejs以及pm2的更多相关文章
- ubuntu下安装nodejs
前言 继前几天在wins环境下使用cygwin模拟器安装nodejs出现了一些问题后,今天我决定在ubuntu下安装nodejs,安装过程非常顺利,没有报错,看来还是linux环境给力啊,由于刚接触l ...
- ubuntu下安装nodejs和npm
第一种安装方法: 安装nodejs : 1 sudo apt-get install nodejs 运行 nodejs -v 会弹出安装node的版本号 这里使用的是 nodejs 并不是常用的nod ...
- ubuntu下安装nodejs,无node情况
Updating nodejs solved the issue: npm cache clean -f npm install -g n n stable node --version node ...
- Linux(Ubuntu)下安装NodeJs
用以下命令来升级系统,并且安装一些Node.JS必要的包. Linux(Ubuntu)下安装NodeJs 安装nodeJS之前,如果没有安装g++ make libssl-dev等, 1.更新系统和依 ...
- Angularjs学习---angularjs环境搭建,ubuntu 12.04下安装nodejs、npm和karma
1.下载angularjs 进入其官网下载:https://angularjs.org/,建议下载最新版的:https://ajax.googleapis.com/ajax/libs/angular ...
- ubuntu下安装git,sublime,nodejs
用的是VMware10.0版本的虚拟机,很早之前下载的今天就直接用了,安装挺简单记得需要一个序列号.在这里:http://mirrors.163.com/ubuntu-releases/15.04/u ...
- Ubuntu 下安装 apt-get install npm 失败的解决方案
Ubuntu 下安装 apt-get install npm 失败的解决方案: sudo apt-get remove nodejs npm ## remove existing nodejs an ...
- Ubuntu下搭建NodeJS+Express WEB开发框架
Ubuntu下搭建NodeJS+Express WEB开发框架 2012-12-27 15:06 作者: NodeJSNet 来源: 本站 浏览: 2,966 次阅读 我要评论暂无评论 字号: 大 中 ...
- Linux之旅-ubuntu下搭建nodejs环境
.NET Core也开源了,并且可移植到Linux下,而ubuntu作为linux发行版的翘楚,极大的方便了初学者的入门,搭建完ASP.NET Core运行环境后,作为半前半后的开发人员,就继续着搭建 ...
随机推荐
- jqury关于cooke的操作写入cookie后只显示一次的DIV提示框代码
有时候当用户登录系统后,需要给用户弹出提示框,但是不需要总是弹出来,在这里加入访问cookie来判断是否弹出过提示框,如果弹出过那么保存cookie,下次根据cookie是否存在来判断是否弹出 < ...
- 牛客小白月赛4——I—合唱队形
链接:https://www.nowcoder.com/acm/contest/134/I来源:牛客网 题目描述 铁子的班级在毕业晚会有一个合唱节目,到了毕业晚会的时候,他们必须排成一排一起合唱&qu ...
- xshell设置使用
一.首先您的xshell先连接上需要远程连接的服务器. 二.打开连接,出现下记页面,就证明与服务器连接正常了. 三.接下来,我们就可以使用命令做一系列操作了. 3-1:cd 是进入下一级目录命令 例如 ...
- http://twitter.github.com/bootstrap/
原文发布时间为:2012-05-22 -- 来源于本人的百度文章 [由搬家工具导入] http://twitter.github.com/bootstrap/
- 行为型设计模式之策略模式(Strategy)
结构 意图 定义一系列的算法,把它们一个个封装起来, 并且使它们可相互替换.本模式使得算法可独立于使用它的客户而变化. 适用性 许多相关的类仅仅是行为有异.“策略”提供了一种用多个行为中的一个行为来配 ...
- C# 代码片段
StringBuilder拼接小技巧 Stopwatch watch = new Stopwatch(); watch.Start(); var sb = new StringBuilder(); ; ...
- [LeetCode] Sqrt(x) 二分搜索
Implement int sqrt(int x). Compute and return the square root of x. Hide Tags Math Binary Search ...
- 【IDEA】使用intellij的idea集成开发工具中的git插件
注意:这里并没有介绍git客户端的安装,如果要安装客户端,大家可以参考如下的链接: http://www.runoob.com/git/git-install-setup.html 1.在使用这个id ...
- Oracle中DBMS_LOB包使用小结
本文主要介绍oracle数据库中dbms_lob包的使用以及使用dbms_lob包来维护lob数据库类型的基本方法.随着社会的发展,在现代信息系统的开发中,需要存储的已不仅仅是简单的文字信息,同时还包 ...
- linux select函数详解【转】
转自:http://www.cnblogs.com/ccsccs/articles/4224253.html 在Linux中,我们可以使用select函数实现I/O端口的复用,传递给 select函数 ...