Sitemap
4 min readJan 12, 2023

--

DevOps On Linux

By — Shivam Bansal

You must need Linux installed in your system to work on DevOps on Linux. If you have windows so you can use Virtual devices for the same

  • VMware
  • Vagrant
  • Azure Virtual Machine
  • Terraform

We are going to use Vagrant in this Article.

In computing, a virtual machine (VM) is the virtualization/emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve specialized hardware, software, or a combination.

What is a Vagrant?

Vagrant is an open-source software product for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS. It tries to simplify the software configuration management of virtualization in order to increase development productivity. Vagrant is written in the Ruby language, but its ecosystem supports development in a few other languages.

Steps to create Vagrantfile to create a Virtual Machine

Step — 1:-

Create a Folder in your system’s desired location and create a new file with the name “Vagrantfile”

Press enter or click to view image in full size

Step -2:

Write your Vagrantfile to Create a Virtual Machine

Vagrant.configure(“2”) do |config|
config.vm.box = “ubuntu/bionic64”
end

The “2” in the first line above represents the version of the configuration object that will be used for configuration for that block (the section between the do and the end). This object can be very different from version to version.

Step-3:

Now some Commands for starting Vagrant on your local machine

Vagrant up → For creating and running the Vagrant

Press enter or click to view image in full size

Now Vagrant is up and running

This shows the description of the Virtual Machine you created

Press enter or click to view image in full size

Vagrant ssh → For using your Virtual Machine on your command line as

Press enter or click to view image in full size

Now you are ready for using Virtual Desktop

Vagrant destroy → For destroying your Virtual machine

Step-4:

Use Command:

-sudo su: This Command allows you to run commands as root.

Step-5:

Now update by using the command and install apache2 in that virtual machine.

apt update && apt install apache2

While doing this may be you will get an error

Press enter or click to view image in full size

To resolve this error write a command:-

Get Shivam Bansal’s stories in your inbox

Join Medium for free to get updates from this writer.

nano /etc/resolv.conf

add nameserver 8.8.8.8

Press enter or click to view image in full size

And then run that command again:-

apt update && apt install apache2

Step -6:

Now go to the directory with the command

cd /var/www/html

and delete the file name index.html using the command

rm index.html

and then create new file name index.html using command

nano index.html

A new page will appear and then write some html syntax in that:-

Now ctrl+s (for save) and ctrl + x (for exit) from the window

In this we created a virtual machine for Ubuntu.

Now let’s install docker in your Virtual Machine Manually.

Installing Docker:-

If you are working in a (sudo su) then you don’t have to add sudo in any commands

1- sudo apt-get update

2- sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

3- sudo mkdir -p /etc/apt/keyrings

4- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg — dearmor -o /etc/apt/keyrings/docker.gpg

5- echo \
“deb [arch=$(dpkg — print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

6- sudo apt-get update

7- sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Now we will Install apache2 using Shell Scripting:-

Step-1:- let’s uninstall apache2 from your server.

1- sudo service apache2 stop
2- sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
3- sudo apt-get autoremove
4- whereis apache2
apache2: /etc/apache2
5- sudo rm -rf /etc/apache2

Step-2 :- Now install apache2 using shell scripting

nano shell.sh

Press enter or click to view image in full size

#!/bin/bash
if [ -z $(dpkg -l |grep ‘apache’) ]
then
sudo apt update
sudo apt install apache2 -y
sed -i ‘s/80/8080/g’ /etc/apache2/ports.conf
echo “my name is shivam bansal” >> /var/www/html/index.html
systemctl restart apache2

else
echo “apache exist”
Fi

Chmod +x shell.sh

Bash shell.sh

(Now apache2 will be installed automatically)

Conclusion:- In This Article, we have learned

  • Creating Vagrantfile
  • Installing server on Linux
  • Learn some Linux Commands
  • Install Docker manually

In this article we have learned how to start Vagrant and install server and docker on vagrant manually but in next article I will show you how to install those things with the help of shell scripting.

--

--