Friday, December 30, 2016

Linux File Systems: Ext2 vs Ext3 vs Ext4 vs XFS

ext2, ext3, ext4 and xfs are all filesystems created for Linux. This article explains the following:
  • High level difference between these filesystems.
  • How to create these filesystems.
  • How to convert from one filesystem type to another.
Ext2
  • Ext2 stands for second extended file system.
  • It was introduced in 1993. Developed by Rémy Card.
  • This was developed to overcome the limitation of the original ext file system.
  • Ext2 does not have journaling feature.
  • On flash drives, usb drives, ext2 is recommended, as it doesn’t need to do the over head of journaling.
  • Maximum individual file size can be from 16 GB to 2 TB
  • Overall ext2 file system size can be from 2 TB to 32 TB

Ext3

  • Ext3 stands for third extended file system.
  • It was introduced in 2001. Developed by Stephen Tweedie.
  • Starting from Linux Kernel 2.4.15 ext3 was available.
  • The main benefit of ext3 is that it allows journaling.
  • Journaling has a dedicated area in the file system, where all the changes are tracked. When the system crashes, the possibility of file system corruption is less because of journaling.
  • Maximum individual file size can be from 16 GB to 2 TB
  • Overall ext3 file system size can be from 2 TB to 32 TB
  • There are three types of journaling available in ext3 file system.
    • Journal – Metadata and content are saved in the journal.
    • Ordered – Only metadata is saved in the journal. Metadata are journaled only after writing the content to disk. This is the default.
    • Writeback – Only metadata is saved in the journal. Metadata might be journaled either before or after the content is written to the disk.
  • You can convert a ext2 file system to ext3 file system directly (without backup/restore).

Ext4

  • Ext4 stands for fourth extended file system.
  • It was introduced in 2008.
  • Starting from Linux Kernel 2.6.19 ext4 was available.
  • Supports huge individual file size and overall file system size.
  • Maximum individual file size can be from 16 GB to 16 TB
  • Overall maximum ext4 file system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte). 1 PB = 1024 TB (terabyte).
  • Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)
  • You can also mount an existing ext3 fs as ext4 fs (without having to upgrade it).
  • Several other new features are introduced in ext4: multiblock allocation, delayed allocation, journal checksum. fast fsck, etc. All you need to know is that these new features have improved the performance and reliability of the filesystem when compared to ext3.
  • In ext4, you also have the option of turning the journaling feature “off”.

XFS File System
  • The XFS file system is an extension of the extent file system. 
  • The XFS is a high-performance 64-bit journaling file system. 
  • The support of the XFS was merged into Linux kernel in around 2002 and In 2009 Red Hat Enterprise Linux version 5.4 usage of the XFS file system. 
  • XFS supports maximum file system size of 8 exbibytes for the 64-bit file system. 
  • There is some comparison of XFS file system is XFS file system can’t be shrunk and poor performance with deletions of the large numbers of files. 
  • Now, the RHEL 7.0 uses XFS as the default filesystem.

Creating an ext2, or ext3, or ext4 filesystem

Once you’ve partitioned your hard disk using fdisk command, use mke2fs to create either ext2, ext3, or ext4 file system.


Create an ext2 file system:

mke2fs /dev/sda1



Create an ext3 file system:

mkfs.ext3 /dev/sda1

(or)

mke2fs –j /dev/sda1



Create an ext4 file system:

mkfs.ext4 /dev/sda1

 (or)

 mke2fs -t ext4 /dev/sda1


Converting ext2 to ext3

For example, if you are upgrading /dev/sda2 that is mounted as /home, from ext2 to ext3, do the following.

umount /dev/sda2

tune2fs -j /dev/sda2

mount /dev/sda2 /home

Note: You really don’t need to umount and mount it, as ext2 to ext3 
conversion can happen on a live file system. But, I feel better doing 
the conversion offline.

Converting ext3 to ext4

If you are upgrading /dev/sda2 that is mounted as /home, from ext3 to ext4, do the following.

umount /dev/sda2

tune2fs -O extents,uninit_bg,dir_index /dev/sda2

e2fsck -pf /dev/sda2

mount /dev/sda2 /home


Again, try all of the above commands only on a test system, where you can afford to lose all your data.

____________________________________________

What is a Journaling Filesystem?

A journaling filesystem keeps a journal or log of the changes that are being made to the filesystem during disk writing that can be used to rapidly reconstruct corruptions that may occur due to events such a system crash or power outage. The level of journaling performed by the file system can be configured to provide a number of levels of logging depending on your needs and performance requirements.

What are the Advantages of a Journaling Filesystem?

There are a number of advantages to using a journaling files system.

Both the size and volume of data stored on disk drives has grown exponentially over the years. The probelm with a non-journaled file system is that following a crash the fsck (filesystem consistency check) utility has to be run. fsck will scan the entire filesystem validating all entries and making sure that blocks are allocated and referenced correctly. If it finds a corrupt entry it will attempt to fix the problem. The issues here are two-fold. Firstly, the fsck utility will not always be able to repair damage and you will end up with data in the lost+found directory. This is data that was being used by an application but the system no longer knows where they were reference from. The other problem is the issue of time. It can take a very long time to complete the fsck process on a large file system leading to unacceptable down time.

A journaled file system records information in a log area on a disk (the journal and log do not need to be on the same device) during each write. This is a essentially an "intent to commit" data to the filesystem. The amount of information logged is configurable and ranges from not logging anything, to logging what is known as the "metadata" (i.e ownership, date stamp information etc), to logging the "metadata" and the data blocks that are to be written to the file. Once the log is updated the system then writes the actual data to the appropriate areas of the filesystem and marks an entry in the log to say the data is committed.

After a crash the filesystem can very quickly be brought back on-line using the journal log reducing what could take minutes using fsck to seconds with the added advantage that there is considerably less chance of data loss or corruption.


What is a Journal Checkpoint?

When a file is accessed on the filesystem, the last snapshot of that file is read from the disk into memory. The journal log is then consulted to see if any uncommitted changes have been made to the file since the data was last written to the file (essentially looking for an "intention to commit" in the log entry as described above). At particular points the filesystem will update file data on the disk from the uncommited log entries and trim those entries from the log. Committing operations from the log and synchronizing the log and its associated filesystem is called a checkpoint.

