Sunday 29 April 2012

Complete LVM steps in rhel 6

[root@station1 Desktop]# fdisk /dev/sda

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
First cylinder (10609-19457, default 10609):
Using default value 10609
Last cylinder, +cylinders or +size{K,M,G} (10609-19457, default 19457): +512M

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

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@station1 Desktop]# reboot
[root@station1 Desktop]# pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created
[root@station1 Desktop]# vgcreate shazam /dev/sda6
Volume group "shazam" successfully created
[root@station1 Desktop]# lvcreate -n storage -L 256M shazam
Logical volume "storage" created
[root@station1 Desktop]# mkfs -t ext4 /dev/shazam/storage
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
32 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185

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

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@station1 Desktop]# mkdir /storage
[root@station1 Desktop]# vim /etc/fstab
/dev/shazam/storage /storage ext4 defaults 1 2
[root@station1 Desktop]# mount -a
[root@station1 Desktop]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 29G 8.6G 19G 32% /
tmpfs 495M 100K 495M 1% /dev/shm
/dev/sda1 985M 39M 897M 5% /boot
/dev/sda5 46G 2.2G 42G 5% /sambashare
/dev/mapper/shazam-storage
248M 11M 226M 5% /storage
[root@station1 Desktop]#

------------------------extending a logical volume---------------------------
NOTE: NO NEED TO UNMOUNT THE VOLUME WHILE EXTENDING

[root@station1 Desktop]# vgdisplay shazam
--- Volume group ---
VG Name shazam
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 516.00 MiB
PE Size 4.00 MiB
Total PE 129
Alloc PE / Size 64 / 256.00 MiB
Free PE / Size 65 / 260.00 MiB --------->FREE SPACE IS 65 EXTENTS SO I USED +32 i.e HALF OF THE FREE SPACE
VG UUID NJ5N0M-09GF-KfKa-TT6Z-uMGL-mdRE-Dq1YPo

[root@station1 Desktop]# lvextend -l +32 /dev/shazam/storage
Extending logical volume storage to 384.00 MiB
Logical volume storage successfully resized
[root@station1 Desktop]# resize2fs /dev/shazam/storage
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/shazam/storage is mounted on /storage; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/shazam/storage to 393216 (1k) blocks.
The filesystem on /dev/shazam/storage is now 393216 blocks long.

[root@station1 Desktop]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 29G 8.6G 19G 32% /
tmpfs 495M 100K 495M 1% /dev/shm
/dev/sda1 985M 39M 897M 5% /boot
/dev/sda5 46G 2.2G 42G 5% /sambashare
/dev/mapper/shazam-storage
372M 11M 343M 3% /storage

--------------------------------Extending Volume Group---------------------------
[root@station1 Desktop]# fdisk /dev/sda

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
First cylinder (10609-19457, default 10609):
Using default value 10609
Last cylinder, +cylinders or +size{K,M,G} (10609-19457, default 19457): +512M

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

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@station1 Desktop]# reboot
[root@station1 Desktop]# pvcreate /dev/sda
sda sda1 sda2 sda3 sda4 sda5 sda6 sda7
[root@station1 Desktop]# pvcreate /dev/sda7
Physical volume "/dev/sda7" successfully created
[root@station1 Desktop]# vgextend shazam /dev/sda7
Volume group "shazam" successfully extended
[root@station1 Desktop]# pvdisplay
--- Physical volume ---
PV Name /dev/sda6
VG Name shazam
PV Size 517.69 MiB / not usable 1.69 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 129
Free PE 33
Allocated PE 96
PV UUID SY87lw-LqeE-2Vxv-4Hh6-fLSV-mTy2-Jt8VNm

--- Physical volume ---
PV Name /dev/sda7
VG Name shazam
PV Size 517.69 MiB / not usable 1.69 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 129
Free PE 129
Allocated PE 0
PV UUID sLoDna-esoW-pqms-Vc3k-Pc4c-RC4g-p8T130
-----------------------------------------to reduce vg-----------------------------

[root@station1 Desktop]# vgreduce shazam /dev/sda7
Removed "/dev/sda7" from volume group "shazam"
[root@station1 Desktop]# pvdisplay
--- Physical volume ---
PV Name /dev/sda6
VG Name shazam
PV Size 517.69 MiB / not usable 1.69 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 129
Free PE 65
Allocated PE 64
PV UUID SY87lw-LqeE-2Vxv-4Hh6-fLSV-mTy2-Jt8VNm

"/dev/sda7" is a new physical volume of "517.69 MiB"
--- NEW Physical volume ---
PV Name /dev/sda7
VG Name
PV Size 517.69 MiB
Allocatable NO
PE Size 0 ----------> look everything is 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID sLoDna-esoW-pqms-Vc3k-Pc4c-RC4g-p8T130

[root@station1 Desktop]# vgdisplay
--- Volume group ---
VG Name shazam
System ID
Format lvm2
Metadata Areas 1 ---------> look 1 is here
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 516.00 MiB ------------> look only 516 is here
PE Size 4.00 MiB
Total PE 129
Alloc PE / Size 64 / 256.00 MiB
Free PE / Size 65 / 260.00 MiB
VG UUID NJ5N0M-09GF-KfKa-TT6Z-uMGL-mdRE-Dq1YPo

NOTE: sda7 is just remove from the shazam it can be added at any time by command 'vgextend shazam /dev/sda7'


Saturday 28 April 2012

how to check our cpu supports kvm module

[root@station1 ~]# egrep -c '(vmx|svm)' /proc/cpuinfo
0
if results = 0 ur cpu not support KVM
if results = 1 support KVM

Tuesday 17 April 2012

how to reinstall the Grub in rhel 6.X / Centos 6.X

The following steps detail the process on how GRUB is reinstalled on the master boot record:

    Boot the system from an installation boot medium.
    Type linux rescue at the installation boot prompt to enter the rescue environment.
    Type chroot /mnt/sysimage to mount the root partition.
    Type /sbin/grub-install bootpart to reinstall the GRUB boot loader, where bootpart is the boot partition (typically, /dev/sda).
    Review the /boot/grub/grub.conf file, as additional entries may be needed for GRUB to control additional operating systems.
    Reboot the system.

how to install vlc in rhel6.X / centos 6.X

Download repository from this link rpmforge  according to your system architecture use uname -i to find your system architecture.

[root@localhost Desktop]# uname -i
x86_64
[root@localhost Desktop]# rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
[root@localhost Desktop]# yum install vlc

To enable Root access to VLC player

vi /usr/bin/vlc
search for all geteuid and replace it with getppid
(use /geteuid to search)

Save&exit

Friday 13 April 2012

Passwordless SSH Authentication

[root@station1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):  (dont type anyting just press enter everywhere)
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
d8:98:4b:01:c2:dc:95:be:17:c3:5a:23:02:dc:06:00 root@station1.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|E=o+....         |
|  =.+..          |
|   o ...         |
|    . o**        |
|     .==S+       |
|     .o..        |
|      ..         |
|                 |
|                 |
+-----------------+
[root@station1 ~]#
[root@station1 ~]# scp -r /root/.ssh/id_rsa.pub 10.65.62.32:/root/.ssh/id_rsa.pub.server
[root@station1 ~]# ssh 10.65.62.32
Password:

[root@station2 ~]# cat /root/.ssh/id_rsa.pub.server >> /root/.ssh/authorized_keys
[root@station2 ~]# vim /etc/ssh/sshd_config

  49 AuthorizedKeysFile      .ssh/authorized_keys

[root@station2 ~]# service sshd restart
[root@station2 ~]# exit
[root@station1 ~]# ssh 10.65.62.32
now with out asking password it will login to station2
[root@station2 ~]#

Observing User activity with “psacct”

[root@station1 Downloads]# rpm -qa *psacct*
psacct-6.3.2-63.el6.x86_64
[root@station1 Downloads]# service psacct start
Starting process accounting:                               [  OK  ]
[root@station1 Downloads]# ac -p
    root                                 8.81
    total        8.81

Above command will give you Times Totals for Users.

Now, to find out which user has executed what command on system,
[root@station1 Downloads]# lastcomm root
Process      Flags    User    Terminal      Time
smbd               F    root     __         0.00 secs Fri Apr 13 19:20
crond             SF    root     __         0.00 secs Fri Apr 13 19:20
sadc              S     root     __         0.00 secs Fri Apr 13 19:20
bash               F    root     pts/3      0.00 secs Fri Apr 13 19:19
ac                      root     pts/3      0.00 secs Fri Apr 13 19:19
service                 root     pts/3      0.01 secs Fri Apr 13 19:19
psacct                  root     pts/3      0.01 secs Fri Apr 13 19:19
touch                   root     pts/3      0.00 secs Fri Apr 13 19:19
accton            S     root     pts/3      0.00 secs Fri Apr 13 19:19
 
Flags:
 

S - executed as super-user
F - executed after  but not following exec
D - terminated with core file
X - terminated with signal SIGTERM
stop the service if you don't want psacct to monitor 
[root@station1 Downloads]# service psacct stop
Shutting down process accounting:                          [  OK  ]


 
 
 
 

Securing SSH

[root@station1 ~]# vim /etc/ssh/sshd_config

 41 LoginGraceTime 2m
 42 PermitRootLogin no
 43 StrictModes yes
 44 MaxAuthTries 3
 45 MaxSessions 3


Find ClientAliveInterval and set to 600 (10 minutes) as follows:

119 ClientAliveInterval 600   ----> client can interact with server for only 10min.
120 ClientAliveCountMax 0

[root@station1 ~]# service sshd restart
Stopping sshd:                                            [  OK  ]
Starting sshd:                                             [  OK  ]

DoS Attack Detection In Linux

You can simply use netstat command to print out a list of all open connection to your Linux box. The list will be sorted out using sort command including total number of connections from a specific IP address.
Login as the root user and type the following command,
[root@station1 ~]# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
      1 124.124.201.170
      1 Address
      1 servers)
      4 209.85.175.191
      4 74.125.236.115

TestDisk – Data Recovery Software for Linux

click here to download testdisk package

[root@station1 ~]# cd /root/Downloads/
[root@station1 Downloads]# ls
fuse-ntfs-3g-2010.10.2-1.el6.rf.x86_64.rpm  testdisk-6.14-WIP.linux26.tar.bz2
[root@station1 Downloads]# tar -xjvf testdisk-6.14-WIP.linux26.tar.bz2
testdisk-6.14-WIP/
testdisk-6.14-WIP/photorec.8
testdisk-6.14-WIP/README
testdisk-6.14-WIP/l/
testdisk-6.14-WIP/l/linux
testdisk-6.14-WIP/NEWS
testdisk-6.14-WIP/readme.txt
testdisk-6.14-WIP/ChangeLog
testdisk-6.14-WIP/fidentify_static
testdisk-6.14-WIP/testdisk_static
testdisk-6.14-WIP/documentation.html
testdisk-6.14-WIP/fidentify.8
testdisk-6.14-WIP/testdisk.8
testdisk-6.14-WIP/VERSION
testdisk-6.14-WIP/THANKS
testdisk-6.14-WIP/INFO
testdisk-6.14-WIP/COPYING
testdisk-6.14-WIP/AUTHORS
testdisk-6.14-WIP/photorec_static
testdisk-6.14-WIP/ico/
testdisk-6.14-WIP/ico/photorec.ico
testdisk-6.14-WIP/ico/testdisk.ico
[root@station1 Downloads]# ls
fuse-ntfs-3g-2010.10.2-1.el6.rf.x86_64.rpm  testdisk-6.14-WIP  testdisk-6.14-WIP.linux26.tar.bz2
[root@station1 Downloads]# cd testdisk-6.14-WIP
[root@station1 testdisk-6.14-WIP]# ls
AUTHORS    COPYING             fidentify.8       ico   l     photorec.8       README      testdisk.8       THANKS
ChangeLog  documentation.html  fidentify_static  INFO  NEWS  photorec_static  readme.txt  testdisk_static  VERSION
[root@station1 testdisk-6.14-WIP]# ./testdisk_static
select the disk and proceed..  This will recover lost data


Apache Linux-Limiting User Upload File Size


To restricts Users from uploading File Size, we can configure Apache with LimitRequestBody Directive. You can add this directive using .htaccess file or httpd.conf file under virtual host or directory configuration options. You can set value (in bytes) from 0 (unlimited) to 2147483647 (2GB) that are allowed in a request body.
For example, limit /var/www/html/example.com/uploads to 200K, you might use the following directive (add to .htaccess or httpd.conf file):
<Directory “/var/www/html/example.com/uploads”>
LimitRequestBody 204800
</Directory>
Restart Apache Server, if added to httpd.conf.
# service httpd restart

Ctrl Alt Delete Deactivation in rhel6

[root@station1 Documents]# vim /etc/init/control-alt-delete.conf

# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed.  Usually used to shut down the machine.

#start on control-alt-delete    ------> comment these two lines

#exec /sbin/shutdown -r now "Control-Alt-Delete pressed"

Linux Kernel Performance and Tuning with vm.swappiness


vm.swappiness is a tunable kernel parameter that controls how much the kernel favors swap over RAM. At the source code level, it’s also defined as the tendency to steal mapped memory. A high swappiness value means that the kernel will be more apt to unmap mapped pages. A low swappiness value means the opposite, the kernel will be less apt to unmap mapped pages. In other words, the higher the vm.swappiness value, the more the system will swap.
The default value I’ve seen on RHEL/CentOS/SLES is 60.
To find out what the default value is on a particular server, run:
[root@station1 Documents]# sysctl vm.swappiness
vm.swappiness = 60
The value is also located in /proc/sys/vm/swappiness.
[root@station1 Documents]# cat /proc/sys/vm/swappiness
60
 
Note: You can set the maximum value up to 100, the minimum is 0.

LAMP server configuration in rhel6

[root@station1 ~]# yum groupinstall "MySQL Database server"
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Setting up Group Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.x86_64 0:5.1.52-1.el6_0.1 will be installed
--> Processing Dependency: mysql = 5.1.52-1.el6_0.1 for package: mysql-server-5.1.52-1.el6_0.1.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.52-1.el6_0.1.x86_64
--> Running transaction check
---> Package mysql.x86_64 0:5.1.52-1.el6_0.1 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                          Arch                     Version                            Repository                Size
=============================================================================================================================
Installing:
 mysql-server                     x86_64                   5.1.52-1.el6_0.1                   server                   8.1 M
Installing for dependencies:
 mysql                            x86_64                   5.1.52-1.el6_0.1                   server                   889 k
 perl-DBD-MySQL                   x86_64                   4.013-3.el6                        server                   134 k

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

Total download size: 9.1 M
Installed size: 26 M
Is this ok [y/N]: y
Downloading Packages:
-----------------------------------------------------------------------------------------------------------------------------
Total                                                                                         37 MB/s | 9.1 MB     00:00    
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-5.1.52-1.el6_0.1.x86_64                                                                             1/3
  Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                                                                         2/3
  Installing : mysql-server-5.1.52-1.el6_0.1.x86_64                                                                      3/3
Installed products updated.

Installed:
  mysql-server.x86_64 0:5.1.52-1.el6_0.1                                                                                    

Dependency Installed:
  mysql.x86_64 0:5.1.52-1.el6_0.1                             perl-DBD-MySQL.x86_64 0:4.013-3.el6                           

Complete!
[root@station1 samba]# service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h station1.example.com password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@station1 samba]# mysqladmin -u root password password
[root@station1 samba]# mysql -u root -ppassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> DELETE FROM mysql.user WHERE user = '';
Query OK, 2 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

Now Download mysql-gui-tools-5.0r12-linux-x86_64.tar.gz this package extract and keep the folder in /opt directory
[root@station1 ~]# cd /opt/mysql-gui-tools-5.0/
[root@station1 mysql-gui-tools-5.0]# cp MySQLAdministrator.desktop MySQLQueryBrowser.desktop /root/Desktop/
now go to your desktop and double click these two files wait for few seconds and click mark trusted option now you
can see the icons. login as shown in the screenshot below password is your mysql password "password"

yum server configuration in rhel6

********INSERT RHEL6 DVD IN TO YOUR DVD ROM*********
[root@station1 Desktop]# mount /dev/cdrom /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@station1 Desktop]# cp -a /mnt/Packages/ /
[root@station1 Desktop]# cd /Packages/
[root@station1 Packages]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
warning: deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:deltarpm               ########################################### [100%]
[root@station1 Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
warning: python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:python-deltarpm        ########################################### [100%]
[root@station1 Packages]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm
warning: createrepo-0.9.8-4.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:createrepo             ########################################### [100%]
[root@station1 Packages]# cp /mnt/repodata/8afad1febf2d8844a235a9ab1aa5f15c9cec1219b9d01060d4794435cf59dffe-comps-rhel6-Server.xml /tmp/
[root@station1 Packages]# createrepo -g /tmp/8afad1febf2d8844a235a9ab1aa5f15c9cec1219b9d01060d4794435cf59dffe-comps-rhel6-Server.xml /Packages/
3596/3596 - anaconda-yum-plugins-1.0-5.1.el6.noarch.rpm                        
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[root@station1 Packages]# cd /etc/yum.repos.d/
[root@station1 yum.repos.d]# ls
rhel-source.repo
[root@station1 yum.repos.d]# cp rhel-source.repo server.repo
[root@station1 yum.repos.d]# vim server.repo
[server]
name=Red Hat Enterprise Linux
baseurl=file:/Packages
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@station1 yum.repos.d]# yum clean all
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Cleaning repos: server
Cleaning up Everything
[root@station1 yum.repos.d]# yum list all
[root@station1 yum.repos.d]# yum grouplist

samba server configuration(CIFS) in rhel6

[root@station1 ~]# yum groupinstall "CIFS file server"
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
server                                                                                                             3596/3596
Setting up Group Process
Resolving Dependencies
--> Running transaction check
---> Package samba.x86_64 0:3.5.10-114.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                   Arch                       Version                               Repository                  Size
=============================================================================================================================
Installing:
 samba                     x86_64                     3.5.10-114.el6                        server                     5.0 M

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

Total download size: 5.0 M
Installed size: 17 M
Is this ok [y/N]: y
Downloading Packages:
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Importing GPG key 0xFD431D51:
 Userid : Red Hat, Inc. (release key 2) <security@redhat.com>
 Package: redhat-release-server-6Server-6.2.0.3.el6.x86_64 (@anaconda-RedHatEnterpriseLinux-201111171049.x86_64/6.2)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Is this ok [y/N]: y
