问题
How do I run MongoDB using PM2? I'm using a Linux VPS (CentOS) and I tried doing this:
pm2 mongod
^ and that works but the problem is I need to bind IP and DBPath name
pm2 mongod -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth
^ But that doesn't work because of PM2 flags. So how can I run it using PM2 or at least make it so it doesn't shut down when I close the terminal
回答1:
You can create an SH file that runs the command, then run the SH file.
1. For example, name it "run.sh"
2. Open/edit file
3. Add this to the first line of the file mongod -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth
4. pm2 start run.sh
Another way that you can do is this;
pm2 start "mongod -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth"
来源:https://stackoverflow.com/questions/55303828/how-to-run-mongodb-using-pm2