Chef Logs

Looking for chef’s log files? Look in your /etc/chef/client.rb file.

Here’s mine on my local test machine…

log_level :info
log_location STDOUT
chef_server_url 'https://localhost:443'
validation_client_name 'chef-validator'

You can change the location of where the log file points to here to something like: /var/log/chef/client.log

If such a place doesnt already exist you can always do:

sudo mkdir /var/log/chef/
sudo touch /var/log/chef/chef-client.log

I suppose if you wanted to be fancy about it you could hook that logfile into Logstash to track whatever type of trends you wanted.

Happy logging…

 

Getting setup with MongoDB and Python, Pymongo, and Bottle on Centos 6

From my older blog. Originally posted Oct 26th 2012

I had to walk through all of this to get setup for my Mongo Developer and Administrator certification classes. I figured I might help you out and put it all together instead of you having to hunt all over the place for this info.

Lets get started…

Step 1: Install MongoDB

To install MongoDB on your fedora system, issue the following commands in your terminal:

su -

Lets make sure that mongo hasnt already been installed while you were playing around with it…

yum -y remove libmongodb mongodb mongodb-server

Setup the mongodb repo…

vi /etc/yum.repos.d/10gen.repo

For 32 Bit, place the following code on that file:
http://gist.github.com/3949816#file_32bit.repo

and for 64 Bit this one:
http://gist.github.com/3949816#file_64bit.repo

Installation…
Run these two commands.

yum install mongo-10gen mongo-10gen-server
mongod -f /etc/mongod.conf

Then open your Mongo Shell in terminal (to ensure it’s functional) with:

mongo

and close it by pressing Ctrl+C; Then add the mongo service to the system’s startup with:

chkconfig --levels 235 mongod on

Reboot and reopen the Mongo Shell with the command:

mongod -f /etc/mongod.conf && mongo

Close it with Ctrl+C and then go to:
http://localhost:27017/
In your web browser, you should see something like this:

“You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number”

If you see this then you have it installed and setup correctly.

Step2. Installing Python, Pymongo, and Python-Bottle

First a little background…

Python – Python is a general-purpose, interpreted high-level programming language whose design philosophy emphasizes code readability. Its syntax is said to be clear and expressive.Python has a large and comprehensive standard library. More info can be found here: http://www.python.org/

Pymongo – PyMongo is a Python distribution containing tools for working with MongoDB, and is the recommended way to work with MongoDB from Python. More info can be found here: http://api.mongodb.org/python/current/

Bottle – Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library. More info is here: http://bottlepy.org/docs/dev/

If you haven’t already you need to install the EPEL repo for Centos 6

Check to see if you already have it installed or not…

yum repolist

You will see something similar to this:

repo id      repo name              status
base         CentOS-6 - Base        6,294
extras       CentOS-6 - Extras      4
updates      CentOS-6 - Updates     830
repolist:                           7,128

Since you dont see it above you need to grab the package…
http://mirror.us.leaseweb.net/epel/6/i386/repoview/epel-release.html

-OR-

wget "http://mirror.us.leaseweb.net/epel/6/i386/epel-release-6-7.noarch.rpm"

Note… the version number in the rpm name…if you are looking at this very late after the pub date of this post then you likely need to grab a more current version. Just follow the link above and you should see it.

do this next to test the rpm…

rpm -ivh epel-release-6-5.noarch.rpm --test

You will get back a NO KEY message.

You now need to download and install the key from FedoraProject and install on your system…

wget https://fedoraproject.org/static/0608B895.txt
mv 0608B895.txt /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Verify that the key got installed successfully…

rpm -qa gpg*
gpg-pubkey-0608b895-4bd22942

Now install the epel-release-6-6.noarch package, which will enable EPEL repository on your system…

rpm -ivh epel-release-6-5.noarch.rpm

Now verify that the EPEL repo is working correctly…

yum repolist

You should see a line that looks similar to this:

epel      Extra Packages for Enterprise Linux 6 - x86_64      7,345

Now lets get Python, Pymongo and Bottle setup…

Pretty simple and straight forward…

sudo yum -y install python python-setuptools python-setuptools-devel
sudo yum -y install python-bson pymongo pymongo-gridfs

To install bottle you may need to install PIP first…
You can do this using curl and python…

curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

Then install bottle…

pip install bottle

Quick primer on MongoDB

Here’s a little presentation i had to give at work to my team when we first deployed MongoDB and i needed to bring them up to speed.

SLIDESHARE

Installing Mongodb with Chef on Centos6.4

I started working on installing MongoDB with Chef-solo…here are the steps, errors and fixes I came up with.