Importing GPG key 0x2FA658E0:
 Userid : Red Hat, Inc. (auxiliary key) <security@redhat.com>
 Package: redhat-release-server-6Server-6.2.0.3.el6.x86_64 (@anaconda-RedHatEnterpriseLinux-201111171049.x86_64/6.2)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : samba-3.5.10-114.el6.x86_64                                                                               1/1
Installed products updated.

Installed:
  samba.x86_64 0:3.5.10-114.el6                                                                                             

Complete!
[root@station1 ~]# chkconfig smb on
[root@station1 ~]# chkconfig nmb on
[root@station1 ~]# vim /etc/samba/smb.conf
 74         workgroup = WORKGROUP
 80         hosts allow = 10.65.62.
289         [public]
290         comment = Public Stuff
291         path = /home/samba
292         public = yes
293         writable = yes
294         printable = no
295         browseable = yes
296         valid users = ranjith
[root@station1 ~]# mkdir /home/samba
[root@station1 ~]# chmod -R 777 /home/samba/
[root@station1 ~]# smbpasswd -a ranjith
New SMB password:
Retype new SMB password:
tdbsam_open: Converting version 0.0 database to version 4.0.
tdbsam_convert_backup: updated /var/lib/samba/private/passdb.tdb file.
account_policy_get: tdb_fetch_uint32 failed for type 1 (min password length), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 2 (password history), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 3 (user must logon to change password), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 4 (maximum password age), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 5 (minimum password age), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 6 (lockout duration), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 7 (reset count minutes), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 8 (bad lockout attempt), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 9 (disconnect time), returning 0
account_policy_get: tdb_fetch_uint32 failed for type 10 (refuse machine password change), returning 0
Added user ranjith.
[root@station1 ~]# smbpasswd -e ranjith
Enabled user ranjith.
[root@station1 ~]# service smb restart
Shutting down SMB services:                                [FAILED]
Starting SMB services:                                     [  OK  ]
[root@station1 ~]# service nmb restart
Shutting down NMB services:                                [FAILED]
Starting NMB services:                                     [  OK  ]
[root@station1 ~]# smbclient -L //10.65.62.30 -U ranjith
Enter ranjith's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.5.10-114.el6]

    Sharename       Type      Comment
    ---------       ----      -------
    public          Disk      Public Stuff
    IPC$            IPC       IPC Service (Samba Server Version 3.5.10-114.el6)
    ranjith         Disk      Home Directories
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.5.10-114.el6]

    Server               Comment
    ---------            -------
    STATION1             Samba Server Version 3.5.10-114.el6

    Workgroup            Master
    ---------            -------
    WORKGROUP            STATION1

After this go to windows pc start->run->\\your samba server ip

How to configure Master DNS in rhel6.X / centos 6.X

[root@upload ~]# yum install bind*
[root@upload ~]# chkconfig named on
[root@upload named]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
10.66.191.230    upload    upload.zumi.com
10.66.191.221    upload2    upload2.zumi.com
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@upload named]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=upload.zumi.com
DNSDOMAINNAME=zumi.com
[root@upload named]# cat /etc/named.conf


options {
        listen-on port 53 { any; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { 10.66.191.230; any; };
        allow-transfer { localhost; 10.66.191.221; };
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";
        managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};
zone "zumi.com." {
       type master;
       file "zumi.com.zone";
       allow-update { none; };
};

zone "191.66.10.in-addr.arpa." {
      type master;
      file "191.66.10.in-addr.arpa.zone";
      allow-update { none; };
};

include "/etc/named.rfc1912.zones";
[root@upload named]# cat zumi.com.zone
$TTL    86400
@    IN      SOA   upload.zumi.com.  root.zumi.com. (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum            
             IN    NS             upload.zumi.com.
             IN    NS             upload2.zumi.com.
         IN       A          10.66.191.230
         IN       MX    1      upload.zumi.com
upload       IN    A              10.66.191.230
upload2         IN    A              10.66.191.221
imap         IN       CNAME          upload
pop         IN       CNAME          upload
pop3         IN       CNAME          upload
www         IN       CNAME          upload
smtp         IN       CNAME          upload
mail         IN       CNAME          upload
[root@upload named]# cat 191.66.10.in-addr.arpa.zone
$TTL    86400
@       IN     SOA     upload.zumi.com. root.zumi.com. (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum

             IN     NS      upload.zumi.com.
          IN     PTR     zumi.com.   
230       IN     PTR     upload.zumi.com.
221       IN     PTR     upload2.zumi.com.

 [root@upload named]# service named restart
Stopping named: .                                          [  OK  ]
Starting named:                                            [  OK  ]
[root@upload named]# nslookup zumi.com
Server:        127.0.0.1
Address:    127.0.0.1#53

Name:    zumi.com
Address: 10.66.191.230

[root@upload named]# nslookup upload.zumi.com
Server:        127.0.0.1
Address:    127.0.0.1#53

Name:    upload.zumi.com
Address: 10.66.191.230

[root@upload named]# dig upload.zumi.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> upload.zumi.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56812
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; QUESTION SECTION:
;upload.zumi.com.        IN    A

;; ANSWER SECTION:
upload.zumi.com.    86400    IN    A    10.66.191.230

;; AUTHORITY SECTION:
zumi.com.        86400    IN    NS    upload.zumi.com.
zumi.com.        86400    IN    NS    upload2.zumi.com.

;; ADDITIONAL SECTION:
upload2.zumi.com.    86400    IN    A    10.66.191.221

;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Oct  4 18:53:36 2013
;; MSG SIZE  rcvd: 101

[root@upload named]#

Postfix configuration in rhel6

[root@station1 ~]# yum install -y postfix*
[root@station1 ~]# vim /etc/postfix/main.cf
 75 myhostname = station1.example.com
 83 mydomain = example.com
 99 myorigin = $mydomain
113 inet_interfaces = all
116 #inet_interfaces = localhost
165 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
[root@station1 ~]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
[root@station1 ~]# mail
No mail for root
[root@station1 ~]# mail root@station1.example.com
Subject: test mail
hai root  (after this press enter and ctrl+d dont type EOT like below)
EOT
[root@station1 ~]# mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 root                  Fri Apr 13 11:55  18/598   "test mail"
& 1  
Message  1:
From root@example.com  Fri Apr 13 11:55:36 2012
Return-Path: <root@example.com>
X-Original-To: root@station1.example.com
Delivered-To: root@station1.example.com
Date: Fri, 13 Apr 2012 11:55:35 +0530
To: root@station1.example.com
Subject: test mail
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: root@example.com (root)
Status: R

hai root

&(press ctrl+d to exit)
[root@station1 ~]# mail ranjith@station1.example.com
Subject: testmail
hai ranjith...(after this press enter and ctrl+d dont type EOT like below)
EOT    
[root@station1 ~]# su - ranjith
[ranjith@station1 ~]$ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/ranjith": 1 message 1 new
>N  1 root                  Fri Apr 13 12:05  18/612   "testmail"
& 1
Message  1:
From root@example.com  Fri Apr 13 12:05:54 2012
Return-Path: <root@example.com>
X-Original-To: ranjith@station1.example.com
Delivered-To: ranjith@station1.example.com
Date: Fri, 13 Apr 2012 12:05:54 +0530
To: ranjith@station1.example.com
Subject: testmail
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: root@example.com (root)
Status: R

hai ranjith...

& R 1
To: root@example.com
Subject: Re: testmail

root@example.com (root) wrote:

> hai ranjith...
hai root i got your mail.

EOT
& d   (to delete the mail) or s to save the mail in mbox
& q   (quit)
[ranjith@station1 ~]$ exit
logout
You have new mail in /var/spool/mail/root
[root@station1 ~]# mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 ranjith               Fri Apr 13 12:07  24/780   "Re: testmail"
& 1
Message  1:
From ranjith@example.com  Fri Apr 13 12:07:37 2012
Return-Path: <ranjith@example.com>
X-Original-To: root@example.com
Delivered-To: root@example.com
Date: Fri, 13 Apr 2012 12:07:37 +0530
To: root@example.com
Subject: Re: testmail
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: ranjith@example.com (ranjith)
Status: R

root@example.com (root) wrote:

> hai ranjith...
hai root i got your mail.

& s   (save the mail)
"/root/mbox" [New file] 26/802
& q
[root@station1 ~]# ls
anaconda-ks.cfg  Documents  install.log         mbox   Pictures  Templates
Desktop          Downloads  install.log.syslog  Music  Public    Videos



Thursday 12 April 2012

how to change mysql password

[root@station1 ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
[root@station1 ~]# mysqld_safe --skip-grant-tables --skip-networking &
[1] 20120
[root@station1 ~]# 120315 12:05:24 mysqld_safe Logging to '/var/log/mysqld.log'.
120315 12:05:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@station1 ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password("redhat") where user="root";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3  Changed: 0  Warnings: 0

mysql> exit
Bye
[root@station1 ~]# service mysqld restart
120315 12:06:25 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[1]+  Done                    mysqld_safe --skip-grant-tables --skip-networking
[root@station1 ~]# mysql -u root -predhat
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

ssh welcome banner

[root@station1 ~]# ssh station2
root@station2 password:
Last login: Mon Apr 10 18:58:43 2012 from localhost.localdomain
[root@station2 ~]#
Changing this message requires editing two different files. Open /etc/motd file and enter banner message.
[root@station2 ~]# vim /etc/motd
welcome to station2
Save and exit the file.
Now open sshd configuration file /etc/ssh/sshd_config,
[root@station2 ~]# vim /etc/ssh/sshd_config
PrintLastLog no ----->find this line and edit
Save and exit the file. Restart SSH service,
[root@station2 ~]# service sshd restart
[root@station2 ~]# exit
Now when you login, we will get below message,
[root@station1 ~]# ssh station2
root@station2 password:
Last login: Mon Apr 10 18:58:43 2012 from localhost.localdomain
Welcome to station2      ---------> see your welcome message
[root@ station2 ~]#

mysql installation and some basics

[root@station1 Desktop]# yum install -y mysql*
[root@station1 Desktop]# service mysqld start
[root@station1 Desktop]# mysqladmin -u root password password   ------> setting password for the root user
[root@station1 Desktop]# mysql -u root -ppassword               ------> login
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
23 rows in set (0.00 sec)
mysql> select * from user;
mysql> DELETE FROM mysql.user WHERE user = '';  ----> to delete anonymous users.
mysql> flush privileges;
mysql> show engines;
mysql> show processlist;
mysql> create database RanjithContacts;
Query OK, 1 row affected (0.00 sec)

how to install virtualbox in rhel6

Download the latest version from here

https://www.virtualbox.org/wiki/Downloads

Download the latest version of dkms from here

http://rpmfind.net/linux/rpm2html/search.php?query=dkms

I have already download and kept these two file in a directory virutalbox_setupfile

[root@station1 samba]# cd virutalbox_setupfile/
[root@station1 virutalbox_setupfile]# ls
dkms-2.1.1.2-1.el6.rf.noarch.rpm  VirtualBox-4.1-4.1.10_76795_rhel6-1.x86_64.rpm
[root@station1 virutalbox_setupfile]# yum install -y gcc
[root@station1 virutalbox_setupfile]# yum install -y kernel-devel
[root@station1 virutalbox_setupfile]# rpm -ivh dkms-2.1.1.2-1.el6.rf.noarch.rpm
warning: dkms-2.1.1.2-1.el6.rf.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing...                ########################################### [100%]
   1:dkms                   ########################################### [100%]
[root@station1 virutalbox_setupfile]# ls
dkms-2.1.1.2-1.el6.rf.noarch.rpm  VirtualBox-4.1-4.1.10_76795_rhel6-1.x86_64.rpm
[root@station1 virutalbox_setupfile]# rpm -ivh VirtualBox-4.1-4.1.10_76795_rhel6-1.x86_64.rpm
warning: VirtualBox-4.1-4.1.10_76795_rhel6-1.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 98ab5139: NOKEY
Preparing...                ########################################### [100%]
   1:VirtualBox-4.1         ########################################### [100%]

Creating group 'vboxusers'. VM users must be member of that group!

No precompiled module for this kernel found -- trying to build one. Messages
emitted during module compilation will be logged to /var/log/vbox-install.log.

Stopping VirtualBox kernel modules [  OK  ]
Uninstalling old VirtualBox DKMS kernel modules [  OK  ]
Trying to register the VirtualBox kernel modules using DKMS [  OK  ]
Starting VirtualBox kernel modules [  OK  ]
[root@station1 virutalbox_setupfile]#

thats all now click applications->system tools->oracle vm virtualbox
i have installed rhel5 see the screen shot below

how to connect reliance net-connect in rhel 6

connect your reliance net-connect to your pc.
open terminal and do the following steps

[root@station1 ~]# yum install -y wvdial
[root@station1 ~]# vim /etc/wvdial.conf

[Dialer reliance]
Auto DNS = on
Auto Reconnect = on
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Baud = 9600
Init1 = ATZ
Phone = #777
Modem = /dev/ttyUSB0
Username = --------------->enter your number
Abort on Busy = off
Password = -----------------> enter the password here obviously it your number itself
Abort on No Dialtone = off
Carrier Check = on
Stupid Mode = on

[root@station1 ~]# service network stop

then click on the reliance icon on the desktop and eject it otherwise device busy error will occur.

[root@station1 Desktop]# wvdial reliance
--> WvDial: Internet dialer version 1.60
--> Warning: inherited section [Modem0] does not exist in wvdial.conf
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
OK
--> Modem initialized.
--> Sending: ATDT#777
--> Waiting for carrier.
ATDT#777
CONNECT 3100000
--> Carrier detected.  Starting PPP immediately.
--> Starting pppd at Thu Apr 12 13:55:15 2012
--> Pid of pppd: 3177
--> Using interface ppp0
--> local  IP address *****************
--> remote IP address ***************
--> primary   DNS address ****************
--> secondary DNS address ****************

now open your browser and check

if its not working then do these steps

[root@station1 ~]# vim /var/run/ppp/resolv.conf
nameserver ***********
nameserver ************
copy these two lines from your terminal and paste in
[root@station1 ~]# vim /etc/resolv.conf

nameserver ***********
nameserver ************

[root@station1 ~]# service named restart

don't close this terminal. now open your web browser and start browsing it should work, to close your internet press ctrl+c in the terminal.

To avoid these steps i just made a simple script one for connection and another one for reverting back to your localnetwork.

For connection script - click here
For localnetwork script (if you have dns configured) -  click here

mv the scripts to /root and change the permission to 777

Note : Open the reliance.sh file and change the nameserver if its is difference for you. ll'y open localnetwork.sh file and change the search and nameserver ip according to your domain. Once done then no need to do the above steps..

Just in terminal run sh /root/reliance.sh for connecting and press ctrl+c to disconnect. Run sh /root/localnetwork.sh to get back your localnetwork.

iscsi client side configuration in rhel6

[root@station2 /]# yum install -y iscsi*
[root@station2 /]# service iscsid start
[root@station2 /]# service iscsi start
[root@station2 /]# iscsiadm --mode discovery --type sendtargets --portal 10.65.62.30
10.65.62.30:3260,1 iqn.2012-26.com.example:ranji.lun0
[root@station2 /]# cat /proc/partitions
major minor  #blocks  name

   8     0    8388608 sda
   8     1     104391 sda1
   8     2    8281507 sda2
 253     0    7208960 dm-0
 253     1    1048576 dm-1
[root@station2 /]# iscsiadm --mode node --targetname iqn.2012-26.com.example:ranji.lun0 --portal 10.65.62.30 --login
Login session [iface: default, target: iqn.2012-26.com.example:ranji.lun0, portal: 10.65.62.30,3260]
[root@station2 /]# cat /proc/partitions
major minor  #blocks  name

   8     0    8388608 sda
   8     1     104391 sda1
   8     2    8281507 sda2
 253     0    7208960 dm-0
 253     1    1048576 dm-1
   8    16   41943040 sdb   ---> this is the device from server
[root@station2 /]# iscsiadm --mode node --targetname iqn.2012-26.com.example:ranji.lun0 --portal 10.65.62.30 --logout
Logout session [sid: 2, target: iqn.2012-26.com.example:ranji.lun0, portal: 10.65.62.30,3260]
[root@station2 /]# cat /proc/partitions
major minor  #blocks  name

   8     0    8388608 sda
   8     1     104391 sda1
   8     2    8281507 sda2
 253     0    7208960 dm-0
 253     1    1048576 dm-1

iscsi server side configuration in rhel6

[root@station1 Desktop]# yum install -y scsi*
[root@station1 Desktop]# yum install -y libibver*
[root@station1 Desktop]# yum install -y libml*
[root@station1 Desktop]# yum install -y librdmacm*
[root@station1 Desktop]# yum install -y perl-Config-General

create an empty partition (in my practise its sda4). dont convert it to linuxlvm system. just create a partition write and save it and follow the steps

[root@station1 Desktop]# pvcreate /dev/sda4
  Writing physical volume data to disk "/dev/sda4"
  Physical volume "/dev/sda4" successfully created
[root@station1 Desktop]# vgcreate vg_ranji /dev/sda4
  Volume group "vg_ranji" successfully created
[root@station1 Desktop]# vgdisplay
  --- Volume group ---
  VG Name               vg_ranji
  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               40.50 GiB
  PE Size               4.00 MiB
  Total PE              10369
  Alloc PE / Size       0 / 0  
  Free  PE / Size       10369 / 40.50 GiB
  VG UUID               D8N5om-uk36-XPRR-elwS-PVNk-VmcM-IrGPYH
  
[root@station1 Desktop]# lvcreate -n lv_lun0 -L 40G vg_ranji
  Logical volume "lv_lun0" created
[root@station1 Desktop]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_ranji/lv_lun0
  VG Name                vg_ranji
  LV UUID                JuJdn2-pRTl-FURv-HlBD-n3KA-wUQZ-KcHCWD
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                40.00 GiB
  Current LE             10240
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

[root@station1 Desktop]# vim /etc/tgt/targets.conf

 37
 38 <target iqn.2012-26.com.example:ranji.lun0>           ----------> remove # add edit these lines
 39     backing-store /dev/vg_ranji/lv_lun0
 40     initiator-address 10.65.62.30
 41 </target>
 42
[root@station1 Desktop]# chkconfig tgtd on
[root@station1 Desktop]# service tgtd restart
Stopping SCSI target daemon: not running                   [FAILED]
Starting SCSI target daemon:                               [  OK  ]