PM2 is a process manager for a node app with load Balancing. When you want to take your standalone code all the CPUs on the server, and ensure that the process is always alive, 0 seconds of overloading, PM2 is perfect, let's look at PM2 commonly used command usage introduction bar.
PM2 (source on GitHub) is an open s
and start four apps. js # You can also pass the 'Max' parameter to start # the correct number of processes depends on the number of Cpu cores $ pm2 start app. js -- name my-api # name Process $ pm2 list # display all process statuses $ pm2 monit # monitor all processes $ pm2
The PM2 is a process manager for a node app with load-balancing capabilities. PM2 is perfect when you want to take advantage of all of your standalone code on all the CPUs on the server and ensure that the process is always alive, with 0 seconds of overloading. installation
NPM install-g PM2
usage
$ npm Install pm2-
environment operation. This is essentially configured in Forever,package.json: "Scripts": {"Start": "Forever App.js","Test": "Supervisor App.js"}, 3, PM2 use it to install it first, with the root account and the global mode installation: NPM install-g PM2 Use it to start the program (in the current directory can be started directly, PM2 start app.js--name uops)
be considered forever finish PM2, why, a picture you know the answer.This is the PM2 website to give the demo, we can clearly see the whole cluster mode, state, CPU utilization and even memory size, and forever give what? NullWhat if I want to monitor all process status in real time?This is the power of PM2, multi-pro
infinite loops)Console Detectionprovide HTTP APIremote control and real-time interface API (Nodejs module, allows interaction with PM2 process Manager)tested Nodejs v0.11 v0.10 v0.8 version, compatible with Coffeescript, based on Linux and MacOS.installationNPM install-g PM2Usage$ npm Install pm2-g # command-line installation PM2$
│├──────────┼────┼──────┼─────┼────────┼───────────┼────────┼─────────────┼──────────┤│app │0│fork│308│online│0│0s│21.879Mb│disabled│└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴─────────────┴──────────┘use ' PM2 InfoID|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 prog
convenient and powerful features allow us to configure the SYSTEMD to enable Caddy boot, we execute the following command
pm2 start caddy --name caddyStart -- -conf /你的Caddyfile路径/Caddyfile
Through the above command we implemented the PM2 start Management Caddy, and then we still have to execute the boot command and save command, as follows
Restart your server, you will find that you have been able to acc
infinite loops)Console Detectionprovide HTTP APIremote control and real-time interface API (Nodejs module, allows interaction with PM2 process Manager)tested Nodejs v0.11 v0.10 v0.8 version, compatible with Coffeescript, based on Linux and MacOS.installationnpm install-g PM2usage$ npm Install pm2-g # command-line installation PM2$
path
pm2 start App.js-o./ Logs/out.log-e./logs/error.log
2. Stop
# AppName and AppId can see through the PM2 list
pm2 stop appname|appid
# Stop all applications
PM2 stop all
3. reboot
4. Delete
# After the stop can be restarted through the restart, delete cannot restart
the application unexpectedly exits the restart, by default 15 times (counting from 0)Exec_mode: Application startup mode, which is set to Cluster_mode (cluster), the default is forkError_file: Error log file for custom applicationOut_file: Custom Application log filesPid_file: Customizing the application's PID fileWatch: If monitoring mode is enabled, the default is False. If set to True, PM2 is automatically overloaded when the application changes.
, which you can deal with in an old-fashioned way:$ tail -f /path/to/log1 /path/to/log2 ...But we thought very thoughtful, we added the logs function:$ pm2 logs# # #快速恢复Now that things are going well, your process is buzzing and you need to do a hard restart (restart). Now? Yes, first of all, dump:$ pm2 dumpYou can then restore it from the file:$ pm2 kill //
First, Introduction
PM2 is an application process manager with load balancing function, similar to Supervisor,forever.
Second, the installation
Linux binaries Download Address: https://nodejs.org/distCD ONEINSTACK/SRCwget https://nodejs.org/dist/v4.2.4/node-v4.2.4-linux-x64.tar.gzTar xzf node-v4.2.4-linux-x64.tar.gzCP node-v4.2.4-linux-x64/bin/node/usr/local/bin/Cp-r node-v4.2.4-linux-x64/lib/node_modules/usr/local/lib/Ln-s/USR/LOCAL/LIB/NODE_MODUL
data, and so on ... This means a lot of log, which you can deal with in an old-fashioned way:$ tail-f/path/to/log1/path/to/log2 ...But we thought very thoughtful, we added the logs function:$ PM2 LogsFast RecoveryNow that things are going well, your process is buzzing and you need to do a hard restart (restart). Now? Yes, first of all, dump:$ PM2 DumpYou can then restore it from the file:$
# You can also pass the ' max ' argument to start# The correct number of processes depends on the number of cores in the CPU$ pm2 Start app.js--name My-api # naming process$ PM2 List # shows all process states$ PM2 Monit # Monitor All Processes$ PM2 Logs # show all process l
.Input, the following command mate ID or name to view the details of a process0Content related to restart times, run time, script path, parameters, log path, run mode, and moreInput$ PM2 MonitStop, restart, etc commandsStop [app-name| ID] #停止某一个进程, you can use app-name or delete [app-name| Delete all #删除并停止所有进程 You can further see the CPU and memory usage of each service.Log monitoringIf you have been using it tail -f log_file.log log_error.log
PM2 is a very good tool for running managed services on a node. JS-based project. It is based on the command line interface and offers many features: built-in load balancer and so on, let's take a look.First, IntroductionPM2 is an application process manager with load balancing, similar to Supervisor,forever.Second, installationLinux binaries:https://nodejs.org/distCD ONEINSTACK/SRCwget https://nodejs.org/dist/v4.2.4/node-v4.2.4-linux-x64.tar.gzTar xz
decompression to complete, it is recommended to change the extracted directory to node, or other meaningful name, or node upgrade too quickly on the original basis of the upgrade but the file directory display version name does not match.3. Configure node to run globallyexport NODE_HOME=/file/software/nodeexport PATH=$NODE_HOME/bin:$PATH #找到下边这一行添加进去,记得你自己的路径搞对了。export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROLRestart it and try it, NODE,NPM can be enabled globally.Recommend the above
Detailed description of pm2 configuration based on Vue + Koa, detailed description of vuekoapm2
Currently, we use the following technology stacks: front-end Vue, backend Koa, and database Mongodb.
However, every time a service is started, npm start, node./server/app. js are required. It is very troublesome to keep these two windows open at the same time.
And because I use koa, and I do not use the koa scaffolding written by Uncle wolf. It is a small m
TODO:Node.js PM2 How to use
The PM2 is a process manager for a node app with load-balancing capabilities.
PM2 is perfect when you want to take advantage of all of your standalone code on all the CPUs on the server and ensure that the process is always alive, with 0 seconds of overloading.
1. Installing PM2
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.