Shashikant shah

Sunday, 30 September 2012

Bonding in RHEL-5.5

               bonding in REDHAT linux              


 Problem:
Configure the bond0 interface with the interface eth0 and eth1

Solution:

1) Create a bond0 interface file in the /etc/sysconfig/network directory.

   # vi /etc/sysconfig/network/ifcfg-bond0
           
   BONDING_MASTER='yes'
   BONDING_MODULE_OPTS='mode=1 miimon=100 use_carrier=0'
   BOOTPROTO='static'
   IPADDR='192.168.10.19'
   NETMASK='255.255.255.0'
   STARTMODE='onboot'
   USERCONTROL='no'
   BONDING_SLAVE0='bus-pci-0000:03:00.0'
   BONDING_SLAVE1='bus-pci-0000:03:00.1'

Note:BONDING_SLAVE” value is available in the ethernet configuration file as a parameter “_nm_name” and also “mode=1” indicates active-backup policy  ( mode=0 indicates Round-robin policy).

2)     configure both the ethernet interface eth0 and eth1 like below

#vi /etc/sysconfig/network/ifcfg-eth-id-xx:xx:xx:xx:xx:xx

            BOOTPROTO='none'
            STARTMODE='off'
            USERCONTROL='no'
                                        
3)     Restart the network service

            # service network restart

4)     To check the status of the bond0 interface use the below command

            # cat /proc/net/bonding/bond0




Enable Auto root Login -RHEL 5.4


#vi /etc/inittab

        Find the Below line,

    1:2345:respawn:/sbin/mingetty tty1

        Replace this line by below one,

    1:2345:respawn:/sbin/mingetty --autologin root --noclear tty1



        In terminal 1, root user gets automatically login in every restart. If you wants, enable autologin in the remaining terminals also with the same. 
 
Pess keys :- ctrl+alt+f1
 
Check terminal 1 :-
 
Press keys :- ctrl+alt+f2
 
check terminal 2 :-

               

Mount Windows Share in Linux :- RHEL5.5


              Mount Windows Share in Linux

Release:
RedHat Enterprise Linux
SUSE Linux
AIX 5.3
Windows Server 2003
Problem:
Need to mount the windows share in the Linux Server using the CIFS.
Solution:
RHEL:

  Mount Windows partition in RHEL using the below command 

 # mount -t cifs -o username=administrator,password='XXXXXX' //172.16.1.50/files /mnt

By default windows share mounted with the full permission (777) in Linux. If u want to change the default permission use the “dir_modeand “file_modeoptions to set directory and file permission.

# mount -t cifs -o username=administrator,password='XXXXXX',dir_mode=0755,file_mode=0755 //172.16.1.50/files /mnt

Where,
/mnt – mount point name
//172.16.1.50/files – share folder name with server IP address

SUSE Linux:

Mount windows partition in SUSE Linux using the below command

# mount -t smbfs -o username=administrator,password='XXXXXX' //172.16.1.50/files /mnt

AIX:

Mount the windows partition in AIX using the below command 

# mount -v cifs -n serverip/username/password -o wrkgrp=domain,fmode=755 /sharename /localmountpoint

Example:
# mount -v cifs -n 172.16.1.50/administrator/XXXXXX -o wrkgrp=domainname,fmode=755 /files /mnt


Mount NTFS Partition in RHEL

 
Need to mount the Windows NTFS partition in RHEL 5
 
 
1)      Download the “ntfs-3g” and “fuse” packages from the below links.


2)      Install the ntfs-3g package by using the below commands
# tar –zxvf ntfs-3g-xxxx.tgz
# cd ntfs-3g-xxxx
# ./configure
# make
# make install

3)      Install the fuse package by using the below commands
# tar –zxvf fuse-xxx.tar.gz
# cd fuse-xxx
# ./configure
# make
# make install
# modprobe fuse
4)      Now mount the ntfs partition using the below command
 
# mount –t ntfs-3g /dev/sdb1 /mnt
 
Note: Here /dev/sdb1 is a windows NTFS partition. Also here usage of fuse version is depend upon the kernel version.

Shrink EXT3 partition Without Losing Data -RHEL 5.5

Shrink EXT3 partition Without Losing Data


Problem:

Resize the ext3 partition without losing data

Solution:

This article shows how to shrink the ext3 partition without losing data. This can be quite useful if you do not use LVM

Note: The partition that is to be resized must be unmounted when we do the resizing

Shrinking an ext3 Partition:

1) Check the disk usage of the server before proceeding

          # df –h

          Filesystem   Size       Used     Avail      Use%       Mounted on
          /dev/sda3    4.4G       2.4G     1.8G       58%          /
          /dev/sda1    99M        14M      80M        15%          /boot
          tmpfs       125M       0        125M        0%          /dev/shm

2) Boot the server into linux rescue mode

Note: If the partition you want to resize doesn't hold any system files, you can do everything from the original system; the steps are the same, just omit booting into rescue system

