Friday, January 13, 2017

Linux Interview Question Final


1) What is Raid and Raid Level

RAID can allow for better storage performance and higher availability, and there are many different RAID types.

RAID (originally redundant array of inexpensive disks; now commonly redundant array of independent disks) is a data storage virtualization technology that combines multiple disk drive components into a logical unit for the purposes of data redundancy or performance improvement.

Raid contains groups or sets or Arrays. A combine of drivers make a group of disks to form a RAID Array or RAID set. It can be a minimum of 2 number of disk connected to a raid controller and make a logical volume or more drives can be in a group. Only one Raid level can be applied in a group of disks. Raid are used when we need excellent performance. According to our selected raid level, performance will differ. Saving our data by fault tolerance & high availability.

In RAID we have different RAID levels
1. Level 0 - striped disk array without fault tolerance
2. Level 1 - mirroring and duplexing
3. Level 2 - error-correcting coding
4. Level 3 - bit-interleaved parity
5. Level 4 - dedicated parity drive
6. Level 5 - block interleaved distributed parity
7. Level 6 - independent data disks with double parity
8. Level 10 - a stripe of mirrors


2) Difference Between Raid 5 and Raid 1 + 0

RAID Level 5: Block-level striping with distributed parity. Each entire data block is written on a data disk; parity for blocks in the same rank is generated on Writes, recorded in a distributed location and checked on Reads. Requires minimum 3 disks to implement
·         
  •  Highest Read data transaction rate
  •  Medium Write data transaction rate
  •  Low ratio of ECC (Parity) disks to data disks means high efficiency
  •  Good aggregate transfer rate

RAID Level 0: It’s just stripping. RAID Level 0 requires a minimum of 2 drives to implement.

  • RAID 0 implements a striped disk array, the data is broken down into blocks and each block is written to a separate disk drive
  • I/O performance is greatly improved by spreading the I/O load across many channels and drives
  • Best performance is achieved when data is striped across multiple controllers with only one drive per controller
  • No parity calculation overhead is involved
  • Very simple design
  • Easy to implement

RAID Level 1: For Highest performance, the controller must be able to perform two concurrent separate Reads per mirrored pair or two duplicate Writes per mirrored pair. Raid level 1 requires a minimum of 2 drives to implement.

  • One Write or two Reads possible per mirrored pair
  • Twice the Read transaction rate of single disks, same Write transaction rate as single disks
  • 100% redundancy of data means no rebuild is necessary in case of a disk failure, just a copy to the replacement disk
  • Transfer rate per block is equal to that of a single disk
  • Under certain circumstances, RAID 1 can sustain multiple simultaneous drive failures
  • Simplest RAID storage subsystem design

3) what is differene between Hardware Raid and Software Raid.

Implementing the RAID will be two types 1.Software RAID and 2.Hardware RAID
Let’s see the difference between those

SOFTWARE RAID
HARDWARE RAID
1. It will use computer system CPU1. It will use its own CPU
2. Low cost compare to H/W RAID2.More cost compare to S/W RAID
3. It has data integrity issues due to system crashes
3.No data integrity issues
4. No write-back cache4.It is capable of write-back cache
5. Limited operating system migrations5.Can be migrated to any OS type
6. Unprotected at boot (cannot manage or protect data at boot):Drive failure or corrupted data during boot and before the RAID software become active leads to an inoperable system6. Protected at boot: No negative impact on data availability
when boot drive has medium errors or fails completely
7. Performance issues will be there7.No performance issues compare to S/W RAID
Software RAID have low performance, because of consuming resource from hosts. Raid software need to load for read data from software raid volumes. Before loading raid software, OS need to get boot to load the raid software. No need of Physical hardware in software raids. Zero cost investment.

Hardware RAID have high performance. They are dedicated RAID Controller which is Physically built using PCI express cards. It won’t use the host resource. They have NVRAM for cache to read and write. Stores cache while rebuild even if there is power-failure, it will store the cache using battery power backups. Very costly investments needed for a large scale.


4) Why FTP work on 21 port?

Purpose:
Reserved TCP port used by File Transfer Protocol (FTP) to initiate and control connections to FTP servers.

Description:
To establish an FTP session, clients initiate a connection to an FTP server that listens on TCP port 21 by default. FTP servers respond with messages that prompt the client for FTP login credentials (username and password). FTP servers do not, however, send files from port number 21.

Instead, the FTP protocol allows for a second connection to be established for data transfer after the control connection is established. Note that only FTP servers use port 21, not FTP clients.


NFS –Network File Sharing
NFS PORT ------2049
NFS Run on UDP Protocol
NFS doesn’t ask to username & password
NFS used for Linux to Linux only
NFS fast and good performance

Starting NFS services: ------ok ] Main Services
Starting NFS quotas: -------ok ]
Starting NFS deamon: ------ok ] Child Service
Starting NFS mountd: ------ok ]

