25 Top Command Examples to Monitor Linux Server Performance

The Top utility tool is a handy tool that gives Linux users a peek at the performance statistics on their systems. You can use it to monitor resource metrics such as memory usage, CPU, load average, uptime and processes that are running on the system.

Top utility tool gives the user an overview of the system’s crucial performance statistics. The image below is a screenshot of the terminal showing the system’s statistics such as users logged in, tasks, uptime, CPU utilization, memory utilization and swap usage.


Every column above represents different information as the horizontal lines indicate a summary of the different areas running in the system. Let us analyze some of the columns for better understanding.

PID –  This stands for Process ID. Every running process on the Linux systems bears a PID

USER – This is the user running the process or use that the process is running under.

PR – Indicates process priority from the Linux Kernel

NI –  represents the nice value that matches the user space. The value ranges from -20 as the highest figure, 0 the default, and +19 as the lowest. There is a relationship between nice value and priority which is PR = 20 + NI

VIRT – represents the amount of virtual memory the process is using. It also describes the virtual size of a process.

RES – Defines the resident memory capacity.

SHR – This refers to shared memory that a process is assigned.  It also indicates how much of the VIRT is available for sharing in terms of libraries or memory.

  • S – Represents the status of a particular process that has the following values:
  • D – A process waiting for something to happen
  • R – Ready to run the process
  • S – Process sleep state waiting for a trigger
  • T – Indicates a traced or stopped process
  • Z – Indicates a dead process (Zombie process) or one that has completed execution

%CPU – time the task has been using since the last update. On machines with more than CPU, the percentage can be more than 100%

%MEM – a percentage of the available physical memory a process is using

TIME+ – Represents the total time a task is utilizing since it was started

COMMAND – Represents the actual process or command currently running

Other output on the command line following the top command may not be visible on the first page. They include:

  • Uptime and load average
  • CPU states
  • Tasks
  • Memory usage

1) Using Top Help Menu

The interactive nature of the help menu gives options on the number of commands administrators use. To get help using the top utility, simply type h or the question mark symbol ?


2) Manual Display Refresh

By default, the top command displays information on a 3 seconds interval. To get the manual refresh mode use the ENTER or SPACE keys.

3) Changing Display Mode

Instead of using a single-window to analyze your system, you can set the output to display four windows each with a different field or group using the names:

  • Mem : sort by %MEM
  • Def : Sort by %CPU
  • Job : sort by PID
  • Usr : Sort by User field

The …

Read More

How to Create and Add EBS Volume in AWS Instance

In this topic, we shed light on how you can add or attach an EBS (Elastic Block Storage) volume on an AWS instance. An extra  EBS volume supplements storage space for your instance. Once attached to the AWS instance, the EBS volume becomes a block device that is later formatted and mounted to make it available for use. Once available for use, the block device becomes accessible just like any other volume and thereby supplement storage space for your AWS instance. Let’s see how this can be achieved.


Step 1: Confirm the availability zone of your AWS instance

To start off, log in to your AWS console and confirm the availability zone of your EC2 instance. For this exercise to succeed, The EBS volume, as well as the AWS instance, ought to be in the same  availability zone

Our AWS instance in this guide sits at the us-east-2c availability zone. Therefore, we must create an EBS volume in the same region


Step 2: Creating an EBS volume

Before creating a new volume, let’s have a peek at the block devices available in our instance. Run the command :

# lsblk


From the above output, we can clearly see that there’s only one block device xvda, with a single partition xvda1. To get more detailed output, run the fdisk -l command:

# fdisk -l


Now let’s add a new volume. On the left section of your AWS dashboard, locate and click on the  ‘Volumes’ option under the Elastic Block Store section as shown.


A pre-existing volume will be displayed on the next page. This volume was created during the creation of your AWS EC2 instance.

To add another volume, click on the ‘Create Volume’ button

Click-Create- volume-aws

Fill in the details of the volume in the next window.

NOTE: Ensure the availability zone of the volume you are creating matches that of your AWS instance. The availability zone, in our case ,  is  us-east-2c.


After filling out all the essential details, click the ‘Create volume’ button.


The new volume will be created and displayed as shown


The new volume’s state is indicated as ‘available’ and not ‘in use’ like the other volume. This is because It’s not yet associated with the AWS instance.

