Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Configuring a Static IP for VirtualBox VM in Ubuntu along with Internet Connectivity in Virtualbox

Leave a Comment

Configuring a Static IP for VirtualBox VM in Ubuntu along with Internet Connectivity in VirtualBox


If you have provisioned any Ubuntu Server/VM running using Oracle Virtual box and want to have both static IP and Internet connectivity enabled. This is the right place for you to learn how to make the required configurations to achieve this.

For this task, we will need to add two Network adaptor , If you also need your VM to have internet access as well, leave Adapter 1 as NAT and enable Adapter 2, configured as a Host-Only adapter. This will allow your VM to connect to the internet using NAT as well as make a local connection to your Host using Host-Only.

1.  Adaptor 1 - NAT

2. Adaptor 2 : - Host only adaptor


Steps:

1. Shutdown/ Power off  the VM 

2. Go to the VM settings and Select adaptor 1 as NAT as shown in the below screenshot.





3. In the advanced setting, select the port forwarding and configure port forwarding as below

for the 'NAT'. I clicked the 'port forwarding' option at the bottom of the screen. I gave it a name 'PuTTY-port-fwd', protocol TCP, host IP 127.0.1.1 host port 2222 guest IP 10.0.2.15 guest port 22. I then launched PuTTY and set it to 127.0.0.1 port 2222 and it connected to my ubuntu vm







4. Power on the VM and let it boot until login prompt  is available , Open any putty terminal,  i use mobaxterm for the ssh access.

Verify ssh access using ssh -p 2222 himanshu@127.0.1.1



Booyeah!  you have successfully configured your Ubuntu VM to be accessible via Putty session along with the internet access.

I hope this post was helpful for you.

Also read : 




Read More...

Passed CKA exam with 87% marks in First attempt

Leave a Comment

Hi all,  today we are going to talk how you can prepare and pass the CKA exam with great marks.

Last month in November, i scheduled and passed the CKA exam with 87 percent marks.

I will share the tips to crack the CKA exam in the first attempt.


CKA exam


Why CKA 

Read More...

Assign static IP address to Centos/RHEL 7 Virtual machines in Oracle VirtualBox

Leave a Comment

Hello readers, in this post we will learn how we can set up static IP address to the Virtual machines created using Oracle Virtual Box.


In case you want to install Oracle Virtual Box and deploy a Linux VM like Ubuntu or Centos on it, please read old post with detailed steps.


When we created these virtual machines, they have IP address assigned which are from the bridged adaptor on my Wi-Fi router network. So, the ip address that my virtual machines are getting are assigned by the Wi-Fi router using dhcp. As the IPs assigned by the DHCP router are dynamic so they can change anytime when you reboot the machines.  Sometimes, when you reboot the machines, you will find that the IP address assigned got changed than the one they had before.


So, in case you want to have your virtual machines to have static IP address, this cannot be achieved using the bridged network, so a alternate way is to create another network that will be host only network. 


It will be a network on my Laptop and my laptop will have a virtual interface on that network and all of the virtual machines will have a virtual interface on that network and we can assign static IPs for the VMs on that network.






In this post, we have performed steps on CentOS 7.9 Linux VM.


Open Host Network Manager from the File menu or Network option from the Tools menu



Host only Ethernet Adapter

Here you will see list of Host only networks that are already created, sometimes you will one of the default as shown in screenshot below already created, else you can create new host only ethernet network.



In this case, i am going to use default one with IP address range 192.168.56.1/24  Make sure dhcp server option is unchecked.





Once you have identified the host only network, you need to attach this network to your virtual machines. Right click on machine and choose settings and go to network.

Adapter 1 with Bridged Network for internet access 



In the adapter one, you can see it is attached to Bridged network which is required for internet connectivity if you want to download any packages. 






Go to Adapter 2 and select attached to : Host-only adapter , leave everything else as default.







Now we have two adapter attached to the machine, one is the bridged router and second one is host only adapter. Click on OK and power on the Virtual machine. You will see a new interface is attached and verified using the ip a s command or ifconfig command,  however IP address is still not assigned to the interface.


Configure Static IP Address in CentOS 7 / RHEL 7




Perform below steps to create a new config file for the newly added interface enp0s8


# cd /etc/sysconfig/network-scripts# vi ifcfg-enp0s8

Add below to the ifcfg-enp0s8

NAME=enp0s8

DEVICE=enp0s8

BOOTPROTO=none

DEFROUTE=yes

ONBOOT=yes

PREFIX=24

IPADDR=192.168.56.2

save and quit the file.


Restart the network service using below command



# systemctl restart network



Now, you will see that IP address 192.168.56.2 given in the config file is plumbed on the interface enp0s8



You can reboot the machine and test ssh via IP, You have successfully assigned static IP address to your Centos 7 /RHEL Linux machine.



