Upload
sai-perchard
View
71
Download
2
Embed Size (px)
Citation preview
Chef
Infrastructure Automation for the Masses.™
http://www.opscode.com/chef/
What is Chef?
• Open source systems integration framework
• Manage infrastructure via source code
• More complex infrastructure with less effort
• Best practices & collaboration via ‘recipes’
• Scalability
“Chef is an open source systems integration framework, built to bring the benefits of server configuration management to your entire infrastructure.”
Quick stats
• Released by Opscode January 15th, 2009
• Over 100 contributors as at March 1, 2010
– Engine Yard, Heroku, Rackspace, 37Signals
• Talent from Amazon, Microsoft, IBM, UBS.
How does it work?
• Infrastructure described via ‘Recipes’
– Describe a series of resources– Describe configuration of these resources
• Two flavours: Solo and Server
– Adam has discussed Solo, I will focus on Server
Chef Server
• A Merb app with indexing
• The Opscode Platform is a commercial cloud-based chef-server
– Free for up to 5 nodes
• You might use Chef Server if you want to…
– Search across the attributes of multiple nodes– Set up clustered services
• Data bags• Search• Centralisation
Terminology
• Nodes
– The things (e.g. server) configured by recipes.
• Roles
– A collection of recipes (or other roles).
• Cookbooks
– Recipes specify resources to manage
– Attributes are variables that can be mixed in to recipes
– Libraries extend Chef or provider helpers
– Files– Templates – Metadata tells Chef about your
recipes (inc. dependencies, platforms, etc.)
• Resources
– Things to be configured (e.g. a package or service)
• Providers
– Abstractions of system commands/API calls used to configure resources.
• Search
– Data stored on Chef server is indexed for search.
• Data bags
– Arbitrary stores of globally available JSON data
Differences from Chef Solo
• chef-client
• Knife
• Data bags
• Search
Search
chef-client
• An agent run by managed nodes
• Compiles and executes Cookbooks
• Can be daemonized to run periodically
$ chef-client -i 3600 -s 600 -d
Knife• The command line tool used to interact with Chef
server
• RESTful sub-commands: create, list & show, edit, delete
• Allows you to:
– Bootstrap a node (install Chef on a target system so it can run chef-client)
– List all nodes, or inspect a particular node, associated with an organisation
– Create new cloud instances – Manage cookbooks, data bags, nodes & roles– Search
Data Bags
• Only available to Chef Server
• Arbitrary stores of globally available JSON data
• Not directly associated with Node/Role attributes
• A central data store via which a cluster of infrastructure may be manipulated
• Managed using knife
1. Sign up for Opscode Platform
• Download user key
• Create an organisation
• Download validation key
• Download knife config file
• Sign up for the Opscode Platform at http://www.opscode.com/platform/• 5 nodes free• Chef Server is a Merb web application
2. Install Chef
$ sudo gem install chef
$ chef-client –v
Chef: 0.9.14
• Requirements
– Xcode– Rubygems 1.3.5+– Git
3. Create Chef repository
$ cd ~
$ git clone http://github.com/opscode/chef-repo.git
$ cd chef-repo/
$ ls
.git/
.gitignore
README.md
Rakefile
certificates/
cookbooks/
data_bags/
environments/
roles/
4. Create the .chef directory
• Contains configuration & authentication files
$ mkdir -p ~/chef-repo/.chef
$ cp ~/Downloads/*.pem .chef
$ cp ~/Downloads/*.rb .chef
$ ls .chef/
knife.rb
nexusnotes-validator.pem
sai.pem
5. Test your configuration
$ cd ~/chef-repo/
$ knife client list
[
"nexusnotes-validator"
]
6. Code your Infrastructure
$ knife cookbook site vendor apache2
$ knife cookbook upload apache2
$ knife cookbook list
Download the apache2 cookbook
Upload the apache2 cookbook to the Chef Server
List all of the cookbooks
• Find recipes at:
– http://community.opscode.com/cookbooks
7. Set up a Chef Client
• Use knife to bootstrap the target system
– Must set up OS & authentication first though
$ cd ~/chef-repo/
$ knife bootstrap HOSTNAME --distro DISTRO [centos5-gems]
8. Deploy your Infrastructure
• So far, we have:
– Signed up for the Opscode Platform (Chef Server)– Set up Chef locally– Vendored a cookbook and uploaded it to Chef Server– Bootstrapped a node
• Now we are ready to deploy
8. Deploy your Infrastructure
• Add the recipe to the node’s run list
• Run chef-client on the node as root
$ knife node run_list add HOSTNAME 'recipe[apache2]'
$ sudo chef client
...
8. Deploy your Infrastructure
• Example output
INFO: Starting Chef Run
INFO: Storing updated cookbooks/getting-started/recipes/default.rb in the cache.
INFO: Storing updated cookbooks/getting-started/README.rdoc in the cache.
INFO: Storing updated cookbooks/getting-started/metadata.rb in the cache.
INFO: Storing updated cookbooks/getting-started/metadata.json in the cache.
INFO: Storing updated cookbooks/getting-started/templates/default/chef-getting-started.txt.erb in the cache.
INFO: Writing updated content for template[/tmp/chef-getting-started.txt] to /tmp/chef-getting-started.txt
INFO: Chef Run complete in 8.950384 seconds
INFO: Running report handlers
INFO: Report handlers complete
Launching Cloud Instances
• Install dependencies
$ sudo gem install net-ssh net-ssh-multi fog highline
• Set up Knife with your AWS credentials
# ~/chef-repo/.chef/knife.rb
knife[:aws_access_key_id] = "Your AWS Access Key"
knife[:aws_secret_access_key] = "AWS Secret Access Key”
knife[:aws_ssh_key_id] = "knife"
Launch Instance
• Launch a new instance
$ knife ec2 server create 'recipe[apache2]'
-i ami-0c423c5e
-f t1.micro
-S knife
-I ~/.ssh/knife.pem
--ssh-user ubuntu
--region ap-southeast-1