Configuration Management with Chef
Have you ever been through a long tedious process of setting up a server, messing with configuration files all over the machine trying to get some poorly documented piece of software working. Finally it works, but you have no idea what you did. This is a constant frustration for loads of people. Configuration Management (maybe) the answer.Stated simply, you write scripts that will configure the server. Need to change something, you modify the script and and rerun. Branch the script and use it in version control so that you keep a track of multiple experiments. All of the advantages of managed code are brought over to managing a server.
We are currently investigating using Chef, which as brilliant as it appears to be, is sorely lacking in straightforward, complete and accurate tutorials. What I need with every new tool I use is a bare bones get up and running walk-through. I don't need to see a highly branched and complete set of instructions designed to tutor people who already know what they are doing. This blog post is my attempt at a bare bones attack.
So here we go.
Configuration
In this walk-through we are creating an entire networked Chef system using virtual machines. To do this we need to set up a local DNS server that will map names to IP addresses on the local virtual network. <<THIS PART IS ASSUMED>>DNS server config
Once you have the DNS server set up you need to make a few modifications.Set it so that it will forward unknown names to your Gateway DNS server
Change the named configuration to forward to <<Gateway DNS>>
Add entries for all components of the Chef networks. The following are assumed to exist
dns.vb (DNS server) 192.168.56.200
chef.vb (Server) 192.168.56.199
node.vb (Node) 192.168.56.101
Host Configuration
Configure your host machine1) Add dns.vb to /etc/hosts
2) Disable wireless (or other connections)
3) Fix the DNS server in your wired connection
- In the IPV4 setting tab add the IP address of dns.vb
Virtual Machine Config
Once this is done you will need to configure each and every machine that is added to the system (Chef Server and Nodes )1) Give the machine a name
A) Edit /etc/sysconfig/network file and change the HOSTNAME: field
B) Run the command hostname <myhostname>
2) Give the machine a static IP address and set the DNS server
vi /etc/sysconfig/network-scripts/ifcfg-eth1
BOOTPROTO=none
IPADDR=<<IP ADDRESS>>
NETWORK=255.255.255.0
DNS1=192.168.56.200
3) Add the machine's IP address and hostname combination to the DNS server
A) Edit the file /etc/named/db.vb and add a line at the bottom for each hostname IP combination
B) Restart the DNS server : service named restart
4) Prevent the eth0 connectuon from setting the DNS
vi /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=dhcp
PEERDNS=no
Set up a Server
This blog entry pretty much covers it
http://www.opscode.com/blog/2013/03/11/chef-11-server-up-and-running/
You basically grab the right version of Chef Server
wget https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.8-1.el6.x86_64.rpm
Install it
sudo yum localinstall chef-server-11.0.8-1.el6.x86_64.rpm --nogpgcheck
Configure and start
sudo chef-server-ctl reconfigure
Set up a Workstation
The workstation is your host machine, where you will write recipes and from which you will deploy them to the nodes.I started following the instructions here: http://docs.opscode.com/install_workstation.html
But that got confusing and inaccurate pretty quickly.
In summary, what I did was:
Start up a new virtuals machine (configure network settings as above), then:
sudo curl -L https://www.opscode.com/chef/install.sh | bash
When that is finished check the install with
chef-client -v
There are three config files the workstation needs
knife.rb
knife configure --initial
admin.pemscp root@chef.vb:/etc/chef-server/admin.pem ~/.chef
chef-validator.pem
scp root@chef.vb:/etc/chef-server/chef-validator.pem ~/.chef
Set up a Node
A Node is a machine for which you will manage the configuration using Chef.Start up a new virtual machine (configure network settings as above), then:
install the Chef client onto the Node using the bootstrap process.
To do this run the command on the workstation:
knife bootstrap node1.vb -x <username> -P <password> --sudo
Once this is done you can add recipes to the node and deploy them.
Create your first Cookbook
Create your first cookbook using the following command on your workstation:sudo knife cookbook create mytest
There will now be a cookbook in the following location
/var/chef/cookbooks/mytest
You can go in and edit the default recipe file:
/var/chef/cookbooks/mytest/recipes/default.rb
Add something simple, for example we will write out a file from a template.
template "test.template" do
path "~/test.txt"
source "test.template.erb"
end
Then create the template file
/var/chef/cookbooks/mytest/templates/default/test.template.erb
add whatever text you like to the file.
Applying the Cookbook
First thing to do is upload the cookbook to the server
sudo knife cookbook upload mytest
Then add the cookbook to the node
knife node run_list add mynode 'recipe[mytest]'
Then use Knife to apply the cookbook using the Chef-client on the node
knife ssh name:mynode -x <username> -P <password> "sudo chef-client"
Done!!!!
No comments:
Post a Comment