What are the disadvantages of a Journaled Filesystem?

Nothing in life is is free and ext3 and journaled filesystems are no exception to the rule. The biggest draw back of journaling is in the area of performance simply because more disk writes are required to store information in the log. In practice, however, unless you are running system where disk performance is absolutely critical the performance difference will be negligable.

____________________________________________________

Common Commands for ext3 and ext4 Compared to XFS
Taskext3/4XFS
Create a file systemmkfs.ext4 or mkfs.ext3mkfs.xfs
File system checke2fsckxfs_repair
Resizing a file systemresize2fsxfs_growfs
Save an image of a file systeme2imagexfs_metadump and xfs_mdrestore
Label or tune a file systemtune2fsxfs_admin
Backup a file systemdump and restorexfsdump and xfsrestore

Linux and Unix dd command

About dd

The dd command copies a file, converting the format of the data in the process, according to the operands specified.


Syntax of ‘dd’ command.

dd if=<source file name> of=<target file name> [Options]

dd [OPERAND]...
dd OPTION


Operands
bs=BYTES  : read and write BYTES bytes at a time (also see ibs=,obs=)

cbs=BYTES  : convert BYTES bytes at a time

conv=CONVS  : convert the file as per the comma separated symbol list. Each symbol may be one of                             the following, and represents a specific type of conversion:
                          ascii
                          from EBCDIC to ASCII

                          ebcdic
                         from ASCII to EBCDIC

                         ibm
                        from ASCII to alternate EBCDIC

                        block
                        pad newline-terminated records with spaces to cbs-size

                       unblock
                       replace trailing spaces in cbs-size records with newline

                      lcase
                      change upper case to lower case

                      nocreat
                     do not create the output file

                     excl
                    fail if the output file already exists

                   notrunc
                   do not truncate the output file

                  ucase
                  change lower case to upper case

                 swab
                 swap every pair of input bytes

                noerror
                continue after read errors

                sync
                pad every input block with NULs to ibs-size; when used with block or unblock, 
                pad with spaces rather than NULs

               fdatasync
              physically write output file data before finishing

              fsync
              likewise, but also write metadata.


count=BLOCKS  :  copy only BLOCKS input blocks

ibs=BYTES : read BYTES bytes at a time (default: 512)

if=FILE   : read from FILE instead of stdin

iflag=FLAGS  : read as per the comma separated symbol list. Each symbol may be 
                           one of the following:

                          append
                          append mode (makes sense only for output; conv=notrunc suggested)

                         direct
                         use direct I/O for data
                         directory
                         fail unless a directory

                        dsync
                        use synchronized I/O for data

                        sync
                       likewise, but also for metadata

                       fullblock
                       accumulate full blocks of input (iflag only)

                       nonblock
                      use non-blocking I/O

                       noatime
                      do not update access time

                      noctty
                     do not assign controlling terminal from file

                     nofollow
                     do not follow symlinks.


obs=BYTES  :  write BYTES bytes at a time (default: 512)
of=FILE  : write to FILE instead of stdout
oflag=FLAGS :  write as per the comma separated symbol list
seek=BLOCKS :  skip BLOCKS obs-sized blocks at start of output
skip=BLOCKS  : skip BLOCKS ibs-sized blocks at start of input
status=noxfer  : suppress transfer statistics

Options
--help       :   Display help and exit.
--version  :    Display version information and exit.

Numerical Suffixes

BLOCKS and BYTES may be followed by the following multiplicative suffixes:

c=1
w=2
b=512
kB=1000
K=1024
MB=1000*1000
M=1024*1024
xM=M
GB=1000*1000*1000
G=1024*1024*1024

and so on for T (terabytes), P (petabytes), E (exabytes), Z (zettabytes), and Y (yottabytes).

This tool can be used for:
• Backing up and restoring an entire hard drive or a partition.
• Copy regions of raw device files like backing up MBR (master boot record).
• Converting data formats like ASCII to EBCDIC.
• Converting lowercase to uppercase and vice versa.
• Creating files with fixed size.

dd examples

Caution: Use dd cautiously — improper usage or entering the wrong values could inadvertently wipe, destroy, or overwrite the data on your hard drive.

dd if=/dev/sr0 of=/home/hope/exampleCD.iso bs=2048 conv=noerror,sync


Create a ISO disc image from the CD in the computer.
dd if=/dev/sda of=~/disk1.img

Create an img file of the /dev/sda hard drive. To restore that image type: dd if=disk1.img of=/dev/sda
dd if=/dev/sda of=/dev/sdb


Copy the contents from the if= drive /dev/sda to the of= drive /dev/sdb.
Related commands

cp — Copy files and directories.
fdisk — A disk partioning utility. 

---------------------------------------------------------------------------------------
Example 1. Backup Entire Harddisk

To backup an entire copy of a hard disk to another hard disk connected to the same system, execute the dd command as shown below. In this dd command example, the UNIX device name of the source hard disk is /dev/hda, and device name of the target hard disk is /dev/hdb.

# dd if=/dev/sda of=/dev/sdb

  • “if” represents inputfile, and “of” represents output file. So the exact copy of /dev/sda will be available in /dev/sdb.
  • If there are any errors, the above command will fail. If you give the parameter “conv=noerror” then it will continue to copy if there are read errors.
  • Input file and output file should be mentioned very carefully, if you mention source device in the target and vice versa, you might loss all your data.
In the copy of hard drive to hard drive using dd command given below, sync option allows you to copy everything using synchronized I/O.

# dd if=/dev/sda of=/dev/sdb conv=noerror,sync

---------------------------------------------------------------------------------------
Example 2. Create an Image of a Hard Disk

Instead of taking a backup of the hard disk, you can create an image file of the hard disk and save it in other storage devices.There are many advantages to backing up your data to a disk image, one being the ease of use. This method is typically faster than other types of backups, enabling you to quickly restore data following an unexpected catastrophe.

# dd if=/dev/hda of=~/hdadisk.img

The above creates the image of a harddisk /dev/hda

---------------------------------------------------------------------------------------
Example 3. Restore using Hard Disk Image

