Monday, June 30, 2014

NAGIOS NETWORK MONITORING

"How to Install & configure Nagios on CentOS"

Nagios is an awesome Open Source monitoring tool, its provides you more comprehensive monitoring environment to always keep an eye on your all machines / networks whether you are in a your data centre or just your small labs.

With Nagios, you can monitor your remote hosts and their services remotely on a single window. It shows warnings and indicates if something goes wrong in your servers which eventually helps us to detect some problems before they occur. It helps us to reduce downtime and business losses.

Recently, Nagios released its latest versions Nagios 4.0.1 on 15th October 2013, and its latest stable release of Nagios plugins 1.5.

Installing Nagios 4.0.1 and Nagios Plugin 1.5
-------------------------------------------------------------


Nagios and its plugins will be installed under /usr/local/nagios directory.
Nagios will be configured to monitor few services of your local machine (Disk Usage, CPU Load, Current Users, Total Processes, etc.)

[ Note:- Before to begine, sure update your CentOS sytem by the "#yum update" command ]

Step 1: Install Required Dependencies
We need to install Apache, PHP and some libraries like gcc, glibc, glibc-common and GD libraries and its development libraries before installing Nagios 4.0.1 with source. And to do so we can use yum default package installer.

[root@tecmint]# yum install -y  httpd  php  gcc  glibc  glibc-common  gd gd-devel  make net-snmp   (RedHat / CentOS)

Step 2: Create Nagios User and Group
Create a new nagios user and nagcmd group account and set a password.

[root@tecmint]# useradd nagios
[root@tecmint]# groupadd nagcmd

Next, add both the nagios user and the apache user to the nagcmd group.

[root@tecmint]# usermod -G nagcmd nagios
[root@tecmint]# usermod -G nagcmd apache

Step 3: Download Nagios Core 4.0.1 and Nagios Plugin 1.5

Create a directory for your Nagios installation and all its future downloads.

[root@tecmint]# mkdir /root/nagios
[root@tecmint]# cd /root/nagios

Now download latest Nagios Core 4.0.1 and Nagios plugins 1.5 packages with wget command.

[root@tecmint nagios~]# wget  http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
[root@tecmint nagios~]# wget  https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz

Step 4: Extract Nagios Core and its Plugins

We need to extract downloaded package with tar command as follows.

root@tecmint nagios~]# tar –xvf nagios-4.0.1.tar.gz
[root@tecmint nagios~]# tar –xvf nagios-plugins-1.5.tar.gz

When we extract these tarballs with tar command, two new folders will appear in that directory.

[root@tecmint nagios ~]# ll
total 3712
drwxrwxr-x 18 root root    4096 Oct 17 03:28 nagios-4.0.1
-rw-r--r--  1 root root 1695367 Oct 15 19:49 nagios-4.0.1.tar.gz
drwxr-xr-x 15  200  300    4096 Oct 14 10:18 nagios-plugins-1.5
-rw-r--r--  1 root root 2428258 Oct  2 11:27 nagios-plugins-1.5.tar.g

Configure Nagios Core

Now, first we will configure Nagios Core and to do so we need to go to Nagios directory and run configure file and if everything goes fine, it will show the output in the end as sample output. Please see below

[root@tecmint nagios~]# cd nagios-4.0.1
[root@tecmint nagios-4.0.1 ]# ./configure --with-command-group=nagcmd

Sample output:

Nagios executable:  nagios
Nagios user/group:  nagios,nagios
Command user/group:  nagios,nagcmd
Event Broker:  yes
Install ${prefix}:  /usr/local/nagios
Install ${includedir}:  /usr/local/nagios/include/nagios
Lock file:  ${prefix}/var/nagios.lock
Check result directory:  ${prefix}/var/spool/checkresults
Init directory:  /etc/rc.d/init.d
Apache conf.d directory:  /etc/httpd/conf.d
Mail program:  /bin/mail
Host OS:  linux-gnu

Now, after configuring we need to Compile and install all the binaries with make command and make install command will install all the needed libraries in your machine and we can proceed further.

[root@tecmint nagios-4.0.1 ]# make all
[root@tecmint nagios-4.0.1 ]# make install

Sample output:

*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

make install-init
     - This installs the init script in /etc/rc.d/init.d

make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

make install-config
     - This installs sample config files in /usr/local/nagios/etc
------------------------------------------------------------------------------------    
    