For the volume to be part of the instance, click on the ‘Actions’ button and click on ‘attach volume


In the pop-up dialogue fill in the details accordingly and click on ‘Attach


Back to Volumes. If you take a closer look at the new volume status, you will notice that is has changed from ‘Available’ to ‘in-use’. This means that the volume has been integrated and is now a part of the ec2 instance.


To confirm the presence of the block volume, run the lsblk command


This can also be confirmed using the fdisk -l command


Step 3: Mounting the newly added EBS volume

Up until this point, we have managed to successfully create and add the EBS volume to an instance. However, we cannot access or save any data on the volume. In fact, the volume is empty and you can confirm this using the command:

# file -x /dev/xvdf


The …

Read More

How to Install Docker CE on CentOS 8 / RHEL 8

Docker is a daemon-based container engine which allows us to deploy applications inside containers. With the release of RHEL 8 and CentOS 8, docker package has been removed from their default package repositories, docker has been replaced with podman and buildah.


If are comfortable with docker and deploy most the applications inside the docker containers and does not want to switch to podman then this tutorial will guide you on how to install and use community version of docker on CentOS 8 and RHEL 8 system.

Docker is available in two versions,

  • Docker CE (Community Edition)
  • Enterprise Edition (EE)

In this guide we will learn how to install Docker CE (Community Edition) on CentOS 8 or RHEL 8 Server.

System Requirements for Docker CE

  • Minimal CentOS 8 / RHEL 8
  • Sudo or root privileges
  • Internet Connection

Installation Steps of Docker CE on CentOS 8/RHEL 8 Server

Step:1) Enable Docker CE Repository

As we said above, docker packages are not available anymore on CentOS 8 or RHEL 8 package repositories, run following dnf command to enable Docker CE package repository.

[[email protected] ~]# dnf config-manager --add-repo=

Step:2) Install Docker CE using dnf command

Once the docker ce repo has been configured successfully then run following command to verify which version of docker is available for installation

[[email protected] ~]# dnf list docker-ce
Available Packages
docker-ce.x86_64              3:19.03.5-3.el7                                           docker-ce-stable
[[email protected] ~]#

Now, use beneath dnf command to install latest version of docker,

[[email protected] ~]# dnf install docker-ce --nobest -y

After the installation of docker, start and enable its service using the following systemctl commands

[[email protected] ~]# systemctl start docker
[[email protected] ~]# systemctl enable docker

Run the following command to verify installed docker version

[[email protected] ~]# docker --version
Docker version 18.06.3-ce, build d7080c1
[[email protected] ~]#

Step:3) Verify and test Docker CE Engine

To verify whether docker ce engine has been setup correctly or not, try to spin up a “hello-world” container using below docker command,

[[email protected] ~]# docker run hello-world

Output of above command


As we can see the informational message in above output which confirms docker engine is setup correctly on CentOS 8 / RHEL 8 Server. Let’s move to docker compose installation.

Step:4) Install Docker Compose

As we know that docker compose is used to link multiple containers using a single command. In other words, Docker Compose is useful where we need to launch multiple containers and these containers depends on each other. Examples like launching LAMP/ LEMP applications (WordPress & Joomla etc) insider containers.

Run the following commands to install docker compose on CentOS 8 / RHEL 8,

[[email protected] ~]# dnf install curl -y
[[email protected] ~]# curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Note: Replace the “1.25.0” with docker compose version that you want to install but at this point of time this is the latest and stable version of docker compose.

Set the executable permission to docker-compose binary

[[email protected] ~]# chmod +x /usr/local/bin/docker-compose

Verify the docker compose version by running the following command.

[[email protected] ~]# docker-compose --version
docker-compose version 1.25.0, build 0a186604
[[email protected] ~]#

That’s all from this tutorial, I hope these steps help you to setup docker and docker compose on CentOS 8 and RHEL 8 server.

Read Also: How to Use docker-compose to launch containers

from Linuxtechi…

Read More

How to Manage Remote Windows Host using Ansible

Ansible is increasingly becoming the go-to platform for application deployment, and software provisioning among developers owing to its ease of use and flexibility. Furthermore, it is easy to set up and no agent s required to be installed on remote nodes, instead, Ansible uses password less SSH authentication to manage remote Unix/Linux hosts. In this topic, however, we are going to see how you can manage Windows Hosts using Ansible.


