mongodb 正在运行吗? [英] Is mongodb running?

查看:40
本文介绍了mongodb 正在运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的 unix 服务器上安装了 mongodb 和 php 驱动程序.

I have installed mongodb and the php drivers on my unix server.

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

My question is how can I tell if mongodb is running? Is there a simple command line query to check status? If I start it once from the shell will it keep running if I exit the shell (this doesn't seem to be the case). How can I make the mongodb connection persistent and auto start on server reboot?

我可以跑:

-bash-3.2$ su
密码:
[root@xxx]# cd/var/lib
[root@xxx]# ./mongodb-linux-i686-1.6.5/bin/mongod
./mongodb-linux-i686-1.6.5/bin/mongod --help 帮助和启动选项
2 月 23 日星期三 08:06:54 MongoDB 开始:pid=7271 port=27017 dbpath=/data/db/32-bit

-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

** 注意:当使用 MongoDB 32 位时,您被限制为大约 2 GB 的数据
** 见 http://blog.mongodb.org/post/137788967/32-位限制

** 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

** 警告:您正在 OpenVZ 中运行.这是已知的坏了!!!

** 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
2 月 23 日星期三 08:06:54 git 版本:0eb017e9b2828155a67c5612183337b89e12e291
2 月 23 日星期三 08:06:54 系统信息:Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri
2 月 15 日 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Wed Feb 23 08:06:54 [initandlisten] 等待端口 27017 上的连接
Wed Feb 23 08:06:54 [websvr] Web 管理界面监听端口 28017

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:

If I open a seperate shell I can then then connect to mongodb:

-bash-3.2$ cd/var/lib
-bash-3.2$ ./mongodb-linux-i686-1.6.5/bin/mongo
MongoDB 外壳版本:1.6.5
连接到:测试
db.foo.find()
{ "_id";: ObjectId("4d63d7d3eb95985ab19c8feb"), "a";:1}

-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 }

但是,如果我关闭初始外壳,则无法连接:

However if I close the initial shell I can't connect:

-bash-3.2$ cd/var/lib
-bash-3.2$ ./mongodb-linux-i686-1.6.5/bin/mongo
MongoDB 外壳版本:1.6.5
连接到:测试
Wed Feb 23 08:25:10 错误:无法连接到服务器 127.0.0.1(匿名):1154
异常:连接失败

-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"命令也将始终显示为一个单独的进程.

to see if mongod is running (you need to be root to do this, or prefix everything with sudo). Please note that the 'grep' command will always also show up as a separate process.

检查日志文件/var/log/mongo/mongo.log,看看是否有任何报告的问题.

Check the log file /var/log/mongo/mongo.log to see if there are any problems reported.

这篇关于mongodb 正在运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