Mount a shared drive in virtualbox

This is mainly because I keep forgetting the commands for this…

sharename="whatever.you.want.to.call.it"; 
sudo mkdir /mnt/$sharename
sudo chmod 777 /mnt/$sharename
sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename
ln -s /mnt/$sharename $HOME/Desktop/$sharename

 

Then add this line to your /etc/rc.local file so that it auto-mounts when you start up your vm.

Chef Error: Knife configure

When doing your initial “knife configure -i” command while setting up a chef workstation, if you encounter this error:

ERROR: Errno::EHOSTUNREACH: No route to host - connect(2)

Make sure you check your firewall settings.

On CentOS you can do:

sudo iptables -S

This will show you what is enabled currently. If you don not have port 443 open you will run into issues. To open it you can do this:

-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT

Make sure you save your changes…

sudo service iptables save

…and restart the firewall…

sudo service iptables restart

Setting up Open Chef Server and a Workstation

The quick and dirty way…

Prep work

For me, I stood up two Centos 6.5 instances in virtualbox. I did the basics of installing the EPEL repo, groupinstall of “Base” and “developer tools” in YUM, setup and configured a user for myself.

Create my user:

useradd -m -G wheel seth
passwd seth

Install EPEL repo:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

YUM Groupinstall:

sudo yum groupinstall base "developer tools"


Downloading the needed files

http://www.getchef.com/chef/install/

First we will install the server…

 

For the server

Pick which package you need here and download it to the “chef-server”

cd /opt
sudo wget "https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm"
sudo rpm -ivh  chef-server-11.0.12-1.el6.x86_64.rpm
sudo chef-server-ctl reconfigure

This command will set up all of the required components, including Erchef, RabbitMQ, and PostgreSQL

 sudo chef-server-ctl test

 

For the Workstation

As root run the curl command supplied to you from the Chef Download page. For me it was…

curl -L https://www.opscode.com/chef/install.sh | bash

Once this completes do this to test the install and see the version number:

chef-client -v

Now install GIT…

yum install git

(This will install version 1.7.1-ish)

From here as my own user I went to my home directory and cloned down the Chef GIT repo:

git clone git://github.com/opscode/chef-repo.git

Next cd into the chef-repo dir and create your .chef folder. This folder will hold your authorization files in a few steps from now.

cd chef-repo
 mkdir .chef

Add your .chef to the .gitignore file so it and its contents will not be uploaded.

echo .chef >> .gitignore

Get the .pem files and knife.rb files
You will need to copy these files from the chefserver that you previously setup. These files essentially give you access to connect to the server via chef-client and with knife. For me the command run from my workstation was…

sudo scp root@192.168.1.152:/etc/chef-server/admin.pem /home/seth/chef-repo/.chef/admin.pem
sudo scp root@192.168.1.152:/etc/chef-server/chef-validator.pem /home/seth/chef-repo/.chef/chef-validator.pem

You then want to run the knife initial command to create the knife.rb file in your .chef folder. Unless you know the hostname of your server and the locations of your admin and chef-validator.pem files this step will fail. You also need to make sure that port 443 is open on your server. You can do that with this:

sudo iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
sudo service iptables save

Now do this:

knife configure --initial

Here is what my output looked like to give you an idea of what to expect:

[seth@chefworkstation001 .chef]$ knife configure --initial
 Overwrite /home/seth/.chef/knife.rb? (Y/N)y
 Please enter the chef server URL: [https://chefworkstation001.devopshomelab:443] https://192.168.1.152:443
 Please enter a name for the new user: [seth]
 Please enter the existing admin name: [admin]
 Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem] /home/seth/chef-repo/.chef/admin.pem
 Please enter the validation clientname: [chef-validator]
 Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem] /home/seth/chef-repo/.chef/chef-validator.pem
 Please enter the path to a chef repository (or leave blank):
 Creating initial API user...
 Please enter a password for the new user:
 Created user[seth]
 Configuration file written to /home/seth/.chef/knife.rb

Once you successfully make it past this point you should be good to go. You can test your configuration and connectivity to your server by running the following two commands:

knife client list
knife user list

Now lets bootstrap our new chef workstation

On the server you will need to configure knife like we did on the client side so do:

sudo knife configure -i

You will see something similar to what we saw the firwst time we ran this. Here is my output…

WARNING: No knife configuration file found
Where should I put the config file? [/root/.chef/knife.rb]
Please enter the chef server URL: [https://chefserver.devopshomelab:443]
Please enter a name for the new user: [seth] chefserver
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem]
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem]
Please enter the path to a chef repository (or leave blank):
Creating initial API user...
Please enter a password for the new user:
Created user[chefserver]
Configuration file written to /root/.chef/knife.rb

If you have everything configured correctly you can now bootstrap your workstation by running the following command:

sudo ./knife bootstrap 192.168.1.153 --sudo -x seth -N "chefworkstation001"

 

You should have successfully installed and configured a working Chef open server and workstation following these steps. If you have questions or comments please feel free to use the comment section below. As always you can also consult the official Chef documentation on this subject by going here:

