0

我无法通过外部 API 或mongo本地客户端连接到我的 mongo 数据库,但可以从远程主机毫无问题地连接。

  • 我已经启动mongod并且可以通过访问确认服务器正在运行127.0.0.1:27017
  • 我没有运气就遵循了这个答案
  • 我尝试为 mongo 创建一个全新的数据库目录以生成一组新的数据库文件,但仍然没有运气 - 所以这不是锁定文件或权限问题。

    $ mongo --verbose
    
    MongoDB shell version: 2.4.4
    Mon Jun 24 20:11:08.764 versionArrayTest passed
    connecting to: test
    Mon Jun 24 20:11:08.847 creating new connection to:127.0.0.1:27017
    Mon Jun 24 20:11:08.847 BackgroundJob starting: ConnectBG
    Mon Jun 24 20:12:11.848 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
    Mon Jun 24 20:12:11.848 User Assertion: 12513:connect failed
    exception: connect failed
    

我正在运行 Ubuntu 12.04,我已经从 10gen repo 安装了 mongo。原本一切正常,但重新启动服务器后,mongo无法连接。

我的 netstat 返回:

    $ netstat -nap

    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      -               
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:28017           0.0.0.0:*               LISTEN      -  
4

2 回答 2

1

我在 CentOs 6.4 上遇到了同样的问题(Mongo 2.4.5,但实际上它也发生在其他版本中)。有奇怪的线程问题。我调试了 mongo 并找到了解决方法。需要 mongo 重新编译。当虚假唤醒发生时,boost 库中的 timed_wait 方法似乎返回超时。我不确定错误在哪里:mongo、boost、glibc、linux 内核。

Mongo 2.4.5 在 src/mongo/util/background.cpp 方法中替换 BackgroundJob::wait

bool BackgroundJob::wait( unsigned msTimeOut ) {
        verify( !_status->deleteSelf ); // you cannot call wait on a self-deleting job
        scoped_lock l( _status->m );
        boost::system_time const endTime = boost::get_system_time()+ boost::posix_time::milliseconds(msTimeOut);
        if ( msTimeOut ) {
            while ( _status->state != Done ) {
               if ( ! _status->finished.timed_wait( l.boost() , endTime ) ){
                  boost::system_time const curTime=boost::get_system_time();
                  if((curTime - endTime).total_milliseconds()>0){
                     return false;
                  }
                  else {
                    LOG( LL_WARNING ) << "backgroundjob " << name() << "warning: spurious wakeup return TIMEOUT code but we want wait "<<(endTime-curTime).total_milliseconds()<<" ms yet! Try again." << endl;
                  }
               }
           }
        }
        else {
           while ( _status->state != Done ) {
              _status->finished.wait( l.boost() );
           }
        }
        return true;
    }

一段时间后,我发现 Perl 的其他问题: perl -MCPAN -e 'install "DateTime"'

简单的 Perl 测试失败:

使用严格;使用警告;

使用测试::更多;

使用日期时间;

{ 我的 $epochtest = DateTime->from_epoch( epoch => '997121000' ); is($epochtest->epoch, 997121000, "epoch 方法返回正确值"); }

我发现如果我删除 /etc/localtime 文件,Perl 和 Mongo 的问题就会消失!

于 2013-08-15T05:42:36.270 回答
0

我在 Ubuntu 14.04 上运行 mongod 3.0.2 时遇到了同样的问题:

MongoDB shell 版本:2.4.9 Sun Apr 26 00:57:31.604 versionArrayTest 通过连接到:xxx.xxx.xxx.xxx:27000/test Sun Apr 26 00:57:31.667 创建新连接到:xxx.xxx.xxx。 xxx:27000 Sun Apr 26 00:57:31.667 BackgroundJob 开始:ConnectBG Sun Apr 26 00:57:31.668 已连接!Sun Apr 26 00:57:31.671 用户断言:18:{ ok: 0.0, errmsg: "auth failed", code: 18 } Sun Apr 26 00:57:31.673 Error: 18 { ok: 0.0, errmsg: "auth failed ”,代码:18 } at src/mongo/shell/db.js:228 Sun Apr 26 00:57:31.673 用户断言:12514:login failed Sun Apr 26 00:57:31.673 freeing 1 uncollected N5mongo20DBClientWithCommandsE objects 异常:登录失败

分发来自 MMS Mongo: https ://mms.mongodb.com/

然后我注意到在我的 MMS 页面上,在 mongod 进程 -> 椭圆菜单下;一个名为:“连接到这个 Mongod 实例”的菜单,它返回一个字符串:“/var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.0.2/bin/mongo RBX1:27000”(RBX1 是我的实例并且 27000 是我设置的端口)一旦我在我的 shell 中应用了这个字符串(我添加了额外的用户/密码和 authenticationDatabase 参数,它就起作用了。

我现在可以在本地和远程连接到我的 Mongod 实例。

你是通过 MMS 安装 MongoDB 的吗?

于 2015-04-26T01:05:48.357 回答