How to Upgrade from CentOS 6.2 to CentOS 6.3

linux centos 6.3CentOS 6.3 had released on 2012-07-09 with the kernel version 2.6.32-279. CentOS is an Enterprise-class Linux Distribution derived from sources freely provided to the public by our Upstream OS Provider (UOP).
For version CentOS-4.x and CentOS-5.x, it is recommend to reinstall rather than attempt an inplace upgrade from CentOS-4 or CentOS-5 to CentOS 6.3. Direct upgrade from CentOS 6.x to CentOS-6.3 for i386 and x86_64 Architectures is highly recommendeded. The ‘yum update’ should move your machine seamlessly from any previous CentOS-6.x release to CentOS-6.3, unless you have edited your yum configs. Follow this steps to upgrade the CentOS-6.x to CentOS6.3

Check older version :

[root@host1 ~]# cat /etc/redhat-release
CentOS release 6.2 (Final)
or
[root@host1 ~]# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m

Official way to do upgrade:

[root@host1 ~]# yum clean all
[root@host1 ~]# yum update -y
[root@host1 ~]# reboot

Check latest version :

[root@host1 ~]# cat /etc/redhat-release
CentOS release 6.3 (Final)

or

[root@host1 ~]# cat /etc/issue
CentOS release 6.3 (Final)
Kernel \r on an \m

How to Fix “-bash: scp: command not found”

Question :

I try to use SCP command on my CentOS 6.3 server, but the following error returned. According to wikipedia, SCP or Secure copy is a means of securely transferring computer files between a local host and a remote host or between two remote hosts and It’s based on the Secure Shell (SSH) protocol. The term SCP can refer to one of two related things, the SCP protocol or the SCP program.

[root@CentOS6.3 ~]# scp
-bash: scp: command not found

Answer :
To fix above error, you have to install openshh-clients in your CentOS 6.3 server as below :

[root@CentOS6.3 ~]# yum install openssh-clients -y

Just type scp command to get more options of the command :

[root@CentOS6.3 ~]# scp
usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
[root@CentOS6.3 ~]#

How to Mount a Windows Shared Folder in Linux CentOS 6.3

In this post, i will share on how to mount windows share folder on linux CentOS 6.3 server. Assumed that windows share folder has been configured properly with administrator privileged. This uses Common Internet File System (CIFS) protocol. CIFS can lets you access to shared folder and files that are remotely on the server and can do read and write to them.

Windows Share: //192.168.2.51/Files
Windows Credentials : username=administrator,password=mypassword

1. Execute the following command to mount Windows share folder :

[root@centos63 /]# mount -t cifs -o username=administrator,password=mypassword //192.168.2.51/Files /mnt

2. Verify that Windows share folder already mounted to /mnt :

[root@centos63 /]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_centos63-lv_root
                       5716804   2451228   2975172  46% /
tmpfs                   515400         0    515400   0% /dev/shm
/dev/sda1               495844     66280    403964  15% /boot
//192.168.2.51/Files 476403708 343375460 133028248  73% /mnt

3. Add that Windows share folder into /etc/fstab file, so that it will auto mount once rebooted :

[root@centos63 ~]# vi /etc/fstab

Add the final line as below :

#
# /etc/fstab
# Created by anaconda on Sun Jul 15 20:17:38 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/vg_centos63-lv_root /                       ext4    defaults        1 1
UUID=2217c7b1-4467-4c81-8596-c3ee7758e2cc /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos63-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
//192.168.2.51/Files    /mnt                    cifs    username=administrator,password=mypassword 0 0

How to Find Default Gateway IP address on Linux

A default gateway is the node (a router) or network point on the computer network that serves as an access point and entrance to another network. It passes traffic between different subnets and networks. Computers running on the network using IP, a default gateway address is needed to reach all computers that are not on the same local IP subnet. This post will show you how to Find default gateway IP address on linux operating system. This command has been tested on CentOS 6.3.

1. Print default gateway using route command :

[root@centos63 ~]# route

Output :

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1002   0        0 eth0
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

2. Print default gateway using netstat command :

[root@centos63 ~]# netstat -rn

Output :

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0

Note : The flag U indicates that route is up and G indicates that it is gateway.

How to Check Disk Read Write Speed in Linux

hard diskMeasuring sequential disk performance is easy in linux as every modern Linux distribution comes with a command line utility called hdparm. Hdparm is a free tool to measure sequential disk performance which is primarily used to tune and optimize disk parameters. It is important to read hdparm man page and perform full backup before using hdparm command line utility. The popular option for hdparm command line utility are -t and -T.