Read More...

Steps to Clone Virtual Machines in Oracle VirtualBox

Leave a Comment

Hello readers,  in our last post, we learnt about installing Oracle Virtual box and deploying a Centos 7 Linux machine using the vdi image.  In case you have a scenario to create multiple machines with similar configurations,  you don't need to repeat the steps to install or deploy a new machine.  You can use Cloning feature of Virtual Box to create more machines.



I was setting up a Lab environment for creating Kubernetes cluster and deployed machine 1 on Oracle Virtual box, to create remaining nodes of the cluster, I used the cloning feature of Virtual Box t that is a really great feature.


Steps to Clone a Virtual Machine in Oracle Virtual machine

Power off the machine that you want to clone.  Make sure the virtual machine is powered off before starting the clone steps else the option will be greyed out or disabled.


Right click on the machine, you want to clone and click on Clone option.




In the next step, you will come across below UI , Enter the name of machine and I have used the Mac Address Policy as "Generate new MAC addresses for all network adapters"



This option makes sure that the clone VM don't get the same MAC address assigned as that of the source VM



You may leave the Additional Options unchecked.



In the next step, you need to choose between Full clone or Linked clone,  Full clone creates a full copy of your virtual hard disk while linked clone does not create full copy of virtual hard disk and helps to save disk space.



For my use case,  Linked clone option was fine.  You may use Full clone option as well depending upon your case.




Click on clone option and instantly your source VM will be cloned.



Power on both machines and they are ready to use.



Also read : 40 Linux commands for Beginners and intermediate users

Hope you are able to do the clone of your virtual machine following these steps.




Read More...

Install Oracle VirtualBox and deploy Centos 7 machine with screenshots

Leave a Comment

Install Oracle VirtualBox on Windows 10 Laptop and deploy Centos 7 machine with screenshots

Hello and welcome to this blog post, In this post we are going to learn how we can set up a Lab environment on our Laptop. We are going to use Oracle Virtual box to setup a lab with a virtual machine and Centos 7.9 installed on it. 


You can choose VMware workstation as well or any virtualization technology you are comfortable with as an alternative option to Oracle VirtualBox.



Install VirtualBox on your Laptop


Download the Oracle Virtual Box software and install the same. It is supported for Linux, Windows, Macintosh  and Solaris

Download page https://www.virtualbox.org/


Go to the download page and install the software for the Laptop OS , in this post we have used Windows 10.




Once downloaded, run the executable and setup wizard, installation is very easy.  Click on the installer with .exe and click on next.





Click next and select the location. We are going to set the default options.








Finally read the warning about the network interfaces, its going to reset the network connection.



Click install and it goes through the installation process and it finishes in a minute




Once installation is finished,  you will see the Oracle Virtual Box interface as shown below






How to install/deploy a Centos Machine on VirtualBox


To deploy the virtual machine, you need a image of the OS you want to deploy. In this demo, we are setting up Centos 7.9 machine.


Download the image from https://osboxes.org/  There are lot of images available for different OS versions,  if you want to download centos image, go directly to https://www.osboxes.org/centos/





It will download a compressed .7z file and it takes about 1 GB space. Once downloaded extract the .7z file.  You will find the centos vdi image in the 64bit folder.





Now go back to Oracle virtual box and start deploy the centos machine.

Click on Machine - New 


It will bring below interface, here you need to specify the name and the OS that you want to install.


Choose Redhat 64 bit as version.






In the next step, select the memory size you want for your machine, i have used 2 GB for my centos 7.9 machine.




I am going to go ahead and select the hard disk, i have used Use an existing virtual hard disk and browse to the path where you have centos vdi image downloaded. 





Click on choose and create




Now, it has deployed the centos image or Centos virtual machine.





Before powering on the Centos machine,  update the settings options and select the network option and set the network type to bridged.  By default, you will find it as NAT.


Update the same and set it to Bridged Adapter and adapter that is going to be bridged to is my wifi router.





You can now proceed to start your virtual machine.









You can now proceed to login to your machine, the password is same as that of user i.e osboxes.org in lowercase.

Hope you are able to deploy centos Linux machine following this tutorial. Feel free to comment in case you are facing any issue or having any doubt.

Read More...

How to install R and RStudio on Linux - CentOS or RHEL 7 in 5 minutes

Leave a Comment

R is a programming language used for statistical computing commonly by Data Scientists and analysts. It is free and open source tool under GNU project and R is maintained by R foundation.


In this article we will learn how to install R and R Studio on a Linux server that can be Centos 7 or Red hat Enterprise Linux 7.  


Please note :  You can install either using root user or a non root user with sudo rights.





Step 1 : Install R 

First, you need to install the epel repo for centos and rhel using below command. Make sure yum works on your machine.

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install R software using below command

sudo yum install R -y


