如何 运行 MongoDB 使用 PM2

How to run MongoDB using PM2

如何 运行 MongoDB 使用 PM2?我正在使用 Linux VPS (CentOS),我尝试这样做:

pm2 mongod

^ 这行得通,但问题是我需要绑定 IP 和 DBPath 名称

pm2 mongod -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth

^ 但由于 PM2 标志,这不起作用。那么我怎样才能 运行 使用 PM2 或者至少让它在我关闭终端时不会关闭

您可以创建一个 SH 文件,其中 运行 命令,然后 运行 SH 文件。

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

另一种方法是这样;

pm2 start "mongod -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth"

官方方式是
pm2 start mongod -- -dbpath /home/[ommitted]/data/db --bind_ip [ommitted] -auth

如他们主页所示 https://pm2.keymetrics.io/docs/usage/quick-start/