Nodejs deployment on the tall-PM2

Source: Internet
Author: User

Today, sitting on the right side of the colleague suddenly delighted to say to me: Hey, recommend you a good thing, with PM2 try, than forever high-end. I have always lagged behind the forefront of fashion technology, I seriously answer: what? PM2.5 still so serious, PM2 came out again!

If not all have been accustomed to my two, this atmosphere is really embarrassed for a while ~ ~ hehe ...

First of all, how do I deploy a program?

  1, the most commonly used genus Nohup, is actually in the background to execute the process, the end of the &

nohup Node/home/zhoujie/ops/app.js & [131490nohup:ignoring input and appending output to ' nohup.out'

That is, the program has been started, direct access, the original program's standard output is automatically redirected to the current directory of the Nohup.out file, played the role of log. This command can continue to run the process after you exit the account/close the terminal. Nohup is the meaning of not hanging (no hang up).

The general form of the command is:nohup Command &

This is not very reliable appearance, often silent process in the background hung

  2, using screen to open a different screens, this way can be directly on the screen to see the operation of the program

Open a screen for the application, such as: Screen-r Ops, starting with NPM start,

Exit the background: CTRL + A, then press D, can not be directly ctrl +c, or exit

This way is not professional, hehe, but convenient to look at the operation of the production environment.

This is essentially configured in the Forever,package.json:

  "Scripts": {    "start": "Forever App.js",    "test": "Supervisor App.js"  },

  3, PM2

Use it to install it first, install it with the root account and the global mode:

Install -G PM2

Use it to start the program (can be started directly under the current directory,pm2 start app.js --name uops)

[[Email protected]Dev uops]$ pm2 start app.js [PM2] spawning PM2 daemon[pm2] success[pm2] Process app.js launched┌────────── ┬────┬──────┬─────┬────────┬───────────┬────────┬─────────────┬──────────┐│app name│ ID │mode│ PID │status│restarted│ uptime │memory│watching│├──────────┼────┼──────┼─────┼────────┼───────────┼────────┼─────────────┼──────────┤│app │0│fork│308│online│0│0s│21.879Mb│disabled│└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴─────────────┴──────────┘use ' PM2 Info<ID|name> ' to get MoreDetails about an app
[Email protected] uops]$

See, it shows the success, the program has been silently successful start, can monitor the operation of the program in real time, such as the execution of a pm2 restart, the above restarted that column becomes 1, you can show how long the program has been running, the memory size, it is so great!

Terminating the program is also simple:pm2 stop

List all programs launched with PM2:pm2 list

[[Email protected]Dev uops]$ pm2 List┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬─────────────┬──────────┐│app Name│ID│mode│pid│status│restarted│Uptime│memory│watching│├──────────┼────┼──────┼─────┼────────┼───────────┼────────┼─────────────┼──────────┤│app │0│fork│984│online│1│3s│64.141Mb│disabled│└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴─────────────┴──────────┘use ' PM2 Info<ID|name> ' to get MoreDetails about an app

To view the startup program details:PM2 describe ID

[Email protected] uops]$pm2 desc 0 describing process with PID0-name App┌───────────────────┬─────────────────────────────────────────┐│status│online ││name│app││ID│0││path│/home/zhoujie/uops/app.js││args│││exec cwd│/home/zhoujie/uops││error Log path│/home/zhoujie/.pm2/logs/app-error-0. Log││out Log path│/home/zhoujie/.pm2/logs/app-out-0. Log││pid path│/home/zhoujie/.pm2/pids/app-0. Pid││mode│fork_mode││node V8 arguments│ ││watch&reload│? ││interpreter│node││restarts│1││unstable restarts│0││Uptime│93s││created at│ -- on-07t09: A: -. 672z│└───────────────────┴─────────────────────────────────────────┘[[email protected]-dev uops]$

It's good enough to see all the running processes and their states through the PM2 List command. But how do you track their resource consumption? Don't worry, use this command:pm2 monit

can get CPU usage and memory consumption for processes (and clusters) (Ctrl +c Exit)

Real-time Centralized log processing: PM2 logs

Powerful API:PM2 web

You want to monitor all the processes that are managed by PM2, and you want to monitor the state of the machines that are running these processes,

[[Email protected]Dev uops]$ pm2 WebLaunching Web interface on port9615[PM2] Process/usr/local/node/lib/node_modules/pm2/lib/httpinterface.js LAUNCHED[PM2] Process Launched┌────────────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐│app Name│ID│mode│pid│status│restarted│Uptime│memory│watching │├────────────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤│app│
     0│fork│984│online│1│9m│74.762MB│DISABLED││PM2-http-interface│1│fork│1878│online│0│0s│15.070mb│disabled │└────────────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘use ' PM2Info<ID|name> ' to get MoreDetails about an app

When you start the program, you access it in the browser: http://localhost:9615

Wipe, my eyes are bright blind, so cool, unexpectedly the deployment of the server information and program information are displayed:

This thing to the program running Monitoring page development is really helpful, hehe ~ ~

Well, I admit I'm a little out of control, a little bit confusing, and I'd like to rearrange the order again:

start <app_name|id|all><app_name|id|all> Restart application: PM2 Restart program information: PM2 describe id| All monitoring: PM2 monit Real-time centralized log processing: PM2 logsapi:p m2 web (port: 9615)

Recommendation: HTTPS://GITHUB.COM/UNITECH/PM2

http://www.oschina.net/translate/goodbye-node-forever-hello-pm2?cmp

Nodejs deployment on the tall-PM2

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.