Lab setup

We shall use the setup below to accomplish our objective

  • Ansible Control node              CentOS 8                      IP:
  • Windows 10 node                    Windows 10                 IP:

Part 1: Installing Ansible on the Control node (CentOS 8)

Before anything else, we need to get Ansible installed on the Control node which is the CentOS 8 system.

Step 1:  Verify that Python3 is installed on Ansible control node

Firstly, we need to confirm if Python3 is installed. CentOS 8 ships with Python3 but if it’s missing for any reason, install using the command:

# sudo dnf install python3

Next, make Python3 the default Python version by running:

# sudo alternatives --set python /usr/bin/python3

To verify if python3 is installed, run the command:

# python --version


Step 2: Install a virtual environment for running Ansible

For this exercise, an isolated environment for running and testing Ansible is preferred. This will keep at bay issues such as dependency problems and package conflicts. The isolated environment we are going to create is called a virtual environment.

Firstly, let’s begin with the installation of the virtual environment on CentOS 8.

# sudo dnf install python3-virtualenv


After the installation of the virtual environment, create a virtual workspace by running:

# virtualenv env


# source env/bin/activate


Great! Observer that the prompt has now changed to (env).

Step 3: Install Ansible

After the creation of the virtual environment, proceed and install Ansible automation tool using pip as shown:

# pip install ansible


You can later confirm the installation of Ansible using the command:

# ansible --version


To test Ansible and see if it’s working on our Ansible Control server run:

# ansible localhost -m ping


Great! Next, we need to define the Windows host system on a host file on the Ansible control node. Therefore, open the default hosts file

# vim /etc/ansible/hosts

Define the Windows hosts as shown below.


Note: The username and password point to the user on the Windows host system.

Next, save and exit the configuration file.

Step 4: Install Pywinrm

Unlike in Unix systems where Ansible uses SSH to communicate with remote hosts, with Windows it’s a different story altogether. To communicate with Windows hosts, you need to install Winrm.

To install winrm, once again, use pip toll as shown:

# pip install pywinrm


Part 2: Configuring Windows Host

In this section, we are going to configure our Windows 10 remote host system to connect with the Ansible Control node. We are going to install the WinRM listener- short for Windows Remote – which will allow the connection between the Windows host system and the Ansible server.

But before we do so, your Windows host system needs to fulfill a few requirements for the installation to succeed:

  • Your Windows host system should be Windows 7 or later. For Servers, ensure that you are
Read More

How to Install Ansible (Automation Tool) on CentOS 8/RHEL 8

Ansible is an awesome automation tool for Linux sysadmins. It is an open source configuration tool which allows sysadmins to manage hundreds of servers from one centralize node i.e Ansible Server. Ansible is the preferred configuration tool when it is compared with similar tools like Puppet, Chef and Salt because it doesn’t need any agent and it works on SSH and python.


In this tutorial we will learn how to install and use Ansible on CentOS 8 and RHEL 8 system

