Tuesday, January 8, 2013

Step by Step guide to Create and manage Logical Volume Manager in Redhat


Logical Volume Manager Configuration
Step by Step guide to Create and manage Logical Volume Manager in Redhat Linux.

1. Creating an LVM Logical Volume on Three Disks (or more if you have available).
2. Creating a Striped Logical Volume
3. Splitting a Volume Group
4. Removing a Disk from a Logical Volume


1. Creating an LVM Logical Volume on Three Disks.
Plan:
logical volume name: new_logical_volume
Disks: /dev/sda1, /dev/sdb1, and /dev/sdc1
partition type: Linux LVM which is 8e.

Warning: Verify that disks does not contain any important data.

a. Creating the Physical Volumes
# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1
# pvdisplay # command to display physical volume detail.

Note: Each physical volume has a UUID.

b. Creating the Volume Group
# vgcreate new_vol_group /dev/sda1 /dev/sdb1 /dev/sdc1
# vgs or # Displays new volume group attributes
# vgdisplay volume_name

Note: volume group name is new_vol_group

c. Creating the Logical Volume
# lvcreate -L 2G -n new_logical_volume new_vol_group  # Creates 2 GB Logical volume
# lvcreate -L 3GB -n mylvvol new_vol_group # Creates 3 GB Logical volume
# lvdisplay # Displays Logical Volume attributes.

Here, L flag is sued to size while n flag is for new logical volume name.
Note: creates 2gb of logical volume new_logical_volume from the volume group new_vol_group.
You can create multiple logical volumes on a single volume group.

d. Creating the File System using mkfs command.
# mkfs.gfs2 -p lock_nolock -j 1 /dev/new_vol_group/new_logical_volume or
# mkfs.ext4 /dev/new_vol_group/new_logical_volume

Note: You can use mke2fs, mkfs.ext3, mkfs.ext4 commands with different options.

e. mount the logical volume
# mount /dev/new_vol_group/new_logical_volume /mnt

f. Add entry to /etc/fstab to be mounted across the reboot.

g. Resize the logical volume to expand or shrink the filesystem.
# lvresize -L 5GB /dev/new_vol_group/new_logical_volume
# resize2fs /dev/new_vol_group/new_logical_volume 5G
# lvresize -L 3GB /dev/new_vol_group/new_logical_volume
# resize2fs /dev/new_vol_group/new_logical_volume 3G

Note: To shrink you have to unmount the filesystem. To resize with new storage space added, use resize2fs command. The filessytem must be ext3 and up to resize the volume.

# resize2fs /dev/new_vol_group/new_logical_volume 5G

h. Remove the logical volume
# lvremove /dev/new_vol_group/new_logical_volume

i. Rename Logical Volume
# lvrename new_vol_group new_logical_volume my_logical_volume
# lvresize -L 10GB /dev/new_vol_group/my_logical_volume

Note: Only renames logical Volume not the volume group.

j. Rename Volume Group.
# vgrename new_vol_group my_vol_group

Note: Once you rename Logical volume or the volume group, make sure to change your mount point and the /etc/fstab entry.


=================================================================

2. Creating a Striped Logical Volume
Plan:
LVM striped logical volume: striped_logical_volume
Disk for stripping: /dev/sda1, /dev/sdb1, and /dev/sdc1

Warning: Any data on the disk will be lost.

a. Creating the Physical Volumes
# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1

b. Creating the Volume Group
# vgcreate volgroup01 /dev/sda1 /dev/sdb1 /dev/sdc1

Verify the volume group attributes,
# vgs

c. Creating the Logical Volume
# lvcreate -i3 -I4 -L2G -n striped_logical_volume volgroup01

The command creates striped logical volume striped_logical_volume with 2 gigabytes in size, with three stripes and a stripe size of 4 kilobytes from the volume group volgroup01.

d. Creating the File System
# mkfs.gfs2 -plock_nolock -j 1 /dev/volgroup01/striped_logical_volume

e. Mount the filesystem.
# mount /dev/volgroup01/striped_logical_volume /mnt
# df -h /mnt

3. Splitting a Volume Group
Plan:
modify ?? below...
If there is enough unused space on the physical volumes, a new volume group can be created without adding new disks.

