2016-09-21 129 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的傳入連接。將會有一個警告聲明您正在向所有人開放端口,但有必要允許連接到數據庫。