Ansible Lab Details:

  • Minimal CentOS 8 / RHEL 8 Server ( with Internet Connectivity
  • Two Ansible Nodes – Ubuntu 18.04 LTS ( & CentOS 7 (

Ansible Installation steps on CentOS 8 

Ansible package is not available in default CentOS 8 package repository. so we need to enable EPEL Repository by executing the following command,

[[email protected] ~]$ sudo dnf install -y

Once the epel repository is enabled, execute the following dnf command to install Ansible

[[email protected] ~]$ sudo dnf install ansible

Output of above command :


Once the ansible is installed successfully, verify its version by running the following command

[[email protected] ~]$ sudo ansible --version


Above output confirms that Installation is completed successfully on CentOS 8.

Let’s move to RHEL 8 system

Ansible Installation steps on RHEL 8

If you have a valid RHEL 8 subscription then use following subscription-manager command to enable Ansible Repo,

[[email protected] ~]$ sudo subscription-manager repos --enable ansible-2.8-for-rhel-8-x86_64-rpms

Once the repo is enabled then execute the following dnf command to install Ansible,

[[email protected] ~]$ sudo dnf install ansible -y

Once the ansible and its dependent packages are installed then verify ansible version by executing the following command,

[[email protected] ~]$ sudo ansible --version

Alternate Way to Install Ansible via pip3 on CentOS 8 / RHEL 8

If you wish to install Ansible using pip (python’s package manager) then first install pyhton3 and python3-pip packages using following command,

[[email protected] ~]$ sudo dnf install python3 python3-pip -y

After pyhthon3 installation, verify its version by running

[[email protected] ~]$ python3 -V
Python 3.6.8
[[email protected] ~]$

Now run below pip3 command to install Ansible,

[[email protected] ~]$ pip3 install ansible --user



Above output confirms that Ansible has been installed successfully using pip3. Let’s see how we can use Ansible

How to Use Ansible Automation Tool?

When we install Ansible using yum or dnf command then its configuration file, inventory file and roles directory created automatically under /etc/ansible folder.

So, let’s add a group with name “labservers” and under this group add ubuntu 18.04 and CentOS 7 System’s ip address in /etc/ansible/hosts file

[[email protected] ~]$ sudo vi /etc/ansible/hosts

Save & exit file.

Once the inventory file (/etc/ansible/hosts) is updated then exchange your user’s ssh public keys with remote systems which are part of “labservers” group.

Let’s first generate your local user’s public and private key using ssh-keygen command,

[[email protected] ~]$ ssh-keygen

Now exchange public key between the ansible server and its clients using the following command,

[[email protected] ~]$ ssh-copy-id [email protected]
[[email protected] ~]$ ssh-copy-id [email protected]

Now let’s try couple of Ansible commands, first verify the connectivity from Ansible server to its clients using ping module,

[[email protected] ~]$ ansible -m ping "labservers"

Note: If we don’t specify the inventory file in above …

Read More

How to Use TimeShift to Backup and Restore Ubuntu Linux

Have you ever wondered how you can backup and restore your Ubuntu or Debian system ? Timeshift is a free and opensource tool that allows you to create incremental snapshots of your filesystem. You can create a snapshot using either RSYNC or BTRFS.


With that. let’s delve in and install Timeshift. For this tutorial, we shall install on Ubuntu 18.04 LTS system.

Installing TimeShift on Ubuntu / Debian Linux

TimeShift is not hosted officially on Ubuntu and Debian repositories. With that in mind, we are going to run the command below to add the PPA:

# add-apt-repository -y ppa:teejee2008/ppa


Next, update the system packages with the command:

# apt update

After a successful system update, install timeshift by running following apt command :

# apt install timeshift


Preparing a backup storage device

Best practice demands that we save the system snapshot on a separate storage volume, aside from the system’s hard drive. For this guide, we are using a 16 GB flash drive as the secondary drive on which we are going to save the snapshot.

# lsblk | grep sdb


For the flash drive to be used as a backup location for the snapshot, we need to create a partition table on the device. Run the following commands:

# parted /dev/sdb  mklabel gpt
# parted /dev/sdb  mkpart primary 0% 100%
# mkfs.ext4  /dev/sdb1


After creating a partition table on the USB flash drive, we are all set to begin creating filesystem’s snapshots!

Using Timeshift to create snapshots

To launch Timeshift, use the application menu to search for the  Timeshift application.


Click on the Timeshift icon and the system will prompt you for the Administrator’s password. Provide the password and click on Authenticate


Next, select your preferred snapshot type.


Click ‘Next’.  Select the destination drive for the snapshot. In this case, my location is the external USB drive labeled as /dev/sdb

Select-snapshot location

Next, define the snapshot levels. Levels refer to the intervals during which the snapshots are created.  You can choose to have either monthly, weekly, daily, or hourly snapshot levels.


Click ‘Finish’

On the next Window, click on the ‘Create’ button to begin creating the snapshot. Thereafter, the system will begin creating the snapshot.


Finally, your snapshot will be displayed as shown


Restoring Ubuntu / Debian from a snapshot

Having created a system snapshot, let’s now see how you can restore your system from the same snapshot. On the same Timeshift window, click on the snapshot and click on the ‘Restore’ button as shown.


Next, you will be prompted to select the target device.  leave the default selection and hit ‘Next’.


A dry run will be performed by Timeshift before the restore process commences.


In the next window, hit the ‘Next’  button to confirm actions displayed.


You’ll get a warning and a disclaimer as shown. Click ‘Next’ to initialize the restoration process.

Thereafter, the restore process will commence and finally, the system will thereafter reboot into an earlier version as defined by the snapshot.



As you have seen it quite easy to use TimeShift to restore your system from a snapshot. It comes in handy when backing up system files and allows you to recover in …

Read More

How to Install VirtualBox 6.0 on CentOS 8 / RHEL 8

VirtualBox is a free and open source virtualization tools which allows techies to run multiple virtual machines of different flavor at the same time. It is generally used at desktop level (Linux and Windows), it becomes very handy when someone try to explore the features of new Linux distribution or want to install software like OpenStack, Ansible and Puppet in one VM, so in such scenarios one can launch a VM using VirtualBox.

VirtualBox is categorized as type 2 hypervisor which means it requires an existing operating system, on top of which VirtualBox software will be installed. VirtualBox provides features to create our own custom host only network and NAT network. In this article we will demonstrate how to install latest version of VirtualBox 6.0 on CentOS 8 and RHEL 8 System and will also demonstrate on how to install VirtualBox Extensions.

Installation steps of VirtualBox 6.0 on CentOS 8 / RHEL 8

Step:1) Enable VirtualBox and EPEL Repository

Login to your CentOS 8 or RHEL 8 system and open terminal and execute the following commands to enable VirtualBox and EPEL package repository.

[[email protected] ~]# dnf config-manager --add-repo=
Adding repo from:
[[email protected] ~]#

Use below rpm command to import Oracle VirtualBox Public Key

[[email protected] ~]# rpm --import

Enable EPEL repo using following dnf command,

[[email protected] ~]# dnf install -y

Step:2) Install VirtualBox Build tools and dependencies

Run the following command to install all VirtualBox build tools and dependencies,

[[email protected] ~]# dnf install binutils kernel-devel kernel-headers libgomp make patch gcc glibc-headers glibc-devel dkms -y

Once above decencies and build tools are installed successfully proceed with VirtualBox installation using dnf command,

Step:3) Install VirtualBox 6.0 on CentOS 8 / RHEL 8

