gpt4 book ai didi

mongodb - mongodb在运行吗?

转载 作者:IT老高 更新时间:2023-10-28 11:12:45 33 4
gpt4 key购买 nike

我已经在我的 Unix 服务器上安装了 Mongodb 和 PHP 驱动程序。

我的问题是如何判断 Mongodb 是否正在运行?是否有一个简单的命令行查询来检查状态?如果我从 shell 启动它一次,如果我退出 shell,它会继续运行(这似乎不是这种情况)。如何使 Mongodb 连接持久并在服务器重启时自动启动?

我可以跑:

-bash-3.2$ su  
Password:
[root@xxx]# cd /var/lib
[root@xxx]# ./mongodb-linux-i686-1.6.5/bin/mongod
./mongodb-linux-i686-1.6.5/bin/mongod --help for help and startup options
Wed Feb 23 08:06:54 MongoDB starting : pid=7271 port=27017 dbpath=/data/db/ 32-bit

** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
** see http://blog.mongodb.org/post/137788967/32-bit-limitations

** WARNING: You are running in OpenVZ. This is known to be broken!!!

Wed Feb 23 08:06:54 db version v1.6.5, pdfile version 4.5
Wed Feb 23 08:06:54 git version: 0eb017e9b2828155a67c5612183337b89e12e291
Wed Feb 23 08:06:54 sys info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri
Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Wed Feb 23 08:06:54 [initandlisten] waiting for connections on port 27017
Wed Feb 23 08:06:54 [websvr] web admin interface listening on port 28017

如果我打开一个单独的 shell,我就可以连接到 mongodb:

-bash-3.2$ cd /var/lib  
-bash-3.2$ ./mongodb-linux-i686-1.6.5/bin/mongo
MongoDB shell version: 1.6.5
connecting to: test
> db.foo.find()
{ "_id" : ObjectId("4d63d7d3eb95985ab19c8feb"), "a" : 1 }

但是,如果我关闭初始 shell,我将无法连接:

-bash-3.2$ cd /var/lib  
-bash-3.2$ ./mongodb-linux-i686-1.6.5/bin/mongo
MongoDB shell version: 1.6.5
connecting to: test
Wed Feb 23 08:25:10 Error: couldn't connect to server 127.0.0.1 (anon):1154
exception: connect failed

最佳答案

检查任一:

ps -edaf | grep mongo | grep -v grep  # "ps" flags may differ on your OS

/etc/init.d/mongodb status     # for MongoDB version < 2.6

/etc/init.d/mongod status # for MongoDB version >= 2.6

service mongodb status         # for MongoDB version < 2.6

service mongod status # for MongoDB version >= 2.6

查看 mongod 是否正在运行(您需要是 root 才能执行此操作,或者在所有内容前加上 sudo)。请注意,“grep”命令也将始终显示为单独的进程。

查看日志文件/var/log/mongo/mongo.log,看看是否有问题报告。

关于mongodb - mongodb在运行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5091624/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com