exportfs –a   -----     re-read the file
exportfs –v   ------    Display

(sync) --------   under the bracket “( )” called Permission
*(sync) ------- * means ----sharing to all network

showmount -e 192.168.10.x ------ to check it out share drive is accessible or not


NFS V3 VS NFS V4

Export Management
  1. In NFSv3, client must rely on auxiliary protocol, the mount protocol to request a list of server’s exports and obtain root filehandle of a given export. It is fed into the NFS protocol proper once the root filehandle is obtained.
  2. In NFSv4 uses the virtual file system to present the server’s export and associated root filehandles to the client.
  3. NFSv4 defines a special operation to retrieve the Root filehandle and the NFS Server presents the appearance to the client that each export is just a directory in the pseudofs
  4. NFSv4 Pseudo File System is supposed to provide maximum flexibility. Exports Path name on servers can be changed transparently to clients.


6) DNS configuration file name


/etc/named.conf

DNS Package name  :  bind*

DNS Port  : 53


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.

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

8) Boot Process.

The following are the 6 high level stages of a typical Linux boot process.


9) If Server Load Increase What is Troubleshooting steps you will follow.

High server load – What is it really?

A server functions with a limited set of resources. For eg., an average server these days will have 8 GB RAM, 4 processors, 75 IOPS SATA II hard disks, and 1 Gigabit NIC cards.

Now, let’s assume one user decided to backup their account. If that process occupies 7.5 GB of RAM, other users or services in the system have to wait for that process to get over. The longer the backup takes, the longer the wait queue. The “length” of the queue is represented as server load. So, a server running at load avg. 20, will have a longer wait queue than a server at load avg. 10.

The key to quickly trace a load spike is to go from what you know to what you don’t.

When you get a high load notification, there’s only one thing you know. That is – there’s some server resource (RAM, CPU, I/O, etc.) that’s being abused.

So, the first step is to find out which resource is being abused. The next step is to find out which service is using that resource. It could be the web server, database server, mail server, or some other service. Once you have the service, you can then find out which user in that service is actually abusing the server.
  1. Find the over-loaded resource
  2. Find the service hogging that resource
  3. Find the virtual host over-using that service

10) Command SAR

SAR System Monitoring  


12)  How DHCP works (DORA Process)

DHCP stands for Dynamic Host Configuration Protocol.

The DORA process in DHCP works as folows.
D ----------> Discover
O ----------> Offer
R ----------> Request
A ----------> Acknowledgement

DHCP (D)iscover | DHCP (O)ffer | DHCP (R)equest | DHCP (A)ck

D – D in the term DORA stands for the DHCP Discover packet. The DHCP Discover packet
is broadcasted by the DHCP client computer in order to find the available DHCP server(s) in the network. Since the DHCP client computer sends the DHCP Discover packet as a broadcast, all the
DHCP servers that are present in the network receive the packet and respond accordingly.

O – O in the term DORA stands for the DHCP Offer packet. The DHCP Offer is a unicast packet that is sent by the DHCP server who receives the DHCP Discover packet from the DHCP client computer. The DHCP Offer packet contains the available IP address that the DHCP server offers to the client computer.

R – R in the term DORA stands for the DHCP Request packet. The DHCP Request is again a unicast packet sent by the DHCP client computer to the DHCP server who had sent the DHCP Offer packet to the client computer. With the help of the DHCP Request packet, the DHCP client computer requests the DHCP server to assign the offered IP address to it.
A – A in the term DORA stands for the DHCP Acknowledge packet. The DHCP Acknowledge is a unicast packet sent by the DHCP server to the DHCP client computer acknowledging the assignment of the offered IP address for a specific lease time.


1) Client makes a UDP Broadcast to the server about the DHCP discovery.
2) DHCP offers to the client.
3) In response to the offer Client requests the server.
4)Server responds all the Ip Add/mask/gty/dns/wins info along with the acknowledgement packet.

13) Subversion

14) LVM Questions




18) Linux Apache Interview Question -1



21) Linux Nagios Interview Question -1

22) Linux Interview Question - Part 1




Wednesday, January 11, 2017

LAMP Server Installation

  1. To set up a LAMP server on a fresh VPS/Dedicated server running CentOS 5.0 with atleast 256mb of RAM. ... 
  2. Install Apache. ... 
  3. Install MySQL Database Server. ... 
  4. Changing MySQL Root Password. ... 
  5. To Create A New MySQL User. ... 
  6. Install PHP5 Scripting Language. ... 
  7. To Test If PHP Is Working Or Not: ... 
  8. Install phpMyAdmin.
________________________________________

1) Install Apache

yum install httpd httpd-devel
/etc/init.d/httpd start


2) Install MySQL Database Server