Here is the Cookbook i used: git@github.com:edelight/chef-mongodb.git

First I ran into an error with the install wanting to use APT to download the packages. The error read something like “APT cookbook/dependancy not found.” Thats not the exact wording but ive already lost the true error because the chef-stacktracefile.out file gets written over when you run chef-solo. I need to set that to append from now on so i can track the errors better.

I looked in the 10gen_repo.rb recipe and found where it was looking for the APT cookbook before it did anything that looked at what OS im on. I just commented that line out and gave it another whirl. this time i got another error…

[seth@lab001 chef-repo]$ sudo chef-solo -c solo.rb -j mongodb.json
Starting Chef Client, version 11.6.0
Compiling Cookbooks...
Converging 6 resources
Recipe: mongodb::default
 * package[mongo-10gen-server] action install
 * No version specified, and no candidate version available for mongo-10gen-server
================================================================================
Error executing action `install` on resource 'package[mongo-10gen-server]'
================================================================================
Chef::Exceptions::Package
-------------------------
No version specified, and no candidate version available for mongo-10gen-server
Resource Declaration:
---------------------
# In /home/seth/chef-repo/cookbooks/mongodb/recipes/default.rb
22: package node[:mongodb][:package_name] do
 23: action :install
 24: version node[:mongodb][:package_version]
 25: end
 26:
Compiled Resource:
------------------
# Declared in /home/seth/chef-repo/cookbooks/mongodb/recipes/default.rb:22:in `from_file'
package("mongo-10gen-server") do
 action [:install]
 retries 0
 retry_delay 2
 package_name "mongo-10gen-server"
 cookbook_name :mongodb
 recipe_name "default"
end
[2013-09-27T09:37:32-04:00] ERROR: Running exception handlers
[2013-09-27T09:37:32-04:00] ERROR: Exception handlers complete
[2013-09-27T09:37:32-04:00] FATAL: Stacktrace dumped to /home/seth/chef-repo/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-09-27T09:37:32-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

The stacktrace revealed this:  ArgumentError: Unable to create Chef::RunList::RunListItem from String:”recipe [mongodb::10gen_repo]”: must be recipe[] or role[]
I wasn’t quite sure what was going on with this one but from the error I figured i needed to look into the 10gen_repo.rb and see what it was doing. This recipe sets up the repositories for stable 10gen packages. i looked in the README file to see if there were any instructions related to this recipe and found this…

Adds the stable 10gen repo for the corresponding platform. Currently only implemented for the Debian and Ubuntu repository.

Usage: just add recipe[mongodb::10gen_repo] to the node run_list before any other MongoDB recipe, and the mongodb-10gen stable packages will be installed instead of the distribution default.

So all I had to do now was add this to my mongodb.json file that im calling when I run chef-solo. That looks like this now…

{
“run_list”: [“recipe[mongodb::10gen_repo]”, “recipe[mongodb]”]
}

Trying it again….