If wish to list available versions of VirtualBox then execute the following dnf command,

[[email protected] ~]# dnf search virtualbox
Last metadata expiration check: 0:14:36 ago on Sun 17 Nov 2019 04:13:16 AM GMT.
=============== Summary & Name Matched: virtualbox =====================
VirtualBox-5.2.x86_64 : Oracle VM VirtualBox
VirtualBox-6.0.x86_64 : Oracle VM VirtualBox
[[email protected] ~]#

Let’s install latest version of VirtualBox 6.0 using following dnf command,

[[email protected] ~]# dnf install VirtualBox-6.0 -y

If any local user want to attach usb device to VirtualBox VMs then he/she should be part “vboxuser ” group, use the beneath usermod command to add local user to “vboxuser” group.

[[email protected] ~]# usermod -aG vboxusers pkumar

Step:4) Access VirtualBox on CentOS 8 / RHEL 8

There are two ways to access VirtualBox, from the command line type “virtualbox” command on then hit enter

[[email protected] ~]# virtualbox

From Desktop environment, Search “VirtualBox” from Search Dash.


Click on VirtualBox icon,


This confirms that VirtualBox 6.0 has been installed successfully, let’s install its extension pack.

Step:5) Install VirtualBox 6.0 Extension Pack

As the name suggests, VirtualBox extension pack is used to extend the functionality of VirtualBox. It adds the following features:

  • USB 2.0 & USB 3.0 support
  • Virtual RDP (VRDP)
  • Disk Image Encryption
  • Intel PXE Boot
  • Host WebCam

Use below wget command to download extension pack under download folder,

[[email protected] ~]$ cd Downloads/
[[email protected] Downloads]$ wget

Once it is downloaded, access VirtualBox and navigate File –>Preferences –> Extension then click on + icon to add downloaded extension pack,


Click on “Install” to start the installation of …

Read More

How to install and Configure Postfix Mail Server on CentOS 8

Postfix is a free and opensource MTA (Mail Transfer Agent) used for routing or delivering emails on a Linux system. In this guide, you will learn how to install and configure Postfix on CentOS 8.


Lab set up:

  • OS :                  CentOS 8 server
  • IP Address :
  • Hostname: (Ensure the domain name is pointed to the server’s IP)

