Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB正在运行,但可以';不能使用shell连接_Shell_Mongodb - Fatal编程技术网

MongoDB正在运行,但可以';不能使用shell连接

MongoDB正在运行,但可以';不能使用shell连接,shell,mongodb,Shell,Mongodb,CentOS 5.x Linux和MongoDB 2.0.1(试用过的主静态和旧静态) MongoDB正在运行: root 31664 1.5 1.4 81848 11148 ? Sl 18:40 0:00 ./mongod -f mongo.conf -vvvvv --fork 使用简单的shell连接访问服务器失败: [root@xxxx bin]# ./mongo MongoDB shell version: 2.0.1 connecting to:

CentOS 5.x Linux和MongoDB 2.0.1(试用过的主静态和旧静态)

MongoDB正在运行:

root     31664  1.5  1.4  81848 11148 ?        Sl   18:40   0:00 ./mongod -f mongo.conf -vvvvv --fork
使用简单的shell连接访问服务器失败:

[root@xxxx bin]# ./mongo
MongoDB shell version: 2.0.1
connecting to: test
Mon Oct 31 18:41:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
端口28017上的web界面可以正常加载,从远程Linux主机使用MongoDB外壳也可以正常加载。也可以telnet到localhost:27017,这意味着没有端口被阻止。这台机器上也没有运行SELinux。我还尝试过显式指定
localhost:2017/db
,但没有效果

$ ./mongo remote-ip:27017
MongoDB shell version: 2.0.1
connecting to: remote-ip:27017/test
> show dbs
local   0.03125GB
>
日志完全不涉及这个主题:

.....
Mon Oct 31 18:40:34 [initandlisten] fd limit hard:1024 soft:1024 max conn: 819
Mon Oct 31 18:40:34 [initandlisten] waiting for connections on port 27017
Mon Oct 31 18:40:34 BackgroundJob starting: snapshot
Mon Oct 31 18:40:34 BackgroundJob starting: ClientCursorMonitor
Mon Oct 31 18:40:34 BackgroundJob starting: PeriodicTask::Runner
Mon Oct 31 18:40:34 [websvr] fd limit hard:1024 soft:1024 max conn: 819
Mon Oct 31 18:40:34 [websvr] admin web console waiting for connections on port 28017
扫描mongo shell客户端只显示一个有问题的调用:

[pid 31708] connect(4, {sa_family=AF_INET, sin_port=htons(27017), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EBADF (Bad file descriptor)
文件系统是干净的,没有ulimit限制(以root身份运行以进行测试)。我可以从图中看出,
mongo
客户端正在尝试通过TCP(
AF\u INET
)进行连接,但是由于它是本地的,并且MongoDB创建了一个文件套接字,有没有办法告诉客户端改为通过该套接字进行连接?或者更好的是,为什么客户会抛出EBADF

编辑:我的基本Mongo配置:

dbpath=/root/mongodb-linux-i686-2.0.1/data
logpath=/root/mongodb-linux-i686-2.0.1/logs/mongo.log
slowms=15
rest=1

我认为这个版本的mongoDb客户端缺少一些默认配置。尝试运行:

mongo 127.0.0.1:27017
这很奇怪,但后来我遇到的问题消失了:)(所以简单的命令‘mongo’w/o any params开始对我再次起作用)


与其说是答案,不如说是供参考的:我刚刚点击了这个,通过搜索找到了这个问题。以下是我的详细经历:

外壳错误

markdsievers@ip-xx-xx-xx-xx:~$ mongo
MongoDB shell version: 2.0.1
connecting to: test
Wed Dec 21 03:36:13 Socket recv() errno:104 Connection reset by peer 127.0.0.1:27017
Wed Dec 21 03:36:13 SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [1] server [127.0.0.1:27017] 
Wed Dec 21 03:36:13 DBClientCursor::init call() failed
Wed Dec 21 03:36:13 Error: Error during mongo startup. :: caused by :: DBClientBase::findN: transport error: 127.0.0.1 query: { whatsmyuri: 1 } shell/mongo.js:84
exception: connect failed
Mongo日志显示

Wed Dec 21 03:35:04 [initandlisten] connection accepted from 127.0.0.1:50273 #6612
Wed Dec 21 03:35:04 [initandlisten] connection refused because too many open connections: 819

这可能表明另一个答案(JaKi)也遇到了同样的问题,其中一些连接被清除,shell(其他客户端)的访问再次成为可能。

这实际上不是一个错误。。。这里发生的事情是Mongo依赖于一个守护进程来运行本地数据库服务器,因此为了“启动”shell中的Mongo服务器,您必须首先启动Mongo服务

对于Fedora Linux(我使用的发行版),您必须运行以下命令:

1 sudo service mongod start
2 mongo
就在这里!服务器即将运行。现在,如果你想要Mongo服务 要在系统启动时启动,则必须运行:

sudo chkconfig --levels 235 mongod on
就这些!如果这样做,现在在shell中只需按顺序键入mongo 要启动服务器,问题是您必须先启动服务,然后再启动服务器:)


另外,我发布的命令可能也适用于其他linux发行版,而不仅仅是fedora。。。如果不是这样,您可能需要根据所使用的发行版调整一些单词;)

我遇到了一个类似的问题,实际上是相同的(mongo进程正在运行,但无法连接到它)。 我所做的是转到我的数据库路径并删除mongod.lock,然后再试一次(重新启动mongo)。在那之后,它起了作用

希望它对你也有用。
我也有这个问题。你的MongoDB有日志记录吗? 我注意到日志文件中有以下“预分配”条目。 一旦我看到最后一行“在端口上等待连接”,我就可以连接了。 请注意,此“更快”模式需要12分钟才能初始化

