How to Change Date and Time Linux on RHEL 6/7 and CentOS 6/7

Change Date and Time

This post assumed that your Red Hat Enterprise Linux 6 (RHEL 6) does not have Date/Time Properties installed. In order to change the date and

In order to change date and time you will have to perform the changes from the command line. Note that in order to perform actions described in this post, you have to be logged in as a root:

1. Change the current date with the following form :

# date +%D -s YYYY-MM-DD

Linux Date Format : YYYY with a four-digit year, MM with a two-digit month, and DD with a two-digit day of the month.
Example :

# date +%D -s 2012-05-30
05/30/12

2. Change the current time with the following form :

# date +%T -s HH:MM:SS

If your system clock is set to use UTC (Coordinated Universal Time), add the following option :

# date +%T -s HH:MM:SS -u

Note : HH stands for an hour, MM is a minute, and SS is a second

Example :

# date +%T -s 22:30:00
22:30:00

or

[root@rhel6 ~]# date +%T -s 22:30:00 -u
22:30:00

3. How to Display current date and time :

[root@rhel6 ~]# date
Wed May 30 22:30:04 MYT 2012

Reference

How to Display IP Address on RHEL/CentOS

In this post, i will share the simple command to display the CentOS and Redhat Enterprise linux(RHEL) ip address. This command has been tested on Linux CentOS 5.8 server and may working on other CentOS and RHEL version as well. There are two alternative command to display ip address :

1. Display ip address using “ip address show” command :

[root@centos58 ~]# ip address show
1: lo:  mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
2: eth0:  mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:a1:17:ad brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.53/24 brd 192.168.1.255 scope global eth0

2. Display the ip address using “ifconfig” command :