SERVER: http://docs.opscode.com/install_server.html

WORKSTATION: http://docs.opscode.com/install_workstation.html

Also check out my other post about bootstrapping a node in your new Chef environment. HERE

Bootstrapping a Chef Client

Installing Chef as client is a fairly straight forward thing to do after you already have your Chef Server setup. Heres a brief overview of the key steps you will need to take.

First you will need to install Chef Client. You can do that by following this link. This will take you to the Opscode page that helps you figure out what you need and gives you options on how to actually get the chef-client package.
For my case since I am running CentOS 6 I chose Enterprise Linux 6 on a 64-Bit platform. The command that the page gave me to use was:

curl -L https://www.opscode.com/chef/install.sh | bash

From here you log in as your root user and run the command. As a side note I tried this using just my sudo user and it did not work because for some reason it could not create a lock file. Here is what my error looked like:

downloading https://www.opscode.com/chef/metadata?v=&prerelease=false&p=el&pv=6&m=x86_64
 to file /tmp/install.sh.5247/metadata.txt
trying wget...
url https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.10.4-1.el6.x86_64.rpm
md5 3fe6dd8e19301b6c66032496a89097db
sha256 edd5d2bcc174f67e5e5136fd7e5fffd9414c5f4949c68b28055b124185904d9f
downloaded metadata file looks valid...
downloading https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.10.4-1.el6.x86_64.rpm
 to file /tmp/install.sh.5247/chef-11.10.4-1.el6.x86_64.rpm
trying wget...
Checksum compare with sha256sum succeeded.
Installing Chef 
installing with rpm...
warning: /tmp/install.sh.5247/chef-11.10.4-1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Permission denied)
Installation failed
Please file a bug report at http://tickets.opscode.com
Project: Chef
Component: Packages
Label: Omnibus
Version:
Please detail your operating system type, version and any other relevant details

Once I tried it again as the actual root user everything worked fine.

And now on to the good stuff…

On your master you need to “create the client”

sudo knife bootstrap 192.168.1.151 --sudo -x seth -N "centos-lab-001"

and you will see something like this…

[sudo] password for seth:
Bootstrapping Chef on 192.168.1.151
Enter your password:
192.168.1.151 Starting Chef Client, version 11.6.0
192.168.1.151 Creating a new client identity for centos-lab-001 using the validator key.
192.168.1.151 resolving cookbooks for run list: []
192.168.1.151 Synchronizing Cookbooks:
192.168.1.151 Compiling Cookbooks...
192.168.1.151 [2014-03-20T22:03:29-04:00] WARN: Node centos-lab-001 has an empty run list.
192.168.1.151 Converging 0 resources
192.168.1.151 Chef Client finished, 0 resources updated

Once this has completed you will need to log into either your on Chef server or as I do, my Opscode hosted management page at https://manage.opscode.com/ Once you have connected go to your Node tab at the top and then click Edit next to your new node that you should see here. From here you will see your available recipes on the left and Run List on the right. What you want to do is click and drag a name of a recipe over to the right to your run list. An easy one to test with is NTP which you can get from the Opscode community or on Github. Once you have done this save and open a terminal to your new node.

do:

sudo chef-client

and you should see a bunch of stuff scroll by and then a success message.

This is a VERY brief guide and there are much more detailed  descriptions of this process that can be found out there. Good luck and feel free to ask questions in the comments or tweet me @devopshomelab

Add a new drive to Centos Virtualbox Guest

I run into this a lot and always forget what the steps are…

With the guest powered off you will need to open VBx manager, right click on your guest name that you want to add the drive to and go to SETTINGS.

Click STORAGE and then either click IDE or SATA controller to highlight it. Then you will click the little drive icon next to it. I always choose new disk at the next little pop up. Follow the prompts….
If you get to this step and that icon is ghosted out make sure your guest is powered off. As of right now I dont think there is a way to hot-add a drive in VBx.

I choose VDI and DYNAMICALLY ALLOCATED, give it a name and a size. I ususally go with about 50GB since all of my VMs are for experimental use and I likely wont use that whole amount.

From here thats all you have to do in VBx itself. Next you will want to start up your gest and mount the drive…

Once you get logged in follow these steps…
sudo fdisk -l
Make sure you see your new drive here. It might be listed as something like /dev/sdb Then do the following….

mkdir /mnt/newdisk
mount -t ext3 /dev/sdb1 /mnt/newdisk
cd /mnt/newdisk
df

to mount automatically on boot, add disk to /etc/fstab my /etc/fstb for example, i added last line

LABEL=79d3d2d4 / ext4 defaults,noatime 0 0
LABEL=e21a3e10 /boot ext3 defaults,noatime 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
/dev/sdb1 /mnt/newdisk ext3 defaults 0 0

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

Openstack via DevStack – A First Look

I decided to try Openstack a look and see what it was all about and maybe pick up a few things about it. I went to the Openstack site and poked around a little bit and saw that there was a local dev environment available for download that you could standup as a single node and have something to play with. you can find that HERE at DevStack.