Step 1) Update the system

The first step is to ensure that the system packages are up to date. To do so, update the system as follows:

# dnf update

Before proceeding further, also ensure that no other MTAs such as Sendmail are existing as this will cause conflict with Postfix configuration. To remove Sendmail, for example, run the command:

# dnf remove sendmail

Step 2)  Set Hostname and update /etc/hosts file

Use below hostnamectl command to set the hostname on your system,

# hostnamectl set-hostname
# exec bash

Additionally, you need to add the system’s hostname and IP entries in the /etc/hosts file

# vim /etc/hosts

Save and exit the file.

Step 3) Install Postfix Mail Server

After verifying that no other MTA is running on the system install Postfix by executing the command:

# dnf install postfix


Step 4) Start and enable Postfix Service

Upon successful installation of Postfix, start and enable Postfix service by running:

# systemctl start postfix
# systemctl enable postfix

To check Postfix status, run the following systemctl command

# systemctl status postfix


Great, we have verified that Postfix is up and running. Next, we are going to configure Postfix to send emails locally to our server.

Step 5) Install mailx email client

Before configuring the Postfix server, we need to install mailx feature, To install mailx, run the command:

# dnf install mailx


Step 6)  Configure Postfix Mail Server

Postfix’s configuration file is located in /etc/postfix/ We need to make a few changes in the configuration file, so open it using your favorite text editor.

# vi /etc/postfix/

Make changes to the following lines:

myhostname =
mydomain =
myorigin = $mydomain
## Uncomment and Set inet_interfaces to all ##
inet_interfaces = all
## Change to all ##
inet_protocols = all
## Comment ##
#mydestination = $myhostname, localhost.$mydomain, localhost
##- Uncomment ##
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
## Uncomment and add IP range ##
mynetworks =,
## Uncomment ##
home_mailbox = Maildir/

Once done, save and exit the configuration file. Restart postfix  service for the changes to take effect

# systemctl restart postfix

Step 7) Testing  Postfix Mail Server

Test whether our configuration is working, first, create a test user

# useradd postfixuser
# passwd postfixuser

Next, run the command below to send email from pkumar local user to another user ‘postfixuser

# telnet localhost smtp
# telnet localhost 25

If telnet service is not installed, you can install it using the command:

# dnf install telnet -y

When you run the command as earlier indicated, you should get the output as shown

[[email protected] ~]# telnet localhost 25
Connected to localhost.
Escape character is '^]'.
220 ESMTP Postfix

Above confirm that connectivity to postfix mail server is working fine. Next, type the command:

# ehlo localhost

Output will be something …

Read More

How to Create Affinity and Anti-Affinity Policy in OpenStack

In the organizations where the OpenStack is used aggressively, so in such organizations application and database teams can come up with requirement that their application and database instances are required to launch either on same compute nodes (hypervisor) or different compute nodes.


So, this requirement in OpenStack is fulfilled via server groups with affinity and anti-affinity policies. Server Group is used control affinity and anti-affinity rules for scheduling openstack instances.

When we try to provision virtual machines with affinity server group then all virtual machines will be launched on same compute node. When VMs are provisioned with ant-affinity server group then all VMs will be launched in different compute nodes. In this article we will demonstrate how to create OpenStack server groups with Affinity and Anti-Affinity rules.

Let’s first verify whether your OpenStack setup support Affinity and Anti-Affinity Policies or not, execute the following grep command from your controller nodes,

# grep -i "scheduler_default_filters" /etc/nova/nova.conf

Output should be something like below,


As we can see Affinity and Ant-Affinity filters are enabled but in case if these are not enabled then add these filters in /etc/nova/nova.conf  file of controller nodes under “scheduler_default_filters” parameters.

# vi /etc/nova/nova.conf

Save and exit the file

To make above changes into the effect, restart the following services

# systemctl restart openstack-nova-scheduler
# systemctl restart openstack-nova-conductor

Now let’s create OpenStack Server Groups with Affinity and Anti-Affinity Policies

Server Group with Affinity Policy

To create a server group with name “app” for affinity policy, execute the following openstack command from controller node,


# openstack server group create –policy affinity <Server-Group-Name>


# nova server-group-create <Server-Group-Name> affinity

Note: Before start executing openstack command, please make sure you source project credential file, in my case project credential file is “openrc