-t is to perform buffered disk read which is the data transfer rate directly from the disk to memory.

-T is to perform timing cached read which is the data transfer rate from a memory buffer without reading the hard drive.

If hdparm is not installed then follow this steps to install hdparm on CentOS 6.3.

Type hdparm without option to get full hard disk parameters as a reference.

[root@centos63 ~]# hdparm

hdparm - get/set hard disk parameters - version v9.16

Usage:  hdparm  [options] [device] ..

Options:
 -a   get/set fs readahead
 -A   get/set the drive look-ahead flag (0/1)
 -b   get/set bus state (0 == off, 1 == on, 2 == tristate)
 -B   set Advanced Power Management setting (1-255)
 -c   get/set IDE 32-bit IO setting
 -C   check drive power mode status
 -d   get/set using_dma flag
 -D   enable/disable drive defect management
 -E   set cd/dvd drive speed
 -f   flush buffer cache for device on exit
 -F   flush drive write cache
 -g   display drive geometry
 -h   display terse usage information
 -H   read temperature from drive (Hitachi only)
 -i   display drive identification
 -I   detailed/current information directly from drive
 -k   get/set keep_settings_over_reset flag (0/1)
 -K   set drive keep_features_over_reset flag (0/1)
 -L   set drive doorlock (0/1) (removable harddisks only)
 -M   get/set acoustic management (0-254, 128: quiet, 254: fast)
 -m   get/set multiple sector count
 -N   get/set max visible number of sectors (HPA) (VERY DANGEROUS)
 -n   get/set ignore-write-errors flag (0/1)
 -p   set PIO mode on IDE interface chipset (0,1,2,3,4,...)
 -P   set drive prefetch count
 -q   change next setting quietly
 -Q   get/set DMA queue_depth (if supported)
 -r   get/set device  readonly flag (DANGEROUS to set)
 -R   obsolete
 -s   set power-up in standby flag (0/1) (DANGEROUS)
 -S   set standby (spindown) timeout
 -t   perform device read timings
 -T   perform cache read timings
 -u   get/set unmaskirq flag (0/1)
 -U   obsolete
 -v   defaults; same as -acdgkmur for IDE drives
 -V   display program version and exit immediately
 -w   perform device reset (DANGEROUS)
 -W   get/set drive write-caching flag (0/1)
 -x   obsolete
 -X   set IDE xfer mode (DANGEROUS)
 -y   put drive in standby mode
 -Y   put drive to sleep
 -Z   disable Seagate auto-powersaving mode
 -z   re-read partition table
 --dco-freeze      freeze/lock current device configuration until next power cycle
 --dco-identify    read/dump device configuration identify data
 --dco-restore     reset device configuration back to factory defaults
 --direct          use O_DIRECT to bypass page cache for timings
 --drq-hsm-error   crash system with a "stuck DRQ" error (VERY DANGEROUS)
 --fibmap          show device extents (and fragmentation) for a file
 --fibmap-sector   show absolute LBA of a specfic sector of a file
 --fwdownload            Download firmware file to drive (EXTREMELY DANGEROUS)
 --fwdownload-mode3      Download firmware using min-size segments (EXTREMELY DANGEROUS)
 --fwdownload-mode3-max  Download firmware using max-size segments (EXTREMELY DANGEROUS)
 --fwdownload-mode7      Download firmware using a single segment (EXTREMELY DANGEROUS)
 --idle-immediate  idle drive immediately
 --idle-unload     idle immediately and unload heads
 --Istdin          read identify data from stdin as ASCII hex
 --Istdout         write identify data to stdout as ASCII hex
 --make-bad-sector deliberately corrupt a sector directly on the media (VERY DANGEROUS)
 --prefer-ata12    use 12-byte (instead of 16-byte) SAT commands when possible
 --read-sector     read and dump (in hex) a sector directly from the media
 --security-help   display help for ATA security commands
 --trim-sectors    tell SSD firmware to discard unneeded data sectors (lba and count)
 --verbose         display extra diagnostics from some commands
 --write-sector    repair/overwrite a (possibly bad) sector directly on the media (VERY DANGEROUS)

Note : Substitute /dev/sda with the name of the disk device.

Example on how to check disk Disk Read Write Speed for /dev/sda on CentOS6.3 :

[root@centos63 ~]# hdparm -tT /dev/sda

/dev/sda:
 Timing cached reads:   4128 MB in  2.00 seconds = 2065.62 MB/sec
 Timing buffered disk reads:  276 MB in  3.06 seconds =  90.30 MB/sec

