📜 ⬆️ ⬇️

Setting up a server with Chef (Quick and easy)

Chef is to use Chef
- getchef.com



Chef is a tool for configuring servers in the Infrastructure as a Code (IaaC) concept.
Personally for me, Chef is, first of all, the ability to store the service architecture in the form of roles, and modify it, avoiding the routine actions to install packages and configuration.

Chef allows you to run any scripts on the server, providing your own syntax to describe them. Cross platform and structured.
It has a fairly high threshold of entry. The reasons are: seemingly confusing terminology and the difference in the use of Chef and Chef solo.
Solo - a simple way for beginners to work with Chef, allows you to manage your configuration without having to have an additional service server, which limits the functionality. However, these restrictions make themselves felt when managing a large fleet of servers.

This article may be called the "Chef outline."
Perhaps the text will be similar to that translated by a prompt, but I think that the terms used in the text should not be translated, I will be glad to know your opinion on this matter.

')
Terms



Using

It's time to put all the terms into a logical chain and understand how Chef is used.

To set up a server, you describe recipes inside cookbooks, and execute them with the utility knife for a node with one or more roles.

And now, practice

You need to have Ruby, and if you don’t have one, then it’s time to install Ruby-lang.org

Install and configure Nginx on a fresh server.

Create a directory, for example chef-test and go to it.
Install the necessary tools for the job: chef, knife-solo and berkshelf.
Berkshelf - cookbook manager, analog bundler

Create a Gemfile file with the following content:
source "https://rubygems.org" gem 'knife-solo' gem 'berkshelf' 

Team bundle finish the installation
 bundle 


In the current directory create the kitchen
 knife solo init . berks init . 

Add the necessary cookboks to the created Berksfile
 cookbook 'nginx' 

And download them
 berks install 


Describe the server configuration (node)
In the nodes directory, create a file and name it as follows: <server ip address> .json
File describes: which scripts (recipes) need to be executed on a given server (node)
 { "nginx": { "version": "1.6.0", "install_method": "source", "default_site_enabled": true, }, "run_list": [ "recipe[nginx]" ] } 

run_list indicates exactly which recipes or recipe groups (roles) need to be executed.
In this variant, the recipe from Nginx cookbook is executed.

Start Chef and enjoy the work of the machine for the person
 knife solo bootstrap username@host -i ~/.ssh/ssh_key.pem 

The result will be a ready server with a working web server.

If you need to make changes, for example, change the version of Nginx, it is enough to change the configuration in the node file and execute
 knife solo cook username@host -i ~/.ssh/ssh_key.pem 

Chef uses only recipes that have been changed, so you can not be afraid of the safety of the server configuration.

I hope this article has helped to overcome the barrier Chef, because more is waiting for you just the joy of ease of use of this great tool.

If you are interested in this topic, in the next article I would like to describe the process of creating a typical infrastructure for rails applications in Amazon AWS.

Chef Alternatives



useful links



We use these tools in the Staply project.
We will tell about it very soon!
image

Source: https://habr.com/ru/post/244111/


All Articles