# source openrc
# openstack server group create --policy affinity app

Server Group with Anti-Affinity Policy

To create a server group with anti-affinity policy, execute the following openstack command from controller node, I am assuming server group name is “database”


# openstack server group create –policy anti-affinity <Server-Group-Name>


# nova server-group-create <Server-Group-Name> anti-affinity


# source openrc
# openstack server group create --policy anti-affinity database

List Server Group’s ID and Policies

Execute either nova command or Openstack command to get server group’s id and their policies

# nova server-group-list | grep -Ei "Policies|database"
# openstack server group list --long | grep -Ei "Policies|app|database"

Output would be something like below,


Launch Virtual Machines (VMs) with Affinity Policy

Let’s assume we want to launch 4 vms with affinity policy, run the following “openstack server create” command


# openstack server create –image <img-name> –flavor <id-or-flavor-name> –security-group <security-group-name> –nic net-id=<network-id> –hint group=<Server-Group-ID> –max <number-of-vms>  <VM-Name>


# openstack server create --image Cirros --flavor m1.small --security-group default --nic net-id=37b9ab9a-f198-4db1-a5d6-5789b05bfb4c --hint group="a9847c7f-b7c2-4751-9c9a-03b117e704ff" --max 4 affinity-test

Output of above command,


Let’s verify whether VMs are launched on same compute node or not, run following command

# openstack server list --long -c Name -c Status -c Host -c "Power State" | grep -i affinity-test


This confirms that our affinity policy is working fine as all the VMs are launched on same compute node.

Now let’s test anti-affinity policy


Read More

How to Schedule and Automate tasks in Linux using Cron Jobs

Sometimes, you may have tasks that need to be performed on a regular basis or at certain predefined intervals. Such tasks include backing up databases, updating the system, performing periodic reboots and so on. Such tasks are referred to as cron jobs. Cron jobs are used for automation of tasks that come in handy and help in simplifying the execution of repetitive and sometimes mundane tasks. Cron is a daemon that allows you to schedule these jobs which are then carried out at specified intervals. In this tutorial, you will learn how to schedule jobs using cron jobs.

Schedule -tasks-in-Linux-using cron

The Crontab file

A crontab file, also known as a cron table, is a simple text file that contains rules or commands that specify the time interval of execution of a task. There are two categories of crontab files:

1)  System-wide crontab file

These are usually used by Linux services & critical applications requiring root privileges. The system crontab file is located at /etc/crontab and can only be accessed and edited by the root user. It’s usually used for the configuration of system-wide daemons. The crontab file looks as shown:


2) User-created crontab files

Linux users can also create their own cron jobs with the help of the crontab command. The cron jobs created will run as the user who created them.

All cron jobs are stored in /var/spool/cron (For RHEL and CentOS distros) and /var/spool/cron/crontabs (For Debian and Ubuntu distros), the cron jobs are listed using the username of the user that created the cron job

The cron daemon runs silently in the background checking the /etc/crontab file and /var/spool/cron and /etc/cron.d*/ directories

The crontab command is used for editing cron files. Let us take a look at the anatomy of a crontab file.

The anatomy of a crontab file

Before we go further, it’s important that we first explore how a crontab file looks like. The basic syntax for a crontab file comprises 5 columns represented by asterisks followed by the command to be carried out.

*    *    *    *    *    command

This format can also be represented as shown below:

m h d moy dow command


m h d moy dow /path/to/script

Let’s expound on each entry

  • m: This represents minutes. It’s specified from 0 to 59
  • h: This denoted the hour specified from 0 to 23
  • d:  This represents the day of the month. Specified between 1 to 31`
  • moy: This is the month of the year. It’s specified between 1 to 12
  • doy:  This is the day of the week. It’s specified between 0 and 6 where 0 = Sunday
  • Command: This is the command to be executed e.g backup command, reboot, & copy

Managing cron jobs

Having looked at the architecture of a crontab file, let’s see how you can create, edit and delete cron jobs

Creating cron jobs

To create or edit a cron job as the root user, run the command

# crontab -e

To create a cron job or schedule a task as another user, use the syntax

# crontab -u username -e

For instance, to run a cron job as user Pradeep, issue the command:

# crontab -u Pradeep -e

If there is …

Read More