In the initial set up, the logical volume mylv is carved from the volume group myvol, which in turn consists of the three physical volumes, /dev/sda1, /dev/sdb1, and /dev/sdc1.

After completing this procedure, the volume group myvg will consist of /dev/sda1 and /dev/sdb1. A second volume group, yourvg, will consist of /dev/sdc1.

a. Determining Free Space
determine how much free space is currently available in the volume group using pvscan
# pvscan - change the output. ..
  PV /dev/sda1  VG myvg   lvm2 [17.15 GB / 0    free]
  PV /dev/sdb1  VG myvg   lvm2 [17.15 GB / 12.15 GB free]
  PV /dev/sdc1  VG myvg   lvm2 [17.15 GB / 15.80 GB free]
  Total: 3 [51.45 GB] / in use: 3 [51.45 GB] / in no VG: 0 [0   ]

b. Moving the Data
You can move all the used physical extents in /dev/sdc1 to /dev/sdb1 with the pvmove command. The pvmove command can take a long time to execute.

# pvmove /dev/sdc1 /dev/sdb1

Verify that the space on /dev/sdc1 is free using the pvscan command.
# pvscan
  PV /dev/sda1   VG myvg   lvm2 [17.15 GB / 0    free]
  PV /dev/sdb1   VG myvg   lvm2 [17.15 GB / 10.80 GB free]
  PV /dev/sdc1   VG myvg   lvm2 [17.15 GB / 17.15 GB free]
  Total: 3 [51.45 GB] / in use: 3 [51.45 GB] / in no VG: 0 [0   ]

c. Splitting the Volume Group

Using vfsplit command you can create new volume group yourvg, to split the volume group myvg.

Make sure your logical volume is inactive. If there are any mounts, unmount before deactiviting the logical volume.

Use lvchange or vgchange command to deactivate the logical volume.

# lvchange -a n /dev/myvg/mylv
# vgsplit myvg yourvg /dev/sdc1

The above command deactivates the logical volume mylv and splits the volume group yourvg from volume group myvg, moving physical volume /etc/sdc1 into new volume group yourvg.


Verify the volume group attributes.
# vgs


d. Creating the New Logical Volume
Now, create new logical volume yourlv after creating the new volume group.
# lvcreate -L5G -n yourlv yourvg

e. Create a File System and mount the New Logical Volume
#  mkfs.gfs2 -plock_nolock -j 1 /dev/yourvg/yourlv

f. Activating and Mounting the Original Logical Volume
# lvchange -a y mylv
# mount /dev/myvg/mylv /mnt
# df


4. Removing a Disk from a Logical Volume
You can remove a disk from existing logical volume to use the disk for other volume or to replace the failed disk. To process, you must have to move the extents on the LVM physical volume to a different disk or the set of disks.

A. Moving Extents to Existing Physical Volumes
Plan:
We have a logical volume that is distributed across four physical volumes in the volume group myvg.
a.
# pvs -o+pv_used
  PV         VG   Fmt  Attr PSize  PFree  Used
  /dev/sda1  myvg lvm2 a-   17.15G 12.15G  5.00G
  /dev/sdb1  myvg lvm2 a-   17.15G 12.15G  5.00G
  /dev/sdc1  myvg lvm2 a-   17.15G 12.15G  5.00G
  /dev/sdd1  myvg lvm2 a-   17.15G  2.15G 15.00G

We want to move the extents off of /dev/sdb1 so that we can remove it from the volume group.
You need to have free extents on other physical volumes in volume group. The extents will be distributed to the other devices.

# pvmove /dev/sdb1
  /dev/sdb1: Moved: 2.0%
 ...
  /dev/sdb1: Moved: 79.2%
 ...
  /dev/sdb1: Moved: 100.0%

Check the distribution of extents using pvs command.
# pvs -o+pv_used

b. Remove the physical volume /dev/sdb1 from the volume group using vgreduce command.
# vgreduce myvg /dev/sdb1
# pvs

Now, disk can be physically remove or use for other purpose.

B. Moving Extents to a New Disk
Plan:
The logical volume is distributed across three physical volumes in the volume group myvg as follows:
# pvs -o+pv_used
  PV         VG   Fmt  Attr PSize  PFree  Used
  /dev/sda1  myvg lvm2 a-   17.15G  7.15G 10.00G
  /dev/sdb1  myvg lvm2 a-   17.15G 15.15G  2.00G
  /dev/sdc1  myvg lvm2 a-   17.15G 15.15G  2.00G