[seth@lab001 chef-repo]$ sudo chef-solo -c solo.rb -j mongodb.json

 Starting Chef Client, version 11.6.0
 Compiling Cookbooks...
 Converging 7 resources
 Recipe: mongodb::10gen_repo
 * yum_repository[10gen] action add (up to date)
 Recipe: <Dynamically Defined Resource>
 * execute[yum-makecache] action nothing (skipped due to action :nothing)
 * ruby_block[reload-internal-yum-cache] action nothing (skipped due to action :nothing)
 * template[/etc/yum.repos.d/10gen.repo] action create
 - create new file /etc/yum.repos.d/10gen.repo
 - update content in file /etc/yum.repos.d/10gen.repo from none to d796d9
 --- /etc/yum.repos.d/10gen.repo 2013-09-27 11:01:44.703021565 -0400
 +++ /tmp/chef-rendered-template20130927-6230-1uuzlx3 2013-09-27 11:01:44.719021599 -0400
 @@ -0,0 +1,7 @@
 +# Generated by Chef for
 +# Local modifications will be overwritten.
 +[10gen]
 +name=10gen RPM Repository
 +baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
 +gpgcheck=0
 +enabled=1
 - change mode from '' to '0644'
 - restore selinux security context
 * execute[yum-makecache] action run
 - execute yum -q makecache
 * ruby_block[reload-internal-yum-cache] action create
 - execute the ruby block reload-internal-yum-cache
 Recipe: mongodb::default
 * package[mongo-10gen-server] action install
 - install version 2.4.6-mongodb_1 of package mongo-10gen-server
 * template[/etc/sysconfig/mongodb] action create
 - create new file /etc/sysconfig/mongodb
 - update content in file /etc/sysconfig/mongodb from none to 514bf6
 --- /etc/sysconfig/mongodb 2013-09-27 11:03:25.096241504 -0400
 +++ /tmp/chef-rendered-template20130927-6230-pbm20a 2013-09-27 11:03:25.102241516 -0400
 @@ -0,0 +1,26 @@
 +# This config file is auto-generated by chef
 +# please don't modify manually
 +
 +DAEMON="/usr/bin/mongod"
 +NAME="mongodb"
 +
 +DAEMON_OPTS=""
 +
 +DAEMON_OPTS="$DAEMON_OPTS --port 27017"
 +DAEMON_OPTS="$DAEMON_OPTS --dbpath /var/lib/mongodb"
 +DAEMON_OPTS="$DAEMON_OPTS --logpath /var/log/mongodb/mongodb.log"
 +
 +DAEMON_OPTS="$DAEMON_OPTS --fork"
 +DBPATH="/var/lib/mongodb"
 - change mode from '' to '0644'
 - change owner from '' to 'root'
 - change group from '' to 'root'
 - restore selinux security context
 * directory[/var/log/mongodb] action create
 - create new directory /var/log/mongodb
 - change mode from '' to '0755'
 - change owner from '' to 'mongod'
 - change group from '' to 'mongod'
 - restore selinux security context
 * directory[/var/lib/mongodb] action create
 - create new directory /var/lib/mongodb
 - change mode from '' to '0755'
 - change owner from '' to 'mongod'
 - change group from '' to 'mongod'
 - restore selinux security context
 * template[/etc/init.d/mongodb] action create
 - create new file /etc/init.d/mongodb
 - update content in file /etc/init.d/mongodb from none to 7360b8
 --- /etc/init.d/mongodb 2013-09-27 11:03:29.560251284 -0400
 +++ /tmp/chef-rendered-template20130927-6230-1no1lyk 2013-09-27 11:03:29.565251294 -0400
 @@ -0,0 +1,74 @@
 +#!/bin/bash
 +
 +# mongodb - Startup script for mongod
 +
 +# chkconfig: 35 85 15
 +# description: Mongo is a scalable, document-oriented database.
 +# processname: mongodb
 +# config: /etc/mongod.conf
 +# pidfile: /var/run/mongo/mongo.pid
 +
 +. /etc/rc.d/init.d/functions
 +
 +SYSCONFIG="/etc/sysconfig/mongodb"
 +DAEMON=/usr/bin/mongod
 +MONGO_USER=mongod
 +
 +. "$SYSCONFIG" || true
 +
 +start()
 +{
 + echo -n $"Starting mongod: "
 + daemon --user "$MONGO_USER" $DAEMON $DAEMON_OPTS
 + RETVAL=$?
 + echo
 + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
 +}
 +
 +stop()
 +{
 + echo -n $"Stopping mongod: "
 + killproc -p "$DBPATH"/mongod.lock -d 300 /usr/bin/mongod
 + RETVAL=$?
 + echo
 + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
 +}
 +
 +restart () {
 + stop
 + start
 +}
 +
 +ulimit -f unlimited
 +ulimit -t unlimited
 +ulimit -v unlimited
 +ulimit -n 64000
 +ulimit -m unlimited
 +ulimit -u 32000
 +
 +RETVAL=0
 +
 +case "$1" in
 + start)
 + start
 + ;;
 + stop)
 + stop
 + ;;
 + restart|reload|force-reload)
 + restart
 + ;;
 + condrestart)
 + [ -f /var/lock/subsys/mongod ] && restart || :
 + ;;
 + status)
 + status $DAEMON
 + RETVAL=$?
 + ;;
 + *)
 + echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
 + RETVAL=1
 +esac
 +
 +exit $RETVAL
 +
 - change mode from '' to '0755'
 - change owner from '' to 'root'
 - change group from '' to 'root'
 - restore selinux security context
 * service[mongodb] action enable
 - enable service service[mongodb]
 * service[mongodb] action start
 - start service service[mongodb]
 * service[mongodb] action restart
 - restart service service[mongodb]
 Chef Client finished, 11 resources updated

[seth@lab001 chef-repo]$ ps -ef | grep mongodb
 mongod 6484 1 1 11:03 ? 00:00:00 /usr/bin/mongod --port 27017 --dbpath /var/lib/mongodb --logpath /var/log/mongodb/mongodb.log --fork
 seth 6496 5542 0 11:04 pts/0 00:00:00 grep mongodb

And there you go. Good luck and let me know how this works for you or if you have suggestions or comments.