yum install mysql mysql-server mysql-devel

First start the mysql daemon, then type mysql:

/etc/init.d/mysqld start
2 Way to Change MySQL Root Password

By default the root password is empty for the mysql database. It is a good idea to change the mysql root password to a new one from a security point of view.

1) mysql_secure_installation

2) mysql
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';

mysql> FLUSH PRIVILEGES;

Once done, check by logging in:

mysql -u root -p

Enter Password: <your new password>


To Create A New MySQL User

To create a new mysql user 'harry' with 'all privileges' on the database 'demo':
mysql > create database demo
mysql >GRANT ALL PRIVILEGES ON demo.* TO 'harry'@'localhost' IDENTIFIED BY 'harry' WITH GRANT OPTION;
mysql> UPDATE user SET Password=PASSWORD('harry') WHERE user='harry';

That's it! MySQL is ready! Don't forget to remember the root password as we might be using it with phpmyadmin.
3) Install PHP5 Scripting Language

Installing PHP5 with the necessary modules is so easy and can be configured for both the Apache and mysql environment.
yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

Don't forget to install php-gd (gd library). It is very important if we plan to run captcha scripts on our server and so as other which are dependent on mysql and other functions.
Restart Apache to load php.

/etc/init.d/httpd restart


To Test If PHP Is Working Or Not:

Create a file named /var/www/html/test.php with the following phpinfo() function inside php quotes.

// test.php
  <?php
  phpinfo();
  ?>

Edit /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /var/www/html/test.php
    ServerName  funny.com
    ErrorLog logs/dummy-host.example.com-error_log
    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>


Then point your browser to http://ip.address/test.php.


4) Install phpMyAdmin

yum install phpmyadmin



Point your browser to: http://ip.address/phpmyadmin.


Edit the /etc/httpd/conf.d/phpmyadmin.conf

# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require all granted
       Require ip ::1
     </RequireAny>
   </IfModule>
#   <IfModule !mod_authz_core.c>
     # Apache 2.2
#     Order Deny,Allow
#     Deny from All
#     Allow from 127.0.0.1
#     Allow from ::1
#   </IfModule>
</Directory>

<Directory /usr/share/phpMyAdmin/setup/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
#     <RequireAny>
#       Require ip 127.0.0.1
#       Require ip ::1
#     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
#     Deny from All
     Allow from All
     Allow from ::1
   </IfModule>
</Directory>

# These directories do not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#
<Directory /usr/share/phpMyAdmin/libraries/>
    Order Deny,Allow
    Deny from All
    Allow from None
</Directory>

<Directory /usr/share/phpMyAdmin/setup/lib/>
    Order Deny,Allow
    Deny from All
    Allow from None
</Directory>

<Directory /usr/share/phpMyAdmin/setup/frames/>
    Order Deny,Allow
    Deny from All
    Allow from None
</Directory>

# This configuration prevents mod_security at phpMyAdmin directories from
# filtering SQL etc.  This may break your mod_security implementation.
#
#<IfModule mod_security.c>
#    <Directory /usr/share/phpMyAdmin/>
#        SecRuleInheritance Off
#    </Directory>
#</IfModule>

Point your browser to: http://ip.address/phpmyadmin.

User Name : root
Password : newpassword

chkconfig httpd on
chkconfig mysqld on

SCM-MANAGER INSTALLATION


Installation of SCM-Manager

1) RPM installation.

Create a new file at /etc/yum.repos.d/SCM-Manager.repo with the following content to install the scm-manager repository

[scm-releases]
name=SCM-Manager Releases
baseurl=http://maven.scm-manager.org/nexus/content/repositories/releases
enabled=1
protect=0
gpgcheck=0
metadata_expire=30
sautorefresh=1
type=rpm-md


2) Install scm-server package.

yum install scm-server


3) Install java Package

yum install java-1.8.0-openjdk-headless


By default it runs on port 8080

Hit http://localhost:8080/scm on the web browser.

Provide username and password as ‘scmadmin’ and log in.

Sunday, January 1, 2017

Script for s3 Becket

#!/bin/sh
# Script to Backup code to Amazon S3

backup_files=."/mnt/logs_bkp_archive_old"
access_log="/mnt/logs_old_archive/access_backup"
app_log="/mnt/logs_new_archive_old/txt_backup/"
# S3 location
s3_loc="s3://bkp-logs"

# Create archive filename.
day=$(date +%y%m%d)

#s3cmd put --recursive --preserve --storage-class STANDARD_IA /mnt/logs_bkp_arch                                                                                       ive_old/backup/2015/70_logs s3://backup/

mail -s 'BKP logs copied to S3' test@gmail.com test222@gmail<< EOF
Hello,

BKP logs are copied to s3 $day.

Have a Nice Day.

Regards,

IT Team
EOF

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