Following command will install the init scripts for Nagios.

[root@tecmint nagios-4.0.1 ]# make install-init

To make nagios work from command line we need to install command-mode.

[root@tecmint nagios-4.0.1 ]# make install-commandmode

Next, install sample nagios files, please run following command.

[root@tecmint nagios-4.0.1 ]# make install-config

Sample output:

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
------------------------------------------------------------------------------------------------

Step 5: Customizing Nagios Configuration

Open the “contacts.cfg” file with your choice of editor and set the email address associated with the nagiosadmin contact definition to receiving email alerts.

# vi /usr/local/nagios/etc/objects/contacts.cfg

Sample Output

###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################

# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.

define contact{
       contact_name                    nagiosadmin             ; Short name of user
       use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
       alias                           Nagios Admin            ; Full name of user

       email                           tecmint@tecmint.com     ; *** CHANGE THIS TO YOUR EMAIL ADDRESS ****
       }

Step 6: Install and Configure Web Interface for Nagios

We are done with all configuration in the backend, now we will configure Web Interface For Nagios with following command. The below command will Configure Web interface for Nagios and a web admin user will be created “nagiosadmin”.

[root@tecmint nagios-4.0.1 ]# make install-webconf

In this step, we will be creating a password for “nagiosadmin”. After executing this command, please provide a password twice and keep it remember because this password will be used when you login in the Nagios Web interface.

[root@tecmint nagios-4.0.1]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Restart Apache to make the new settings take effect.

[root@tecmint ]# service httpd start         (On RedHat / CentOS)

Step 7: Compile and Install Nagios Plugin

We have downloaded nagios plugins in /root/nagios, Go there and configure and install it as directed below.

[root@tecmint nagios]# cd /root/nagios
[root@tecmint nagios]# cd nagios-plugins-1.5
[root@tecmint nagios]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@tecmint nagios]# make
[root@tecmint nagios]# make install

Step 8: Verify Nagios Configuration Files

Now we are all done with Nagios configuration and its time to verify it and to do so please insert following command. If everything goes smooth it will show up similar to below output.