Example on how to check disk Disk Read Write Speed for /dev/sdb on CentOS6.3 :

[root@centos63 ~]# hdparm -tT /dev/sdb

/dev/sdb:
 Timing cached reads:   3410 MB in  2.00 seconds = 1705.84 MB/sec
 Timing buffered disk reads:  364 MB in  3.00 seconds = 121.29 MB/sec

How to Fix “-bash: hdparm: command not found” on Linux CentOS 6.3

hard diskQuestion:
When i try to run hdparm command to check to check the hard drive read and writing speed, the following error has been returned. Hdparm is a command line utility to measure sequential disk performance which is primarily used to tune and optimize disk parameters. Hdparm is free software under the BSD license.

[root@centos63 ~]# hdparm -t /dev/sda
-bash: hdparm: command not found

To Fix this, install hdparm command line utility on CentOS 6.3 using two method :

Method 1: Install hdparm using yum command :

[root@centos63 ~]# yum install hdparm -y

Example :

[root@centos63 ~]# yum install hdparm -y
Loaded plugins: fastestmirror, presto, priorities
Loading mirror speeds from cached hostfile
 * base: mirrors.sin3.sg.voxel.net
 * extras: mirrors.sin3.sg.voxel.net
 * updates: mirror.issp.co.th
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package hdparm.i686 0:9.16-3.4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package               Arch                Version                        Repository           Size
====================================================================================================
Installing:
 hdparm                i686                9.16-3.4.el6                   base                 72 k

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

Total download size: 72 k
Installed size: 134 k
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 72 k
hdparm-9.16-3.4.el6.i686.rpm                                                 |  72 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : hdparm-9.16-3.4.el6.i686                                                         1/1
  Verifying  : hdparm-9.16-3.4.el6.i686                                                         1/1

Installed:
  hdparm.i686 0:9.16-3.4.el6

Complete!

Method 2 : Install hdparm using RPM packages as per OS and bit :

For 32 Bit :

[root@centos63 ~]# rpm -Uvh http://mirrors.hostemo.com/CentOS/6.3/os/i386/Packages/hdparm-9.16-3.4.el6.i686.rpm

For 64 Bit :

[root@centos63 ~]# rpm -Uvh http://mirrors.hostemo.com/CentOS/6.3/os/x86_64/Packages/hdparm-9.16-3.4.el6.x86_64.rpm

Verify if the hdparm RPM is installed or not by using the following command :

[root@centos63 ~]# rpm -qa | grep hdparm
hdparm-9.16-3.4.el6.i686

How to Setup Nginx With PHP-FastCGI on CentOS 6.2/CentOS 6.3 VPS Server

At the previous post, i have setup Nginx as reverse proxy to apache web server. This post will covers the steps how to setup nginx web server to use PHP-FastCGI for dynamic content. Nginx (pronounced “Engine-X”) is a free, open-source HTTP Web server and one of the alternative to Apache http server. It’s a high performance edge web server with the lowest memory footprint and the key features to build modern and efficient web infrastructure. FastCGI is a language independent, scalable, open extension to CGI that provides high performance without the limitations of server specific APIs. FastCGI provides better scalability and performance.

1. Prepared yum repository for nginx :