To restore a hard disk with the image file of an another hard disk, use the following dd command example.
# dd if=hdadisk.img of=/dev/hdb
The image file hdadisk.img file, is the image of a /dev/hda, so the above command will restore the image of /dev/hda to /dev/hdb.
---------------------------------------------------------------------------------------
Example 4. Creating a Floppy Image
Using dd command, you can create a copy of the floppy image very quickly. In input file, give the floppy device location, and in the output file, give the name of your floppy image file as shown below.
# dd if=/dev/fd0 of=myfloppy.img
---------------------------------------------------------------------------------------
Example 5. Backup a Partition

You can use the device name of a partition in the input file, and in the output either you can specify your target path or image file as shown in the dd command example below.

# dd if=/dev/hda1 of=~/partition1.img
---------------------------------------------------------------------------------------
Example 6. CDROM Backup

dd command allows you to create an iso file from a source file. So we can insert the CD and enter dd command to create an iso file of a CD content.
# dd if=/dev/cdrom of=tgsservice.iso bs=2048

dd command reads one block of input and process it and writes it into an output file. You can specify the block size for input and output file. In the above dd command example, the parameter “bs” specifies the block size for the both the input and output file. So dd uses 2048bytes as a block size in the above command.
Note: If CD is auto mounted, before creating an iso image using dd command, its always good if you unmount the CD device to avoid any unnecessary access to the CD ROM.

Wednesday, December 28, 2016

how to set the ssh timeout in linux


vim /etc/ssh/sshd_config


ClientAliveInterval 600    ---------------------change the value
ClientAliveCountMax 3

That will give you an timeout of 30 minutes (600 sec x 3)

after that restast sshd service and try

Wednesday, December 14, 2016

IMP Definition for Interview

RSYNC COMMAND

rsync (remote sync) is used to transfer data between two servers. it is basically a remote synchronization tool which helps to copy or synced data from one machine to another machine. it is a Unix-Linux based tool.

BENEFITS OF RSYNC COMMAND:

Rsync is a very useful tool for system admins because every sysadmin should use this command at list once in a day. It has many benefits we will see some of them important points.

1. Rsync efficiently sync files to and from systems.
2. It is faster sync tool than any other syncing tools like SCP.
3. It has the feature of incremental data transfer means it will not sync data which is already available on another system.
4. Rsync has provided progress of data transfer which is also plus. you will know how much data is copied and how much is remaining.
5. when sending and receiving data rsync will use compression and decompression method. It comes with benefits of using less bandwidth.
6. Rsync will copy everything as it is which means sync links, owner, permission, groups.

SOME IMPORTANT OPTIONS OF RSYNC COMMAND:

-v, --verbose : Verbose or Providing detailed output for diagnostic purposes.
-a, --archive : archiving allow copying files with symlinks, permissions, owners, groups etc
-z, --compress : Compress data during file transfer
-h, --human-readable : output numbers in a human-readable format
-P, --progress : show progress during transfer
_____________________________________________________

WHAT IS FTP SERVER?

Ftp server stands for File transfer Protocol. Defination on ftp server explain everything in full form of ftp.
It is used for transferring files from one server to another via secure way.
Ftp is TCP based service and there is no UDP component for FTP.
FTP utilizes two port one is command port i.e. 21 and other is data port i.e. 20.

WHY WE NEED FTP SERVER?

FTP Server is basically using for data transfer. We need ftp to provide secure access on server codebase to developers or also for clients.
As i am working as linux admin lots of time client need ftp access to codebase directory on server to transfer some media files or to work on some code so that time ftp is very useful to provide access in secure way. Here secure way means we can use another port no. instead of default port no. which is easy to guess and also we can whitelist ftp port for Client office only or for specific public ip. This way ftp help to manage data transfer process very well.
____________________________________________________

NFS SERVER

NFS means Network File System which is using to share one system data or directory over the remote network on multiple systems and you will able to access shared directory on your local system as local files or directory.

WHY WE NEED NFS SERVER?
  • NFS allows local access to remote files.
  • with help of NFS, we can create centralized storage which will be accessible from multiple systems.
  • No need to refresh filesystem to get new files.
  • Not necessary that both the client and host machine has a same operating system
client : mount  -t  nfs  192.168.3.39:/sharenfsdir   /mnt/nfsshare
/etc/fstab ----add below entry in fstab
192.168.3.39:/sharenfsdir     /mnt/nfsshare      nfs    defaults   0  0


SOME IMPORTANT COMMANDS FOR NFS :
  1. showmount -e : it will shows you available shared directory on server.
  2. showmount -d : List all the sub directories.
  3. exportfs -a : it will help to reflect and listed the changes done under the /etc/exports
  4. exportfs -v : Display's list of share files and options on server.
  5. exportfs -r : Reflect the changes after modifying /etc/exports
_________________________________________________

REDIS CACHE

Redis Cache is an open source, advanced key-value store and a serious solution for building high-performance, scalable web applications.

Redis cache will handle the persistent data. Redis is more efficient caching application because it consumes comparatively fewer memory resources for metadata.

The good thing about the Redis cache, it will supports Master-slave replication which means whenever once of your Redis node goes down other will handle the request. It is providing stronger data structure.
Redis will supports multiple databases using same server instance. With that much of feature Redis will obviously first choice of any PHP developer to improve performance of website.

FEATURES OF REDIS :
  1. Redis cache handle persistent data
  2. Redis cache is more efficient because it consumes comparatively fewer memory resources for metadata.
  3. Redis supports master-slave replication.
  4. Redis has stronger data structures.
  5. Redis key-length has a maximum of 2GB.
  6. Redis support for multiple databases using same server instance.
______________________________________________________

AWS AMI [AMAZON MACHINE IMAGE]

In the full form, you will understand the use of AMI. It's basically a copy of your running EC2 Machine which we store on AWS as a backup of your machine.

You can transfer AMI with specific AWS accounts without making the AMI public. All you need are the AWS account IDs.

____________________________________________________

AWS CLOUD ELASITC COMPUTE CLOUD (EC2)

Aws Cloud provides very user-friendly console by which you can launch your own EC2 instance without any hard work.

Aws Cloud provides more than 20 instance types and you can use whichever is good for your project and according to your budget.
_______________________________________________________

INTRODUCTION MEMCACHED

