If you’re looking for a tool to automate your infrastructure provisioning, Chef has what you need. A Chef is a configuration management tool that simplifies the manual and repetitive tasks for infrastructure management. In this article, we’ll cover simple Chef installation and its configuration on CentOS.
Before going through the installation process, we’ll briefly cover Chef’s architecture, which includes three components:
In our demo, we’ll use just one client as an example to simplify the process. Typically, a user may have multiple clients. The Chef installation process consists of six easy steps:
The following example is using Oracle VM VirtualBox Manager, and two machines—the master and the node. Both of these are sent to seven machines on the server.
This demo is using this as a service on the cloud. Let's look at the master system first, which includes an open terminal that displays a black background with green text.
This is the node system, which has a black background with white text.
This is how users can easily differentiate the two.
Let’s begin with the master system. The first step for installing Chef is to download ChefDK and use the following command:
wget |
After the command execution:
The latest version today is Red Hat Enterprise Linux 8.
For this Chef installation demo, we are using Red Hat Enterprise Linux 7. If you prefer to use the latest version, you can check the same source and copy the required URL.
Our downloaded version of ChefDK in this demo is then copied and pasted down in the command.
The ChefDK installation is now complete, but we will also add a sample recipe on our work station by doing the following:
mkdir chef-repo |
cd chef-repo |
mkdir cookbooks cd cookbooks |
In the next step, we will create a cookbook that will have the actual recipe with the following command:
chef generate cookbook sample |
“Sample” here is the name of the cookbook.
The cookbook is now created, and for the next step, you’ll want to move into the cookbook.
When we create the cookbook, a hierarchical structure is automatically generated. Let's look at this hierarchical structure to understand what exactly a cookbook is.
To see the hierarchical structure, use the following command:
tree |
You can see here within our cookbook we have a folder, “recipes,” and under this, there is the default.rb recipe.
This is where we'll be creating our recipe, so we'll alter the content of default.rb.
Let’s move on to writing our recipes.
cd ./recipes |
gedit default.rb |
The recipe used in this Chef Installation demo involves installing the httpd package on our client node. This is your Apache server, which will also host a very straightforward webpage.
Additionally, the recipes in Chef are written in Ruby.
The first line is where httpd is installed.
The second line for service is where you start or enable the httpd service on that line.
That's our first task. The second part of the Chef Installation process includes creating a web page.
This is when you store your web page, which is a default path where our web pages are created.
The text that will appear on our web page will be, "Congratulations on completing the Chef demo."
After this recipe is created, save and close it. The next step in this Chef Installation process will move on to the server.
Now that the recipe has been created, all of the work at the Chef Workstation is complete.
It is now time to move on to the server.
In our demo, we will be using the server as a service on the cloud, so go to your browser and type manage.chef.io.
This is the Chef server log-in the homepage.
To move further in the Chef installation process, a free Chef server account is required, so you’ll need to create one if you don’t have one already.. The process to create an account is fast and simple, and is shown below:
You'll then receive an email from Chef software. Click on this link to verify your email address. You’ll then be prompted to create a password.
Let's continue on our Chef Workstation machine.
The first time you log into your Chef server, you'll see a pop-up appear, where you will need to create a new organization.
This organization is the name that will be associated with a collection of client machines.
The first thing you’ll do is go to the administration tab and download the starter kit.
During this part of the Chef installation process, ensure you're on your workstation because this is where your folder needs to be installed. It downloads when the file is saved.
The chef-starter kit is the key to connecting Chef Workstation with the server and the server with the node.
In our case, the two machines are "the workstation and the node" and "the one server."
The cookbooks folder is the one that contains the recipe, and that is where the knife tool command is present so that these recipes can be sent over to the server.
Next, we’ll check the contents of our cookbook to ensure that our chef-starter.zip file is in it.
You can see it's here. Our next step is to unzip this folder.
Once it’s unzipped, your Chef Workstation and your server are now linked.
After linking the workstation to your server, the next step in the Chef installation process is to upload the recipes onto the server.
Get the overview of Chef and demonstrate the Chef configuration with the DevOps Certification Training Course. Enroll today!
There is a tool called a knife that enables the communication and transfer of cookbooks between the three machines.
The knife command tool is used to transfer or upload recipes, which we created on the server’s workstation. Prior to executing the command, we’ll need to move into the cookbooks directory. This is where we unzipped the Chef starter kit, so that is where the knife command can be found.
knife cookbook upload sample |
After you execute the command, you can see the entire cookbook being uploaded onto the server.
Check the server after the knife command is executed.
It's the first time it has been uploaded, so it is version 0.1.0.
When you go to the Nodes tab, you will see that there are no nodes present.
If there aren’t any nodes, there isn’t an available machine to execute your cookbooks on.
The nodes are not visible right now because they haven’t been configured, which is what we’ll do in the next step.
So far, we completed this entire process on the master machine, but
Before moving on, verify the IP of the node machine.
After confirming that you’ve uploaded a sample workbook, the next step is to ensure that a server and node can communicate with each other.
We also use the knife tool for this with the following command:
knife bootstrap *IP address of your node* |
Logging in there will use the node as the root user. The root password for the node also needs to be specified, and the node needs to be named. This is how you will identify the node on the server.
In this demo, we are using the term SSH, which is a secure shell. This provides a secure communication channel between the two machines in the environment.
After the execution of the command, the Chef server and the Chef node must be able to communicate with each other. If they can, we should be able to send the cookbook from the server to ournode that we had previously uploaded from a Chef Workstation onto the server.
After this process is complete, we will return to the Chef server and refresh the page. The node that we wanted to identify should be easy to find.
The “Nodes” tab, which was initially empty, contains a node named chef_node.
The node is a CentOS platform, and you can also see the IP address. The uptime states the hours of activation, and the last time a user checked in to this node.
Now, we’ll create a run list and add a sample to it.
Now that we have updated the run list, the recipe is sent to the node.
The next required step is executing this at our node.
chef client |
Here, you can see everything that is happening.
Now, the next question that may arise: How can you verify if the entire Chef installation was successful??
To verify:
If you see a "Congratulations on completing the Chef demo" message, it means that the httpd package, which was the Apache server, is installed. Furthermore, the sample web page is also successfully hosted.
We hope that our comprehensive guide to the Chef installation was helpful. We discussed Chef’s architecture, including a hands-on demo of the installation process, plus configuration. The six steps we outlined in this article can help users easily and efficiently install Chef.
Do you have any questions for us? Please feel free to ask them in the comments section of our article, and we’ll have our experts answer them for you.
DevOps is the wave of the future, and Chef is one of the most popular tools used in the field. If you are looking to kickstart your career in this exciting field, check out Simplilearn’s DevOps Certification Training course today! What are you waiting for?
Ishan Gaba is a Research Analyst at Simplilearn. He is proficient in Java Programming, Data Structures, and Project Management. Graduated in Information Technology, Ishan is also passionate about writing and traveling.
DevOps Engineer
Certified Kubernetes Administrator
DevOps Certification Training
*Lifetime access to high-quality, self-paced e-learning content.
Explore CategoryHow to Become a DevOps Engineer?: Roles, Responsibilities, and Skills Required
DevOps Engineer Resume Guide
What is a DevOps Engineer? Salary, Roles and Responsibilities
The AI Trends In Fintech That are Changing Digital Economy Job Roles
What is DevOps: DevOps Core, Working, and Uses Explained
DevOps Career Guide: A Comprehensive Playbook To Becoming A DevOps Engineer