Bootstrap a Node 1 and Deploy Apache Web Server

Share via:

Bootstrap a Node 1 and Deploy Apache Web Server

In this article,we will see Bootstrap a Node 1 and Deploy Apache Web Server.

Attaching a node to chef server is called bootstrapping.

A Chef node is a physical or virtual machine with an operating system that is connected to the Chef server.

Once the node has made the connection to the Chef server, the installed Chef Client can execute Chef cookbooks to configure the machine.

Bootstrapping is the process to connect the node the first time to the Chef server, or to attach it again if the node lost the connectivity to the Chef server.

To be able to bootstrap a node, your workstation needs to have the Chef Development Kit installed.

The kit includes the ‘knife’ command that communicates with the Chef server.

Prepare cookbooks

  1. see the list of cookbook.
  2. Move two cookbook to cookbooks of chef-repo directory.
  3. Remove cookbooks directory.
  4. Verify the two cookbook inside cookbooks of chef-repo directory.

Bootstrap a node 1

  1. Check Availability Zone of your workstation.
  2. Create a Node “Chef-Node-1” by launching instance.
  3. Open your workstation Linux terminal through putty.
  4. Switch to root user.
  5. Go to chef-repo.
  6. Copy chef-node-1 pem key file “chef.pem” to chef-repo directory of your workstation through WinScp.
  7. Verify key file “chef.pem” of your node “chef-node-1”.
  8. Run bootstrap command to bootstrap a node 1.
  9. Verify bootstrap nodes.

Deploy an Apache Web Server

  1. open existing recipe “ktexperts-apache-recipe.rb” and write script to create apache  web server.
  2. Upload cookbook to chef server.
  3. Verify cookbooks in chef server.
  4. Verify cookbooks in chef server graphically.
  5. Attatch recipe “ktexperts-apache-recipe’rb” to node “ktexperts-node1”.
  6. Verify recipe in run list.
  7. Verify recipe in run list graphically.
  8. Connect to node 1 “Chef-Node-1” Linux Terminal through putty and run chef-client command.
  9. Verify the content of node 1 “Chef-Node-1”.
  10. Modify recipe “ktexperts-apache-recipe.rb”.
  11. Upload cookbook to chef server.
  12. Go inside the node 1″Chef-Node-1″ and Run chef-client command.
  13. Verify the content of node 1 “Chef-Node-1”.

Prepare cookbooks

To see the list of cookbook

we can see two cookbook are being presented in custom cookbooks directory.

Move two cookbook to cookbooks of chef-repo directory

Remove cookbooks directory

Verify the two cookbook inside cookbooks of chef-repo directory

Bootstrap a node 1

Make sure workstation and node should be same Availability Zone (optional).

Now onwards,Run any commands be inside the chef-rep directory.

Two actions will be done while bootstrapping

Adding node to chef server.

Installing chef package.

Check Availability Zone of your workstation

we can see the Availability Zone “ap-south-1a” of your workstation.

Note

Workstation is in ap-south-1a AZ.

we create a node in the same Availability Zone “ap-south-1a”.

we need to open SSH and HTTP ports.

Create a Node “Chef-Node-1” 

Launch Linux EC2 Instance

Check below link to Launch Linux EC2 Instance.

Launch Linux EC2 Instance

We can see the node  “Chef-Node-1” which was created earlier.

Open your workstation Linux terminal through putty

Switch to root user

To see the list of files/directories

we can see the chef-repo directory which was copied from local machine(windows) through WinScp Tool.

Go to chef-repo

Copy chef-node-1 pem key file “chef.pem” to chef-repo directory of your workstation through WinScp

Verify key file “chef.pem” of your node “chef-node-1” 

The key file “chef.pem” has been copied to chef-repo directory.

Run bootstrap command to bootstrap a node 1

knife bootstrap 172.31.35.120 –ssh-user ec2-user –sudo -i chef.pem -N ktexperts-node1

Private IP — SSH communication happens internally.

we need mention private IP key file of chef-node-1 .

Copy private IP of chef-node-1

Specify username,private IP(chef-node-1) and pem key “chef.pem” (chef-node-1) in the bootstrap command.

Note

Two actions will be done while bootstrapping.

  • Adding node to chef server.
  • Installing chef package.

Verify bootstrap nodes

To the bootstrap nodes

The ktexperts-node1 has added to chef server successfully.

Deploy an Apache Web Server

open existing recipe “ktexperts-apache-recipe.rb” and write script to create apache  web server

Note

:wq! — to quit.

Upload cookbook to chef server

Verify cookbooks in chef server

Verify cookbooks in chef server graphically

Attatch recipe “ktexperts-apache-recipe’rb” to node “ktexperts-node1”

Verify recipe in run list

Verify recipe in run list graphically

Go to chef server,

In the Nodes click on Edit Run List.

In the Edit Run List, we can see the recipe and their belonging cookbook.

Connect to node 1 “Chef-Node-1” Linux Terminal through putty and run chef-client command

 

Switch to root user

Run chef-client 

Note

Once run the chef-client in the node 1 then the node became a Apache Web Server.

Verify the content of node 1 “Chef-Node-1”

Copy the IPV4 Public IP of node 1″Chef-Node-1″

 

Search IPV4 Public IP in browser

We can able to see the content of node 1 “Chef-Node-1”

Modify recipe “ktexperts-apache-recipe.rb” 

Note

:wq! — to quit.

Upload cookbook to chef server

we can’t upload individual recipes so,we can upload cookbook that the recipe present inside the cookbook itself.

Go inside the node 1″Chef-Node-1″ and Run chef-client command

Verify the content of node 1 “Chef-Node-1”

Refresh IPV4 Public IP the browser

we can see the content has been modified successfully.

Key Points

Attaching node to chef server is called bootstrapping.

we should be inside the chef-rep directory and run commands.

Two actions will be done while bootstrapping.

  •    Adding node to chef server.
  •    Installing chef package automatically by chef server.

All cookbooks must be inside the cookbooks directory comes by default with chef-repo repo directory to upload to chef server.

Never ever delete the default cookbooks folder comes by default with chef-repo directory.

Note

In this article ,we have seen bootstrap a node.

Open existing recipe and write script to create web server.

By running the chef-client in the node 1 “Chef-Node-1”  the node 1 became a web server.

For every time we need to go inside the node 1 “Chef-Node-1” and run the chef-client manually.

  • Thank you for giving your valuable time to read the above information.

Follow us on 

Website :  www.ktexperts.com

Facebook Page : KTexperts

Linkedin Page : KT EXPERTS

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

2 thoughts on “Bootstrap a Node 1 and Deploy Apache Web Server

  1. This Article really helped me in knowing DevOps at a glance. Thanks for making me know that DevOps is not as boring as it seems.

Add Comment