You will get an idea about the working of Memcached with his name only.
Memcached is an open source high performance and free caching system or service.
It's helps to cache API calls, database data and pages in RAM to perform application faster.
This cached system works on TCP protocol which means you can able to install it on a separate server and use it on another server which leads to the big hash table to store your data.
One more important thing about Memcached is if your Memcached is running out of space then older data is overwritten or replaced by newer data. It will work as a non-persistent cache.
It will work or runs on default port i.e. 11211

You all know the open source applications are totally free cost. Memcached is also Open source so you do not need to pay anything to make your site perform better.

You can use Memcached to decrease the load on the database by caching database queries which are most frequently or more user visited.

ADVANTAGES:

1. It is open source cache system which means its freely available.
2. It will work as cross-platform.
3. It will also handle the sessions.
4. it is a distributed memory system.

DISADVANTAGES:

1. Data will not be persistent means data will be flush out if you restart the service.
2. It will be using only 1/4 of the size of your RAM memory, so if your size out of space then data is overwritten.

WHEN WE USE MEMCACHED?

We will use memcached to decrease the load on the database by caching database queries which are most frequently or more user visited.

RESTART SERVICE
/etc/init.d/memcached start|stop|restart

CHECK MEMCACHED IS RUNNING
netstat -tulnp | grep memcached
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 1391/memcached
______________________________________________________

VARNISH CACHE

Varnish cache is one of the best caching application which you can use to optimize PHP application. It is the latest and most used stable caching application. It will lead to your site to perform better and smooth.

Varnish cache is a web application accelerator also known as HTTP reverse proxy.

It is working on port 80 as a front web application. Varnish will improve your website speed 1000x faster and it's work well in good server architecture.

Varnish always run on 80 and 443 [if SSL is configured]port because on internet domains run through the HTTP or HTTPS. To configure varnish cache you need to understand the working of varnish vcl conf file.

Varnish cache will support multiple platforms like Linux, FreeBSD and various Solaris-descendants like Oracle Solaris, OmniOS, and SmartOS.

If you really want your site to perform better then varnish cache is the best option for your website. It has lots of benefits when it comes to providing performance for the website.

_________________________________________________________

LVM [ LOGICAL VOLUME MANAGER ]

LVM is a tool for logical volume management which is used to allocating disks and resizing logical volumes.

With the help of Logical Volume Manager, you will be able to increase and decrease the size of your disks or hard drives and also allocate it to one or more physical volumes.

WHY WE NEED LVM?

LVM is very useful in a various scenario where your hard disk is getting full, and you want to increase hard drive size without losing data, or also you can reduce as per the requirement.

COMMANDS USE IN LVM

$ pvcreate: - is used to create a physical volume on the harddrive.

$ pvdisplay :- is used to display created a physical volume on the harddisk.

$ pvremove :- is used to remove a physical volume from harddisk.

$ vgcreate :- is used to create volume group by adding created physical volume in a single group.

$ vgextend :- we can also extend the already created volume group with the help of vgextend command.

$ vgdisplay :- is used to display volume groups on harddrives.

$ vgremove :- we can also remove created volume groups from harddrives with the help of vgremove command.

$ lvcreate :- with the support of this command, we can create logical volume as per the user required a size from the Volume group.

$ lvdisplay :- is used to display created volumes.

$ lvreduce :- we can also reduce the size of already created logical volumes with the help of lvreduce command without losing data.

$ lvremove :- we can also remove created logical volumes if we don’t require.

$ lvextend :- is used to extend the size of the already created logical volume.

REDUCE VOLUME SIZE

if you want to reduce the size of Logical volume use below commands,

umount /dev/mynewvg/lvol1
e2fsck -f /dev/mynewvg/lvol1
resize2fs /dev/mynewvg/lvol1 600M
lvreduce -L -500M /dev/mynewvg/lvol1

EXTEND VOLUME GROUP

if you want to increase the Volume group, you need to add another physical volume in volume group use below command,

# vgextend /dev/mynewvg /dev/sda4
Extending logical volume lvol1 to 3.99 GiB
Logical volume mynewvg successfully resized
________________________________________________________

SWAP PARTITION:

Swap is extra space which is used when the physical memory (RAM) running out of space or full. When the system needs extra memory and the RAM is full that time inactive pages in RAM memory will move to the swap storage.
You can also call Swap as another small RAM which helps to boost performance while physical ram running out of space.

BENEFITS OF SWAP MEMORY:
  • Provide extra space when physical memory full
  • Move not-so-needed items from high-speed memory
  • Allow to hibernate which means without swap hibernation is not possible on Linux.
DISADVANTAGES:
  • Consume disk space on server
  • Not necessarily improve performance
___________________________________________________________

MONGODB:
  • MongoDb is an open-source application. It will be designed for ease of development. 
  • MonogDb is a NoSql database which means you can not store data in tables like Mysql/Postgres.
  • MongoDb stores data in JSON format in the document structure.
  • MongoDb available in only 64-bit for Debian/mint/ubuntu.
  • MongoDb runs on default port "27017".
  • MongoDb main configuration file is "mongod.conf" which is resides under "/etc" directory.
KEY FEATURES:

High Performance
- Index support faster queries
- use keys from Arrays
- Reduce Input/Output activity on database
Rich Query Language
- Support faster read & write operations
High Availability
- Replication feature provides automatic failover & data redundancy

Horizontal Scalability
- Supports sharding of data over cluster system's

Support for Multiple Storage Engines
- WiredTiger Storage Engine
- MMAPv1 Storage Engine.
________________________________________________________

TAR COMMAND

The Linux “tar command” stands for tape archive, which is used to deal with the tape drive backups.
The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux.

tar files easily moved from one disk to another or machine to machine.

The GNU tar command included with Linux distributions has integrated compression. It can create a .tar archive and then compress it with gzip or bzip2 compression in a single command. That’s why the resulting file is a .tar.gz file or .tar.bz2 file.
  • c – Creates a new .tar archive file
  • v – Verbosely show the .tar file progress
  • f – File name type of the archive file.
  • t - list the contents of .tar file
  • x - untar or extract the files.
  • C (capital) - used to extract the files in another directory or folder.
  • z - used to compress tar with .gz extention
  • j – filter archive through bzip2.
  • r – append or update files or directories to existing archive file.
  • W – Verify a archive file.
  • wildcards – Specify patters in unix tar command.
__________________________________________________________

ELASTICSEARCH :