3) Run the filesystem-specific fsck on the filesystem.

               # fsck –n /dev/sda3

         e2fsck 1.39 (29-May-2006)
         /dev/sda3: clean, 115974/577152 files, 636274/1152640 blocks

4) Remove the journal from /dev/sda3, thus turning it into an ext2 partition

         # tune2fs -O ^has_journal /dev/sda3

         tune2fs 1.39 (29-May-2006)

5) Run fsck on the filesystem

         # e2fsck –f /dev/sda3

         e2fsck 1.39 (29-May-2006)
         Pass 1: Checking inodes, blocks, and sizes
         Pass 2: Checking directory structure
         Pass 3: Checking directory connectivity
         Pass 4: Checking reference counts
         Pass 5: Checking group summary information
         /dev/sda3: clean, 115974/577152 files (0.5% non-contiguous), 636274/1152640 blocks

6) Now resize the filesystem using resize2fs. resize2fs can resize ext2 file systems, but not ext3 file systems


         # resize2fs /dev/sda1 3600M

         resize2fs 1.39 (29-May-2006)
         Resizing the filesystem on /dev/sda3 to 921600 (4k) blocks.
         The filesystem on /dev/sda3 is now 921600 blocks long.

Please take note of the amount of blocks (921600) and their size (4k).


Note: Currently, 2.3 GB are used on /dev/sda3 (see the df -h output above), so it's safe to shrink it from 4.4GB to about 3.6GB (if you make it smaller than 2.3GB, you will lose data!).

7) Now we delete our /dev/sda1 partition (don't be afraid, no data will be lost) and create a new, smaller one (but still big enough to hold our resized file system!).

        # fdisk /dev/sda

        Command (m for help): d
        Partition number (1-4): 3
        Command (m for help): n
        Command action
        l logical (5 or over)
        p primary partition (1-4)
        p
        Partition number (1-4): 3
        First cylinder (79-652, default 79):
        Using default value 79
        Last cylinder or +size or +sizeM or +sizeK (79-652, default 652): +3870720K


        Command (m for help): w
        The partition table has been altered!
        Calling ioctl() to re-read partition table.
        Syncing disks.

Note: We multiply the amount of blocks from the resize2fs output (921600) by the size of a block (4k), and to go sure the partition is big enough, we add 3 to 5% to it (5% was enough for me, but if you want to go sure take 3%)

                   921600 * 4k * 1.05 = 3870720k

8) Now restart the server once and boot into the rescue mode once again

        # exit

9) Once again run the filesystem-specific fsck on the filesystem

        # fsck –n /dev/sda3


        fsck 1.39 (29-May-2006)
        e2fsck 1.39 (29-May-2006)
        /dev/sda3: clean, 115962/464928 files, 599592/921600 blocks

10) Now create the journal on our new /dev/sda3, thus turning it into an ext3 partition again

        # tune2fs -j /dev/sda3

        tune2fs 1.39 (29-May-2006)
        Creating journal inode: done
        This filesystem will be automatically checked every 25 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.


11) Now restart the server and boot from the harddisk.

# exit


Sync Data between Two Servers RHEL 5.5

        Sync Data between Two Servers 

 Assumption:

a) Source server ip address: 192.168.0.151

b) Destination server ip address: 192.168.0.152



Source server - The server we are connecting from to upload the data

Destination server - The server we are connecting to receive the data



Setting the SSH key authentication:


1) Make sure the Destination server have the ability to use key authentication enabled. In the sshd configuration file (usually ‘/etc/ssh/sshd_config’) enable the following options if they are not already set.

# vi /etc/ssh/sshd.conf

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile .ssh/authorized_keys



2) In Source server create the public / private key pair to used for authentication with the following command

# ssh-keygen -t rsa



Note: Do not enter a passphrase for this, just hit enter when prompted.

3) Now two files (public and private key) are created in the home directory of the user. If you are execute this as a root user means the files will be in,

# /root/.ssh/id_rsa.pub (public key file)

#/root/.ssh/id_rsa (private key file)



4) Now upload the public key to the Destination Server

# scp /root/.ssh/id_rsa.pub 192.168.0.152:/root/.ssh



Note: Be sure to keep this private key safe. With it anyone will be able to connect to the Destination Server that contains the public key.



5) In the Destination Server rename the public key file ( id_rsa.pub) to “authorized_keys”

# cd /root/.ssh

# mv id_rsa.pub authorized_keys



6) Change the file permission of that public key as well as ssh folder permission also

# chmod 600 /root/.ssh/authorized_keys

# chmod 700 /root/.ssh



7) Test the keys are working or not , by connecting the Destination Server from the Source Server

# ssh root@192.168.0.152


If all is working it should not be prompted for a password but instead connected directly to a shell on the Destination Server.



Creating rsync script:


8) Create one simple rsync script to sync both the servers and place it into the user’s home directory

# vi /root/rsync.sh

#!/bin/bash

SOURCEPATH=’/home’

DESTPATH=’/home’

DESTHOST=’192.168.0.152′

DESTUSER=’root’

LOGFILE=’rsync.log’

