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.

Error with chef-solo installs: block in from_file

I have found that when you run into an error like this, it helps if you use “sudo”. 🙂 the error is slightly misleading. I kept looking at the code on line 22 and could not figure out what was so wrong. After i took a break and came back to this I noticed further down in package.rb this bit of code:

template "#{node['php']['conf_dir']}/php.ini" do
 source "php.ini.erb"
 owner "root"
 group "root"
 mode "0644"
 variables(:directives => node['php']['directives'])
end

That’s when I realized I should be running this as sudo…worked like a charm. Live and learn.

Here’s the original error:

[seth@lab001 chef-repo]$ chef-solo -c solo.rb -j php.json
Starting Chef Client, version 11.6.0
Compiling Cookbooks...
Converging 7 resources
Recipe: php::package
 * package[php] action install
================================================================================
Error executing action `install` on resource 'package[php]'
================================================================================

Chef::Exceptions::Exec
----------------------
 returned 1, expected 0

Resource Declaration:
---------------------
# In /home/seth/chef-repo/cookbooks/php/recipes/package.rb
22: package pkg do
 23: action :install
 24: end
 25: end

Compiled Resource:
------------------
# Declared in /home/seth/chef-repo/cookbooks/php/recipes/package.rb:22:in `block in from_file'
package("php") do
 action [:install]
 retries 0
 retry_delay 2
 package_name "php"
 version "5.3.3-23.el6_4"
 cookbook_name :php
 recipe_name "package"
end

[2013-09-23T13:36:49-04:00] ERROR: Running exception handlers
[2013-09-23T13:36:49-04:00] ERROR: Exception handlers complete
[2013-09-23T13:36:49-04:00] FATAL: Stacktrace dumped to /home/seth/chef-repo/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-09-23T13:36:49-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

GITHUB LOCATION

Here’s my GitHub home: https://github.com/sethfloydjr

There’s nothing really useful there right now but I think it will house some cookbooks for chef and resources for Puppet as i get this project rolling along a little more. It will also have some scripting stuff that i tinker with here and there.

Apache2 install with Chef

Ive been working on getting an install of Apache2 up and running using Chef. Everything has worked so far until I run: chef-solo -c solo.rb -j web.json

The error im running into is:

Starting Chef Client, version 11.6.0

Compiling Cookbooks…
[2013-09-17T14:31:57-04:00] WARN: Cloning resource attributes for service[apache2] from prior resource (CHEF-3694)
[2013-09-17T14:31:57-04:00] WARN: Previous service[apache2]: /home/seth/chef-repo/cookbooks/apache2/recipes/default.rb:24:in `from_file’
[2013-09-17T14:31:57-04:00] WARN: Current service[apache2]: /home/seth/chef-repo/cookbooks/apache2/recipes/default.rb:221:in `from_file’
Converging 74 resources
Recipe: apache2::default
* package[apache2] action install
================================================================================
Error executing action `install` on resource ‘package[apache2]’
================================================================================

Chef::Exceptions::Exec
———————-
returned 1, expected 0

Resource Declaration:
———————
# In /home/seth/chef-repo/cookbooks/apache2/recipes/default.rb

20: package “apache2” do
21: package_name node[‘apache’][‘package’]
22: end
23:

 

Compiled Resource:
——————
# Declared in /home/seth/chef-repo/cookbooks/apache2/recipes/default.rb:20:in `from_file’

package(“apache2”) do
action :install
retries 0
retry_delay 2
package_name “httpd”
version “2.2.15-29.el6.centos”
cookbook_name :apache2
recipe_name “default”
end

 

[2013-09-17T14:32:07-04:00] ERROR: Running exception handlers
[2013-09-17T14:32:07-04:00] ERROR: Exception handlers complete
[2013-09-17T14:32:07-04:00] FATAL: Stacktrace dumped to /home/seth/chef-repo/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-09-17T14:32:07-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Im not exactly sure whats going on here but im suspecting based on similar issues that there is a problem with me being on Centos and not using Apt. Still digging into this though since I know this should work even if its on Centos.

SSH and GitHub

When you create an account on Github.com you might not realize that you need to setup your SSH keys. Here is what I did to make that happen…

On my box I did ssh-keygen -t rsa  I answered with the default yes’…although not as secure, since this is just for practice Im not worried a ton about that aspect right now.

I then logged onto my github account and added my SSH key by going to account settings and then the SSH Key section. I copied my PUBLIC key content from my key located at ~/.ssh/id_rsa.pub and pasted it in the window forthe key content.

Once this was complete I ran ssh -vT git@github.com to make sure I could connect ok…

If successful you should see something like this…

 

[seth@lab001 DevOpsHomeLab]$ ssh -vT git@github.com
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [192.30.252.131] port 22.
debug1: Connection established.
debug1: identity file /home/seth/.ssh/identity type -1
debug1: identity file /home/seth/.ssh/id_rsa type 1
debug1: identity file /home/seth/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1+github5
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1+github5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host ‘github.com’ is known and matches the RSA host key.
debug1: Found key in /home/seth/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/seth/.ssh/identity
debug1: Offering public key: /home/seth/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Hi sethfloydjr! You’ve successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2272, received 3032 bytes, in 0.1 seconds
Bytes per second: sent 25456.3, received 33971.6
debug1: Exit status 1

Installation tip on Centos6

Note to self….once you set up a new user and enable sudoer then install the system-config tools…

sudo yum install system-config-*

Fresh start – Installing Centos 6.4

Today I decided to start fresh with my lab and re-install and setup everything as before but documenting it all along the way.

So far today I have installed Centos 6.4 386. The box I have to currently work with is just a old Gateway that only has a 40Gb drive with 1Gb of ram in it. Its the first gen 1Ghz processor from AMD.

I chose the min install so that I could have the smallest footprint I could manage and then configure everything by hand. First thing I did was get networking setup. I went into the /etc/sysconfig/network-scripts file/ifcfg-eth0 and entered my info. Here is what I added…

DEVICE=eth0
HWADDR=00:03:47:DC:36:7E
TYPE=Ethernet
UUID=c6edba1c-1fbb-4d83-9593-aef1c086af15
ONBOOT=yes <- NOTE this line and set to On if you want the NIC to turn on at bootup
NM_CONTROLLED=yes
BOOTPROTO=static
DNS=xxx.xxx.xxx.xxx
GATEWAY=xxx.xxx.xxx.xxx
IPADDR=xxx.xxx.xxx.xxx
NETMASK=255.255.255.0

I then altered the /etc/hosts file to look like this:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

And then I altered the /etc/resolve.conf file to look like this:

domain home
search homenameserver 192.168.1.1

Ran /etc/init.d/network restart and just like that I was able to connect to the outside world. The first thing I did was run a YUM UPDATE and then a yum groupinstall “Networking Tools”

There was a little gotcha that I ran across. Centos6.4 minimum install doesnt automatically install Network Manager or system-config-network or system-config-network-tui so thats why I had to manually configure all of this by hand.

That was all for today. Next i will be installing Puppet and get started working on setting up resources with that.