Once yum completes the installation of R package, you may verify the same using below command.

On your Linux machine, run command R, if successfully installed you will see output as given below.

root@techbuzztimes #  R 






You are done with one part that is R installation, next you need to install R studio.



Step 2: Install R studio


You can find the latest version of R studio for Centos and RHEL 7 from here
Make sure wget is installed on your machine, you need to download the package first and then install it using yum command as given below

wget https://download2.rstudio.org/server/centos6/x86_64/rstudio-server-rhel-1.3.1093-x86_64.rpm
sudo yum install rstudio-server-rhel-1.3.1093-x86_64.rpm

During the installation, at the end it will try to enable and start the service as shown in below screenshot, make sure Rtsudio service is up and running.



Check the Rstudio service using below command.

systemctl status rstudio-server.service

Make sure service is enabled so that it comes up after the server restarts.

systemctl enable rstudio-server.service


Step 3 : Verify Rstudio GUI 

Ok, so you are done with the installation steps, now you can go ahead and verify the R studio gui on web browser.

By default, R studio runs on port 8787


In your web browser open URL http://hostname:8787


You will see gui like below



You can verify access on the R studio using any user, make sure user exists on the server and having valid home directory on the server, you may check using below command.

getent passwd username


Once successfully logged in, you will see Gui as shown below. All these steps will take between 5 to 10 minutes.  Please let us know how your R studio installation went in comments.



 

 

Read More...

How to install Docker on RHEL 8 beta

Introduction

This post will guide you about the steps required to get started with Docker on RHEL 8 beta system. RHEL 8 beta was announced a few months back and it is available to download for testers and developers, It comes with a lot of advancement and new features and If you want to install and explore RHEL 8 you can read our old post that shows the detailed steps of RHEL 8 installation on VMware workstation
One of the new features added in RHEL 8 is Containers without daemons. Buildah and Podman can help you build containers without any requirement of Dockers.
There are two versions of Dockers available: Docker CE [Community edition] and Docker EE [Enterprise Edition].
Well, if you are wondering of RHEL 8 Beta supports docker? There is no official documentation regarding the installation of Dockers on RHEL 8 beta, we tested installation of Docker CE on RHEL 8 beta to play with dockers on RHEL 8.

Steps of Installing Docker CE on RHEL 8 beta

Before installing Docker CE on a machine, we need to setup the docker repository. Once this step is done, we can install Docker from the repository.

1. Set up the repository

Install required packages, dnf-utils, device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.
Note that : DNF (dandified yum)is used as package management utility in RHEL 8.
# dnf install -y dnf-utils \
  device-mapper-persistent-data \
  lvm2
Use the following command to set up the repository.
#  dnf config-manager \ 
  --add-repo \
  https://download.docker.com/linux/centos/docker-ce.repo
Now, the docker ce repository is set up, you can check using dnf repolist or yum repolist

2. Install Docker CE

You can install the latest version of the docker ce using below command.
# dnf install docker-ce
While installing, if you are prompted to accept the GPG key, accept the same by entering y
Note: We encountered below error while running the install command for the first time. We re-ran the install command, it did not appear and prompt for accepting gpg key came next and after entering y, the installation went smooth and was finished in about a minute.
Curl error (6): Couldn’t resolve host name for https://download.docker.com/linux/centos/gpg [Could not resolve host: download.docker.com]

Once installed, you will see the download complete message with the package details that are installed.

Next step is to start and enable docker using systemctl
# systemctl start docker
# systemctl enable docker
Finally, you are done with the Docker CE installation on your RHEL 8 machine, now lets verify that it is installed correctly by running the hello-world image.

That’s all for this post, hope you are able to install docker on your RedHat Linux 8 machine.
If you have thoughts on this, please feel free to comment below.
Read More...

Different Instructions in a Dockerfile and their usage

Learn about different components/Instructions that makes a Dockerfile

What is Dockerfile?

The set of instructions for building a container are written in Dockefile. It is a text file that contains the base image, all the settings, and the list of commands required for preparing and starting a container.


Dockerfile basic Example

A basic example of a Dockerfile for installaing and building a apache web server.
FROM centos:latest

MAINTAINER admin

RUN yum update && yum -y install httpd

RUN echo "Hello, Welcome to the world of Dockers" > /var/www/html/index.html

EXPOSE 80

CMD [“/usr/sbin/httpd”, “-D”, “FOREGROUND”]

Instructions in Dockerfile

The syntax of Dockerfile is simple and contains below instructions:

FROM:

FROM is the first instruction in any Dockerfile and it defines the base image to use. Base image can be any existing Docker image, typically it is operating system image or a specific application framework.
Usage:
FROM <image>
FROM <image>:<tag>

MAINTAINER:  [deprecated]

It is used to set the author of that image. You can do same task using LABEL instruction.
Usage:
MAINTAINER <name>

