Bootstrap a Node 2 and Deploy Apache Web Server
In this article,we will see Bootstrap a Node 2 and Deploy Apache Web Server.
Implementation Steps
Bootstrap a Node 2
- Check Availability Zone of your workstation.
- Create a Node “Chef-Node-1” by launching instance.
- Open your workstation Linux terminal through putty.
- Switch to root user.
- Go to chef-repo.
- Run bootstrap command to bootstrap a node 2.
- Verify bootstrap nodes.
Deploy an Apache Web Server
- Attach recipe “ktexperts-apache-recipe’rb” to node “ktexperts-node 2”.
- Verify recipe in run list.
- Connect to node 2 “Chef-Node-2” Linux Terminal through putty.
- Switch to root user.
- Open “crontab” file inside the /etc directory and write script to run automatically.
- Run chef-client.
- Verify the content of node 2 “Chef-Node-2”.
- Modify recipe “ktexperts-apache-recipe.rb”.
- Upload cookbook to chef server.
- Verify the content of node 1 “Chef-Node-1”.
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-2”
Launch Linux EC2 Instance
Check below link to Launch Linux EC2 Instance.
We can see the node “Chef-Node-2” which was created earlier.
Open your workstation Linux terminal through putty
Using username “ec2-user”. Authenticating with public key “imported-openssh-key” Last login: Fri Dec 27 09:02:29 2019 from 124.123.103.5 __| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___| https://aws.amazon.com/amazon-linux-2/
Switch to root user
[ec2-user@ip-172-31-42-243 ~]$ sudo su [root@ip-172-31-42-243 ec2-user]#
Go to chef-repo
[root@ip-172-31-42-243 ec2-user]# cd chef-repo/ [root@ip-172-31-42-243 chef-repo]#
Run bootstrap command to bootstrap a node 2
we need specify private IP key file of chef-node-1 in bootstrap command.
Copy private IP of chef-node-2
Specify username,private IP(chef-node-2) and pem key “chef.pem” (chef-node-2) in the bootstrap command.
Note
Two actions will be done while bootstrapping.
Adding node to chef server.
Installing chef package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
[root@ip-172-31-42-243 chef-repo]# knife bootstrap 172.31.35.130 --ssh-user ec2-user --sudo -i chef.pem -N ktexperts-node2 --ssh-user: This flag is deprecated. Use -U/--connection-user instead. Connecting to 172.31.35.130 The authenticity of host '172.31.35.130 ()' can't be established. fingerprint is SHA256:Civje7e3xj68RbKKpMJhqqRpGNGs4wUu9oFS4JxfxKQ. Are you sure you want to continue connecting ? (Y/N) Y Connecting to 172.31.35.130 Creating new client for ktexperts-node2 Creating new node for ktexperts-node2 Bootstrapping 172.31.35.130 [172.31.35.130] -----> Installing Chef Omnibus (stable/15) downloading https://omnitruck.chef.io/chef/install.sh to file /tmp/install.sh.3624/install.sh trying wget... [172.31.35.130] el 7 x86_64 Getting information for chef stable 15 for el... downloading https://omnitruck.chef.io/stable/chef/metadata?v=15&p=el&pv=7&m=x86_64 to file /tmp/install.sh.3629/metadata.txt [172.31.35.130] trying wget... [172.31.35.130] sha1 27c8caeb7fcbab3642d3a2c320d2f880a6cf8541 sha256 9cb48fed74779b261a03c34178e375bbbf27860db3641ef5b392f7b1e439414e url https://packages.chef.io/files/stable/chef/15.6.10/el/7/chef-15.6.10-1.el7.x86_64.rpm version 15.6.10 [172.31.35.130] [172.31.35.130] downloaded metadata file looks valid... [172.31.35.130] downloading https://packages.chef.io/files/stable/chef/15.6.10/el/7/chef-15.6.10-1.el7.x86_64.rpm to file /tmp/install.sh.3629/chef-15.6.10-1.el7.x86_64.rpm [172.31.35.130] trying wget... [172.31.35.130] Comparing checksum with sha256sum... [172.31.35.130] Installing chef 15 installing with rpm... [172.31.35.130] warning: [172.31.35.130] /tmp/install.sh.3629/chef-15.6.10-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY [172.31.35.130] Preparing... [172.31.35.130] ######################################## [172.31.35.130] [172.31.35.130] Updating / installing... chef-15.6.10-1.el7 [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] # [172.31.35.130] [172.31.35.130] Thank you for installing Chef Infra Client! For help getting started visit https://learn.chef.io [172.31.35.130] Starting the first Chef Infra Client Client run... [172.31.35.130] +---------------------------------------------+ ✔ 2 product licenses accepted. +---------------------------------------------+ [172.31.35.130] Starting Chef Infra Client, version 15.6.10 [172.31.35.130] [172.31.35.130] resolving cookbooks for run list: [] [172.31.35.130] [172.31.35.130] Synchronizing Cookbooks: [172.31.35.130] [172.31.35.130] Installing Cookbook Gems: Compiling Cookbooks... [2019-12-31T11:57:02+00:00] WARN: Node ktexperts-node2 has an empty run list. [172.31.35.130] Converging 0 resources [172.31.35.130] [172.31.35.130] [172.31.35.130] [172.31.35.130] Running handlers: [172.31.35.130] [172.31.35.130] Running handlers complete [172.31.35.130] Chef Infra Client finished, 0/0 resources updated in 06 seconds [172.31.35.130] |
Verify bootstrap nodes
To the bootstrap nodes
The ktexperts-node2 has added to chef server successfully.
1 2 3 |
[root@ip-172-31-42-243 chef-repo]# knife node list ktexperts-node1 ktexperts-node2 |
Deploy an Apache Web Server
We have already uploaded the recipe to chef server.
Attach recipe “ktexperts-apache-recipe’rb” to node “ktexperts-node 2”
1 2 3 4 |
[root@ip-172-31-42-243 chef-repo]# knife node run_list set ktexperts-node2 "recipe[ktexperts-apache-cookbook::ktexperts-apache-recipe]" ktexperts-node2: run_list: recipe[ktexperts-apache-cookbook::ktexperts-apache-recipe] |
Verify recipe in run list
1 2 3 4 5 6 7 8 9 10 11 12 13 |
che-cookbook::ktexperts-apache-recipe]" ktexperts-node2: run_list: recipe[ktexperts-apache-cookbook::ktexperts-apache-recipe] [root@ip-172-31-42-243 chef-repo]# knife node show ktexperts-node2 Node Name: ktexperts-node2 Environment: _default FQDN: ip-172-31-35-130.ap-south-1.compute.internal IP: 13.127.5.149 Run List: recipe[ktexperts-apache-cookbook::ktexperts-apache-recipe] Roles: Recipes: Platform: amazon 2 Tags: |
Connect to node 2 “Chef-Node-2” Linux Terminal through putty
Switch to root user
1 2 |
[ec2-user@ip-172-31-35-130 ~]$ sudo su [root@ip-172-31-35-130 ec2-user]# |
Open “crontab” file inside the /etc directory and write script to run automatically
In the crontab file we set the time interval to run the chef-client depends on interval.
Note
We have provide space in between stars.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@ip-172-31-35-130 ec2-user]# vi /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed <span style="color: #ff0000;">* * * * * root chef-client</span> |
Note
:wq! — to quit.
Run chef-client
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[root@ip-172-31-35-130 ec2-user]# chef-client Starting Chef Infra Client, version 15.6.10 resolving cookbooks for run list: ["ktexperts-apache-cookbook::ktexperts-apache-recipe"] Synchronizing Cookbooks: - ktexperts-apache-cookbook (0.1.0) Installing Cookbook Gems: Compiling Cookbooks... Converging 3 resources Recipe: ktexperts-apache-cookbook::ktexperts-apache-recipe * yum_package[httpd] action install - install version 0:2.4.41-1.amzn2.0.1.x86_64 of package httpd * file[/var/www/html/index.html] action create - create new file /var/www/html/index.html - update content in file /var/www/html/index.html from none to 5e527b --- /var/www/html/index.html 2019-12-31 12:09:27.466920742 +0000 +++ /var/www/html/.chef-index20191231-3915-1lw4kds.html 2019-12-31 12:09:27.466920742 +0000 @@ -1 +1,2 @@ +wwww.ktexperts.com && Knowledge sharing platform * service[httpd] action enable - enable service service[httpd] * service[httpd] action start - start service service[httpd] Running handlers: Running handlers complete Chef Infra Client finished, 4/4 resources updated in 13 seconds |
Note
Once run the chef-client in the node 1 then the node became a Apache Web Server.
Verify the content of node 2 “Chef-Node-2”
Copy the IPV4 Public IP of node 1″Chef-Node-2″
Search IPV4 Public IP in browserWe can able to see the content of node 1 “Chef-Node-2”
Modify recipe “ktexperts-apache-recipe.rb”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@ip-172-31-42-243 chef-repo]# vi cookbooks/ktexperts-apache-cookbook/recipes/ktexperts-apache-recipe.rb package 'httpd' do action :install end file '/var/www/html/index.html' do content "wwww.ktexperts.com && Knowledge sharing platform && Help to share Knowledge" action :create end service 'httpd' do action [ :enable, :start ] end |
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.
1 2 3 |
[root@ip-172-31-42-243 chef-repo]# knife cookbook upload ktexperts-apache-cookbook Uploading ktexperts-apache-cookbook [0.1.0] Uploaded 1 cookbook. |
Verify the content of node 1 “Chef-Node-1”
Refresh IPV4 Public IP the browser
we can see the content has been modified successfully.
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates
KTEXPERTS is always active on below social media platforms.
Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform