How to Configure FTP Server in Linux RHEL 6

In this post i will show how to install Very Secure FTP (Vsftpd) and how to configure ftp server in linux Red Hat Enterprise Linux 6 (RHEL 6). Vsftpd is a GPL licensed FTP server for UNIX systems, including Linux. It is secure and extremely fast and it is stable.

As an example I will install and configure the vsftpd server and will also transfer files from the clients running on the Windows XP command prompt.

-A linux server with ip address 192.168.1.43 running on RHEL 6 Operating system
-A window client with ip address 192.168.1.52 running on Windows XP Pro
-RHEL 6 server Running portmap/rpcbind and xinetd services
-Firewall and SElinux should be off on server

how to configure ftp server in linux

How to Install FTP Server in Linux ?

1. Install vsftpd, rpcbind and xinetd service using the following command :

# yum install vsftpd rpcbind xinetd -y

2. Check vsftpd, xinetd and rpcbind/portmap exist and installed on the server :

# rpm -qa vsftpd
vsftpd-2.2.2-6.el6.i686

# rpm -qa xinetd
xinetd-2.3.14-29.el6.i686

# rpm -qa rpcbind
rpcbind-0.2.0-8.el6.i686

3. Make all these services auto start at boot :

# chkconfig vsftpd on
# chkconfig xinetd on
# chkconfig rpcbind on

4. Check the xinetd and rpcbind status :

# service xinetd status
xinetd (pid  1326) is running...

# service rpcbind status
rpcbind (pid  1178) is running...

5. Create the a new user named ftpuser and set password :

# useradd ftpuser
# passwd ftpuser
Changing password for user ftpuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

6. Login as ftpuser on other terminal and create a new files named “files”.

# su - ftpuser
[ftpuser@rhel6 ~]$ cat > files
This is file created on RHEL 6 ftp server

7. Start the vsftpd service :

# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]

8. Stop the iptables linux firewall and disabled selinux :

# service ip6tables stop
ip6tables: Flushing firewall rules:                        [  OK  ]
ip6tables: Setting chains to policy ACCEPT: filter         [  OK  ]
ip6tables: Unloading modules:                              [  OK  ]

# service iptables stop
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
# setenforce 0
setenforce: SELinux is disabled

How to Configure FTP Server in Linux ?

9. It’s good to make backup of your original configuration file.

[root@rhel6 ~]# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf-bak

10. login from user account and download the files :

D:\>ftp 192.168.1.43
Connected to 192.168.1.43.
220 (vsFTPd 2.2.2)
User (192.168.1.43:(none)): ftpuser
331 Please specify the password.
Password:
230 Login successful.
ftp> get files
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for files (42 bytes).
226 Transfer complete.
ftp: 42 bytes received in 0.00Seconds 42000.00Kbytes/sec.
ftp> quit
221 Goodbye.

11. Check the contain of downloaded files :

D:\>type files
This is file created on RHEL 6 ftp server

12. By default root account is not allowed to login the vsftpd server as it’s exist in /etc/vsftpd/ftpusers.

D:\>ftp 192.168.1.43
Connected to 192.168.1.43.
220 (vsFTPd 2.2.2)
User (192.168.1.43:(none)): root
530 Permission denied.
Login failed.
ftp>

13. Open /etc/vsftpd/ftpusers file. Remove or comment out the line for user “root” and add “ftpuser” instead. Users whose name are set in this file will not allowed to login from ftp.

[root@rhel6 ~]# vi /etc/vsftpd/ftpusers
# Users that are not allowed to login via ftp
#root
ftpuser
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

14. Open /etc/vsftpd/user_list file. Remove or comment out entry in /etc/vsftpd/user_list files. Remove or comment out the line for user “root” and add “ftpuser” instead. Users whose names are set in this file are also not allowed to login from ftp even they are not prompt for password.

# vi /etc/vsftpd/user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
#root
ftpuser
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

15. Root now allowed to access ftp server :

D:\>ftp 192.168.1.43
Connected to 192.168.1.43.
220 (vsFTPd 2.2.2)
User (192.168.1.43:(none)): root
331 Please specify the password.
Password:
230 Login successful.
ftp> quit
221 Goodbye.

16. ftpuser now not allowed to access ftp server :

D:\>ftp 192.168.1.43
Connected to 192.168.1.43.
220 (vsFTPd 2.2.2)
User (192.168.1.43:(none)): ftpuser
530 Permission denied.
Login failed.
ftp>

17. How to set login banner for ftp server :
Open /etc/vsftpd/vsftpd.conf look for “ftpd_banner” :

# vi /etc/vsftpd/vsftpd.conf

Uncomment ftpd_banner and customize the login banner string as below :

# You may fully customise the login banner string:
ftpd_banner=Welcome to eHowStuff.com RHEL6 FTP server
#

18 Restart the ftp service :

# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]

19. Try login to ftp server. Check the banner, it will appear before user login as below :

D:\>ftp 192.168.1.43
Connected to 192.168.1.43.
220 Welcome to eHowStuff.com RHEL6 FTP server
User (192.168.1.43:(none)):

If you encounter any issues on how to configure ftp server in linux, you can put a few questions in the comments below.

7 Useful Linux Utilities

Linux UtilitiesThere are 7 useful linux utilities that you must install on new linux server. Most Linux distributions are equipped with tons of linux command utility, but if you have installed minimal operating system, all these software will not exist. These tools will very useful in your troubleshooting and will help to find possible causes of a problem. Most of the utilities have the same function in CentOS or Red Hat Enterprise Linux (RHEL).

You can easily identify whether the utility installed on your linux operating system or not. You will see one or more below warning :

[root@rhel62 ~]# wget
-bash: wget: command not found
[root@rhel62 ~]# telnet
-bash: telnet: command not found
[root@rhel62 ~]# scp
-bash: scp: command not found
[root@rhel62 ~]# man scp
-bash: man: command not found
[root@rhel62 ~]# nslookup
-bash: nslookup: command not found
[root@rhel62 ~]# dig
-bash: dig: command not found
[root@rhel62 ~]# host
-bash: host: command not found

7 Useful Linux Utilities

1. What is wget ?
Wget is a network utility to retrieve files from the Web using http and ftp, the two most widely used Internet protocols.

Example :

[root@rhel62 ~]# wget http://files2.zimbra.com/downloads/8.0.2_GA/zcs-8.0.2_GA_5569.RHEL6_64.20121210115059.tgz

2. What is telnet ?
Telnet is a network protocol used on the Internet or local area networks. Telnet is a user command and an underlying TCP/IP protocol for accessing remote computers and very useful for troubleshooting and verify the opened ports.

Example :

[root@rhel62 ~]# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 rhel62.ehowstuff.local ESMTP Postfix

3. What is scp ?
scp also call secure copy, is remote file copy utility between hosts on a network. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

Example :

[root@rhel62 ~]# scp root@192.168.2.60:/tmp/VMwareTools-9.2.2-893683.tar.gz .
The authenticity of host '192.168.2.60 (192.168.2.60)' can't be established.
RSA key fingerprint is 76:78:87:36:44:c1:46:fa:c4:b4:61:4a:e5:b3:be:e3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.60' (RSA) to the list of known hosts.
root@192.168.2.60's password:
VMwareTools-9.2.2-893683.tar.gz                                                       100%   63MB  63.3MB/s   00:01

4. What is man ?
man is used to display the manual page for other commands It’s help to explain the functions for the commands that commonly used. The term “man” is short for manual.

Example :

[root@rhel62 ~]# man wget
WGET(1)                            GNU Wget                            WGET(1)

NAME
       Wget - The non-interactive network downloader.

SYNOPSIS
       wget [option]... [URL]...

DESCRIPTION
       GNU Wget is a free utility for non-interactive download of files from the Web.  It supports HTTP,
       HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.

       Wget is non-interactive, meaning that it can work in the background, while the user is not logged on.
       This allows you to start a retrieval and disconnect from the system, letting Wget finish the work.
       By contrast, most of the Web browsers require constant userâs presence, which can be a great
       hindrance when transferring a lot of data.

       Wget can follow links in HTML, XHTML, and CSS pages, to create local versions of remote web sites,
       fully recreating the directory structure of the original site.  This is sometimes referred to as
       "recursive downloading."  While doing that, Wget respects the Robot Exclusion Standard (/robots.txt).
       Wget can be instructed to convert the links in downloaded files to point at the local files, for
       offline viewing.

5. What is nslookup, dig, host ?
nslookup, dig and host are part of the bind utilities.These utilities are the basic tools for DNS client and DNS server troubleshooting.

Examples :

[root@rhel62 ~]# nslookup
> set type=mx
> ehowstuff.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
ehowstuff.com   mail exchanger = 0 ehowstuff.com.

Authoritative answers can be found from:
>
[root@rhel62 ~]# dig ehowstuff.com

; < <>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6 < <>> ehowstuff.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<
[root@rhel62 ~]# host -t mx ehowstuff.com
ehowstuff.com mail is handled by 0 ehowstuff.com.

How to install wget, scpt, telnet, man, nslookup, dig and host utilities ?

Simply run the following commands :

[root@rhel62 ~]# yum install wget telnet openssh-clients bind-utils man -y

How to Install VMware Tools on Red Hat Enterprise Linux 6.2 (RHEL 6.2)

This post will shows how to install VMware Tools on Red Hat Enterprise Linux 6.2 (RHEL 6.2). VMware Tools is a group of utilities that enhances the overall performance of the virtual machine’s guest operating system (OS) and improves management of the virtual machine (VM). This is one of important components in order to provide perfect VM OS. Without the VMware Tools, guest OS performance will lacks some of the important functionality.

1. Install prerequisites :

[root@rhel62 ~]# yum install perl gcc make -y

2. Right click on the VM, click install VMware tools.
3. Mount the installer.

[root@rhel62 ~]# mount -t iso9660 /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only

4. Copy the isntaller to /tmp :

[root@rhel62 ~]# cd /mnt
[root@rhel62 mnt]# cp VMwareTools-9.2.2-893683.tar.gz /tmp

5. Extract the installer :

[root@rhel62 mnt]# cd /tmp
[root@rhel62 tmp]# tar xzvf VMwareTools-9.2.2-893683.tar.gz

6. Go to vmware-tools-distrib directory and install :

[root@rhel62 tmp]# cd vmware-tools-distrib/
[root@rhel62 vmware-tools-distrib]# ls
bin  doc  etc  FILES  INSTALL  installer  lib  vmware-install.pl

Full installation steps :

[root@rhel62 vmware-tools-distrib]# ./vmware-install.pl
Creating a new VMware Tools installer database using the tar4 format.

Installing VMware Tools.

In which directory do you want to install the binary files?
[/usr/bin]

What is the directory that contains the init directories (rc0.d/ to rc6.d/)?
[/etc/rc.d]

What is the directory that contains the init scripts?
[/etc/rc.d/init.d]

In which directory do you want to install the daemon files?
[/usr/sbin]

In which directory do you want to install the library files?
[/usr/lib/vmware-tools]

The path "/usr/lib/vmware-tools" does not exist currently. This program is
going to create it, including needed parent directories. Is this what you want?
[yes]

In which directory do you want to install the documentation files?
[/usr/share/doc/vmware-tools]

The path "/usr/share/doc/vmware-tools" does not exist currently. This program
is going to create it, including needed parent directories. Is this what you
want? [yes]

The installation of VMware Tools 9.2.2 build-893683 for Linux completed
successfully. You can decide to remove this software from your system at any
time by invoking the following command: "/usr/bin/vmware-uninstall-tools.pl".

Before running VMware Tools for the first time, you need to configure it by
invoking the following command: "/usr/bin/vmware-config-tools.pl". Do you want
this program to invoke the command for you now? [yes]

Initializing...


Making sure services for VMware Tools are stopped.



The VMware FileSystem Sync Driver (vmsync) allows external third-party backup
software that is integrated with vSphere to create backups of the virtual
machine. Do you wish to enable this feature? [no]

Found a compatible pre-built module for vmci.  Installing it...


Found a compatible pre-built module for vsock.  Installing it...


The module vmxnet3 has already been installed on this system by another
installer or package and will not be modified by this installer.  Use the flag
--clobber-kernel-modules=vmxnet3 to override.

The module pvscsi has already been installed on this system by another
installer or package and will not be modified by this installer.  Use the flag
--clobber-kernel-modules=pvscsi to override.

The module vmmemctl has already been installed on this system by another
installer or package and will not be modified by this installer.  Use the flag
--clobber-kernel-modules=vmmemctl to override.

The VMware Host-Guest Filesystem allows for shared folders between the host OS
and the guest OS in a Fusion or Workstation virtual environment.  Do you wish
to enable this feature? [yes]

Could not create the '/mnt/hgfs' directory.
The filesystem driver (vmhgfs module) is used only for the shared folder
feature. The rest of the software provided by VMware Tools is designed to work
independently of this feature.

If you wish to have the shared folders feature, you can install the driver by
running vmware-config-tools.pl again after making sure that gcc, binutils, make
and the kernel sources for your running kernel are installed on your machine.
These packages are available on your distribution's installation CD.
[ Press Enter key to continue ]

Found a compatible pre-built module for vmxnet.  Installing it...


The vmblock enables dragging or copying files between host and guest in a
Fusion or Workstation virtual environment.  Do you wish to enable this feature?
[yes]

NOTICE:  It appears your system does not have the required fuse packages
installed.  The VMware blocking filesystem requires the fuse packages and its
libraries to function properly.  Please install the fuse or fuse-utils package
using your systems package management utility and re-run this script in order
to enable the VMware blocking filesystem.

!!! [EXPERIMENTAL] !!!
VMware automatic kernel modules enables automatic building and installation of
VMware kernel modules at boot that are not already present.  By selecting yes,
you will be enabling this experimental feature.  You can always disable this
feature by re-running vmware-config-tools.pl.

Would you like to enable VMware automatic kernel modules?
[no]

No X install found.

Creating a new initrd boot image for the kernel.
vmware-tools-thinprint start/running
vmware-tools start/running
The configuration of VMware Tools 9.2.2 build-893683 for Linux for this running
kernel completed successfully.

You must restart your X session before any mouse or graphics changes take
effect.

You can now run VMware Tools by invoking "/usr/bin/vmware-toolbox-cmd" from the
command line.

To enable advanced X features (e.g., guest resolution fit, drag and drop, and
file and text copy/paste), you will need to do one (or more) of the following:
1. Manually start /usr/bin/vmware-user
2. Log out and log back into your desktop session; and,
3. Restart your X session.

Enjoy,

--the VMware team

How to Remove Volume Group and Physical Volume on LVM

icon-redhatlinuxBasically, adding and removing LVM will always involves these three logical “layers” which are Physical volumes (pv), Volume groups (vg) and Logical volumes (lv). This post assumed that the Logical volumes haven’t created. In certain situation, linux administrators are required to remove the existing Physical Volume or Volume Group only. It is possible to perform the required task if that system administrator has the right skill on linux. The steps as below :

1. Display the physical volumes and Volume Group using pvdisplay command :

[root@centos63 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               vg_data
  PV Size               4.99 GiB / not usable 2.41 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              1278
  Free PE               1278
  Allocated PE          0
  PV UUID               qTmTeq-8qoL-xxEk-Dj5V-zOjl-vEag-P6Jl7L

2. Remove the Volume Group using vgremove command :

[root@centos63 ~]# vgremove vg_data
  Volume group "vg_data" successfully removed

3. Remove Physical Volume using pvremove command :

[root@centos63 ~]# pvremove /dev/sdb1
  Labels on physical volume "/dev/sdb1" successfully wiped

Additional Note :
How to Remove a Logical Volume on CentOS 6.3/RHEL6

How to Secure OpenSSH (SSHD) on Linux

OpenSSH is a open source alternative to the proprietary Secure Shell software. It is also the SSH connectivity tools that allows you to remotely login, transfer remote file via scp or sftp. It was created as an open source alternative to the proprietary Secure Shell software. OpenSSH options are controlled through the /etc/ssh/sshd_config file. In order to improve OpenSSH server security, certain default sshd setting need to be change. This post will show you three example to Secure OpenSSH (SSHD) on Linux. This steps has been tested on CentOS 6.3 and may working on CentOS 6.2, CentOS 5.x and Redhat Enterprise Linux 5 (RHEL 5) and Redhat Enterprise Linux 6 (RHEL 6).

1.Change SSH Default Port :

By default ssh runs on port 22. Hacker would need to know the SSH port number in order to access your system. One of the method to improve security is to change the default port to a non-standard port. That would helps to stop brute force attacks.

#Port 22

Uncomment and change to :

Port 2202

2. Disable Root Login (PermitRootLogin) :

Add the following entry to sshd_config to disable root to login to the server directly.

#PermitRootLogin yes

Uncomment and change to :

PermitRootLogin no

3. Listen Specific IP only :

By default ssh will listen on all of the above ip-addresses. If you want users to login only using ip-address 192.168.1.200 and 192.168.1.202, do the following in your sshd_config :

ListenAddress 192.168.1.200
ListenAddress 192.168.1.202

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 Remove a Logical Volume on CentOS 6.3/RHEL6

In previous post, i have cover the steps to create additional Logical volume manager (LVM). In certain situation, linux administrator is required to remove the existing logical volume. It is possible to perform the required 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 this working with the system’s data. This post assumed centos63_vol has been created and will be remove later. In summary, removing a logical volume (centos63_vol) will involve the following processes:

a) Unmount the LV
b) Remove the LV
c) Update /etc/fstab

1. Begin by listing all the logical volumes on the system :

[root@centos63 ~]# lvs
  LV           VG          Attr     LSize Pool Origin Data%  Move Log Copy%  Convert
  lv_root      vg_centos63 -wi-ao-- 5.54g
  lv_swap      vg_centos63 -wi-ao-- 1.97g
  centos63_vol vg_data     -wi-ao-- 4.99g

2. Check current disk layout and find where centos63_vol is mounted :

[root@centos63 ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos63-lv_root
                      5.5G  2.2G  3.1G  41% /
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

3. View current /etc/fstab value :

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

#
# /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

4. Unmount centos63_vol (mounted at /mydata) :

[root@centos63 ~]# umount /mydata

5. Verify that centos63_vol has unmounted :

[root@centos63 ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos63-lv_root
                      5.5G  2.2G  3.1G  41% /
tmpfs                 504M     0  504M   0% /dev/shm
/dev/sda1             485M   65M  395M  15% /boot

6. Remove the logical volume /dev/mapper/vg_data-centos63_vol :

[root@centos63 ~]# lvremove /dev/mapper/vg_data-centos63_vol
Do you really want to remove active logical volume centos63_vol? [y/n]: y
  Logical volume "centos63_vol" successfully removed

7. Verify the logical volume has been removed :

[root@centos63 ~]# lvs
  LV      VG          Attr     LSize Pool Origin Data%  Move Log Copy%  Convert
  lv_root vg_centos63 -wi-ao-- 5.54g
  lv_swap vg_centos63 -wi-ao-- 1.97g
[root@centos63 ~]#

8. Update /etc/fstab to reflect the removal of the file system :

[root@centos63 ~]# vi /etc/fstab
#
# /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

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 Add Webtatic Repository on CentOS 6.3

This post covers the steps on how to setup additional yum repository using Webtatic. Webtatic yum repository is a repository containing updated web-related packages for CentOS and Redhat Enterprise Linux (RHEL). 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@centos63 ~]# wget http://repo.webtatic.com/yum/el6/i386/webtatic-release-6-2.noarch.rpm

Example :

[root@centos63 ~]# wget http://repo.webtatic.com/yum/el6/i386/webtatic-release-6-2.noarch.rpm
--2012-08-13 23:42:08--  http://repo.webtatic.com/yum/el6/i386/webtatic-release-6-2.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: 11576 (11K) [application/x-redhat-package-manager]
Saving to: âwebtatic-release-6-2.noarch.rpmâ

100%[==========================================================>] 11,576      15.7K/s   in 0.7s

2012-08-13 23:42:10 (15.7 KB/s) - âwebtatic-release-6-2.noarch.rpmâ

2. Download or directly import webtatic-andy GPG key :

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

3. Do verification on the webtatic-release package that you have downloaded :

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

4. Install Webtatic Repository :

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

5. How you can use Webtatic repository to install, update the packages :

[root@centos63 ~]# yum --enablerepo=webtatic install [rpm package]

Examples :

[root@centos63 ~]# yum --enablerepo=webtatic install postfix -y

How to Check Postfix Version

PosfixThis short guides shows how to quickly check your postfix mail server version. Basically, postfix is a open-source mail transfer agent (MTA) that routes and delivers electronic mail. Postfix is an alternative for Sendmail service which provide the same function.

Please execute the following command :

postconf -d | grep mail_version

Examples :

[root@centos62 ~]# postconf -d | grep mail_version
mail_version = 2.6.6
milter_macro_v = $mail_name $mail_version

How to Switching or Changing Between Different Runlevels on Linux

linuxThe runlevel is a software configuration of the system which allows only a selected group of processes to exist. Usually runlevel 0, 1 and 6 are the same and reserved for the following purposes :

0 – halt
1 – single mode
6 – reboot

Meanwhile runlevel 2,3,4 and 5 used for the following :

2 – Multi-User Mode
3 – Multi-User Mode with Networking
4 – Not used/User-definable
5 – Start the system normally with appropriate display manager. ( with GUI )

How to Check and Display Runlevel on Unix or Linux System

In this post, i will show two method to switching or changing between different runlevels on linux. The steps has been tested on CentOS 6.2.

Method 1. Changing run level temporarily without reboot :

In order to change the run level immediately without reboot, you can use init command. Assumed that you are currently in the default run level 3 and want to switch to run level 1 which is will enter single user mode, execute “init 1” :

[root@centos62 ~]# init 1

To shutdown the system, execute “init 0” :

[root@centos62 ~]# init 0

To reboots the system, execute “init 6” :

[root@centos62 ~]# init 6

Please note that above command is not permanent and the system will return to default run level after reboot.

Method 2. Changing the run level permanently :

[root@centos62 ~]# vi /etc/inittab

Let assumed the default run level is 3.

#
id:3:initdefault:

Change the initdefault to 5 as below :

#
id:5:initdefault:

How to Check and Display Runlevel on Unix or Linux System

This example shows the correct ways to check run level on unix or linux server. The runlevel is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init command/process for each of these runlevels are defined in the /etc/inittab file. Usually runlevel 0, 1 and 6 are the same and reserved for the following purposes :

0 – halt
1 – single mode
6 – reboot

Meanwhile runlevel 2,3,4 and 5 used for the following :

2 – Multi-User Mode
3 – Multi-User Mode with Networking
4 – Not used/User-definable
5 – Start the system normally with appropriate display manager. ( with GUI )

1. Check and display runlevel using “who” command :

[root@centos62 ~]# who -r
         run-level 3  2012-07-07 09:58

2. Check and display current and previous system runlevel using “runlevel” command :

[root@centos62 ~]# runlevel
N 3

How to Switching or Changing Between Different Runlevels on Linux