[root@centos58 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:A1:17:AD
          inet addr:192.168.1.53  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:72408 errors:0 dropped:0 overruns:0 frame:0
          TX packets:64177 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:24607729 (23.4 MiB)  TX bytes:6678283 (6.3 MiB)
          Interrupt:75 Base address:0x2000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

How to Grep Multiples Lines and using Specific Keyword on Linux

grep is a command line text search utility originally written for Unix or linux. In linux you can grep multiple lines before or after matching the keywords. This examples has been tested on linux CentOS 6.2, but it may workings on other linux version such as Redhat Enterprise Linux 5 (RHEL5) or (RHEL6).

Get grep command help :

[root@centos62 ~]# grep --help

Example :

Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM

Assumed that you have exported all log for 29 March 2012 from /var/log/messages into 29032012.txt as below :

[root@centos62 ~]# more /var/log/messages | grep "Mar 29" > 29032012.txt

1. How to Grep Multiples Lines

Please grep “cubic” with -B1 and -A4 :

[root@centos62 ~]# grep -B1 -A4 "cubic" 29032012.txt

The output will return like this :

Mar 29 21:04:16 centos62 kernel: usbhid: v2.6:USB HID core driver
Mar 29 21:04:16 centos62 kernel: TCP cubic registered
Mar 29 21:04:16 centos62 kernel: Initializing XFRM netlink socket
Mar 29 21:04:16 centos62 kernel: NET: Registered protocol family 17
Mar 29 21:04:16 centos62 kernel: Using IPI No-Shortcut mode
Mar 29 21:04:16 centos62 kernel: registered taskstats version 1

2. How to Grep using Specific Keyword :
Grep only keyword “BIOS-e820” from 29032012.txt file as below :

[root@centos62 ~]# more 29032012.txt | grep "BIOS-e820"

The output will return like this :

Mar 29 21:04:16 centos62 kernel: BIOS-e820: 0000000000000000 - 000000000009f800 (usable)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 000000000009f800 - 00000000000a0000 (reserved)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 00000000000ca000 - 00000000000cc000 (reserved)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 00000000000dc000 - 00000000000e0000 (reserved)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 00000000000e4000 - 0000000000100000 (reserved)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 0000000000100000 - 000000003fef0000 (usable)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 000000003fef0000 - 000000003feff000 (ACPI data)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 000000003feff000 - 000000003ff00000 (ACPI NVS)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 000000003ff00000 - 0000000040000000 (usable)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 00000000e0000000 - 00000000f0000000 (reserved)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 00000000fee00000 - 00000000fee01000 (reserved)
Mar 29 21:04:16 centos62 kernel: BIOS-e820: 00000000fffe0000 - 0000000100000000 (reserved)

How to Open the File in Read Only Mode on Linux

Question :
How to open a file on read only mode on linux?

Answer :
This command has been tested on Redhat Enterprise linux 6 (RHEL6) server. To open the file with vim in read only mode on linux, you need to run “vim -R” as below. Vim is enhanced version of vi editor that viewing the text file with coloring. “vim -R” is good command if you want to avoid accidentally deleted any important line as in read only.

Example :

[root@rhel6 ~]# vim -R /etc/passwd

read only mode

How Display Logged in User Information and Terminal number on Linux Server

In this post i will show on how to display logged in user information and terminal number on Linux server. This post provides practical examples for future references. This steps has been tested on Redhat Linux Enterprise server 6 and may working CentOS server as well.

1. “who am i” command is use to display the username of currently logged.

[root@rhel6 ~]# who am i
root     pts/1        2012-04-17 06:14 (192.168.1.52)

2. who command will display all the user currently logged in all terminals.

[root@rhel6 ~]# who
root     tty1         2012-04-17 04:29
root     pts/0        2012-04-17 04:29 (192.168.1.52)
root     pts/1        2012-04-17 06:14 (192.168.1.52)
root     pts/2        2012-04-17 06:01 (192.168.1.52)

3. tty command is used to display the terminal number of currently logged in terminals.

[root@rhel6 ~]# tty
/dev/pts/1

4. The w command shows who is logged in to the system and what they are doing.

[root@rhel6 ~]# w
 06:18:39 up  1:50,  4 users,  load average: 0.02, 0.02, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1     -                04:29    1:48m  4.80s  4.78s ping www.google.com
root     pts/0    192.168.1.52     04:29    1:49m  0.02s  0.02s -bash
root     pts/1    192.168.1.52     06:14    0.00s  0.05s  0.01s w
root     pts/2    192.168.1.52     06:01   26.00s  0.11s  0.03s -bash

How to Turn Off or Disable Output Buffering for php.ini on PHP 5.3.2

Output buffering is used by PHP to improve performance and to perform a few tricks. PHP will send buffer to browser every get_opt(‘output_buffering’) bytes. Turning on output buffering alone decreases the amount of time it takes to download and render our HTML because it’s not being sent to the browser in pieces as PHP processes the HTML. In this post, i will show how turn off or disable output buffering for php.ini on PHP 5.3.2. This steps has been tested on the Red Hat Linux Enterprise 6 (RHEL 6) server. This steps may also working on other versions such as CentOS 5.1, CentOS 5.2, CentOS 5.3, CentOS 5.4, CentOS 5.5, CentOS 5.6, CentOS 5.7, CentOS 6.x and RHEL 5.x.

1. Open /etc/php.ini :

[root@rhel6 ~]# vi /etc/php.ini

In PHP 5.3.2, output_buffering’s directive is set to ‘enabled’ or ‘On’ with buffer size 4096 by default. It’s on line 264 on /etc/php.ini file :

; http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering
output_buffering = 4096

2. In order to disable or turn it ‘off’, you have to comment out the line 264 as below :

; http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering
;output_buffering = 4096

3. Don’t forget to restart httpd service to take effect immediately :

[root@rhel6 ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

How to Fix “cannot restore segment prot after reloc: Permission denied” error While Restarting zmcontrol on Zimbra

Question :

I want to start the Zimbra services. But i am getting the following issue while restarting zmcontrol using “zmcontrol start” command as per below error messages :

[zimbra@mail ~]$ zmcontrol start
Host mail.bloggerbaru.local
        Starting zmconfigd...Done.
        Starting logger...Done.
        Starting mailbox...Done.
        Starting antispam...Done.
        Starting antivirus...Done.
        Starting snmp...Done.
        Starting spell...Failed.
Starting apache...httpd: Syntax error on line 232 of /opt/zimbra/conf/httpd.conf: Cannot load /opt/zimbra/httpd/modules/libphp5.so into server: /opt/zimbra/httpd/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
failed.

Answer :
It was SELinux caused the Zimbra services problems failed to start and you have to disable selinux file as below :

1. Disable SELinux on your next reboot.

[root@centos6 ~]# vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0

To disable SELinux, without having to reboot, you can use the setenforce command as below:

[root@mail ~]# setenforce 0

2. Rerun zmcontrol start command again :

[zimbra@mail ~]$ zmcontrol start
Host mail.bloggerbaru.local
        Starting zmconfigd...Done.
        Starting logger...Done.
        Starting mailbox...Done.
        Starting antispam...Done.
        Starting antivirus...Done.
        Starting snmp...Done.
        Starting spell...Done.
        Starting mta...Done.
        Starting stats...Done.

How to Add Persistent Static Routes on RHEL 6/CentOS 6

This example will show you on how to configure the Persistent static route in RedHat Enterprise Linux 6 (RHEL 6) server. This configuration may different with other version of RHEL but the basic is almost the same. Persistent static route will permanently stored the setting and will not be deleted after rebooted. The following setting is just example only, you need to update the ip addresses and netmask in order to fit your environment :

To add a persistent static route in Redhat Enterprise Linux 6, create a file called route-X in the /etc/sysconfig/network-scripts/ directory. In this case, i will add persistent static route for eth0 and eth1.
1. Create a file route-eth0 rot eth0 routing :

[root@rhel6 ~]# vi /etc/sysconfig/network-scripts/route-eth0
ADDRESS0=192.168.1.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.1.1

2. Create a file route-eth1 rot eth1 routing :

[root@rhel6 ~]# vi /etc/sysconfig/network-scripts/route-eth1
ADDRESS1=192.168.2.0
NETMASK1=255.255.255.0
GATEWAY1=192.168.2.1

Display routing table :

[root@rhel6 ~]# netstat -rn

How to Install nmap on RHEL 6 Linux Server

Nmap (“Network Mapper”) is a free and open source tool for network exploration or security auditing. It can help you to find open port on a network. Nmap very useful for system and network administrator to perform system and network administration’s task and sometimes may helps in troubleshooting to narrow down the issue. Nmap uses raw IP packets in novel ways to determine what hosts are available on the network, what services (application name and version) those hosts are offering, what operating systems (and OS versions) they are running, what type of packet filters/firewalls are in use, and dozens of other characteristics. It was designed to rapidly scan large networks, but works fine against single hosts. Nmap runs on all major computer operating systems, and official binary packages are available for Linux, Windows, and Mac OS X. In this post i will show the quick step to install nmap on your Red Hat Enterprise Linux 6 (RHEL 6) server.

Simply run the following yum command :

[root@rhel6 ~]# yum install nmap -y
Loaded plugins: rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nmap.i686 2:5.21-3.el6 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package          Arch             Version                   Repository                        Size
====================================================================================================
Installing:
 nmap             i686             2:5.21-3.el6              DVD-RHEL6-Repository             2.2 M

Transaction Summary
====================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 2.2 M
Installed size: 7.2 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : 2:nmap-5.21-3.el6.i686                                                       1/1

Installed:
  nmap.i686 2:5.21-3.el6

Complete!

Type nmap without argument will show the available option for nmap command :

[root@rhel6 ~]# nmap
Nmap 5.21 ( http://nmap.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:
  Can pass hostnames, IP addresses, networks, etc.
  Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
  -iL : Input from list of hosts/networks
  -iR : Choose random targets
  --exclude : Exclude hosts/networks
  --excludefile : Exclude list from file
HOST DISCOVERY:
  -sL: List Scan - simply list targets to scan
  -sP: Ping Scan - go no further than determining if host is online
  -PN: Treat all hosts as online -- skip host discovery
  -PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports
  -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
  -PO[protocol list]: IP Protocol Ping
  -n/-R: Never do DNS resolution/Always resolve [default: sometimes]
  --dns-servers : Specify custom DNS servers
  --system-dns: Use OS's DNS resolver
  --traceroute: Trace hop path to each host
SCAN TECHNIQUES:
  -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
  -sU: UDP Scan
  -sN/sF/sX: TCP Null, FIN, and Xmas scans
  --scanflags : Customize TCP scan flags
  -sI : Idle scan
  -sY/sZ: SCTP INIT/COOKIE-ECHO scans
  -sO: IP protocol scan
  -b : FTP bounce scan
PORT SPECIFICATION AND SCAN ORDER:
  -p : Only scan specified ports
    Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080
  -F: Fast mode - Scan fewer ports than the default scan
  -r: Scan ports consecutively - don't randomize
  --top-ports : Scan  most common ports
  --port-ratio : Scan ports more common than 
SERVICE/VERSION DETECTION:
  -sV: Probe open ports to determine service/version info
  --version-intensity : Set from 0 (light) to 9 (try all probes)
  --version-light: Limit to most likely probes (intensity 2)
  --version-all: Try every single probe (intensity 9)
  --version-trace: Show detailed version scan activity (for debugging)
SCRIPT SCAN:
  -sC: equivalent to --script=default
  --script=:  is a comma separated list of
           directories, script-files or script-categories
  --script-args=: provide arguments to scripts
  --script-trace: Show all data sent and received
  --script-updatedb: Update the script database.
OS DETECTION:
  -O: Enable OS detection
  --osscan-limit: Limit OS detection to promising targets
  --osscan-guess: Guess OS more aggressively
TIMING AND PERFORMANCE:
  Options which take 

How to Create Additional LVM on RHEL 6/CentOS 6

Most of the linux administrator facing run out of disk space to store data and sometimes there is another request for them to create additional logical volume manager(LVM) for new system or to store data. It is possible to perform this task if that system administrator has the right skill on linux. Otherwise, they will put themselves and the organization in the disaster or risk as working with the system’s data is on of the most critical job that must be perform with the right steps and skills. In this post, i will show how to create additional LVM on Red Hat Enterprise Linux 6 (RHEL 6) system. This step may apply to CentOS 6.0. CentOS 6.1 and CentOS 6.2.

1. By typing the mount command with no arguments shows us all currently mounted filesystems

[root@rhel6 ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

2. Print the current partition table of the hard disk :

[root@rhel6 ~]# fdisk -l

Disk /dev/sda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000690f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1567    12069888   8e  Linux LVM

Disk /dev/dm-0: 10.2 GB, 10242490368 bytes
255 heads, 63 sectors/track, 1245 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table

Disk /dev/sdb: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

3. Create new partition for /dev/sdb using below command :

[root@rhel6 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x1adc0629.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1566, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1566, default 1566):
Using default value 1566

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

4. Convert this disk into a physical volume :

[root@rhel6 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

Display the physical volume :

[root@rhel6 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               11.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2946
  Free PE               0
  Allocated PE          2946
  PV UUID               tzxpC7-70n1-OuUQ-kMfT-H627-VHAA-kroHvm

  "/dev/sdb1" is a new physical volume of "12.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               12.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               SoWQ5U-CmmA-tjIY-KDh0-H3gU-qVpa-tx4n6n

5. With the physical volume created we now need to create new volume group for it. In this case i will give the volume group name VolGroup_rhel6 :

[root@rhel6 ~]# vgcreate VolGroup_rhel6 /dev/sdb1
  Volume group "VolGroup_rhel6" successfully created

Display the volume group

[root@rhel6 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup_rhel6
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               11.99 GiB
  PE Size               4.00 MiB
  Total PE              3070
  Alloc PE / Size       0 / 0
  Free  PE / Size       3070 / 11.99 GiB
  VG UUID               mg2I2s-8u5l-Mjm7-oKrQ-yYJ3-yzaO-mq2u9v

  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               11.51 GiB
  PE Size               4.00 MiB
  Total PE              2946
  Alloc PE / Size       2946 / 11.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               uROlLN-3aef-Cb7G-rJ8W-EyY0-aDaf-TyeE5T

6. Create logical volumes with the name of rhelvol into VolGroup_rhel6 volume group :

[root@rhel6 ~]# lvcreate --name rhelvol -l 100%FREE VolGroup_rhel6
  Logical volume "rhelvol" created

Display logical volume :

[root@rhel6 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup_rhel6/rhelvol
  VG Name                VolGroup_rhel6
  LV UUID                o3RQMB-O3Lu-TB2h-7pSm-A2kI-sh1W-rXb1Ce
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                11.99 GiB
  Current LE             3070
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Name                /dev/VolGroup/lv_root
  VG Name                VolGroup
  LV UUID                1f4tl8-rCgZ-yI9J-xCsI-Hrh2-5DUS-DJF5N2
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                9.54 GiB
  Current LE             2442
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup/lv_swap
  VG Name                VolGroup
  LV UUID                Kpw601-Wcvj-EM8b-FJnh-v2f6-5CqT-rV2JdT
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

7. Creating a file with the mke2fs command :

[root@rhel6 ~]# mke2fs -j /dev/VolGroup_rhel6/rhelvol
[root@rhel6 ~]# mke2fs -j /dev/VolGroup_rhel6/rhelvol
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
786432 inodes, 3143680 blocks
157184 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3221225472
96 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@rhel6 ~]# e2label /dev/VolGroup_rhel6/rhelvol /opt
[root@rhel6 ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Jan  4 03:41:29 2012
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
/dev/VolGroup_rhel6/rhelvol /opt                       ext4    defaults        1 1
UUID=0e03e7c9-6971-4783-8fb9-fc251febf486 /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
[root@rhel6 /]# mount /opt
[root@rhel6 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      9.4G  2.1G  6.9G  23% /
tmpfs                 504M     0  504M   0% /dev/shm
/dev/sda1             485M   29M  432M   7% /boot
/dev/mapper/VolGroup_rhel6-rhelvol
                       12G  159M   12G   2% /opt

Type the mount command with no arguments to shows the updated mounted filesystems. /dev/mapper/VolGroup_rhel6-rhelvol now exist at the bottom :

[root@rhel6 ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/VolGroup_rhel6-rhelvol on /opt type ext4 (rw)

How to Add a New Hard Disk Without Rebooting VM Guest on RHEL 6/CentOS 6

Assumed that you need additional hard disk for your Linux RHEL 6 server to provide more storage space but this the server cannot be reboot due to production environment. This server also assumed to be running on the VMware ESXi machine. In order to add additional hard disk without reboot, you have to perform the following steps. This steps has been tested on Red Hat Enterprise Linux 6 (RHEL 6). It may works on RHEL 5 and CentOS 5.

1. Perform the steps to add a new disk to VM Guest through VMware vCenter Server/VMware vSphere. In this case i will add 12 GB space to second hard disk space which on raw devide /dev/sdb.

2. Find scsi_host value using the following command:

[root@rhel6 ~]# ls /sys/class/scsi_host
host0  host1  host2

In this rhel 6 server, there are three scsi_host exist, host0, host1 and host2.

3. Rescan the SCSI Bus to Add a SCSI Device Without rebooting the VM

[root@rhel6 host0]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@rhel6 host0]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@rhel6 host0]# echo "- - -" > /sys/class/scsi_host/host2/scan

4. Check the new hard disk /dev/sdb :

[root@rhel6 ~]# fdisk -l

Disk /dev/sda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000690f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1567    12069888   8e  Linux LVM

Disk /dev/dm-0: 10.2 GB, 10242490368 bytes
255 heads, 63 sectors/track, 1245 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table

Disk /dev/sdb: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

How to Install Webtatic Repository on RHEL 6/CentOS 6

In this post, i will share on how to install Webtatic repository on Red Hat Enterprise Linux 6 (RHEL 6). However the steps may working on CentOS 6.0, CentOS 6.1 and CentOS 6.2. From the webtatic.com, the Webtatic yum repository is a CentOS/RHEL repository containing updated web-related packages. Webtatic goals are to provide CentOS/RHEL administrators with the latest stable minor releases of web development/hosting software, which are not provided in CentOS/RHEL distribution minor releases. It’s also serve as an additional installation option for some of Webtatic’s projects.

RHEL 6/ CentOS 6 for i386
RHEL 6/ CentOS 6 for x86_64

1.Download the webtatic-release package :

[root@rhel6 ~]# wget http://repo.webtatic.com/yum/el6/i386/webtatic-release-6-1.noarch.rpm
[root@rhel6 ~]# wget http://repo.webtatic.com/yum/el6/i386/webtatic-release-6-1.noarch.rpm
--2012-03-14 05:15:57--  http://repo.webtatic.com/yum/el6/i386/webtatic-release-6-1.noarch.rpm
Resolving repo.webtatic.com... 184.22.117.192
Connecting to repo.webtatic.com|184.22.117.192|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11488 (11K) [application/x-redhat-package-manager]
Saving to: âwebtatic-release-6-1.noarch.rpmâ

100%[==========================================================>] 11,488      8.15K/s   in 1.4s

2012-03-14 05:16:03 (8.15 KB/s) - âwebtatic-release-6-1.noarch.rpmâ

2. Download and import webtatic-andy GPG key :

[root@rhel6 ~]# rpm --import http://repo.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy

3. Verify the webtatic-release package you have downloaded :

[root@rhel6 ~]# rpm -K webtatic-release-6-1.noarch.rpm
webtatic-release-6-1.noarch.rpm: (sha1) dsa sha1 md5 gpg OK

4. Install Webtatic Repository :

[root@rhel6 ~]# rpm -Uvh webtatic-release-6-1.noarch.rpm
Preparing...                ########################################### [100%]
   1:webtatic-release       ########################################### [100%]

How to use Webtatic repository :
[root@rhel6 ~]# yum –enablerepo=webtatic install [rpm package]