Installing MongoDB for Graylog2

We will installing and configuring MongoDB on CentOS 6 as Part 2 of our series on Monitoring your systems with logstash and Graylog2. ::Part 1::Part 3::Part 4::, in order to support our Graylog2 server.

Our goals are simple:

  • Run as an unprivileged user
  • Consistent installation, logging, and configuration locations
  • Ability to scale to securely monitor other remote systems
  • Automating the installation
IMPORTANT NOTE BEFORE WE PROCEED!
You may be concerned about the installation of unsigned RPMs onto your system from the 10gen site. It this is the case, you should build from source.
YOU’VE BEEN WARNED

The installation overview:

  1. Add 10gen as a yum repository
  2. Download and install MongoDB
  3. Configure MongoDB
  4. Start MongoDB
  5. Create Admin User
  6. Create Greylog2 database
  7. Create Greylog2 user

We will assume you know the basics of system administration (ie.file permissions, ownership, etc.).
So let’s get this working!

We’ll first configure yum to check the 10gen repository for the lastest MongoDB
We’ll just echo the meager contents to create our file as root.
Below is for x86_64 CentOS

echo "[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0" > /etc/yum.repos.d/10gen.repo2

And below would be for the i386 32 bit CentOS

echo "[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0" > /etc/yum.repos.d/10gen.repo2

Next we’ll download and install MongoDB using yum, again as root:

yum info mongo*
yum install mongo-10gen*

Next we edit the MongoDB config file “/etc/mongod.conf” with our favorite editor
We want to set the following options

 logpath=/var/spool/mongo/log/mongod.log
 dbpath=/var/spool/mongo/data
 port = 27017
 auth = true

Now we will create the data directory and set permissions so mongod can write to the database. Again as root:

mkdir -p /var/spool/mongo/data
mkdir -p /var/spool/mongo/log
chown mongod.root /var/spool/mongo/*

Now we’re ready to start MongoDB. As root:

/etc/init.d/mongod start

Our next step is to create our default admin user. As normal user:

mongo
~ mongo now changes to a “>” shell prompt
>use admin
>db.addUser('admin', 'secure-password')

We next first authenticate, then create the graylog2 database.

>db.auth('admin', 'secure-password')
>use graylog2

That’s all there is to creating the database. Just too easy!

Next we create the graylog2 user and password for connecting to the database. Note the credentials for configuring the graylog2 server

>db.addUser('gluser', 'grayloguser-password')
>exit

We are now finished with configuring MongoDB, I hope it took just a few minutes. If you’d like to read up on MongoDB security, just head on over to the documentation.

4 thoughts on “Installing MongoDB for Graylog2

  1. Perfect instructions. One problem with my installation (CentOS6 64bit) was that I had to rename the file to 10gen.repo (instead of 10gen.repo2)

  2. Why does your documenatation keep using /var/spool/$app/log? Changing valid FSH settings to non standards. From the File Standards Heirarchy [1]
    “/var/spool” Spool for tasks waiting to be processed, e.g., print queues and unread mail.
    “/var/log” Log files. Various logs

    [1] http://www.pathname.com/fhs/pub/fhs-2.3.html

    • Howdy Jim,

      I eagerly await your rewrite of my humble documentation to conform to your expected standards.

      All the best,

      – Shaun

      • Fair comment, it is good documentation and I am grateful to have found it, I just have an OCD thing going on with the FSH.

        Jim

Comments are closed.