2016-09-21 130 views
0

我已经通过官方文档在亚马逊的linux环境中安装mongodb。与mongodb的远程连接

安装后,我做了

[[email protected] etc]# service mongod restart 
dirname: missing operand 
Try 'dirname --help' for more information. 
Stopping mongod:           [ OK ] 
Starting mongod:           [FAILED] 

启动失败,但是当我只写的mongod是说

[[email protected] etc]# mongod 
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] MongoDB starting : pid=16633 port=27017 dbpath=/data/db 64-bit host=ip-172-31-20-59 
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] db version v3.2.9 
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c 
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.0-fips 29 Mar 2010 
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] allocator: tcmalloc 
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] modules: none 
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten] build environment: 
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten]  distmod: amazon 
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten]  distarch: x86_64 
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten]  target_arch: x86_64 
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten] options: {} 
2016-09-21T05:23:57.726+0000 I -  [initandlisten] Detected data files in /data/db created by the 'mmapv1' storage engine, so setting the active storage engine to 'mmapv1'. 
2016-09-21T05:23:57.735+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal 
2016-09-21T05:23:57.735+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed 
2016-09-21T05:23:57.899+0000 I JOURNAL [durability] Durability thread started 
2016-09-21T05:23:57.899+0000 I JOURNAL [journal writer] Journal writer thread started 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] **  We suggest setting it to 'never' 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] 
2016-09-21T05:23:57.907+0000 I FTDC  [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data' 
2016-09-21T05:23:57.907+0000 I NETWORK [initandlisten] waiting for connections on port 27017 
2016-09-21T05:23:57.907+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker 

,然后另一台主机上,我开始mongo

[[email protected] etc]# mongo 
MongoDB shell version: 3.2.9 
connecting to: test 
Server has startup warnings: 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] **  We suggest setting it to 'never' 
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] 
> 

和在mongod控制台它接受了连接

2016-09-21T05:25:09.684+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:49068 #1 (1 connection now open) 

现在我有几个问题,

1.I我不能够理解我的蒙戈是工作或没有? (东阳开始的mongod总是失败,但上键入唯一的mongod工作)

2.我无法通过我的robomongo连接到远程服务器蒙哥它说:“无法连接到MongoDB的”

我mongo.config文件 - >

# mongod.conf 

    # for documentation of all options, see: 
    # http://docs.mongodb.org/manual/reference/configuration-options/ 

    # where to write logging data. 
    systemLog: 
     destination: file 
     logAppend: true 
     path: /var/log/mongodb/mongod.log 

    # Where and how to store data. 
    storage: 
     dbPath: /var/lib/mongo 
     journal: 
     enabled: true 
    # engine: 
    # mmapv1: 
    # wiredTiger: 

    # how the process runs 
    processManagement: 
     fork: true # fork and run in background 
    #pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile 

    # network interfaces 
    net: 
     port: 27017 
     bindIp: 0.0.0.0,10.0.0.1,127.0.0.1 # Listen to local interface only, comment to listen on all interfaces. 

回答

0

你的bindIp设置有点怪异。为什么用逗号分隔列表?只需使用0.0.0.0

之后,打开安全组中的端口27017,您将能够连接。

+0

谢谢我做了所有的事情,但忘了添加在安全组中您的答案提醒我 – adasdasd

0

回答您的问题:

  1. 如果能够连接使用mongo外壳,然后服务器正在运行。否则,您将看到类似Connection refusedexception: connect failedexception: connect failed的错误

  2. 默认情况下,AWS防火墙的限制性很强。请检查您是否允许从任何主机到端口27017的传入连接。将会有一个警告声明您正在向所有人开放端口,但有必要允许连接到数据库。