Elasticsearch is a distributed, open source search and analytics engine, designed for horizontal scalability, reliability, and easy management. elasticsearch combines the speed of search with the power of analytics via a sophisticated, developer-friendly query language covering structured, unstructured, and time-series data.

FEATURES OF ELASTICSEARCH :
  • Real-Time Data
  • Real-Time Advanced Analytics
  • Massively Distributed
  • High Availability
  • Multitenancy
  • Full-Text Search
  • Document-Oriented
  • Schema-Free
  • Developer-Friendly, RESTful API
  • Per-Operation Persistence
_________________________________________________________

ARCHIVE :

Basically it means you take 10 files and combine them into one file.

Archive does not reduce the size of files when its combined.

For eg if you have 10 files with 100kb per size after archiving these 10 files size of single combined file is 1000kb.

ZIP
Zip is a compress tool which is available in most of the operating systems such as Linux/Unix, Apple OS, Microsoft OS etc. In this post we will see how to install, use and tips about zip command.

Zip has a feature to provide speed for compression process below are some points which would help you to understand zip compression process clearly.

To regulate the speed of compression using value from 0 to 9 :
  • 0 indicates no compression just store or archive files.
  • 1 indicates fastest compression speed but less compression.
  • 9 indicatest slowest compression speed but more compression.
  • 6 is the default compression speed.

ZCAT
Sometime we have file with .gz compression and we want to read content of that file without extracting gz file so in this situation Zcat command would read the file content without extracting and also used for extract purpose.

BZCAT
bzcat also work like zcat used to extract or to read the contents of file
________________________________________________________

UMASK ON LINUX:

Umask stands for User mask or User creation mask. When you create any new file or directory on linux system. These files get default permissions from system. This permission is provided or given by Umask configuration on linux. In simple words, it is a system default permissions for new files or directories.

DEFAULT UMASK VALUE :


By default umask values define under the "/etc/profile" or "~/.bashrc"file. On most of the linux distros default value set to files "022".

For directory, default minimum and maximum value is "000" & "777"
For files, default minimum and maximum value is "000" & "666"

So, with a umask of 022, the default permissions for a file will become 644 (rw-r--r--, 666-022) and the default permissions for a directory will become 755 (rwx-r-xr-x, 777-022).

BELOW ARE THE COMMON UMASK VALUES:

$ 000 : Full Access to Everyone or 666
$ 006 : No Access to Other or 660
$ 022 : Full Access to Owner and Read to Group & Other or 644
$ 066 : Full Access to Owner and No access to group & others or 600

Normally, you can subtract from 666 but be very careful as it may be 777. Before changing or working on umask make sure what umask value is set on your linux distro.
____________________________________________________

FSTAB [FILE SYSTEM TABLE] :

FSTAB is a file which contains all the information about partitions and storage devices present on the system. This file is basically located under the "/etc/" directory.
This file gives you information of where your storage devices should be mounted.

FSTAB is very critical and important file present in "/etc" directory where all the configuration files stored. It is the responsibility of SysAdmin to properly create and maintain this file.

You need to understand the structure of this file before writing anything into this. Because if add something with wrong format or structure it will result in crashing your system. You need to handle this very carefully.

Total six columns are present in FSTAB file. Each column defines or performs a different role. To add or mount new device use new row.
LET'S UNDERSTAND THE WORKING OF EACH COLUMN.
1ST COLUMN:

The first column will define the "Label" of partitions. For eg. "LABEL=/boot" or driver's path, eg. "/dev/cdrom". Device driver's path tells the system to mount the device with the mentioned device driver.

2ND COLUMN:

The second column describes the mount point for the filesystem. There is some filesystem should be specified as 'none' like swap partition. The mount point is actually a name of the directory where that device is mounted. Using this mount point we can be able to view and modify the content of that partition. You can modify the mount point according to your requirement.

3RD COLUMN:

The third column will be used to define the Filesystem type of partition or device. Several no. of filesystems supported by Linux and some of them listed below,

- ext2
- ext3
- iso9660
- autofs
- nfs
- swap

If you are not sure about the filesystem then use "auto" option. "auto" will help to determine the file system and mount the device with that filesystem.
4TH COLUMN:

The fourth column is for permissions to be given to the partition at the time of booting. There are many options which constitute the fourth column.

They are as follows : -
1) ro - Read Only
2) rw - Read Write
3) auto - Mount on startup
4) noauto- Do not mount on startup
5) user - Any user can mount, but only unmount device mounted by him
6) nouser- the Only root can mount & unmount the device
7) users - Every user can mount and also unmount the device mounted by others
8) owner - Same as user (above no. 5)
9) dev - User can use device driver to mount the device
10) nodev - User cannot use device driver to mount the device
11) exec - Users can execute binaries on the partition
12) noexec- Users cannot execute binaries on the partition
13) async - Asynchronous, whenever a file is saved it will be first saved in the RAM and after 30 seconds all the queued files will be written on the hard disk
14) sync - Synchronous, whenever a file is saved it will be directly written to the hard disk
15) suid - Allow set-user-identifier for the device where users are allowed to run binaries even though they do not have to execute permissions. These binaries are temporarily made available to them to perform certain tasks
16) nosuid- Do not allow set-user-identifier
17) defaults- auto, rw, dev, async, suid, exec & nouser

5TH COLUMN:

This column is used as a backup option. It will contain two values either 0 or 1. Here 0 stands for "no" and 1 stands for "yes". if option 1 used then system checks are enabled at the time of booting and if 0 used then system checks will be ignored. Backup option supported only ext3 filesystem which means for another filesystem this option should be disabled by default.

6TH COLUMN :

6th column is using for "fsck" option. Fsck stands for filesystem check. with this option system will scan the filesystem at time of start up. Here The / partition is assigned top priority i.e. 1 and the rest of the partitions are assigned second priority i.e. 2. If the value is set to 0 means no scanning will be done at the time of startup. If the same number is given to different partitions then the partitions are scanned together with equal priority. This minimizes error because if a link is present on one partition with higher priority and the source file in another partition with a priority lower than the link, it will give an error.
________________________________________________________

RPM PACKAGE MANAGER:

RPM stands for Red hat Package Manager. It is a powerful package manager tool for Redhat, open-suse, fedora etc. RPM can be used to install, build, verify, update, query and remove individual application or software packages.
RPM is default package manager for RedHat Linux systems.
RPM are basically files which contain installable software and that package has .rpm extension or suffix.
RPM is a free tool created or developed by Redhat software.
RPM will store information about packages in a database "/var/lib/rpm".

ADVANTAGES OF RPM PACKAGE MANAGER:
  • Straightforward program installation and uninstallation
  • Automatic installation
  • Ease of updating programs originally installed with RPM
  • Availability of versions for most distributions of Linux
DISADVANTAGES OF RPM PACKAGE MANAGER:
  • Distribution packages
  • Architecture-specific
  • Dependency
_______________________________________________________

1. SYMLINK [SYMBOLIC LINK]:

A symlink is also called as Soft link. Symlink is a file which contains a reference to another file or directory in the form of absolute or relative path.

In simple word, you can create a shortcut of file or directory to the other path using symlink feature.

IMPORTANT POINTS ABOUT THE SYMLINK:
$ Links have different inode numbers.

$ Removing symlink will not affect the original file but if you remove original file then symlink will not work. the symlink will be changed to red color once original file removed

$ Symbolic links are set up using the ln command with the -s option.
$ Symlink is slightly slower at runtime compared to hard link but it's more flexible and more often used in day to day admin work.
$ Symlink always created with the 777 permission.
$ Symlink can create directories

HARDLINK :

A HardLink is where a file has two names which are both on an equal weighting, and both of the file names in the "inode table" point directly to the blocks on the disc that contain the data.

IMPORTANT POINTS FOR HARDLINK :
$ All Links have same inode number.

$ Links have actual file contents.
$ Removing any link just reduces the link count but doesn't affect other links.
$ Hard links can not cross partition which means you can not create hard link of one file to another partition.
$ Hardlinks can not create directories.
$ Hardlink can be create using ln command without any option.

$ Try creating hardlink with directories it will give you the error like "hard link not allowed for directory".
$Try creating hardlink to another partition it will produce an error like " failed to create hard link ‘/boot/qwe’ => ‘/opt/new-file/abc’: Invalid cross-device link".
_____________________________________________________

1. ABOUT SCREEN COMMAND

screen command is used to run the multiple processes in different shells as a background process.

It is a very useful command for system admins. Screen will offers multiple terminal processes inside a one single terminal manager.

2. BENEFITS OF SCREEN COMMAND
  • screen command will help to create a process which actually runs in the background and if you are network got fluctuated and if you are running any important command then normal window gets disconnected but in the screen, you can again login on the machine and reattached screen with running process.
  • It helps sysadmins to run rsync command with big data transfer, restoring or dumping large MySQL file etc this time screen command plays a very important part.
____________________________________________________

1. ABOUT SSL CERTIFICATE

SSL stands for Secure Socket Layer.

SSL is basically used to encrypt the site information and make a secure connection. It is maintaining encrypted link or secure way of connection between a Server and Client.

SSL helps to maintain or allow sensitive information like Credit Card nos., Usernames, Passwords, emails etc.

SSL will not allow or stop hackers to stolen important information from websites. It will provide a guarantee to customers that the important data will be safe with or because of SSL.

2. WHAT IS SELF-SIGNED SSL CERTIFICATE?

We just see the information about SSL Certificate. Now understand about the Self-signed SSL certificate.
Self-Signed Certificate is basically a certificate which is created or signed by a person with local encryption technique.

This type of certificate is not a tested or approved by trusted certificate authority. Self Signed certificates are not used on live websites.
If any one of the people using self-signed then customers will get the message "The Site Security Certificate not Trusted!".

No one is using a Self-signed certificate on live sites.

3. WHEN SHOULD A SELF-SIGNED CERTIFICATE AND SHOULDN'T BE USED?

The self-signed certificate should not be used on Live websites like where website using credit cards info, username, passwords etc. if you used it then you are site going under risk of hack information. Hackers will steal or tampered the important information from your website. Also, you are customers will see the error message while accessing your site. Customers will not go to provide any sensitive information with the non-trusted site. It will definitely harm your business. So don't use any kind of Self-signed certificate on your live website.

Self-signed certificate is basically used on a development server where developer's need to test or develop some functionality or application. You no need to pay for trusted certificate when you want to implement it on local or development server. This is the main importance of self-signed certificate.

Tuesday, December 13, 2016

Nagios NRPE Script though Installation on Client


#!/bin/bash
########## Author Shrikant Mohinkar ##########
/bin/echo "NAGIOS CLIENT INSTALATION STARTED"
/usr/bin/yum install gcc wget glibc glibc-common gd gd-devel make net-snmp openssl-devel -y
useradd nagios
echo "nagios123" |passwd nagios --stdin
###############
mkdir -p /root/nagios
cd /root/nagios
/usr/bin/wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
/usr/bin/wget https://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
###############
cd /root/nagios
tar xzf nagios-plugins-2.1.1.tar.gz
###############
cd /root/nagios/nagios-plugins-2.1.1
./configure
make
make install
###############
/usr/bin/chown nagios.nagios /usr/local/nagios
/usr/bin/chown -R nagios.nagios /usr/local/nagios/libexec
sleep 5
yum install xinetd -y
cd /root/nagios
tar xzf nrpe-2.15.tar.gz
cd /root/nagios/nrpe-2.15
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
sleep 5
/bin/sed -i 's/127.0.0.1/127.0.0.1 localhost 203.97.48.107/g' /etc/xinetd.d/nrpe
/bin/echo "nrpe 5666/tcp #NRPE" >> /etc/services
service xinetd start
chkconfig xinetd on
/bin/netstat -at | grep nrpe
/usr/local/nagios/libexec/check_nrpe -H localhost
/bin/echo "NAGIOS CLIENT SUCCESSFULLY INSTALLED "

Monday, December 12, 2016

Linux Interview Question - Linux basic 3

1. How to check memory stats and CPU stats.?
Ans: Using vmstat command we can check memory stats and CPU stats. We can also check memory usage and CPU usage in real time using top command

