Mongo – Manual Install and Testing

So after our build eventually finished we are left with a few files in the build directory.  Time to make a home for MongoDB.  We should also add a user for the service to run under, then copy those file across to the new home.  The symlink just gives us a nice way to switch versions later on.  Our scripts will refer to /opt/mongo at all times, but we can point that link at whatever version we want later on, so upgrades should be simple enough.

# cd /opt
# mkdir mongo-3.0.4
# ln -s mongo-3.0.4 mongo
# useradd -d /opt/mongo -s /sbin/nologin mongo
# passwd mongo
# cp /root/Downloads/mongodb-src-r3.0.4/dbtest /opt/mongo/
# cp /root/Downloads/mongodb-src-r3.0.4/mongo /opt/mongo/
# cp /root/Downloads/mongodb-src-r3.0.4/mongobridge /opt/mongo/
# cp /root/Downloads/mongodb-src-r3.0.4/mongod /opt/mongo/
# cp /root/Downloads/mongodb-src-r3.0.4/mongoperf /opt/mongo/
# cp /root/Downloads/mongodb-src-r3.0.4/mongos /opt/mongo/
# cp /root/Downloads/mongodb-src-r3.0.4/mongosniff /opt/mongo/
# chown -R mongo:mongo mongo
# mkdir /opt/mongo-data

I guess now we should be able to get things started, lets start up a mongod and connect to it with a mongo shell!.

# ./mongod –fork –smallfiles –dbpath /opt/mongo-data/ –logpath /var/log/mongod.log

# ./mongo

> show dbs
local 0.031GB
> use test
switched to db test
> db.test.insert( { x : 1 } )
WriteResult({ “nInserted” : 1 })
> db.test.findOne()
{ “_id” : ObjectId(“55a9785c183a7cf4beb7e73f”), “x” : 1 }

So our build was successful, we have a working mongod and a working mongo shell 🙂  We created the “test” db and inserted a record into the “test” collection, then we queried the test db and  test collection and found our new record.

Later we will setup a simple python script to capture some data and log it in the database so that we have something to query.

Mongo – Illegal Instruction

I decided to do a few simple things yesterday, when I ran into this scenario

[[email protected] ~]# mongod

Illegal instruction (core dumped)

I had intended to do the following

  1. Download install and setup MongoDB on my web server
  2. Create a script that would log temperature info (remember this!)
  3. Develop something in python to display that info on a web page

So after some quick research on the internet it became clear that this issue affected 32-bit binaries of Mongo, the vast majority of issues were from users of arch linux.  The problem was solved for some by building from source others had the same issue after building from source.

So I downloaded the mongodb source files, unzipped them and install scons to build the binaries.

[[email protected] ~]# wget

[[email protected] ~]# unzip

[[email protected] ~]# cd mongodb-src-r3.0.4

[[email protected] ~]# pacman -S scons

So now I started the build again, but soon it failed because a variable is unused in the code.  By default, scons treats all warnings as errors, so I started the build again with options to disable “warnings as errors”.

[[email protected] ~]# scons –disable-warnings-as-errors –32 all

As this was running I notice that one of the compile parameters being passed to gcc was -march=nocona.  This is an Intel architecture built around 90nm, that introduced SSE3 instructions, hyper-threading and 64-bit!

According to a quick check of “cat /proc/cpuinfo” my CPU on this server is 32-bit which supports up to SSE2.  So this build was also going to result in “Illegal Instruction” as soon as it ran another SSE3 command.


So with that, I issued CTRL+c to stop the build and decided to edit the SConstruct file.  I found the following on line number 1417 and changed nocona to pentium3

if using_gcc() or using_clang():

myenv.Append( CCFLAGS=[‘-march=nocona‘, ‘-mtune=generic’] )

New version:

if using_gcc() or using_clang():

myenv.Append( CCFLAGS=[‘-march=pentium3‘, ‘-mtune=generic’] )

So I started the build again, third time lucky…  I’d love to tell you it resulted in a working binary but my machine hit a CPU temperature of 99C while building and triggered a thermal shutdown.



So I’ll add some cooling, lock the CPU to its slowest speed and try again later.  OR…. upgrade the server 🙂


It worked with a bit more tweaking, see this post