MongoDB installation Ubuntu 12.04 LTS errors

installationmongodbUbuntu

I need some help with my MongoDB installation on a clean, fresh Ubuntu 12.04 LTS server with no nonsense installed. I thought it would be a piece of cake, but I got some errors and the Ubuntu-forums didn't had the answer I was looking for.

Before I started with the actual installation of MongoDB, I wanted the server to be up-to-date, so I typed:

$ sudo apt-get clean && sudo apt-get update && sudo apt-get upgrade

I went to to website from MongoDB (http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/) and followed their tutorial, so I typed:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
$ echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org

At this point I have MongoDB installed. Like we all know, in order to use MongoDB you need to start it using a terminal and after that you'll be able to connect with a seperated terminal/connection.

So, I typed:

ubuntu-user@ubuntu-vm:~$ mongo
MongoDB shell version: 3.0.1
connecting to: test
Server has startup warnings: 
2015-03-27T12:37:30.430+0100 I CONTROL  [initandlisten] 
2015-03-27T12:37:30.430+0100 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-03-27T12:37:30.430+0100 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-03-27T12:37:30.430+0100 I CONTROL  [initandlisten] 
> ^C

ubuntu-user@ubuntu-vm:~$ mongod
2015-03-27T12:38:54.773+0100 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2015-03-27T12:38:54.774+0100 I CONTROL  [initandlisten] dbexit:  rc: 100

Ofcourse, I don't want to use stackoverflow right away, before doing my own investigation first. I went online to look for answers and I noticed that lots of people using "export LC_ALL=C" to fix the variable problem. I also tried using dpkg.

ubuntu-user@ubuntu-vm:~$ export LC_ALL=C

ubuntu-user@ubuntu-vm:~$ dpkg-reconfigure locales
root@ubuntu-vm:~# dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = "en_US:en",
    LC_ALL = "c",
    LC_PAPER = "nl_NL.UTF-8",
    LC_ADDRESS = "nl_NL.UTF-8",
    LC_MONETARY = "nl_NL.UTF-8",
    LC_NUMERIC = "nl_NL.UTF-8",
    LC_TELEPHONE = "nl_NL.UTF-8",
    LC_IDENTIFICATION = "nl_NL.UTF-8",
    LC_MEASUREMENT = "nl_NL.UTF-8",
    LC_NAME = "nl_NL.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (c)
Generating locales...
  en_AG.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_AU.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_BW.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_CA.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_DK.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_GB.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_HK.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_IE.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_IN.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_NG.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_NZ.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_PH.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_SG.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_US.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_ZA.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_ZM.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
  en_ZW.UTF-8... /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (c)
up-to-date
Generation complete.

Apparently, that didn't work properly, so I needed to continue my search. I came up with another solution: edit the /etc/default/grub file with GRUB_CMDLINE_LINUX_DEFAULT="transparent_hugepage=never" and then I got this:

ubuntu-user@ubuntu-vm:~$ mongo
Failed global initialization: BadValue Invalid or no user locale set.
Please ensure LANG and/or LC_* environment variables are set correctly.

ubuntu-user@ubuntu-vm:~$ mongod
2015-03-27T12:56:19.085+0100 F CONTROL  Failed global initialization:
BadValue Invalid or no user locale set. Please ensure LANG and/or LC_*
environment variables are set correctly.

So, practically I have no idea what went wrong. I looked all over the internet and couldn't find the exact answer I am looking for. I did a clean install just like the website said. A few months ago I did the same tutorial and everything was working perfectly, with version 2.6.x, this is 3.0.1.

Could you guys help me out? Any comments/tips/tricks will be sincerely appreciated 🙂

Best Answer

There is actually nothing really wrong here, at least not based on what you have included in the question. Go back to this point:

ubuntu-user@ubuntu-vm:~$ mongo

MongoDB shell version: 3.0.1
connecting to: test
Server has startup warnings: 
2015-03-27T12:37:30.430+0100 I CONTROL  [initandlisten] 
2015-03-27T12:37:30.430+0100 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-03-27T12:37:30.430+0100 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-03-27T12:37:30.430+0100 I CONTROL  [initandlisten] 
> ^C

At this point you have a running mongod (the procedure you followed installs it as a service), and you have successfully connected to it using the mongo shell, it just has a hugepages warning - that is something you should fix long-term but it does not prevent MongoDB from running.

You then exited the shell and attemped to start another mongod for some reason (you do not need to, the service is still running). If you run mongod without a config file or any options, it will attempt to start with its defaults (port 27017, data directory = /data/db). In this case /data/db does not exist and so you get the error and it terminates.

To fix the error in terms of the hugepages you can alter grub.conf file, as outlined in this answer but you may have made a mistake or omitted something when you made your changes. It's also possible that you will lose those changes if/when you upgrade your kernel. Hence I would recommend undoing your grub changes and trying the second option listed in the answer above, that is, add the command to your /etc/rc.local file.

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

As an added bonus, you can run this from the command line (as root), then restart the mongod service to confirm the changes have been picked up successfully.