We want to move the extents of /dev/sdb1 to a new device, /dev/sdd1.

a. Creating the New Physical Volume

scenario: Create a new physical volume from /dev/sdd1.

# pvcreate /dev/sdd1

b. Adding the New Physical Volume to the Volume Group
# vgextend myvg /dev/sdd1
# pvs -o+pv_used

c. Moving the Data
Use the pvmove command to move the data from /dev/sdb1 to /dev/sdd1.

# pvmove /dev/sdb1 /dev/sdd1

# pvs -o+pv_used

d. Removing the Old Physical Volume from the Volume Group
After you have moved the data off /dev/sdb1, you can remove it from the volume group.
# vgreduce myvg /dev/sdb1

Based on the online doc @redhat....

http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html-single/Logical_Volume_Manager_Administration/index.html#troubleshooting

How to limit unauthorized access to grub.conf file.



How to limit unauthorized access to grub.conf file.

If you want to protect illegal access to grub.conf file and unauthorized password change or reboot, you can protect the grub.conf file with encrypted password. Use the encrypted password generated by grub-md5-crypt.

1. Generate md5 password.

# /sbin/grub-md5-crypt
Password:
Retype password:
$1$7CzLO0$r4wIx9cb2TN3aTiPvjwaH1
[root@durava ~]#

2. Add md5 password just generated to the grub.conf file right after splashimage entry.
password --md5 $1$7CzLO0$r4wIx9cb2TN3aTiPvjwaH1

==========================================

# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,0)
#          kernel /boot/vmlinuz-version ro root=/dev/sda1
#          initrd /boot/initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
password --md5 $1$7CzLO0$r4wIx9cb2TN3aTiPvjwaH1
title Red Hat Enterprise Linux Server (2.6.18-238.9.1.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-238.9.1.el5 ro root=LABEL=/ elevator=deadline audit=1
        initrd /initrd-2.6.18-238.9.1.el5.img
title Red Hat Enterprise Linux Server (2.6.18-238.5.1.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-238.5.1.el5 ro root=LABEL=/ audit=1
        initrd /initrd-2.6.18-238.5.1.el5.img
title Red Hat Enterprise Linux Server (2.6.18-194.26.1.el5)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.18-194.26.1.el5 ro root=LABEL=/ audit=1
        initrd /boot/initrd-2.6.18-194.26.1.el5.img
[root@sungava ~]#

Mount windows share on Linux/UNIX

Procedure to mount remote windows shared partition (the share) to Linux/Unix and adding it to fstab for permanent mount.

#Mount the sahre from Windows

mount -t cifs //compsrv302/oracle/developer/sam/out -o username=mytest,password=Welcome1 /d11/oracle/HYPUAT/hyperion/oradata/hyp_in
mount -t cifs //compsrv302/oracle/developer/sam/log -o username=mytest,password=Welcome1 /d11/oracle/HYPUAT/hyperion/oradata/hyp_log

# Add the following entry to the fstab

[BhusalK@compserv319 hyp_in]$ more /etc/fstab

//compsrv302/oracle/developer/sam/out    /d11/oracle/HYPUAT/hyperion/oradata/hyp_in    cifs    username=mytest,password=Welcome1    0    0
//compsrv302/oracle/developer/sam/log    /d11/oracle/HYPUAT/hyperion/oradata/hyp_log    cifs    username=mytest,password=Welcome1    0    0



[root@compserv303 samba]# cat smb.conf
[global]
        workgroup = mwaadev
;       netbios name = compserv303
        security = share
        load printers = No
        default service = global
        path = /home
        available = No
;       encrypt passwords = yes
;       server string = samba 3.0.33-3.7.el5
;       guest ok = yes
        guest account = mwaa_hyp
[oradata]
        writeable = yes
        admin users = root
        path = /d11/oracle/SYS/hyperion/oradata
;       force user = bidev
;       guest ok = yes
        available = yes
        browseable = yes

DNS notes

first record of the zone is source of authority..

usually prefix using @ sign folllowed by tab followed by IN internet type followed by SOA source of authority followed by domain in our case localhost followed by domain owner in our case root followed by open parenthesis for few settings...

@     IN SOA    localhost    root (
   
now just below SOA we define serial number yymmdd-01 followed by semicolum

        2010081801;    SERIAL number
        1D      ;    refresh => refresh rate is 1 day
        1H      ;    retry  ==> retry pperiod set to 1 hrs
        1W      ;    expiration ==>> how long zone period expires 1 week
        1D )      ;     min    86400 sec -->> min time some can hold this information.
       
// make sure to close the parenthesis. this all section is source of authority for a given zone now specify the name server

IN type record IN name server NS record  @ (means domain here in our case localhost)
IN     NS     @

now define the resource record. zone file should contain resource record..
resource record is defined by A (address resource record) points to the hosts so we use its ipaddress which is locahost ip address 127.0.0.1

now on reverse zone

we modify soa file just adding . on the domain like localhost. followed by root.localhost.

on the NS instead of @ we use the domain that is localhost.
on the A address record we use PTR pointer record followed by localhost.

==================

DNS record types

A ==>> COmmonly used to map hostnames to an ip address of the host
AAAA - ipv6 map hostnames to an ip address of the host
CNAME ==> Alias of one name to another.
MX =>> Maps a domain name to a list of message transfer agent (MTA) for that domain
NS => Delegates a DNS zone to use the given authoritative name server...
PTR => Pointer to a canonical name. use for reverse DNS lookup.

SOA =>> Start of authority=>>    Specifies anthoritative information about a DNS zone, including primary name server, e-mail of domain admin, domain serial number, timer related to refreshing the zone..

Incomplete note:

Sunday, January 6, 2013

How to reset redhat root password and change the default runlevel.


1. Turn on your machine and wait till you see the Grub menu with count down.
2. Press any key to interrupt the countdown.
3. Move your key pointer to the kernel with the use of arrow key.
4. Once kernel line is highlighted, press e to go to edit the configuration.
5. You will be at the end of the line right after "rhgb quiet". Type 1 after quiet and press enter.
if you want to get a detail diagnostic information, remove the quiet value.

6. Press b to boot the system. This will take you to single user mode with out supplying pw as a root user.
7. at the prompt use passwd command to reset the pw.
# passwd

Note: You will follow same procedure to troubleshoot your system. This is just an example to reset the pw.

If you want to change default run level, simple change the value on /etc/inittab file.
# cat /etc/inittab

id:3:initdefault:

here if you want to change from run level 3 to 5 simply change the value of 3 to 5.

id:5:initdefault:

Saturday, January 5, 2013

Filesystem parameters on Redhat

Filesystem parameters on Redhat

a. Check/Modify filesystem parameters
# tune2fs -l /dev/sda5
Note your UUID number or other different parameters.

b. Creating fs journal
# tune2fs -j /dev/sda3

c. Assign fs lebel
# tune2fs -L mylabel /dev/sda2
If you are using GUI disk utility, you will be able to add label on the GUI utility.

d. Specify the mount options. Note -o option will clear all other default options.
# tune2fs -o user_xattr,acl /dev/sda3

How to set up VNC server on redhat?

How to set up VNC server on redhat?

Environment
vncserver: Redhat 6.1; install tigervnc-server
vncclient: ubuntu 12.04; install gvncviewer/tightvnc

A. Install vnc server.
a. install tigetvnc-server from the DVD using rpm or yum.
b. once installation is completed, edit the file /etc/sysconfig/vncservers and add the following information.

VNCSERVERS="1:sam 2:hari"

here we have two users are allowed to use the vnc server DISPLAY session 1 and 2.
c. create vnc password for the user sam and hari. Login as each user and use vncpasswd to create the pw. do not use root to create the pw.

$ vncpasswd
enter the password and verify the pw for both users.
d. restart the vncserver.
# service vncserver status/start/restart.

Make sure your vncservers file has correct entry. if you have any typos, you will not be able to start or connect.

B. VNC Client install and connect to the server.

a. Install client packages
$ sudo apt-get install gvncviewer
$ sudo apt-get install tightvncserver [Note: this is server package ].




b. Connect to the server.
$ gvncviewer hari@192.168.10.155:2

just supply your password and your will be on your remove server using vnc.