Skip to main content

Shared Application Configuration with Azure Files

Hands-On Lab

 

Photo of Will Boyd

Will Boyd

DevOps Team Lead in Content

Length

00:30:00

Difficulty

Intermediate

Azure File Shares are a powerful tool for managing data in the cloud. The data stores that uses File Shares can take many forms, and it can even include configuration data.

One way to use Azure Files shares is to store shared configuration files in them so that the shared configuration files can be accessed across multiple servers.

In this lab, we will explore Azure File shares. We will configure an Nginx web server on two machines using a shared configuration file stored in an Azure File share. This will provide you with some hands-on experience with what it might look like to manage shared configuration using Azure File shares.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Shared Application Configuration with Azure Files

In this lab, we will be using the Azure File share to keep the configuration for all of our servers in a central location (Azure). By mounting the file share to all of the web servers, we can ensure that any changes to the shared configuration can be rolled out to all servers.

We will create a file share to store the configuration file, mount it to both web servers, and add the shared configuration file to the mounted share. After completing these tasks, we should be able to view the static website on both servers.

We will need the following information to complete this task:

  • The storage account that contains the File Share that begins with the text webconfig.
  • The File Share called config mounted at /etc/nginx/sites-enabled on both servers.
  • The Samba credentials file that exists on both servers at /etc/smbcredentials/webconfig.cred.
  • The configuration file called default.
  • The contents of the configuration file, which are:

    server {
       listen 80 default_server;
       listen [::]:80 default_server;
    
       root /www/satt;
    
       index index.html index.htm index.nginx-debian.html;
    
       server_name _;
    
       location / {
           try_files $uri $uri/ =404;
       }
    }

Before We Begin

Before we start, we need to log in to our Azure portal and our two virtual machines using the login credentials provided. We will be working in the terminal but will need information from the portal.

To make this lab go quickly, having two terminals open to work in (one for each server) is best. Use ssh to log in to both terminals and the provided IP addresses.

Create a File Share

To get started, we first need to head to our Azure portal. Here, we need to find the storage account. To do so, look for the item that starts with webconfig.

Click on the storage account, then select File Shares and then click + File Share to create a new file share. Here, set the name of the new file share to config and click Create.

Mount the File Share to both Web Servers

With the file share created, it is time to mount the file to our web servers. To get started, we need to edit the fstab file on both servers using sudo vi /etc/fstab.

Next, we need to add a new entry at the end of the file on each server. We want to replace the <storage account name> in the Samba address with our real storage account name, which we can find in the Azure portal.

Replace the placeholder with the account name and enter the following:

//<storage account name>.file.core.windows.net/config /etc/nginx/sites-enabled cifs nofail,vers=3.0,credentials=/etc/smbcredentials/webconfig.cred,serverino

On both servers, finish mounting the File Share by mounting all filesystems in fstab using sudo mount -a.

Create the Shared Configuration File Within the File Share

With both of our servers set up, we can continue working.

On one of the two servers, edit the config file using sudo vi /etc/nginx/sites-enabled/default. In it, add the contents of the configuration file:

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  root /www/satt;

  index index.html index.htm index.nginx-debian.html;

  server_name _;

  location / {
    try_files $uri $uri/ =404;
  }
}

With the information added, reload the Nginx configuration on both servers using sudo nginx -s reload.

We can now view the website by accessing the server's public IP address in a browser. We can also verify this when logged in to one of the servers with the curl localhost command.

Conclusion

Upon finishing this lab, we are now able to share the configuration of an application between two servers. Congratulations on completing the lab!