[root@tecmint nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Sample Output

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

*** Nagios/Apache conf file installed ***

 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
...
...
Total Warnings: 0
Total Errors:   0

Step 9: Add Nagios Services to System Start-up

To make Nagios work across reboots, we need to add nagios and httpd with chkconfig command.

[root@tecmint ]# chkconfig --add nagios
[root@tecmint ]# chkconfig --level 35 nagios on
[root@tecmint ]# chkconfig --add httpd
[root@tecmint ]# chkconfig --level 35 httpd on

Restart Nagios to make the new settings take effect.

[root@tecmint ]# service nagios start (On RedHat / CentOS)

Step 10: Login to the Nagios Web Interface
Your nagios is ready to work, please open it in your browser with “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and Provide the username “nagiosadmin” and password.
------------------------------------------------------------------------------------------------------------------------------

Saturday, May 24, 2014

LOGIN TO LINUX SERVER THROUGH WEB BROWSER

HOW  TO ACCESS YOUR LINUX SERVER FROM WEB BROWSER 

System Administrator usually use SSH to remote his Linux servers. So he might need a SSH client to do that. If he use a Linux client, his Linux might already have SSH client installed. If he use Windows client, one of the most popular SSH client is Putty.

What is shellinabox
-----------------------------
Shellinabox is a web based terminal that uses Ajax technology to provide the look and feel of a native shell. Using this, as long as your device have a browser, you can remote to your Linux server.

Installation &  Configuration 
---------------------------------------
 To install the 'Shellinabox' go though the bellow url and step

 step 1. access this below mentioned url

 url :-   http://pkgs.org/centos-6/epel-i386/shellinabox-2.14-24.git88822c1.el6.i686.rpm.html

 step 2. click on package - Binary package:

shellinabox-2.14-24.git88822c1.el6.i686.rpm     ( Note :- this package is for 32bits CentOS, you can find same url 64 bits also)

step 3. after download the package from site run the below command. 

#rpm  -ivh  shellinabox-2.14-24.git88822c1.el6.i686.rpm 

step 4. Once 'shellinabox' installed, you need to make sure that shellinabox daemon is running.

#service  shellinaboxd restart [ simply restart the service]

OR
# /etc/init.d/shellinaboxd start    

setp 5. On the service permanently through "chkconfig" command.

#chkconfig  shellinaboxd   --list [ to check that service is on or not ]

#chkconfig shellinaboxd  on [ to on the service permanently ]

setp 6. By default, shellinabox is using port 4200. If you want to change it, you can configure shellinabox configuration file.

#vim /etc/sysconfig/shellinaboxd    [ go into this file and the port name what you want to keep - by default is 4200]

#Basic options
USER=shellinabox
GROUP=shellinabox
CERTDIR=/var/lib/shellinabox
PORT=4200
OPTS="--disable-ssl-menu -s /:LOGIN"

( change the port number and save the file ) 

Note:- After changing the port number  do restart the service

#service  shellinabox restart

step 7. When everything is set, then its time to try shellinabox. You can point your browser to the server. Just type

 https://server_ip_address:4200 

Exp. - https://172.16.0.1:4200 

login : tom
passwd :


Note:- login through local user than you can switch to root user
-----------------------------------------------------------------

Friday, May 23, 2014

REMOTE BACKUP OR SYNCRONIZATION OF LINUX SERVER


Remote Backup 
=============
15 rsync command examples: Every sysadmin should master the usage of rsync. rsync utility is used to synchronize the files and directories from one location to another. First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast.

rsync stands for remote sync.
******************************

rsync is used to perform the backup operation in UNIX / Linux.

rsync utility is used to synchronize the files and directories from one location to another in an effective way. Backup location could be on local server or on remote server.

Important features of rsync

Speed: First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast.
Security: rsync allows encryption of data using ssh protocol during transfer.
Less Bandwidth: rsync uses compression and decompression of data block by block at the sending and receiving end respectively. So the bandwidth used by rsync will be always less compared to other file transfer protocols.
Privileges: No special privileges are required to install and execute rsync
Syntax

$ rsync options source destination

Source and destination could be either local or remote. In case of remote, specify the login name, remote server name and location.

Example 1. Synchronize Two Directories in a Local Server
-----------------------------------------------------------------

To sync two directories in a local computer, use the following rsync -zvr command.

$ rsync -zvr /var/opt/installation/inventory/ /root/temp

building file list ... done
sva.xml
svB.xml
.
sent 26385 bytes  received 1098 bytes  54966.00 bytes/sec
total size is 44867  speedup is 1.63
$
In the above rsync example:

-z is to enable compression
-v verbose
-r indicates recursive
Now let us see the timestamp on one of the files that was copied from source to destination. As you see below, rsync didn’t preserve timestamps during sync.

$ ls -l /var/opt/installation/inventory/sva.xml /root/temp/sva.xml

-r--r--r-- 1 bin  bin  949 Jun 18  2009 /var/opt/installation/inventory/sva.xml
-r--r--r-- 1 root bin  949 Sep  2  2009 /root/temp/sva.xml

Example 2. Preserve timestamps during Sync using rsync -a
-------------------------------------------------------
rsync option -a indicates archive mode. -a option does the following,

Recursive mode
Preserves symbolic links
Preserves permissions
Preserves timestamp
Preserves owner and group
Now, executing the same command provided in example 1 (But with the rsync option -a) as shown below:

$ rsync -azv /var/opt/installation/inventory/ /root/temp/
building file list ... done
./
sva.xml
svB.xml
.
sent 26499 bytes  received 1104 bytes  55206.00 bytes/sec
total size is 44867  speedup is 1.63
$
As you see below, rsync preserved timestamps during sync.

$ ls -l /var/opt/installation/inventory/sva.xml /root/temp/sva.xml
-r--r--r-- 1 root  bin  949 Jun 18  2009 /var/opt/installation/inventory/sva.xml
-r--r--r-- 1 root  bin  949 Jun 18  2009 /root/temp/sva.xml


Example 3. Synchronize Only One File
---------------------------------------------------------
To copy only one file, specify the file name to rsync command, as shown below.

$ rsync -v /var/lib/rpm/Pubkeys /root/temp/
Pubkeys

sent 42 bytes  received 12380 bytes  3549.14 bytes/sec
total size is 12288  speedup is 0.99


Example 4. Synchronize Files From Local to Remote
----------------------------------------------------------------
rsync allows you to synchronize files/directories between the local and remote system.

$ rsync -avz /root/temp/ thegeekstuff@192.168.200.10:/home/thegeekstuff/temp/
Password:
building file list ... done
./
rpm/
rpm/Basenames
rpm/Conflictname

sent 15810261 bytes  received 412 bytes  2432411.23 bytes/sec
total size is 45305958  speedup is 2.87
While doing synchronization with the remote server, you need to specify username and ip-address of the remote server. You should also specify the destination directory on the remote server. The format is username@machinename:path

As you see above, it asks for password while doing rsync from local to remote server.

Sometimes you don’t want to enter the password while backing up files from local to remote server. For example, If you have a backup shell script, that copies files from local to remote server using rsync, you need the ability to rsync without having to enter the password.

To do that, setup ssh password less login as we explained earlier.


Example 5. Synchronize Files From Remote to Local
------------------------------------------------
When you want to synchronize files from remote to local, specify remote path in source and local path in target as shown below.

$ rsync -avz thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp
Password:
receiving file list ... done
rpm/
rpm/Basenames
.
sent 406 bytes  received 15810230 bytes  2432405.54 bytes/sec
total size is 45305958  speedup is 2.87

Example 6. Remote shell for Synchronization
------------------------------------------------------------------
rsync allows you to specify the remote shell which you want to use. You can use rsync ssh to enable the secured remote connection.

Use rsync -e ssh to specify which remote shell to use. In this case, rsync will use ssh.

$ rsync -avz -e ssh thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp
Password:
receiving file list ... done
rpm/
rpm/Basenames

sent 406 bytes  received 15810230 bytes  2432405.54 bytes/sec
total size is 45305958  speedup is 2.87

Example 7. Do Not Overwrite the Modified Files at the Destination
-----------------------------------------------------------------

In a typical sync situation, if a file is modified at the destination, we might not want to overwrite the file with the old file from the source.

Use rsync -u option to do exactly that. (i.e do not overwrite a file at the destination, if it is modified). In the following example, the file called Basenames is already modified at the destination. So, it will not be overwritten with rsync -u.

$ ls -l /root/temp/Basenames
total 39088
-rwxr-xr-x 1 root root        4096 Sep  2 11:35 Basenames

$ rsync -avzu thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp
Password:
receiving file list ... done
rpm/

sent 122 bytes  received 505 bytes  114.00 bytes/sec
total size is 45305958  speedup is 72258.31

$ ls -lrt
total 39088
-rwxr-xr-x 1 root root        4096 Sep  2 11:35 Basenames

Example 8. Synchronize only the Directory Tree Structure (not the files)
---------------------------------------------------------------
Use rsync -d option to synchronize only directory tree from source to the destination. The below example, synchronize only directory tree in recursive manner, not the files in the directories.

$ rsync -v -d thegeekstuff@192.168.200.10:/var/lib/ .
Password:
receiving file list ... done
logrotate.status
CAM/
YaST2/
acpi/

sent 240 bytes  received 1830 bytes  318.46 bytes/sec
total size is 956  speedup is 0.46

Example 9. View the rsync Progress during Transfer
-------------------------------------------------
When you use rsync for backup, you might want to know the progress of the backup. i.e how many files are copies, at what rate it is copying the file, etc.

rsync –progress option displays detailed progress of rsync execution as shown below.

$ rsync -avz --progress thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/
Password:
receiving file list ...
19 files to consider
./
Basenames
     5357568 100%   14.98MB/s    0:00:00 (xfer#1, to-check=17/19)
Conflictname
       12288 100%   35.09kB/s    0:00:00 (xfer#2, to-check=16/19)
.
.
.
sent 406 bytes  received 15810211 bytes  2108082.27 bytes/sec
total size is 45305958  speedup is 2.87
You can also use rsnapshot utility (that uses rsync) to backup local linux server, or backup remote linux server.


Example 10. Delete the Files Created at the Target
-------------------------------------------------

If a file is not present at the source, but present at the target, you might want to delete the file at the target during rsync.

In that case, use –delete option as shown below. rsync delete option deletes files that are not there in source directory.

# Source and target are in sync. Now creating new file at the target.
$ > new-file.txt

$ rsync -avz --delete thegeekstuff@192.168.200.10:/var/lib/rpm/ .
Password:
receiving file list ... done
deleting new-file.txt
./

sent 26 bytes  received 390 bytes  48.94 bytes/sec
total size is 45305958  speedup is 108908.55
Target has the new file called new-file.txt, when synchronize with the source with –delete option, it removed the file new-file.txt


Example 11. Do not Create New File at the Target
-----------------------------------------------

If you like, you can update (Sync) only the existing files at the target. In case source has new files, which is not there at the target, you can avoid creating these new files at the target. If you want this feature, use –existing option with rsync command.

First, add a new-file.txt at the source.

[/var/lib/rpm ]$ > new-file.txt
Next, execute the rsync from the target.

$ rsync -avz --existing root@192.168.1.2:/var/lib/rpm/ .
root@192.168.1.2's password:
receiving file list ... done
./

sent 26 bytes  received 419 bytes  46.84 bytes/sec
total size is 88551424  speedup is 198991.96
If you see the above output, it didn’t receive the new file new-file.txt

Example 12. View the Changes Between Source and Destination
----------------------------------------------------------

This option is useful to view the difference in the files or directories between source and destination.

At the source:

$ ls -l /var/lib/rpm
-rw-r--r-- 1 root root  5357568 2010-06-24 08:57 Basenames
-rw-r--r-- 1 root root    12288 2008-05-28 22:03 Conflictname
-rw-r--r-- 1 root root  1179648 2010-06-24 08:57 Dirnames
At the destination:

$ ls -l /root/temp
-rw-r--r-- 1 root root    12288 May 28  2008 Conflictname
-rw-r--r-- 1 bin  bin   1179648 Jun 24 05:27 Dirnames
-rw-r--r-- 1 root root        0 Sep  3 06:39 Basenames
In the above example, between the source and destination, there are two differences. First, owner and group of the file Dirname differs. Next, size differs for the file Basenames.

Now let us see how rsync displays this difference. -i option displays the item changes.

$ rsync -avzi thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/
Password:
receiving file list ... done
>f.st.... Basenames
.f....og. Dirnames

sent 48 bytes  received 2182544 bytes  291012.27 bytes/sec
total size is 45305958  speedup is 20.76
In the output it displays some 9 letters in front of the file name or directory name indicating the changes.

In our example, the letters in front of the Basenames (and Dirnames) says the following:

> specifies that a file is being transferred to the local host.
f represents that it is a file.
s represents size changes are there.
t represents timestamp changes are there.
o owner changed
g group changed.

Example 13. Include and Exclude Pattern during File Transfer
-----------------------------------------------------------

rsync allows you to give the pattern you want to include and exclude files or directories while doing synchronization.

$ rsync -avz --include 'P*' --exclude '*' thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/
Password:
receiving file list ... done
./
Packages
Providename
Provideversion
Pubkeys

sent 129 bytes  received 10286798 bytes  2285983.78 bytes/sec
total size is 32768000  speedup is 3.19
In the above example, it includes only the files or directories starting with ‘P’ (using rsync include) and excludes all other files. (using rsync exclude ‘*’ )


Example 14. Do Not Transfer Large Files
------------------------------------------------------------

You can tell rsync not to transfer files that are greater than a specific size using rsync –max-size option.

$ rsync -avz --max-size='100K' thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/
Password:
receiving file list ... done
./
Conflictname
Group
Installtid
Name
Sha1header
Sigmd5
Triggername

sent 252 bytes  received 123081 bytes  18974.31 bytes/sec
total size is 45305958  speedup is 367.35
max-size=100K makes rsync to transfer only the files that are less than or equal to 100K. You can indicate M for megabytes and G for gigabytes.


Example 15. Transfer the Whole File
-------------------------------------------------------

One of the main feature of rsync is that it transfers only the changed block to the destination, instead of sending the whole file.

If network bandwidth is not an issue for you (but CPU is), you can transfer the whole file, using rsync -W option. This will speed-up the rsync process, as it doesn’t have to perform the checksum at the source and destination.

#  rsync -avzW  thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp
Password:
receiving file list ... done
./
Basenames
Conflictname
Dirnames
Filemd5s
Group
Installtid
Name

sent 406 bytes  received 15810211 bytes  2874657.64 bytes/sec
total size is 45305958  speedup is 2.87
===========================================================

HOW TO BACKUP OF LINUX SERVER


1. BACKUP OF THE DRIVE. 

 Disk to disk backup using "dd" command: 
********************************************************
"dd" is a powerful UNIX utility, which is used by the Linux kernel makefiles to make boot images. It can also be used to copy data. This blog explains how to backup entire hard disk and create an image of a hard disk using dd command.

*Data loss will be costly. At the very least, critical data loss will have a financial impact on companies of all sizes. In some cases, it can cost your job. I’ve seen cases where sysadmins learned this in the hard way.

There are several ways to backup a Linux system, including rsync and rsnapshot that we discussed a while back.

*This article provides 6 practical examples on using dd command to backup the Linux system. dd is a powerful UNIX utility, which is used by the Linux kernel makefiles to make boot images. It can also be used to copy data. Only superuser can execute dd command.

Warning: While using dd command, if you are not careful, and if you don’t know what you are doing, you will lose your data!

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, we can create an image file of the hard disk and save it in other storage devices.There are many advantages to backing up our 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.

OR

The dd command is a useful tool for copying one entire hard drive to another. This can be helpful if we want to move your entire computer system to a new hard drive. The trick is making sure you know which drive we are copying from and which drive we are copying to. There is no recovering your data if you accidentally copy an empty drive to your system drive. It will overwrite all your information.

The Process

Here are some commands and tools that we will want to use:

df -h  (this will show you your drives and the disk free space)
dd if=/dev/sdb of=/dev/sdc (important: sdb and sdc are examples you will need to know what your specific drives are )

We can also use dd to create image backup 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

Restore:

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.

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

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.
- See more at: http://www.linuxtechtips.com/2013/11/backup-harddisk-using-dd-command.html#sthash.19pThjAH.dpuf
-----------------------------------------------------------------
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.
===========================================================

Monday, May 12, 2014

How to create ISO image from CD/DVD

Create ISO image from CD/DVD through command mode
=================================================
1. Steps to follow
----------------------------
(I).Create an ISO image from optical media
In this example, we're going to copy the contents of a disk in the CD/DVD drive (/dev/cdrom) to an ISO image file. Open a terminal window and type the following at the command line.

#dd if=/dev/cdrom of=/directory/example.iso

Notations:
- dd is the program used to convert and copy a file.
- if defines an input file.
- of defines an output file.
- iso is the resulting ISO image file.

(II).Create an ISO image from files in a directory
To create an ISO image from files within a directory is just as simple. State an output directory and name of the ISO to create, along with a source directory. For example:

#mkisofs -o /home/linuxlookup/example.iso /source/directory/

2. Steps to follow
-------------------
 Linux makes it easy to create an ISO image from your CD or DVD.

1. Insert the CD or DVD that you want to make an ISO image of.

2. Open a terminal window.

3. Execute the following command:

#cat /dev/scd0 > /home/shamanstears/test.iso

where /dev/scd0 is the device name for your drive (to find this, go to the Main Menu, click on System, mouseover Administration and select System Monitor. Click the File Systems tab. The device name will be listed in the Device column). Also make sure to change the path and iso filename to the desired path and filename.

The disc will begin to spin and the ISO image will start being constructed. Once it has completed, you have an ISO image of your CD. To verify that the image was properly created, mount the ISO file and check the contents.
-----------------------------------------------------------------

VMware-Player Configuration on CentOS

*How to Install & Uninstall VMware-Player

1.To install vmware on CentOS6.5

Step (I).Download the package from url - > https://my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_player/5_0

Step(II).Change permission of the VMware Player installation file using the command below

#chmode  777  VMware-Player-5.0.1-894247.i386.bundle

Step(II).Execute command below to install VMware Player

#./VMware-Player-5.0.1-894247.i386.bundle
-----------------------------------------------------------------
2.To Uninstall the VMware Player 

Step (I).To remove the vmware and want to keep the configuration run this command.

#/usr/bin/vmware-installer  -u   vmware-player
-----------------------------------------------------------------

Wednesday, March 12, 2014

CONFIGURATION OF VNC-SERVER


  Step by Step Configuration of VNC server
-------------------------------------------------
Step (1) Install the package of vncserver

# [root@server ~]#yum install tigervnc-server* -y



# [root@server ~]#chkconfig vncserver restart

Monday, February 24, 2014

Lnux file system and directory structure for RHCE


Overview of the FHS
Everything in Linux can be reduced to a file. Partitions are associated with files such as /dev/hda1. Hardware components are associated with files such as /dev/modem. Detected devices are documented as files in the /proc directory. The Filesystem Hierarchy Standard (FHS) is the official way to organize files in Unix and Linux directories.

Linux file system and directory structure
Several major directories are associated with all modern Unix/Linux operating systems. These directories organize user files, drivers, kernels, logs, programs, utilities, and more into different categories. The standardization of the FHS makes it easier for users of other Unix-based operating systems to understand the basics of Linux. Every FHS starts with the root directory, also known by its label, the single forward slash (/). All of the other directories shown in Table are subdirectories of the root directory. Unless they are mounted separately, you can also find their files on the same partition as the root directory.

/ -  The root directory, the top-level directory in the FHS. All other directories are subdirectories of root, which is always mounted on some partition. All directories that are not mounted on a separate partition are included in the root directory?s partition.
/bin - Essential command line utilities. Should not be mounted separately; otherwise, it could be difficult to get to these utilities when using a rescue disk.
/boot - Includes Linux startup files, including the Linux kernel. Can be small; 16MB is usually adequate for a typical modular kernel. If you use multiple kernels, such as for testing a kernel upgrade, increase the size of this partition accordingly.
/etc - Most basic configuration files.
/dev - Hardware and software device drivers for everything from floppy drives to terminals. Do not mount this directory on a separate partition.
/home -  Home directories for almost every user.
/lib -  Program libraries for the kernel and various command line utilities. Do not mount this directory on a separate partition.
/mnt  - The mount point for removable media, including floppy drives, CD-ROMs, and Zip disks.
/opt -  Applications such as WordPerfect or StarOffice.
/proc -  Currently running kernel-related processes, including device assignments such as IRQ ports, I/O addresses, and DMA channels.
/root -  The home directory of the root user.
/sbin -  System administration commands. Don't mount this directory separately.
/tmp  -  Temporary files. By default, Red Hat Linux deletes all files in this directory periodically.
/usr Small programs accessible to all users. Includes many system administration commands and utilities.

/var Variable data, including log files and printer spools.

Types of Files Used by Linux
When working with Linux, you need to be aware of the fact that there are a number of different file types used by the file system. This is another area where the Linux file system differs significantly from the Windows file system. With a Windows file system you basically have two entry types in the file system:
>Directories
>Files
Granted, you can have normal files, hidden files, shortcut files, word processing files, executable files, and so on. However, these are all simple variations of the basic file when working with Windows.
With Linux, however, there are a variety of different file types used by the file system. These include the file types shown in Table

File Type                                          Description
-------------                                --------------------      
Regular files  - These files are similar to those used by the file systems of other operating systems—for example, executable files, OpenOffice.org files, images, text configuration files, etc.
Links  - These files are pointers that point to other files in the file system.
FIFOs  - FIFO stands for First In First Out. These are special files used to move data from one running process on the system to another. A FIFO file is basically a queue where the first chunk of data added to the queue is the first chunk of data removed from the queue. Data can only move in one direction through a FIFO.
Sockets - Sockets are similar to FIFOs in that they are used to transfer information between sockets. With a socket, however, data can move bi-directionally.                           

File Function 
-----------                               -------------------
/etc/fstab Listthe partions and file systems that will be automatically mounted when the system boots.
/etc/group Contains local group definitions.
/etc/grub.conf Contains configuration parameters for the GRUB bootloader (assuming it's being used on the system).
/etc/hosts Contains a list of hostname-to-IP address mappings the system can use to resolve hostnames.
/etc/inittab Contains configuration parameters for the init process.
/etc/init.d/ A subdirectory that contains startup scripts for services installed on the system. On a Fedora or Red Hat system, these are located in /etc/rc.d/init.d.
/etc/modules.conf Contains configuration parameters for your kernel modules.
/etc/passwd Contains your system user accounts.
/etc/shadow Contains encrypted passwords for your user accounts.
/etc/X11/ Contains configuration files for X Windows.
------------------------------------------------------------------------------------------------------------

Sunday, February 23, 2014

NAME OF THE SERVICES

All services
----------------------------------
1.NIS
2.BRIDGE
3.YUM-SERVER
4.SYSLOG-SERVER
5.PRINTER-SERVER
6.VNC-SERVER
7.Sendmail-Server
8.LDAP-Server
9.Kistart-Server
10.LVM
11.RAID
12.ISCSI-Server
13.IPTables
14.DHCP
15.FTP
16.NFS
17.DNS
18.SAMBA
19.HTTP/Apache
20.Squid/Proxy
21.Telnet
22.SSH
23.NTP
-------------------------------------------------------------------------------------------