2. How to change the default run level in Linux.?
Ans: In RHEL/Centos 5/6 by changing the value in /etc/inittab file as mentioned below
[root@Arkit-RHEL6 ~]# vi /etc/inittab |grep id
# Individual runlevels are started by /etc/init/rc.conf
id:5:initdefault:
3. What are the default ports used for SMTP,DNS,FTP,DHCP, SSH and HTTP.?
Ans:
SMTP = 25
DNS = 53
FTP = 20 and 21
DHCP = 67 and 68
SSH = 22
HTTP = 80 and HTTPS = 443

4. How to check which ports are listening in my Linux Server.?
Ans: Using nmap, netstat and lsof commands we can check which are the ports listening in local host
Command Examples:
# nmap -sT -O localhost 
# ss -tunlap
# netstat -anp
5. How to add & change the kernel parameters.?
Ans: We can change the kernel parameters using /etc/sysctl.conf file

6. What is Puppet Server.?
Ans: Puppet software is a open-source configuration management tool. Which will support for multiple operating system such as Unix-like systems and Microsoft windows.

7. What are Symbolic Links and hard links.?
Ans: Symbolic links are the links which reference to actual files with other nicknames. We can add symbolic links to files and directories.

8. How to you execute more than one command or programs from Crontab entry.?
Ans: It is well possible to run/execute more commands from single crontab schedule by adding semicolon in between multiple commands.# crontab -e * * * * * cat /etc/passwd; ls -l /etc/ >> /tmp/etcfiles

9. Write a command that will look for files with an extension “c”, the string “apple” in it.?
Ans:
# find / -name "*.c" -print | xargs grep apple
10. What, if anything, is wrong with each of the following commands
ls -l-s
cat file1, file2
ls -s Factdir

Ans: There is no space used in ls -l-s command. Correct command is ls -l -s. In cat command we do not use ,(comma) for reading multiple files. Correct command is cat file1 file2

11. What is the difference between cron and anacron.?
Ans: cron jobs will run when server/machine is online 24/7. Anacron does not required to be online 24/7 like server when machine is switched on scheduled jobs will run

12. What are the fields in the /etc/passwd file.? Please explain.?
Ans:
# cat /etc/passwd
charan:x:1003:1003:Administrator from HYD:/home/charan:/bin/bash
charan = User Name
1003 = UID
1003 = GID group id
Administrator from HYD = Description of the user
/home/charan = Home directory of charan user
/bin/bash = Default shell prompt is bash for charan user

13. How Environment variable is set so that the file permissions assign the newly created files.?
Ans: By setting umask value newly created files will get default permissions

14. If you have only on IP address, but you want to host two web sites. What will you do.?
Ans: Create multiple virtual hosts using different ports

15. How do you check for the httpd.conf consistency..?
Ans: Using apachectl configtest command we check http.conf file consistency and errors

16. What is ‘.htaccess’ file in Apache web server.?
Ans: .htaccess file is a Hypertext Access file which is used to write URL redirection and SSL certification configuration etc..

17. In ‘kill -9’ command, what is the ‘-9’ signal indicates..?
Ans: -9 represent SIGKILL which means Kill signal

18. What are the process states in Unix.?
Ans:
Running State
Stopped State
Sleeping State
Uninterrupted sleep state
Defcunt State Or zombie State

19. List out different multi-processing modules in Apache web server description about it.?
Ans: mpm_worker_module is a module multi-processing module

20. What are the different storage engines used in MySQL..?
Ans:
Below are the few MySql storage engines
MyISAM.
InnoDB.
Memory.
CSV.
Merge.
Archive.
Federated.
Blackhole.

Linux Interview Question - Linux Basic 2

1. You are tasked to build a new Linux workstation. User wants to install a word processor and spreadsheets that offers a similar version for Microsoft Windows system. Which office suite should you install?
Ans:- You should use Apache OpenOffice. Its free and open source project. And works fine on both Window and Linux systems.


2. A technician uses the ps command to see what processes are running. When the current running processes are shown, he notices a process that he terminated 10 minutes ago by using the kill command is still running. What command should he use next to terminate this process?
Ans:- He should use -9 argument with kill command that will send a kill signal to the process. This will terminate the specific process immediately.


3. A technician quickly notices a kernel error message on the screen during the boot process. Unfortunately, the error message disappear so quickly for the technician to read it all. What log directory can the technician use to examine boot-time messages?

Ans:-
Linux system keeps almost all log files under the /var/log directory. Most of the boot messages are kept in buffer, which can be accessed by using the dmesg command. He can examine the /var/log/dmesg.log file. For boot time message he can also check the /var/log/boot.log file.


4. A technician wants to view a list of all running processes on the server. How can he do this?

Ans:-
He should use the ps command with -ef argument. ps -ef command will show a list of all running process.

EXAMPLES
       To see every process on the system using standard syntax:
          ps -e
          ps -ef
          ps -eF
          ps -ely

       To see every process on the system using BSD syntax:
          ps ax
          ps axu

       To print a process tree:
          ps -ejH
          ps axjf

       To get info about threads:
          ps -eLf
          ps axms

       To get security info:
          ps -eo euser,ruser,suser,fuser,f,comm,label
          ps axZ
          ps -eM

       To see every process running as root (real & effective ID) in user format:
          ps -U root -u root u

       To see every process with a user-defined format:
          ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
          ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
          ps -eopid,tt,user,fname,tmout,f,wchan

        Print only the process IDs of syslogd:
          ps -C syslogd -o pid=

       Print only the name of PID 42:
          ps -q 42 -o comm=


5. Where inittab file is located?

Ans:-
Default location of inittab file is /etc directory. This file describes which process would be start at boot time.


6. A technician want to boot the system in CLI mode on start up. Which runlevel should he assign and in which file ?

Ans:-
He could assign runlevel 3 as the default runlevel in /etc/inittab file.


7. What program a technician can use to analyze program’s core dump files and to debug the application while it is actually running?

Ans:-
He can use gdb program to analyze program’s core dump files and also debug the application while it is actually running.


8. As a technician you want to shutdown the Linux system. What command should you use?

Ans:-
You could use shutdown command.


9. As a technician you need to perform a scheduled shutdown that will occur in 10 minutes. What should you use to shut down the server in 10 minutes.?
Ans:- You can use -h argument with shutdown command which allows you to specify the time in second. To shutdown the system in 10 minute you should run shutdown -h 600 command.


10. What command will halt the system?

Ans:-
halt will halt the system.