echo $’\n\n’ >> $LOGFILE

rsync -av –rsh=ssh $SOURCEPATH \ $DESTUSER@$DESTHOST:$DESTPATH 2>&1 >> $LOGFILE

echo “Completed at: `/bin/date`” >> $LOGFILE


Note: In this script 4 variables are used

SOURCEPATH - Source path to be synced

DESTPATH - Destination path to be synced

DESTHOST - Destination IP address or host name

DESTUSER - User on the destination server

The script will send all output to the ‘rsync.log’ file specified in the script



9) Give the executable permission for this script

# chmod 700 /root/rsync.sh



10) Now run the script and check, it is connect to the Destination Server, and transfer the files all without your interaction.


Setting up the cron job:

11) Setup a cron job to run the script automatically at a predefined interval.

# crontab –e

         0 * * * * /root/rsync.sh

This will run the script once in every hour. Your 2 servers should now be syncing the chosen directory once every hour.

Saturday, 22 September 2012

Parted Command

The parted utility is an alternative to fdisk. It can perform all the operations of fdisk, but it has additional functionality, such as resizing and copying partitions and creating file systems. The utility is called from the "root" user, passing the disk device as a parameter. Typing help at the prompt lists the commands available.
For additional information on a specific command, type help followed by the command.
(parted) help mklabel  
mklabel,mktable LABEL-TYPE create a new disklabel(partition table)

LABEL-TYPE is one of:aix,amiga,bsd,dvh,gpt,mac,msdos,pc98,sunloop
(parted)
When working with a new disk, the first thing we need to do is label the disk using the mklabel command displayed above. Oddly enough, we have to use the label type of "msdos" for Linux partitions.
(parted) mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted)
To check the free space on the drive using the print free command.
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type  File system  Flags
        32.3kB  10.7GB  10.7GB        Free Space

(parted)

Create a Partition

To create a new partition use the mkpart command. If the FS-TYPE parameter is specified, the system ID of the partition is set accordingly, but no file system is created. The following example uses mkpart to create a 2G partition with no file system on it.
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext4
Start? 1MB
End? 2GB
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  2000MB  1999MB  primary
        2000MB  10.7GB  8738MB           Free Space

(parted)
Notice the partition starts at "1MB". This is to leave space for the master boot record.
The mkpartfs command allows you to create a new partition with a file system, but when you try to use it you get a warning that the file system creation is not robust. For this reason, it should probably be avoided.

Delete a Partition

The rm command is used to delete a partition. It accepts the partition number as a parameter. The following example deletes the partition we just created.
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  2000MB  1999MB  primary
        2000MB  10.7GB  8738MB           Free Space

(parted) rm 1
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type  File system  Flags
        32.3kB  10.7GB  10.7GB        Free Space

(parted)

Boot Partitions

Boot partitions are created in a similar manner to regular partitions, but the boot flag is set using the toggle or set command after the partition is created, as shown below.
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext4
Start? 1MG
End? 500MB
(parted) toggle 1 boot
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  500MB   499MB   primary               boot
        500MB   10.7GB  10.2GB           Free Space

(parted)

Swap Partitions

Swap partitions are created in a similar manner to regular partitions, but the file system type is set to linux-swap. The example below creates a 2G swap partition after the boot partition created previously.
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? linux-swap
Start? 500MB
End? 2.5GB
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  500MB   499MB   primary               boot
 2      500MB   2500MB  2000MB  primary
        2500MB  10.7GB  8238MB           Free Space

(parted)

LVM Partitions

LVM partitions are created in a similar manner to regular partitions, but lvm flag is set using the toggle or set command after the partition is created, as shown below.
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext4
Start? 2.5GB
End? 10.7GB
(parted) toggle 3 lvm
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  500MB   499MB   primary               boot
 2      500MB   2500MB  2000MB  primary
 3      2500MB  10.7GB  8238MB  primary               lvm

(parted)

Wednesday, 12 September 2012

CHANGE USER HOME DIRECTORY

     We are changing home directory of shashi user


1. shashi (user name)

2. data (directory)

Create User

# useradd shashi

Check  default home directory path

# cat /etc/passwd | grep shashi

 shashi:x:501:501: :/home/shashi:/bin/bash

Create a directory

# mkdir /data

 Change user home directory path

# usermod -d /data shashi
 
 # cp -i /etc/skell/.* /data

Give to owner ship directory

# chown -R shashi:shashi /data

Check user dicectory path

# cat /etc/passwd | grep shashi

 shashi:x:501:501: :/data:/bin/bash

HOW TO CHANGE USRENAME


  1. shashi (new username)
  2. unicom (old username)

# usermod -d /home/shashi -m -l shashi unicom

# groupadd shashi ( Create a group for shashi )

# system-config-users (GUI interface)

# shashi (select user)


# Go to properties – Group – unselected unicom


# select shashi




# chown -R shashi:shashi /home/shashi ( change the Ownership )

# cat /etc/passwd | grep shashi

shashi:x:508:510::/home/shashi:/bin/bash