Jad Bitar

Tids and bits on just about everything.

Setup Chef (Server + Client) on Debian

| Comments

My personal notes on installing the Chef server + WebUI on Debian Squeeze and be able to manage it from my local workstation running Mac OS. The official documentation is just TOO long and spread across different pages - having it all put together makes it easier to follow the next time around.

DISCLAIMER: If it works for me, does not mean it will work for you. You’ve been warned.

Good, with that out of the way, let’s get to the action.

Create own chef-repo

To work with Chef, a repository is the preferred method as it will nicely integrate with Knife cookbook commands.

Local SSH
1
2
3
4
5
6
7
8
9
10
$ git clone git://github.com/opscode/chef-repo.git chef-repo
$ cd chef-repo
$ rm -rf .git
$ git init
$ git add .
$ git commit -m 'Initial commit.'
$ git remote add origin git@github.com:jadb/chef-repo.git
$ git push -u origin master
$ cd ..
$ rm -rf chef-repo

Now that the repository is ready and available online (private or not doesn’t matter), we are ready to start the setup.

On the remote server

Install some required packages:

Remote SSH
1
2
3
4
5
6
7
8
9
10
11
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install sudo git lsb-release
$ sudo echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | sudo tee /etc/apt/sources.list.d/opscode.list
$ sudo mkdir -p /etc/apt/trusted.gpg.d
$ sudo gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
$ sudo gpg --export packages@opscode.com | sudo tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null
$ sudo apt-get update
$ sudo apt-get install opscode-keyring
$ sudo apt-get upgrade
$ sudo apt-get install chef chef-server

During the package installation, you will be prompted with 3 configuration questions. The URL for the WebUI (important to keep the port number) and a password for each, the AMQP and the WebUI.

Once the package installation is done, check that services are all running and listening to the correct ports:

Remote SSH
1
$ netstat -a | grep LISTEN

This should show the following ports: 4000, 4040, 5984, 8983 and amqp.

It’s now time to configure the CLI client on the server:

Remote SSH
1
$ knife configure -i

The answers I gave:

  • .chef/knife.rb
  • http://localhost:4000
  • jadb-remote
  • chef-webui
  • .chef/webui.pem
  • chef-validator
  • .chef/validation.pem
  • chef-repo

To check that all is working, run knife client list; which should return a list like this:

1
2
3
chef-validator
chef-webui
jadb-remote

Ok! Half-way there. It’s now time to setup the local machine. But before switching to it, let’s create the client login/keys:

Remote SSH
1
2
3
$ mkdir tmp
$ cp .chef/validation.pem tmp/.
$ knife client create jadb-local -d -a -f tmp/jadb-local.pem

Verify the client was correctly created:

Remote SSH
1
$ knife client show jadb-local

You are now ready to move to local (and probably never touch the server setup again).

On the local workstation

Local SSH
1
2
3
4
5
6
7
$ sudo gem install chef --no-ri --no-rdoc
$ sudo mkdir /etc/chef
$ sudo chown -R $USER /etc/chef
$ mkdir .chef
$ scp user@hostname:~/tmp/*.pem .chef/.
$ git clone git@github.com:jadb/chef-repo /etc/chef/repo
$ knife configure

Like on the remote, this will prompt you with some questions. To which I answered:

  • .chef/knife.rb
  • http://chef.jadb.io:4000
  • jadb-local
  • chef-validator
  • .chef/validator.pem
  • /etc/chef/repo

To make sure it’s working and can connect to the server, run:

Local SSH
1
$ knife client show chef-validator

We’re done with the initial setup! It’s now time to start exploring and configuring environments, roles, nodes, cookbooks, etc.

Sublime Text & Crontab

| Comments

A year or so ago, I switched from Textmate to Sublime Text 2. Like with its predecessor, I wanted to be able use it as my default editor for stuff like crontab -e or git commit. After some research and configuration all was working well, until I had to re-setup my workstation because my hard drive died.

I was able to find the solution again in their documentation, but this time and after following all the steps, it was failing with git and crontab. By quickly peaking at my backups, I realized what I had previously done to solve that and decided to post it here so I can always refer back to it.

Firt, I created ~/bin/sublw:

sublw (sublw.bash)
1
2
3
#!/bin/bash

subl -w $*

And then I ran the following commands:

terminal
1
2
3
4
$ chmod +x ~/bin/sublw
$ echo "export EDITOR='sublw'" >> ~/.bash_profile
$ echo "export GIT_EDITOR='subl -w'" >> ~/.bash_profile
$ source ~/.bash_profile

Briefly, I allowed the sublw to be executed and defined the default editors to use Sublime Text 2. That’s it!

Live From… Home!

| Comments

Was gone M.I.A. five years ago, but back now; at a different address, with a different look, no friends nor recent memories. You’ve certainly guessed that I was talking about no other than my blog.

Some 5 years ago, I had to take it down during my company’s server farm migration and as ambitious as I am, I thought I’d move it from Wordpress to a custom-built CakePHP blog while at it. The result: weekend hackathon crapped, got distracted shortly after that, the backup somehow got corrupted and that was the end of it.

So, earlier this year, when I decided to try blogging again, I knew I needed something where I wouldn’t have to worry about hosting (cost, uptime, etc.) nor backups. After some research, I believe I have found the best solution:

Octopress on Github Pages.

Set myself a goal to have it installed over the weekend (which I just did) and start playing with it over the next week (think I’m done doing that already). It’s now ready for some blogging…

~ Stay tuned!