How to install and configure Chef server on ubuntu

Chef is a ruby based technology which makes the work of developers easy and smooth. Like if a developer wants to push an update of its working application on a running server he has to go through all the node server of the company to get the job done. But what if there are 100 of node servers in the company, that’s an havoc. He has to go through all the server nodes and push that update in each of that nodes separately. That’s an Hectic, tedious and time consuming stuff. So now ‘CHEF’ comes into play .Using the chef technology the developer has to push and configure the update to the CHEF server from his chef workstation and the node servers will automatically extract the update from the chef server using the ‘Knife tool’. That makes the job a lot more easy

In this tutorial I will guide you through the basic but detailed installation of Chef Technology which will help you to better understand the core part of this technology. so go through it.

Points to be remembered before going through it:

‘ubuntuunicopserver’ is our Chef server.

‘ubuntuunicopwstation’ is our chef workstation.

‘ubuntuunicopnode’ is our client node

Steps to install CHEF technology

Configuration and installation of CHEF server

Chef server is the main central hub which acts a central connecting hub where all the updates are being pushed from the multiple workstations and Clients extracts all those updates from the chef server.

Download the latest chef server using below command

#  wget   https://packages.chef.io/files/stable/chef-server/12.18.14/ubuntu/21.04/chef-server-core_12.18.14-1_amd64.deb

Now install the server package with command

#  dpkg -i chef-server-core_*.deb

Now start the chef server services

# chef-server-ctl reconfigure

On successful start of services below output message will appear

Create Chef user and organization with associated private RSA keys

Now to Link all the available workstations and Nodes to the cheff server we have to create an administrator and organisation with shared private keys.

Create a .chef directory in home directory to store the keys

# mkdir .chef

SCREENSHOT

Create a user with user name , first name, last name E-mail, Password

chef-server-ctl user-create USER_NAME FIRST_NAME LAST_NAME EMAIL ‘PASSWORD’ –filename ~/.chef/USER_NAME.pem

Note: PEM extension is for USER_NAME

create chef administrator

root@ubuntuunicopserver:~# chef-server-ctl user-create chefadmin Chef Administrator chefadmin@@ubuntuunicopserver.com ‘*******’ –filename ~/.chef/chefadmin.pem

If you want to have a look on the list of all users then type the below command

root@ubuntuunicopserver:~# chef-server-ctl user-list

Create an organization and attach a user listed above

chef-server-ctl org-create ORG_NAME “ORG_FULL_NAME” –association_user USER_NAME –filename ~/.chef/ORG_NAME.pem

SCREENSHOT

After editing the file put the below the command

root@ubuntuunicopserver:~# chef-server-ctl org-create chef-on-ubuntu “Chef Infrastructure on Ubuntu 18.04” –association_user chefadmin –filename ~/.chef/chef-on-ubuntu.pem

To view the list of all organization on your chef server type the command

Now its time to install the chef workstation where we will create recipies and cookbooks

Download latest chef workstation(This can be a local machine or a remote server)

root@ubuntuunicopwstation:~# wget  https://packages.chef.io/files/stable/chef-workstation/0.2.43/ubuntu/21.04/chef-workstation_0.2.43-1_amd64.deb

OUTPUT

Now install it

root@ubuntuunicopwstation:~# dpkg -i chef-workstation_*.deb

Now generate chef repository to store your cookbooks

# chef generate repo chef-repo

Create a .chef subdirectory which will store the knife configuration files and the .Pem files which are going to be further used for RSA key pair authentication with chef server

root@ubuntuunicopwstation:~# mkdir ~/chef-repo/.chef

root@ubuntuunicopwstation:~# cd chef-repo

root@ubuntuunicopwstation:~/chef-repo#

Now generate a RSA key-pair on the workstation to gain access to chef server

Chef server communicates with the workstation and the nodes using the public key. The RSA private keys generated on the chef server are also copied to the workstation for a proper authenticated connection between them.

root@ubuntuunicopwstation:~# ssh-keygen -b 4096

Now next upload the workstation node’s public key to chef server node

Now workstation’s public key also needs to be uploaded to the chef server

root@ubuntuunicopwstation:~# ssh-copy-id root@ubuntuunicopserver.com

Now copy .Pem files from chef server to your workstation

root@ubuntuunicopwstation:~# scp root@ubuntuunicopserver.com:~/.chef/*.pem ~/chef-repo/.chef/

Time to generate a new chef cookbook

root@ubuntuunicopwstation:~# chef generate cookbook chef-first-cookbook

Now generate a chef repo and move in the new directory

# chef generate app chef-repo

# cd chef-repo

Finally its the Time to do ‘Knife’ configuration

Just go to the   ~/chef-repo/.chef directory and create a file with name config.rb and copy the below configuration

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                'node_name'
client_key               "USER.pem"
validation_client_name   'ORG_NAME-validator'
validation_key           "ORGANIZATION-validator.pem"
chef_server_url          'https://ubuntubox1.com/organizations/ORG_NAME'
cache_type               'BasicFile'
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
cookbook_path            ["#{current_dir}/../cookbooks"]

Major things to note :

(1)NODE_NAME is the username on the chef server

(2)Validation_client_Name is the organization’s name

(3)Chef _server_url is the Chef server’s domain

Now open the chef-repo directory and copy the required SSL certificates from the chef server

root@ubuntuunicopwstation:~/chef-repo/.chef# cd ..

root@ubuntuunicopwstation:~/chef-repo# knife ssl fetch

root@ubuntuunicopwstation:~/chef-repo# knife client list

chef-on-ubuntu-validator

At last Bootstrap the client node

Now we have to bootstrap the client node using its ROOT user

root@ubuntuunicopwstation:~/chef-repo/.chef# knife bootstrap ubuntuunicopnode.com -x root -P ******* –node-name chef-client-node

OUTPUT SCREENSHOT

Check whether the node client is bootstrapped successfully or not?

root@ubuntuunicopwstation:~/chef-repo/.chef# knife node list

chef-client-node

root@ubuntuunicopwstation:~/chef-repo/.chef# knife node show chef-client-node

FINAL CONCLUSION:

Finally I had tried to put all the detailed things and the basic configuration  of the Chef technology  stepwise and as simple as possible so that you don’t find yourself in a stuck kind of a situation and can easily get a hands on experience of Chef technology.

I Hope this small step by step tutorial would help you understand the basic working of CHEF technology.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

x