11. As a technician you need to restart the Apache Web Server. What command should you use.?

Ans:-
You could use following command to restart the Apache web server.
#service httpd restart


12. Which command will restart the FTP Server?

Ans:-
#service vsftpd restart
Above command will restart the FTP server.


13. What line printer control command is used to control the operation of the line printer system?

Ans:-
lpc command is used with various argument to control the operations of line printer system.


14. A technician wants to terminate an active spooling daemon on the local host immediately and then disables printing for the specified printers. What command should he use?

Ans:-
He should use lpc command with abort options. lpc abort lpc abort terminates an active spooling daemon on the local host immediately and then disables printing for the specified printers,


15. What print command stops a spooling daemon after the current job completes and disables printing?

Ans:-
The lpc stop command stops a spooling daemon after the current job completes and disables printing


16. What command allows you to directly see what jobs are currently in a printer queue?

Ans:-
The lpc command allows you to directly see what jobs are currently in a printer queue


17. A technician wants to halt the Linux server. What command should he use ?

Ans:-
He can use init 0 command to halt the Linux server.


18. What line printer command lets you remove print jobs from the printer queue?

Ans:-
The lprm command will let you remove print jobs from the printer queue.


19. What is the default text editor of Linux which include almost every version of Linux?

Ans:-
Default editor of Linux is vi editor that can used to edit any ASCII text.


20. What command is used for combining a large number of files into one single file for archival to tape?

Ans:-
vi is a text editor that can be used to edit any ASCII text. It is especially useful for editing programs.


21. Where do all your configurations for your services, programs, and daemons reside by default?

Ans:- By default, all configurations for your services, programs, and daemons reside in the /etc directory.


22. What type of backup tape will only back up files that have changed since the previous backup and clear the archive bit?

Ans:-
An Incremental backup will backup only files that have changed since the previous backup and clear the archive bit.


23. Which argument is used with tar command to create a new archive file?

Ans:-
  -c argument is used to create new archive file.


24. Which argument is used with tar command to extract the files from archive ?

Ans:-
-x argument is used with tar command to extract the files form archive.


25. What is default name of super or administrator account name in Linux?

Ans:-
Super or administrator account in Linux is known as root user.


26. A technician is going to install Linux on a workstation. The technician wants to customize the installation. What type of installation will the technician use to customize the installation?

Ans:-
Only a custom installation can be used to customize what is installed during an installation. A custom installation will allow you to choose what packages you want to install and what packages you don’t want to install.


27. Where is the password file for Linux located?

Ans:-
The password file for Linux is located by default in the /etc/passwd location.


28. Which program is mostly used for remote login securely in Linux?

Ans:-
SSH is used for secure login. SSH is the replacement of old unsecure services like telnet.


29. What file contains a list of user names that is not allowed to log in to the FTP server?

Ans:-
The ftpusers file contains a list of usernames that a Linux administrator has previously set to not allow specific users to login to the FTP server. ftpusers file is located in /etc/vsftpd directory.


30. Which command can be used to schedule recurring tasks?

Ans:-
Cron command can be used to set scheduled recurring tasks.


31. In which directory Linux store crontab files for particular users?

Ans:-
The /var/spool/cron is the directory where user’s crontabs are saved with a directory for each user in which all user’s cron jobs are stored.


32. What command should you use to activate a swap partition?
Ans:- swapon command is used to activate the swap partition.


33. A technician is verifying the network configuration of a Linux server. Which command he should used to accomplish this?

Ans:-
ifconfig is the proper command to examine network configuration.


34. A technician wants to assign IP addresses to all the systems that will connect to the server automatically. What type of server he should set up?

Ans:-
He should set up DHCP Server which assigns IP address to client automatically on start up.


35. A technician wants to add a new user to the current domain. What command will the technician use to accomplish this?

Ans:-
He should use useradd command followed by the username will create a new user or update default new user information. You need to specify the password separately with the passwd command.


36. What option a technician can use with usermod command to unlock to user’s password?

Ans:-
The -U option is used with usermod command to unlock the user’s password.


37. What option of the mkfs command should you use to check the device for bad blocks before building the file system?

Ans:-
The –c option when used with the mkfs command will check the device for bad blocks before building the file system.


38. What at command argument will send mail to the user when the job has completed, even if there was no output?

Ans:-
-m argument with at command will send mail to the users when the job has completed even if there was no output.


39. A user wants to verify the current active shell. Which command will he use?

Ans:-
He should use the env command to verify the current active shell


40. What command can a technician use to search for a specific file?

Ans:-
He can use either find or locate command to search for a specific file.


41. How can you send the output of a file to another file?

Ans:-
The > option is used to send the output of a file to another file.

42. What is the -t option with fsck command used for?

Ans:-
The –t option used with fsck is used to specify the type of filesystem to be checked.

43. Which utility should you use to display the CPU processes?

Ans:-
top utility lets you see all on one screen how much memory and CPU usage that you are currently using, and also the resource usage by each program and process.


44. What command can you use to obtain information about your serial port resource usage, such as IRQ and IO addresses?

Ans:-
 setserial is a utility that you can use to obtain information about serial port resource usage, such as IRQ and IO addresses.


45. A technician wants to delete the a user account. Which command should he use?

Ans:-
The userdel command is used to delete a user from the system.


46. Which command is used to change from one directory to another?

Ans:-
cd command is used to navigate the Linux hierarchical file system structure, use the cd command to change from one directory to another.


47. A user wants to copy a file from the /tmp directory to the his home directory. Which command would he use?

Ans:-
He can use cp command to copy the files from one directory other directory.


48. What is the file extension of Red Hat Package manager?

Ans:-
RPM extension is associated with the Red Hat Package manager

49. What command can you use to mount a CD-ROM drive?

Ans:-
mount command will mount the CD-ROM.


50. A technician wants to monitor connections to a Linux server. Which command should the technician use?

Ans:-
He should use netstat command. Netstat is a perfect way to see and monitor the both inbound and outbound connections. This command also be used to view packet statistics so you can see how many packets have been sent and received.


51. Which command a user can use to exit a login shell?

Ans:-
The logout or exit command will exit him from a login shell.


52. A technician is having problems connecting to a mail server. What command can he use to test if the mail server is on the network?

Ans:-
He can use ping command to test connectivity between local system and remote server.