Search code examples
mongodbubuntucodio

Installing mongodb 3.2 in Codio using the built-in Terminal (Ubuntu 14.04.3)


I am trying to install mongodb 3.2 into codio using the terminal and I am following the guide on their website here. (I'm new to mongodb and nosql)

I got to Step 4 Installing mongodb using this command:

sudo apt-get install -y mongodb-org

Got the following at the end:

..    
The following packages will be upgraded:                                                                                                                                     
      mongodb-org                                                                                                                                                                
    1 upgraded, 0 newly installed, 0 to remove and 51 not upgraded.                                                                                                              
    2 not fully installed or removed.                                                                                                                                            
    Need to get 3,554 B of archives.                                                                                                                                             
    After this operation, 0 B of additional disk space will be used.                                                                                                             
    Get:1 http://repo.mongodb.org/apt/ubuntu/ trusty/mongodb-org/3.2/multiverse mongodb-org amd64 3.2.2 [3,554 B]                                                                
    Fetched 3,554 B in 0s (249 kB/s)                                                                                                                                             
    (Reading database ... 37250 files and directories currently installed.)                                                                                                      
    Preparing to unpack .../mongodb-org_3.2.2_amd64.deb ...                                                                                                                      
    Unpacking mongodb-org (3.2.2) over (3.2.1) ...                                                                                                                               
    Setting up mongodb-org-server (3.2.2) ...                                                                                                                                    
    start: Job failed to start                                                                                                                                                   
    invoke-rc.d: initscript mongod, action "start" failed.                                                                                                                       
    dpkg: error processing package mongodb-org-server (--configure):                                                                                                             
     subprocess installed post-installation script returned error exit status 1                                                                                                  
    dpkg: dependency problems prevent configuration of mongodb-org:                                                                                                              
     mongodb-org depends on mongodb-org-server; however:                                                                                                                         
      Package mongodb-org-server is not configured yet.                                                                                                                          

    dpkg: error processing package mongodb-org (--configure):                                                                                                                    
     dependency problems - leaving unconfigured                                                                                                                                  
    Errors were encountered while processing:                                                                                                                                    
     mongodb-org-server                                                                                                                                                          
     mongodb-org                                                                                                                                                                 
    E: Sub-process /usr/bin/dpkg returned an error code (1)

Then I run

sudo service mongod start

or

sudo service mongodb start

Both commands will response with start: Job failed to start or mongodb: unrecognized service

Am I missing something here like e.g. mongodb requires other packages to be installed? following wrong guide version? do I need to create config file? if I do how? because it did not create one, or mongodb doesn't work on codio using the built-in terminal? Is mongodb-org-server already installed or running? I've been searching for exact or similar things, also tried different command but no luck.


Solution

  • This is because of the ulimit settings in the service script of mongod.

    Mongodb recommends 64000 for 'open files' key in ulimit settings.

    https://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

    In codio this is set to 4096.

    run the below command in codio terminal and see the 'open files' setting.

    ulimit -a

    I don't think this value can be changed at OS level in codio. However, we can remove this setting (NOT recommended by MongoDb) from the upstart file.

    Steps:


    1. To keep it simple and less verbose, start with installing just mongodb-org-server instead of installing the complete mongodb-org.

    sudo apt-get install -y mongodb-org-server


    2. As we know it fails with errors - '..Job failed to start ..' bla..bla. Just ignore them for a min. Edit '/etc/init/mongod.conf' file as root in whatever editor you like. I like vim. :)

    sudo vim /etc/init/mongod.conf


    3. Comment out(type '#' at the beginning of the line) the line starts with 'limit nofile' as below. Then save and close the file.

    #limit nofile 64000 64000


    4. Now install the complete 'mongodb-org' package by running the command in terminal as shown below.

    sudo apt-get install -y mongodb-org


    5. Go ahead try mongo in terminal now. If the mongod service is running, it connects to the default db successfully.



    Hope this helps.

    Thank you.