RUN:

RUN is used to run or execute commands in the container. Usage of RUN is RUN <command> , command is run in a shell, which is by default /bin/sh –c
Usage:
RUN <command> (shell form, the command is run in a shell, which by default is /bin/sh –c)

ADD:

ADD is used to copy the files, directories, remote file URLs from current directory into the container. Eg ADD <src><dest>.
<src> file can also be tar archive, the same will be unpacked for you as a directory into the docker image.
If <dest> path do not exist, it will be created for you.
Usage:
ADD <src><dest>

COPY:

It is similar to ADD, but it do not support the compression and URL file functionality. It is used to copy the files or directories from <src> and adds them to the destination path.
Usage:
COPY <source>… <destination>

CMD:

When container starts up, these commands will be executed/run. It is used to provide defaults for an executing container. The defaults can be executables or in case executable is omitted/excluded then you must specify an ENTRYPOINT instruction as well. In case there are more than one CMD in the dockerfile, then only the last CMD will take effect.
In case a user specify any arguments to docker run, then they will override the defaults mentioned in CMD.
Usage :
CMD [“executable”,”param1″,”param2″]  (exec form)
CMD [“param1″,”param2”] (default parameters to ENTRYPOINT)

LABEL:

It is used to add metadata to an image. A label is a key-value pair. An image can have more than one label. You can view image labels using docker inspect command.
Eg of Label:
LABEL version=”1.0″

EXPOSE:

It is used to inform Docker that container listens on the specified network port at the runtime. You can specify the protocol as well (TCP or UDP), by default  TCP is the protocol if nothing is specified.
Using EXPOSE,  the ports are exposed and can be used to publish and map one or more ports using –p option with docker run.
Regardless, of the EXPOSE instruction, the settings can be override at runtime by using the –p flag.
For eg.
docker run –p 80:80/tcp –p 5050:5050 ….
Usage:
 EXPOSE <port> [<port>/<protocol>…]

ENV:

The ENV instruction is used  to set the environment variable <key> to the value <value>
First format given in usage below will set single variable to value, while the second format can be used to set multiple variables at one time. You can view all the set environment variables using docker inspect command and change them using dockerrun –env<key>=<value>
Usage:
ENV <key><value>
ENV <key>=<value> …

ENTRYPOINT:

ENTRYPOINT allows you to configure a container that will run as an executable.

What’s the difference between CMD and ENTRYPOINT

Docker has default entrypoint (/bin/sh -c) but does not have a command. For example, running below <docker run image>, here the default Entrypoint will be /bin/sh -c and CMD will be bash. So that means, CMD is run via the ENTRYPOINT or CMD will be the parameter of the entrypoint.
Docker run –i –t ubuntu bash
Entrypoint : /bin/sh –c
Cmd : bash
Another example, suppose you want to use ENTRYPOINT as /bin/cat. So, when docker run image /etc/passwd command will run /etc/passwd is command and it is passed to the ENTRYPOINT /bin/cat and the execution is /bin/vat /etc/passwdd
Final Conclusion is ENTRYPOINT specifies a command that will always be executed when container starts.
CMD specifies arguments that will be fed to the ENTRYPOINT
Usage:
ENTRYPOINT [“executable”, “param1”, “param2”] (exec form, preferred)
ENTRYPOINT command param1 param2 (shell form)

VOLUME:

Volume defines a path or creates a mount point in the container that Docker exposes to the host system and it can be mapped using the -v option.
The docker run command initializes the specified volume along with the existing data in the volume within the base image.
Usage:
VOLUME [“/path”]
VOLUME  /path1 /path2 ..

USER:

USER instruction sets the username or UID to use while running the image. Also, GID or user group can also be specified with USER instructions.
Usage:
USER <user>[:<group>]
USER <UID>[:<GID>]

WORKDIR:

The WORKDIR instruction is used to set the working directory for any ADD, COPY, CMD, RUN or ENTRYPOINT instruction that follows it. It can be used multiple times in a Dockerfile.
Usage:
WORKDIR </path>

ARG:

ARG instruction is used to define a variable that can be passed at build time to the builder docker build using the –build-arg <variable>=<value>
A dockerfile can contain multiple ARG instructions. Environment variable defined using ENV instruction always override the ARG instruction.
It is not recommended to pass user credentials, github keys as build time variables as the same will be visible in docker history command.
Usage:
ARG <name>[=<default value>]

SHELL:

SHELL instruction is particulary useful for Windows and it allows to override the default shell (/bin/sh -c) for Linux and (“cmd” “/S”, “/C” ).
SHELL instruction also allows to use alternate shells like zsh, tsh, powershell etc.
Usage:
SHELL [“<executable>”, “<param1>”, “<param2>”]
Please comment down your thoughts on Dockerfiles and let us know if you have any query.

Read More...