web.sh

Let's now create our web.sh bash script, which will handle the provisioning of our web servers. This script is much simpler than the load balancer script we created earlier, as follows:

#!/bin/bash
echo 'Starting Provision: web'$1
sudo apt-get update
sudo apt-get install -y nginx
echo "<h1>Machine: web"$1 "</h1>" > /var/www/html/index.html
echo 'Provision web'$1 'complete'

Again, in the preceding snippet, we are echoing out the progress at the beginning and end of our provision progress. In lines 2-4 we are updating Ubuntu and installing nginx. In line 5 we are overwriting the default index HTML file with a basic title, which will help us differentiate between the two web servers.

In this script you will notice the use of $1. This is a variable in bash and references the first argument. Later on in this section you will learn how to pass an argument into the shell script, as this will help us differentiate between web server 1 and web server 2.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.190.167