At first glance the install and setup looked pretty easy. Run as yourself, follow the prompts, wait a few minutes and there you go. Not so for me…I made it through the prompts and while i was waiting i was reading down through the instructions and looking for the URL of the dashboard you use to command this thing. I found this:

At this point you should be able to access the dashboard.”

Where??? Whats not said here is that at the end of the stack.sh script you will be given this information based on your own setup and computer’s IP address. i didn’t figure this out until the very end though.

Centos Experience

My experience with DevStack on Centos was not a good one. My VM met all of the requirements and then some and there were no firewalls enabled. The speed of “setup” was the same VS on Ubuntu but the results were very different. On the first run there were issues trying to download some dependencies. Once that was fixed I then kept seeing errors like this at the end of the stack.sh script run…

2013-11-05 09:23:41 + service_check 
2013-11-05 09:23:41 + local service 
2013-11-05 09:23:41 + local failures 
2013-11-05 09:23:41 + SCREEN_NAME=stack 
2013-11-05 09:23:41 + SERVICE_DIR=/opt/stack/status 
2013-11-05 09:23:41 + [[ ! -d /opt/stack/status/stack ]] 
2013-11-05 09:23:41 ++ ls /opt/stack/status/stack/horizon.failure /opt/stack/status/stack/n-api.failure 
2013-11-05 09:23:41 + failures='/opt/stack/status/stack/horizon.failure 
2013-11-05 09:23:41 /opt/stack/status/stack/n-api.failure' 
2013-11-05 09:23:41 + for service in '$failures' 
2013-11-05 09:23:41 ++ basename /opt/stack/status/stack/horizon.failure 
2013-11-05 09:23:41 + service=horizon.failure 
2013-11-05 09:23:42 + service=horizon 
2013-11-05 09:23:42 + echo 'Error: Service horizon is not running' 
2013-11-05 09:23:42 Error: Service horizon is not running 
2013-11-05 09:23:42 + for service in '$failures' 
2013-11-05 09:23:42 ++ basename /opt/stack/status/stack/n-api.failure 
2013-11-05 09:23:42 + service=n-api.failure 
2013-11-05 09:23:42 + service=n-api 
2013-11-05 09:23:42 + echo 'Error: Service n-api is not running' 
2013-11-05 09:23:42 Error: Service n-api is not running 
2013-11-05 09:23:42 + '[' -n '/opt/stack/status/stack/horizon.failure 
2013-11-05 09:23:42 /opt/stack/status/stack/n-api.failure' ']' 
2013-11-05 09:23:42 + echo 'More details about the above errors can be found with screen, with ./rejoin-stack.sh' 
2013-11-05 09:23:42 More details about the above errors can be found with screen, with ./rejoin-stack.sh 
2013-11-05 09:23:42 + set +o xtrace 
2013-11-05 09:23:42 stack.sh completed in 1185 seconds.

From here i tried hitting the dashboard to see what i would get and i finally did get something…more errors. From the dashboard url at 192.1681.1.151:5000/v2.0 I got an error that says that the XML had no style.

<version id="v2.0" status="stable" updated="2013-03-06T00:00:00Z" xmlns="http://docs.openstack.org/identity/api/v2.0"> <media-types> <media-type base="application/json" type="application/vnd.openstack.identity-v2.0+json"> <media-type base="application/xml" type="application/vnd.openstack.identity-v2.0+xml"> </media-type></media-type></media-types> <links> <link href="http://192.168.1.151:5000/v2.0/" rel="self"/> <link href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/" rel="describedby" type="text/html"/> <link href="http://docs.openstack.org/api/openstack-identity-service/2.0/identity-dev-guide-2.0.pdf" rel="describedby" type="application/pdf"/> </links> <link href="http://192.168.1.151:5000/v2.0/" rel="self"/> <link href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/" rel="describedby" type="text/html"/> <link href="http://docs.openstack.org/api/openstack-identity-service/2.0/identity-dev-guide-2.0.pdf" rel="describedby" type="application/pdf"/> </version>

Ubuntu Experience

Once I saw this i decided to give this a try on Ubuntu. Not my flavor of choice but wanted to see if i got the same results. I spun up a new VM in virtualbox using ubuntu server 12.04, ran the update, installed Git, and then cloned down the devstack repo. On the very first run of stack.sh I got a successful install and something i had not seen before…

Horizon is now available at http://192.168.1.152/ Keystone is serving at http://192.168.1.152:5000/v2.0/
Examples on using novaclient command line is in exercise.sh
The default users are: admin and demo
The password: ********
This is your host ip: 192.168.1.152
stack.sh completed in 1255 seconds.

Right off the bat Im liking this. The dashboard isnt cluttered and is easy to read. Never using something like this, I had an instance and volume attached within 3 minutes of just poking around. Id say this is pretty cool and easy for someone to pick up and learn. im going to keep playing around with it for a while and see what all i can come up with to do. It looks like there are some exercises to run though so Ill be checking that out also soon.