[root@centos63 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

2. Install Nginx :

[root@centos63 ~]# yum install nginx -y

3. Install required php packages :

[root@centos63 ~]# yum install php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy -y

Examples of Software Installed and the Dependency:

Installed:
  php-eaccelerator.i686 1:0.9.6.1-1.el6   php-imap.i686 0:5.3.3-14.el6_3      php-ldap.i686 0:5.3.3-14.el6_3
  php-magickwand.i686 0:1.0.9-1.el6       php-magpierss.noarch 0:0.72-6.el6   php-mssql.i686 0:5.3.3-1.el6
  php-odbc.i686 0:5.3.3-14.el6_3          php-pear.noarch 1:1.9.4-4.el6       php-shout.i686 0:0.9.2-6.el6
  php-snmp.i686 0:5.3.3-14.el6_3          php-soap.i686 0:5.3.3-14.el6_3      php-tidy.i686 0:5.3.3-14.el6_3
  php-xml.i686 0:5.3.3-14.el6_3           php-xmlrpc.i686 0:5.3.3-14.el6_3

Dependency Installed:
  ConsoleKit.i686 0:0.4.1-3.el6                        ConsoleKit-libs.i686 0:0.4.1-3.el6
  GConf2.i686 0:2.28.0-6.el6                           ImageMagick.i686 0:6.5.4.7-6.el6_2
  ORBit2.i686 0:2.14.17-3.1.el6                        atk.i686 0:1.28.0-2.el6
  avahi-libs.i686 0:0.6.25-11.el6                      cairo.i686 0:1.8.8-3.1.el6
  cups-libs.i686 1:1.4.2-48.el6_3.1                    dbus.i686 1:1.2.24-7.el6_3
  eggdbus.i686 0:0.6-3.el6                             fontconfig.i686 0:2.8.0-3.el6
  freetds.i686 0:0.91-2.el6                            ghostscript.i686 0:8.70-14.el6_3.1
  ghostscript-fonts.noarch 0:5.50-23.1.el6             gtk2.i686 0:2.18.9-10.el6
  hicolor-icon-theme.noarch 0:0.11-1.1.el6             jasper-libs.i686 0:1.900.1-15.el6_1.1
  lcms-libs.i686 0:1.19-1.el6                          libICE.i686 0:1.0.6-1.el6
  libIDL.i686 0:0.8.13-2.1.el6                         libSM.i686 0:1.1.0-7.1.el6
  libXcomposite.i686 0:0.4.1-2.el6                     libXcursor.i686 0:1.1.10-2.el6
  libXdamage.i686 0:1.1.2-1.el6                        libXext.i686 0:1.1-3.el6
  libXfixes.i686 0:4.0.4-1.el6                         libXfont.i686 0:1.4.1-2.el6_1
  libXft.i686 0:2.1.13-4.1.el6                         libXi.i686 0:1.3-3.el6
  libXinerama.i686 0:1.1-1.el6                         libXrandr.i686 0:1.3.0-4.el6
  libXrender.i686 0:0.9.5-1.el6                        libXt.i686 0:1.0.7-1.el6
  libc-client.i686 0:2007e-11.el6                      libcroco.i686 0:0.6.2-5.el6
  libfontenc.i686 0:1.0.5-2.el6                        libgsf.i686 0:1.14.15-5.el6
  libogg.i686 2:1.1.4-2.1.el6                          librsvg2.i686 0:2.26.0-5.el6_1.1.0.1.centos
  libshout.i686 0:2.2.2-5.1.el6                        libthai.i686 0:0.1.12-3.el6
  libtheora.i686 1:1.1.0-2.el6                         libtidy.i686 0:0.99.0-19.20070615.1.el6
  libtiff.i686 0:3.9.4-6.el6_3                         libvorbis.i686 1:1.2.3-4.el6_2.1
  libwmf-lite.i686 0:0.2.8.4-22.el6.centos             lm_sensors-libs.i686 0:3.1.1-10.el6
  net-snmp.i686 1:5.5-41.el6_3.1                       net-snmp-libs.i686 1:5.5-41.el6_3.1
  pango.i686 0:1.28.1-3.el6_0.5.1.centos               pixman.i686 0:0.18.4-1.el6_0.1
  polkit.i686 0:0.96-2.el6_0.1                         sgml-common.noarch 0:0.6.3-32.el6
  speex.i686 0:1.2-0.12.rc1.1.el6                      unixODBC.i686 0:2.2.14-11.el6
  urw-fonts.noarch 0:2.4-10.el6                        xorg-x11-font-utils.i686 1:7.2-11.el6

Dependency Updated:
  dbus-libs.i686 1:1.2.24-7.el6_3

Complete!

4. Configure EPEL Repository on CentOS 6.3 and install spawn-fcgi :

[root@centos63 ~]# yum install spawn-fcgi -y

5. Start configure nginx. It is better to backup original nginx config file :

[root@centos63 ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

6. Create nginx DocumentRoot for ehowstuff.local virtual host :

[root@centos63 ~]# mkdir -p /var/www/html/ehowstuff.local
[root@centos63 ~]# mkdir -p /var/www/html/ehowstuff.local/public_html
[root@centos63 ~]# chown -R nginx:nginx /var/www/html/ehowstuff.local/public_html

7. Create folder where to store access.log and error.log :

[root@centos63 ~]# mkdir -p /var/log/nginx/ehowstuff.local
[root@centos63 ~]# chown -R nginx:nginx /var/log/nginx/ehowstuff.local

8. Modify default nginx config file :

[root@centos63 ~]# vi /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}


9. Add the host configuration file under /etc/nginx/conf.d/. Nginx config file will load all *.conf files under conf.d folder :

As example, the website domain is ehowstuff.local. So virtual server ehowstuff.local will be created and named as ehowstuff.local.conf :

[root@centos63 ~]# vi /etc/nginx/conf.d/ehowstuff.local.conf
server {
    server_name www.ehowstuff.local ehowstuff.local;
    access_log /var/log/nginx/ehowstuff.local/access.log;
    error_log /var/log/nginx/ehowstuff.local/error.log;
    root /var/www/html/ehowstuff.local/public_html;

    location / {
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/html/ehowstuff.local/public_html$fastcgi_script_name;
    }
}

10. Check your nginx version :

[root@centos63 ~]# nginx -v
nginx version: nginx/1.2.4

11. Configure php-fastcgi :

[root@centos63 ~]# cd /opt
[root@centos63 opt]# wget -O php-fastcgi-rpm.sh http://library.linode.com/assets/696-php-fastcgi-rpm.sh
[root@centos63 opt]# mv php-fastcgi-rpm.sh /usr/bin/php-fastcgi
[root@centos63 opt]# chmod +x /usr/bin/php-fastcgi
[root@centos63 opt]# wget -O php-fastcgi-init-rpm.sh http://library.linode.com/assets/697-php-fastcgi-init-rpm.sh
[root@centos63 opt]# mv php-fastcgi-init-rpm.sh /etc/rc.d/init.d/php-fastcgi
[root@centos63 opt]# chmod +x /etc/rc.d/init.d/php-fastcgi

12. Start php-fastcgi to control spawn-fcgi :

[root@centos63 ~]# /etc/init.d/php-fastcgi start
Starting php-cgi: spawn-fcgi: child spawned successfully: PID: 3380
                                                           [  OK  ]

13. Start Nginx service :

[root@centos63 ~]# service nginx start

14. Make Nginx and php-fastcgi start at boot :

[root@centos63 opt]# chkconfig --add nginx
[root@centos63 opt]# chkconfig nginx on
[root@centos63 opt]# chkconfig --add php-fastcgi
[root@centos63 opt]# chkconfig php-fastcgi on

Three Ways to Configure Persistent Static Routes on Linux CentOS

centos6There are several different ways to configure persistent static routes on Linux CentOS. By using Static routes, we can improves overall performance of the network and static routing is achieved by manually adding routes to the routing table. Static route can be added and delete using “route” command. But it will forget the static routes configuration when server rebooted. This will lead to the network interruption. Follow one of these three options to configure static route on CentOS.

1. Edit the file /etc/sysconfig/network-scripts/route- and then add the following lines :

[root@centos63 ~]# vi /etc/sysconfig/network-scripts/route-eth0

GATEWAY0=<gateway address>
NETMASK0=<network netmask>
ADDRESS0=<network address>
GATEWAY1=<gateway address>
NETMASK1=<network netmask>
ADDRESS1=<network address>

Examples :

GATEWAY0=192.168.1.1
NETMASK0=255.255.255.0
ADDRESS0=192.168.1.54
GATEWAY1=192.168.2.1
NETMASK1=255.255.255.0
ADDRESS1=192.168.2.54

2. Edit the file /etc/sysconfig/network-scripts/route- and then add the following lines :

192.168.1.0/24 via 192.168.1.1 dev eth0
192.168.2.0/24 via 192.168.2.1 dev eth0

3. Edit the file /etc/sysconfig/static-routes as below :

any -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1
any -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1

How to Create Additional LVM on CentOS 6.3

This post will covers the steps to create additional Logical volume manager (LVM) on CentOS 6.3. This will very useful when the production system facing run out of disk space to store data. Sometimes there is another request for them to create additional 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. Follow below steps :

1. Assumed that second disk has been added called /dev/sdb. Create new partition for /dev/sdb using below command :

[root@centos63 ~]# 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 0xd29f2d59.
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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):
Using default value 652

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0xd29f2d59

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0xd29f2d59

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         652     5237158+  8e  Linux LVM

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

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

2. Convert this disk into a physical volume :

[root@centos63 ~]# pvcreate /dev/sdb1
  Writing physical volume data to disk "/dev/sdb1"
  Physical volume "/dev/sdb1" successfully created

Display the physical volume :

[root@centos63 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_centos63
  PV Size               7.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1922
  Free PE               0
  Allocated PE          1922
  PV UUID               521faS-HW2C-nUrs-yI1E-4OO9-eLmj-1e3bGW

  "/dev/sdb1" is a new physical volume of "4.99 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               4.99 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               qTmTeq-8qoL-xxEk-Dj5V-zOjl-vEag-P6Jl7L

3. 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 vg_data.

[root@centos63 ~]# vgcreate vg_data /dev/sdb1
  Volume group "vg_data" successfully created

Display the volume group :

[root@centos63 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_data
  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               4.99 GiB
  PE Size               4.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0
  Free  PE / Size       1278 / 4.99 GiB
  VG UUID               YV3IYN-3CF9-3Yd1-69ue-wcq4-0UKk-Zk49Vk

  --- Volume group ---
  VG Name               vg_centos63
  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               7.51 GiB
  PE Size               4.00 MiB
  Total PE              1922
  Alloc PE / Size       1922 / 7.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               G3H7s2-0yfo-vU9W-5g9g-fq9K-tpNO-U2Y7BQ

4. Create logical volumes with the name of centos63_vol into vg_data volume group :

[root@centos63 ~]# lvcreate --name centos63_vol -l 100%FREE vg_data
  Logical volume "centos63_vol" created

Display logical volume :

[root@centos63 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_data/centos63_vol
  LV Name                centos63_vol
  VG Name                vg_data
  LV UUID                bVRJwM-5CuR-mLf4-tqHV-j5e4-cs3o-ffKL41
  LV Write Access        read/write
  LV Creation host, time centos63.ehowstuff.local, 2012-09-28 22:55:13 +0800
  LV Status              available
  # open                 0
  LV Size                4.99 GiB
  Current LE             1278
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg_centos63/lv_root
  LV Name                lv_root
  VG Name                vg_centos63
  LV UUID                3Se9Zl-RmAu-f707-1Fv2-wMvX-oH3z-maExU0
  LV Write Access        read/write
  LV Creation host, time centos63.ehowstuff.local, 2012-07-15 20:17:31 +0800
  LV Status              available
  # open                 1
  LV Size                5.54 GiB
  Current LE             1418
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_centos63/lv_swap
  LV Name                lv_swap
  VG Name                vg_centos63
  LV UUID                KijzOf-uPjy-JbJd-dcjw-u0XO-aqPA-2GKScq
  LV Write Access        read/write
  LV Creation host, time centos63.ehowstuff.local, 2012-07-15 20:17:33 +0800
  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

5. Format the LVM using mke2fs with -j switch command :

[root@centos63 ~]# mke2fs -j /dev/vg_data/centos63_vol
[root@centos63 ~]# mke2fs -j /dev/vg_data/centos63_vol
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
327680 inodes, 1308672 blocks
65433 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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

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.

6. Create a mount point for the newly created logical volume :

[root@centos63 ~]# mkdir /mydata

7. Define mount point to use this partitions :

[root@centos63 ~]# e2label /dev/vg_data/centos63_vol /mydata

8. Modify /etc/fstab and add the following:

[root@centos63 ~]# vi /etc/fstab
/dev/vg_data/centos63_vol /mydata                       ext4    defaults        1 1
#
# /etc/fstab
# Created by anaconda on Sun Jul 15 20:17:38 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/vg_centos63-lv_root /                       ext4    defaults        1 1
UUID=2217c7b1-4467-4c81-8596-c3ee7758e2cc /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos63-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
/dev/vg_data/centos63_vol /mydata                       ext4    defaults        1 1

9. Mount the newly created logical volume :

[root@centos63 ~]# mount /mydata

10. The newly created logical volume will now mount automatically each time the system is booted.

[root@centos63 ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos63-lv_root
                      5.5G  2.0G  3.3G  39% /
tmpfs                 504M     0  504M   0% /dev/shm
/dev/sda1             485M   65M  395M  15% /boot
/dev/mapper/vg_data-centos63_vol
                      5.0G  139M  4.6G   3% /mydata

How to Install PostgreSQL 9.2 on CentOS 6.3

This quick post shows the basic steps to install PostgreSQL Database Server (PostgreSQL 9.2) on CentOS 6.3. This steps has been tested using CentOS 6.3. However, It may works on other version CentOS or Redhat as well. PostgreSQL is a Sophisticated open-source Object-Relational DBMS supporting almost all SQL constructs, including subselects, transactions, and user-defined types. PostgreSQL is a powerful, open source object-relational database system that available for many platforms including Linux, FreeBSD, Solaris, Microsoft Windows and Mac OS X.

PostgreSQL Global Development Group (PGDG) builds RPMs for various Linux distributions. At the time of this writing, there are available RPMs and SRPMs for the following platforms :

  • PostgreSQL 9.2

Follow these steps to install PostgreSQL 9.2 on CentOS 6.3 :

1. Download the latest production release for your distro here: http://yum.pgrpms.org/repopackages.php

[root@centos63 ~]# wget http://yum.pgrpms.org/9.2/redhat/rhel-6-i386/pgdg-centos92-9.2-5.noarch.rpm
--2012-09-25 21:50:05--  http://yum.pgrpms.org/9.2/redhat/rhel-6-i386/pgdg-centos92-9.2-5.noarch.rpm
Resolving yum.pgrpms.org... 98.129.198.114
Connecting to yum.pgrpms.org|98.129.198.114|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5220 (5.1K) [application/x-redhat-package-manager]
Saving to: âpgdg-centos92-9.2-5.noarch.rpmâ

100%[==========================================================>] 5,220       4.76K/s   in 1.1s

2012-09-25 21:50:06 (4.76 KB/s) - âpgdg-centos92-9.2-5.noarch.rpmâ

2. Install the repo :

[root@centos63 ~]# rpm -ivh pgdg-centos92-9.2-5.noarch.rpm
Preparing...                ########################################### [100%]
   1:pgdg-centos92          ########################################### [100%]

3. Edit the CentOS-Base.repo to exclude postgreql.

[root@centos63 ~]# vi /etc/yum.repos.d/CentOS-Base.repo

Add ‘exclude=postgresql*’ to the [base] and [updates] sections:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
exclude=postgresql*

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
exclude=postgresql*

4. Use ‘yum list’ to check the packages that are now available.

[root@centos63 ~]# yum list postgres*
Loaded plugins: fastestmirror, presto, priorities
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * extras: centos.ipserverone.com
 * updates: centos.ipserverone.com
Available Packages
postgresql.i686                              8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-contrib.i686                      8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-devel.i686                        8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-docs.i686                         8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-jdbc.i686                         8.4.701-3.el6                      CentOS6.3-Repository
postgresql-jdbc.noarch                       8.4.701-8.el6                      CentOS6.3-Repository
postgresql-libs.i686                         8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-odbc.i686                         08.04.0200-1.el6                   CentOS6.3-Repository
postgresql-plperl.i686                       8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-plpython.i686                     8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-pltcl.i686                        8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-server.i686                       8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql-test.i686                         8.4.11-1.el6_2                     CentOS6.3-Repository
postgresql92.i686                            9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-contrib.i686                    9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-debuginfo.i686                  9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-devel.i686                      9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-docs.i686                       9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-libs.i686                       9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-odbc.i686                       09.01.0200-1PGDG.rhel6             pgdg92
postgresql92-odbc-debuginfo.i686             09.01.0200-1PGDG.rhel6             pgdg92
postgresql92-plperl.i686                     9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-plpython.i686                   9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-pltcl.i686                      9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-server.i686                     9.2.1-1PGDG.rhel6                  pgdg92
postgresql92-tcl.i686                        2.0.0-1.rhel6                      pgdg92
postgresql92-tcl-debuginfo.i686              2.0.0-1.rhel6                      pgdg92
postgresql92-test.i686                       9.2.1-1PGDG.rhel6                  pgdg92

5. Start install PostgreSQL 9 using yum:

[root@centos63 ~]# yum install postgresql92 postgresql92-devel postgresql92-server postgresql92-libs postgresql92-contrib -y

6. Verify, Initialize and Start PostgreSQL service :

[root@centos63 ~]# service postgresql-9.2 status
 is stopped
[root@centos63 ~]# service postgresql-9.2 initdb
Initializing database:                                     [  OK  ]
[root@centos63 ~]# service postgresql-9.2 start
Starting postgresql-9.2 service:                           [  OK  ]

How to Fix “-bash: man: command not found” on CentOS 6.3

centos6This quick post shows the step to install “man” command on Linux. In linux CentOS 6.2 and CentOS 6.3 operating system, “man” command has not been installed automatically. The Linux command “man” is used to display the manual page for other command and also will help you to explain the functions for the commands that commonly used. The term “man” is short for manual.

If you typed “man” command on the linux server that has not been installed with man command, you will get the following message :

[root@centos63 ~]# man tar
-bash: man: command not found

To install “man“, simply run this command :

[root@centos63 ~]# yum install man -y
Loaded plugins: fastestmirror, presto, priorities
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * extras: centos.ipserverone.com
 * updates: centos.ipserverone.com
base                                                                         | 3.7 kB     00:00
extras                                                                       | 3.0 kB     00:00
updates                                                                      | 3.5 kB     00:00
updates/primary_db                                                           | 2.3 MB     00:19
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package man.i686 0:1.6f-30.el6 will be installed
--> Processing Dependency: lzma for package: man-1.6f-30.el6.i686
--> Running transaction check
---> Package xz-lzma-compat.i686 0:4.999.9-0.3.beta.20091007git.el6 will be installed
--> Processing Dependency: xz = 4.999.9-0.3.beta.20091007git.el6 for package: xz-lzma-compat-4.999.9-0.3.beta.20091007git.el6.i686
--> Running transaction check
---> Package xz.i686 0:4.999.9-0.3.beta.20091007git.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package                Arch         Version                                     Repository    Size
====================================================================================================
Installing:
 man                    i686         1.6f-30.el6                                 base         260 k
Installing for dependencies:
 xz                     i686         4.999.9-0.3.beta.20091007git.el6            base         137 k
 xz-lzma-compat         i686         4.999.9-0.3.beta.20091007git.el6            base          16 k

Transaction Summary
====================================================================================================
Install       3 Package(s)

Total download size: 413 k
Installed size: 864 k
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 413 k
(1/3): man-1.6f-30.el6.i686.rpm                                              | 260 kB     00:01
(2/3): xz-4.999.9-0.3.beta.20091007git.el6.i686.rpm                          | 137 kB     00:00
(3/3): xz-lzma-compat-4.999.9-0.3.beta.20091007git.el6.i686.rpm              |  16 kB     00:00
----------------------------------------------------------------------------------------------------
Total                                                               138 kB/s | 413 kB     00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : xz-4.999.9-0.3.beta.20091007git.el6.i686                                         1/3
  Installing : xz-lzma-compat-4.999.9-0.3.beta.20091007git.el6.i686                             2/3
  Installing : man-1.6f-30.el6.i686                                                             3/3
  Verifying  : xz-4.999.9-0.3.beta.20091007git.el6.i686                                         1/3
  Verifying  : man-1.6f-30.el6.i686                                                             2/3
  Verifying  : xz-lzma-compat-4.999.9-0.3.beta.20091007git.el6.i686                             3/3

Installed:
  man.i686 0:1.6f-30.el6

Dependency Installed:
  xz.i686 0:4.999.9-0.3.beta.20091007git.el6 xz-lzma-compat.i686 0:4.999.9-0.3.beta.20091007git.el6

Complete!

Once man command has been installed successfully, you will be able to read the manual pages :

[root@centos63 ~]# man tar
TAR(1)                           User Commands                          TAR(1)

NAME
       tar - manual page for tar 1.23

SYNOPSIS
       tar [OPTION...] [FILE]...

DESCRIPTION
       GNU  âtarâ  saves  many  files together into a single tape or disk archive, and can
       restore individual files from the archive.

EXAMPLES
       tar -cf archive.tar foo bar
              # Create archive.tar from files foo and bar.

       tar -tvf archive.tar
              # List all files in archive.tar verbosely.

       tar -xf archive.tar
              # Extract all files from archive.tar.

..
..

How to Install php-mcrypt on CentOS 6.3

mcrypt exension for PHP is necessary if we want to use cookie based authentication with phpymyadmin. In default CentOS 6.3 yum repository or in CentOS 6.3 installation CD/DVD, php-mcrypt exension are not included. To install php-mcrypt on CentOS 6.3, we have to use third party yum repository. Follow this steps :

1. Download epel repository :

[root@centos62 ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
[root@centos62 ~]# wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6

2. Install epel repository :

[root@centos62 ~]# rpm --import RPM-GPG-KEY-EPEL-6
[root@centos62 ~]# rpm -i epel-release-6-7.noarch.rpm

3. Simply run the following command to install php-mcrypt :

[root@centos63 ~]# yum install php-mcrypt -y
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: mirror1.ku.ac.th
 * epel: mirrors.ispros.com.bd
 * extras: mirror.issp.co.th
 * updates: mirror1.ku.ac.th
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-mcrypt.i686 0:5.3.3-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package                   Arch                Version                    Repository           Size
====================================================================================================
Installing:
 php-mcrypt                i686                5.3.3-1.el6                epel                 18 k

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

Total download size: 18 k
Installed size: 38 k
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 18 k
php-mcrypt-5.3.3-1.el6.i686.rpm                                              |  18 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : php-mcrypt-5.3.3-1.el6.i686                                                      1/1
  Verifying  : php-mcrypt-5.3.3-1.el6.i686                                                      1/1

Installed:
  php-mcrypt.i686 0:5.3.3-1.el6

Complete!