威廉

Tue Apr 17 16:48:01 [initandlisten] MongoDB starting : pid=2248 port=27017 dbpath=E:\MongoData 64-bit host=ME
Tue Apr 17 16:48:01 [initandlisten] db version v2.0.0-rc0, pdfile version 4.5
Tue Apr 17 16:48:01 [initandlisten] git version: 8d4bf50111352cee5a4f1abf25b63442d6c45dc4
Tue Apr 17 16:48:01 [initandlisten] build info: windows (6, 1, 7601, 2, 'Service Pack 1') BOOST_LIB_VERSION=1_42
Tue Apr 17 16:48:01 [initandlisten] options: { bind_ip: "ip", dbpath: "E:\MongoData", directoryperdb: true, journal: true, logpath: "E:\MongoData\mongo.log", quiet: true, rest: true, service: true }
Tue Apr 17 16:48:01 [initandlisten] journal dir=E:/MongoData/journal
Tue Apr 17 16:48:01 [initandlisten] recover : no journal files present, no recovery needed
Tue Apr 17 16:48:02 [initandlisten] preallocateIsFaster=true 9.68
Tue Apr 17 16:48:04 [initandlisten] preallocateIsFaster=true 8.44
Tue Apr 17 16:48:06 [initandlisten] preallocateIsFaster=true 9.68
Tue Apr 17 16:48:06 [initandlisten] preallocateIsFaster check took 4.921 secs
Tue Apr 17 16:48:06 [initandlisten] preallocating a journal file E:/MongoData/journal/prealloc.0
Tue Apr 17 16:52:37 [initandlisten] preallocating a journal file E:/MongoData/journal/prealloc.1
Tue Apr 17 16:56:54 [initandlisten] preallocating a journal file E:/MongoData/journal/prealloc.2
Tue Apr 17 17:01:42 [initandlisten] waiting for connections on port 27017
Tue Apr 17 17:01:42 [websvr] admin web console waiting for connections on port 28017
我觉得很有用

如果您收到以下消息

start: Rejected send message, 1 matched rules; type="method_call", sender=":1.84" (uid=1000 pid=3215 comm="start mongodb ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
shriprasad@shriprasad-HP-430-Notebook-PC:/var/lib/mongodb$ mongo
您必须以root以外的用户身份尝试启动mongodb服务。您必须是root用户。因此,以root用户身份登录,然后按如下方式运行以下命令:

sudo bash

service mongodb start

删除
/var/lib/mongodb/mongod.lock
,然后发布
sudo服务mongodb start
,然后
mongo
,我还没有看到一个可接受的答案,所以我只需要加上2美分


我刚才也有同样的问题。过了一会儿,我意识到我已经在iptables规则中锁定了localhost。所以,检查你的防火墙。

我也有同样的问题。在我的例子中,MongoDB服务器没有运行

尝试在web浏览器中打开此文件:

http://localhost:28017

如果不能,这意味着您必须启动MongoDB服务器

在另一个终端选项卡中运行
mongod

然后在主选项卡中运行
mongo
,这是连接到MongoDB服务器的shell。

面临与Garrett上述错误相同的问题。 1.启用日志记录的MongoDB服务器正在运行,如使用ps命令所示 2.Mongo客户端或Mongoose驱动程序无法连接到数据库

解决方案: 1.删除Mongo.lock文件似乎可以恢复CentOS服务器的正常运行。 2.我们在生产中运行MongoDB方面是相当新的,并且每周都会看到同样的问题出现几次。 3.我们已经设置了一个cron计划来定期清理锁文件,并告知管理员发生了事件


正在搜索此问题的错误修复或任何其他更持久的解决方法。

您可能需要检查配置以查看是否设置了绑定ip

绑定ip:127.0.0.1

如果是,则只允许本地登录。将此注释掉并重新启动mongo,这可能会有所帮助。

在Ubuntu上:

1月27日星期三10:21:32错误:无法连接到服务器127.0.0.1 shell/mongo.js:84 异常:连接失败

解决方案

通过以下命令查找mongodb是否正在运行:

ps -ef | grep mongo
如果mongo未运行,您将获得:

 vimal     1806  1698  0 10:11 pts/0    00:00:00 grep --color=auto mongo
您正在看到mongo守护进程不在那里

然后通过配置文件(使用root priev)启动它:

您可以查看其他详细信息:

root@vimal:~# more /etc/mongodb.conf
打开一个新终端以查看mongod的结果——config/etc/mongodb.conf& 然后输入mongo。它应该是运行或grep

root@vimal:/data# ps -ef | grep mongo

root      3153     1  2 11:39 ?        00:00:23 mongod --config /etc/mongodb.conf
root      3772  3489  0 11:55 pts/1    00:00:00 grep --color=auto mongo 
现在

你得到了mongoDB的外壳


这不是故事的结尾。我将发布修复方法,以便每次都自动启动,大多数开发机器每天都会关闭,VM必须在下次启动时自动启动mongo。

如果您的bind_ip设置为127.0.0.1以外的任何值,那么您甚至需要从本地机器显式添加ip。所以
root@vimal:~# more /etc/mongodb.conf
root@vimal:/data# ps -ef | grep mongo

root      3153     1  2 11:39 ?        00:00:23 mongod --config /etc/mongodb.conf
root      3772  3489  0 11:55 pts/1    00:00:00 grep --color=auto mongo 
root@vimal:/data# mongo

MongoDB shell version: 2.0.4
connecting to: test
$mongod --dbpath <db name>
$mongo --shell
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip=127.0.0.1
bind_ip = 127.0.0.1,192.168.1.5
sudo service mongod restart
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org