Cannot start MongoDB as a service

后端 未结 24 1488
情话喂你
情话喂你 2020-12-07 10:07

I have been developing for MongoDB for some months now and would like to install it as a service on my Windows 7 Enterprise machine. The following is the command that I hav

相关标签:
24条回答
  • 2020-12-07 10:33

    To others who may have the same problem on Windows Server 2012:

    I have just got the same problem with Mongo 3.0.3 on Windows Server 2012. I am not a system admin so I don't know what they have changed for sc.exe. I have to use

    sc.exe create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=C:\mongodb\mongod.cfg" DisplayName= "MongoDB" start= "auto"
    

    This is without the \"\" for both binary and config file paths comparing to the one on their website.

    0 讨论(0)
  • 2020-12-07 10:33

    I had made few changes in the Config start-up file, which caused this issue. When I looked in the "mongo.log" file, it said

    "Cannot start server. Detected data files in E:\Mongo\data\db created by storage engine 'wiredTiger'. The configured storage engine is 'mmapv1'., terminating"

    Resetting the storage engine back to 'wiredTiger' resolved the issue for me. Hope this helps others.

    0 讨论(0)
  • 2020-12-07 10:34

    I ran this command:

    C:\MongoDB\Server\3.4\bin>net start MongoDB
    

    And got this message:

    The service is not responding to the control function. More help is available by typing NET HELPMSG 2186.

    After some trials and errors, I noticed when following the tutorial it asked me to name my file mongod.conf but the command was trying to refer to mongod.cfg.

    As soon as I corrected that name and re-run the commands,

    C:\MongoDB\Server\3.4\bin>sc.exe delete MongoDB
    [SC] DeleteService SUCCESS
    
    C:\MongoDB\Server\3.4\bin>sc.exe create MongoDB binPath= "\"C:\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\MongoDB\Server\3.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
    [SC] CreateService SUCCESS
    
    C:\MongoDB\Server\3.4\bin>net start MongoDB
    The MongoDB service is starting....
    The MongoDB service was started successfully.
    

    The service started running fine.

    0 讨论(0)
  • 2020-12-07 10:35

    Have your checked you logging to see the real problem?

    I suggest extracting the Mongo installation to c:\mongodb.

    Create the c:\mongodb\logs and the c:\mongodb\data\db directories.

    Then browse the the c:\mongodb\bin directory and run the following to remove the service (if you've installed it!):

    mongod --remove
    

    Then install the service, specifying the log and data directories:

    mongod --logpath c:\mongodb\logs\mongo.log --dbpath c:\mongodb\data\db --directoryperdb --install
    

    Then if there is a problem starting the service you should see the reason in the specified log file.

    More info here.

    0 讨论(0)
  • 2020-12-07 10:37

    Following works with MongoDB 3.6.0

    Make sure you have these folders:

    • C:\mongodb\data
    • C:\mongodb\data\db

    Then all you need are these commands:

    • mongod --directoryperdb -dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --service --install
    • net start MongoDB
    • mongo
    0 讨论(0)
  • 2020-12-07 10:37

    Remember to create the database before starting the service

    C:\>"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe" --dbpath d:\MONGODB\DB
    2016-10-13T18:18:23.135+0200 I CONTROL  [main] Hotfix KB2731284 or later update is installed, no need to zero-out data files
    2016-10-13T18:18:23.147+0200 I CONTROL  [initandlisten] MongoDB starting : pid=4024 port=27017 dbpath=d:\MONGODB\DB 64-bit host=mongosvr
    2016-10-13T18:18:23.148+0200 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
    2016-10-13T18:18:23.149+0200 I CONTROL  [initandlisten] db version v3.2.8
    2016-10-13T18:18:23.149+0200 I CONTROL  [initandlisten] git version: ed70e33130c977bda0024c125b56d159573dbaf0
    2016-10-13T18:18:23.150+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1p-fips 9 Jul 2015
    2016-10-13T18:18:23.151+0200 I CONTROL  [initandlisten] allocator: tcmalloc
    2016-10-13T18:18:23.151+0200 I CONTROL  [initandlisten] modules: none
    2016-10-13T18:18:23.152+0200 I CONTROL  [initandlisten] build environment:
    2016-10-13T18:18:23.152+0200 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
    2016-10-13T18:18:23.153+0200 I CONTROL  [initandlisten]     distarch: x86_64
    2016-10-13T18:18:23.153+0200 I CONTROL  [initandlisten]     target_arch: x86_64
    2016-10-13T18:18:23.154+0200 I CONTROL  [initandlisten] options: { storage: { dbPath: "d:\MONGODB\DB" } }
    2016-10-13T18:18:23.166+0200 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=8G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
    2016-10-13T18:18:23.722+0200 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
    2016-10-13T18:18:23.723+0200 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'd:/MONGODB/DB/diagnostic.data'
    2016-10-13T18:18:23.895+0200 I NETWORK  [initandlisten] waiting for connections on port 27017
    

    Then you can stop the process Control-C

    2016-10-13T18:18:44.787+0200 I CONTROL  [thread1] Ctrl-C signal
    2016-10-13T18:18:44.788+0200 I CONTROL  [consoleTerminate] got CTRL_C_EVENT, will terminate after current cmd ends
    2016-10-13T18:18:44.789+0200 I FTDC     [consoleTerminate] Shutting down full-time diagnostic data capture
    2016-10-13T18:18:44.792+0200 I CONTROL  [consoleTerminate] now exiting
    2016-10-13T18:18:44.792+0200 I NETWORK  [consoleTerminate] shutdown: going to close listening sockets...
    2016-10-13T18:18:44.793+0200 I NETWORK  [consoleTerminate] closing listening socket: 380
    2016-10-13T18:18:44.793+0200 I NETWORK  [consoleTerminate] shutdown: going to flush diaglog...
    2016-10-13T18:18:44.793+0200 I NETWORK  [consoleTerminate] shutdown: going to close sockets...
    2016-10-13T18:18:44.795+0200 I STORAGE  [consoleTerminate] WiredTigerKVEngine shutting down
    2016-10-13T18:18:45.116+0200 I STORAGE  [consoleTerminate] shutdown: removing fs lock...
    2016-10-13T18:18:45.117+0200 I CONTROL  [consoleTerminate] dbexit:  rc: 12
    

    Now your database is prepared and you can start the service using

    C:\>net start MongoDB
    The MongoDB service is starting.
    The MongoDB service was started successfully.
    
    0 讨论(0)
提交回复
热议问题