Bootstrap a Node 3 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 3
- 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.
- 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”.
Bootstrap a Node 3
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.
we need to specify some commands in the userdata while launching instance.
Create a Node “Chef-Node-3”
Launch Linux EC2 Instance
Check below link to Launch Linux EC2 Instance.
We can see the node “Chef-Node-3” which was created earlier.
Open your workstation Linux terminal through putty
1 2 3 4 5 6 7 8 9 |
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
we need specify private IP key file of chef-node-1 in bootstrap command.
Copy private IP of chef-node-3
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.32.223 --ssh-user ec2-user --sudo -i chef.pem -N ktexperts-node3 --ssh-user: This flag is deprecated. Use -U/--connection-user instead. Connecting to 172.31.32.223 The authenticity of host '172.31.32.223 ()' can't be established. fingerprint is SHA256:TRLPeVLqc6N2SY2Z+mvJtnHPPN9eJnAGHge/ANESUKo. Are you sure you want to continue connecting ? (Y/N) Y Connecting to 172.31.32.223 Creating new client for ktexperts-node3 Creating new node for ktexperts-node3 Bootstrapping 172.31.32.223 [172.31.32.223] -----> Installing Chef Omnibus (stable/15) downloading https://omnitruck.chef.io/chef/install.sh to file /tmp/install.sh.12429/install.sh trying wget... [172.31.32.223] 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.12434/metadata.txt [172.31.32.223] trying wget... [172.31.32.223] 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.32.223] [172.31.32.223] downloaded metadata file looks valid... [172.31.32.223] 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.12434/chef-15.6.10-1.el7.x86_64.rpm [172.31.32.223] trying wget... [172.31.32.223] Comparing checksum with sha256sum... [172.31.32.223] Installing chef 15 installing with rpm... [172.31.32.223] warning: [172.31.32.223] /tmp/install.sh.12434/chef-15.6.10-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY [172.31.32.223] Preparing... [172.31.32.223] ######################################## [172.31.32.223] [172.31.32.223] Updating / installing... chef-15.6.10-1.el7 [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] # [172.31.32.223] [172.31.32.223] Thank you for installing Chef Infra Client! For help getting started visit https://learn.chef.io [172.31.32.223] Starting the first Chef Infra Client Client run... [172.31.32.223] +---------------------------------------------+ ✔ 2 product licenses accepted. +---------------------------------------------+ [172.31.32.223] Starting Chef Infra Client, version 15.6.10 [172.31.32.223] [172.31.32.223] resolving cookbooks for run list: [] [172.31.32.223] [172.31.32.223] Synchronizing Cookbooks: [172.31.32.223] [172.31.32.223] Installing Cookbook Gems: Compiling Cookbooks... [2019-12-31T12:25:43+00:00] WARN: Node ktexperts-node3 has an empty run list. [172.31.32.223] Converging 0 resources [172.31.32.223] [172.31.32.223] [172.31.32.223] [172.31.32.223] Running handlers: [172.31.32.223] [172.31.32.223] Running handlers complete [172.31.32.223] Chef Infra Client finished, 0/0 resources updated in 06 seconds [172.31.32.223] |
Verify bootstrap nodes
To the bootstrap nodes
The ktexperts-note 3 has added to chef server successfully.
1 2 3 4 |
[root@ip-172-31-42-243 chef-repo]# knife node list ktexperts-node1 ktexperts-node2 ktexperts-node3 |
Deploy an Apache Web Server
We have already uploaded the recipe to chef server.
Attatch recipe “ktexperts-apache-recipe’rb” to node “ktexperts-node 3”
1 2 3 |
[root@ip-172-31-42-243 chef-repo]# knife node run_list set ktexperts-node3 "recipe[ktexperts-apache-cookbook::ktexperts-apache-recipe]" ktexperts-node3: run_list: recipe[ktexperts-apache-cookbook::ktexperts-apache-recipe] |
Verify recipe in run list
1 2 3 4 5 6 7 8 9 10 |
[root@ip-172-31-42-243 chef-repo]# knife node show ktexperts-node3 Node Name: ktexperts-node3 Environment: _default FQDN: ip-172-31-32-223.ap-south-1.compute.internal IP: 13.232.161.203 Run List: recipe[ktexperts-apache-cookbook::ktexperts-apache-recipe] Roles: Recipes: Platform: amazon 2 Tags: |
Verify the content of node 1 “Chef-Node-3”
Copy the IPV4 Public IP of node 1″Chef-Node-3″
Search IPV4 Public IP in browser
We can able to see the content of node 3 “Chef-Node-3”
Modify recipe “ktexperts-apache-recipe.rb”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[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 && Write article on different technologies" 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 3 “Chef-Node-3”
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