Prakash Sawarkar: Kernel 3.8 Released, how to Compile in Redhat, CenOS and Fedora..

Kernel 3.8 Released, how to Compile in Redhat, CentOS and Fedora.

Sunday, 26 December 2010

RedHat / Centos minimal services

I always disable most of the services witch are activated by a default Centos 5.5 instalation
To disable them, run the following commands:
chkconfig anacron off
chkconfig apmd off
chkconfig atd off
chkconfig autofs off
chkconfig cpuspeed off
chkconfig cups off
chkconfig cups-config-daemon off
chkconfig gpm off
chkconfig isdn off
chkconfig netfs off
chkconfig nfslock off
chkconfig openibd off
chkconfig pcmcia off
chkconfig portmap off
chkconfig rawdevices off
chkconfig readahead_early off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig smartd off
chkconfig xfs off
chkconfig ip6tables off
chkconfig avahi-daemon off
chkconfig firstboot off
chkconfig yum-updatesd off
chkconfig mcstrans off
chkconfig pcscd off
chkconfig bluetooth off
chkconfig hidd off
And you might consider disable this:
chkconfig sendmail off
chkconfig xinetd off
chkconfig acpid off
chkconfig microcode_ctl off
chkconfig irqbalance off
chkconfig haldaemon off
chkconfig messagebus off
chkconfig mdmonitor off

Sunday, 21 November 2010

Install tomcat6 in 3 step CentOS

# cd /etc/yum.repos.d
# wget 'http://www.jpackage.org/jpackage50.repo'
# yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps 
# service tomcat6 start
 http://localhost:8080

Saturday, 20 November 2010

How to Delete Nodes from a GPFS Cluster

Taken from Deleting Nodes from a GPFS Cluster (IBM)  
Step 1: Shutdown the Nodes before deleting
On the NSD Node
# mmshutdown -N node01
mmshutdown -N node01 
Wed Nov  1 05:13:43 SGT 2010: mmshutdown: Starting force unmount of GPFS file systems
Wed Nov  1 05:13:48 SGT 2010: mmshutdown: Shutting down GPFS daemons
node01:  Shutting down!
node01:  'shutdown' command about to kill process 10682
node01:  Unloading modules from /lib/modules/2.6.18-194.el6.x86_64/extra
node01:  Unloading module mmfs26
node01:  Unloading module mmfslinux
node01:  Unloading module tracedev
Wed Jun  1 05:14:02 SGT 2010: mmshutdown: Finished
Step 2: Deleting a Node
# mmdelnode -N node01
Verifying GPFS is stopped on all affected nodes ...
mmdelnode: Command successfully completed
mmdelnode: Propagating the cluster configuration data to all
affected nodes.  This is an asynchronous process. 
Step 3: Confirm that the nodes has been deleted.
# mmlscluster
Step 4: If you are deleting the client permanently, check and update the license file
# mmlslicense
Summary information
Number of nodes defined in the cluster:                         20
Number of nodes with server license designation:                 3
Number of nodes with client license designation:                17
Number of nodes still requiring server license designation:      0
Number of nodes still requiring client license designation:      0

Sunday, 14 November 2010

5 Step Jboss set up RHEL/Cent OS 5.X

Step:1:-  yum install mysql mysql-server java-1.6.0-openjdk -y
Step:2:- service mysqld start
Step:3:- wget  http://sourceforge.net/projects/jboss/files/JBoss/JBoss-6.0.0.M4/jboss-as-distribution-6.0.0.20100721-M4.zip/download
Step:4:- unzip jboss-as-distribution-6.0.0.20100721-M4.zip
Step:5:- /opt/jboss/bin/run.sh 

http://yourdomain.com:8080 

Sunday, 31 October 2010

Linux Find FC ID WWNN of a disk/LUN

If your server is connected to more than two SANs of the same type it is really hard to find what disk is on what SAN and how it is connected to your server. You can get the Fiber Channel addresses of the HBAs by typing the following commands:
# systool -c fc_host -v
Type the following command to determine the fibre channel target WWN:
# systool -c fc_transport -v

Sunday, 3 October 2010

How to Set Up Master Slave Replication in MySQL

The following tutorial aims to provide you a simple step-by-step guide for setting up MySQL(Master-Slave) Replication in RHEL 6.x/5.x, CentOS 6.x/5.x and Fedora 17,16,15,14,13,12 using latest MySQL version. This guide is specially written for CentOS 6.3 Operating System, but also work with older version of Linux distributions with MySQL 5.x.

MySQL replication is a process that allows you to easily maintain multiple copies of a MySQL data by having them copied automatically from a master to a slave database. This can helpful for many reasons including facilating a backup for the data,a way to analyze it without using the main database, or simply as a means to scale out.

The MySQL Replication is very useful in terms of Data Security, Fail-over Solution, Database Backup from Slave, Analytics etc. We use the following things to carry the replication process. In your scenario it would be different.

This tutorial will cover a very simple example of mysql replication—one master will send information to a single slave. For the process to work you will need two IP addresses: one of the master server and and one of the slave. 


Master IP Address is: 172.24.0.1. - Master Database 

Slave IP Address is: 122.24.0.2. - Slave Database

Master and Slave are on the same LAN network.

Master allow remote MySQL connections on port 3306.

Step 1 —Configure the Master Database Server

Install a MySQL in Master Server

First, proceed with MySQL installation using YUM command. If you already have MySQL installation, you can skip this step.

#  yum install mysql-server mysql

Open up the mysql configuration file on the master server.

#  vi /etc/my.cnf

Add the following entries under [mysqld] section and don’t forget to replace  prakash  with database name that you would like to replicate on  Slave.

server-id = 1
binlog-do-db=prakash
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin

Restart the MySQL service.

# /etc/init.d/mysqld restart

Login into MySQL as root user and create the slave user and grant privileges for replication. Replace slave_user with user and your_password with password.

#  mysql -u root -p























Please write down the File (mysql-bin.000001) and Position (107) numbers, we required these numbers later on Slave server. Next apply READ LOCK to databases to export all the database and master database information with mysqldump command.

#  mysqldump -u root -p --all-databases --master-data > /root/dbdump.db

Once you’ve dump all the databases, now again connect to mysql as root user and unlcok tables.


mysql> UNLOCK TABLES;
mysql> quit;

Upload the database dump file on Slave Server (172.24.0.2) using SCP command.

#  scp /root/dbdump.db root@172.24.0.2:/root/

That’s it we have successfully configured Master server

Step 2 —Configure the Slave Database Server

Configure Slave Server (172.24.0.2) for Replication.

#  yum install mysql-server mysql

Configure a MySQL in Slave Server

Open my.cnf configuration file with VI editor.

# vi /etc/my.cnf

Add the following entries under [mysqld] section and don’t forget to replace IP address of Master server, prakash with database name etc, that you would like to replicate with Master.

server-id = 2
master-host=172.24.0.1
master-connect-retry=60
master-user=slave_user
master-password=yourpassword
replicate-do-db=prakash
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin

Restart the MySQL service.

#  /etc/init.d/mysqld restart

Login into MySQL as root user and stop the slave. Then tell the slave to where to look for Master log file, that we have write down on master with SHOW MASTER STATUS; command as File (mysql-bin.000001) and Position (107) numbers. You must change 172.24.0.1 to the IP address of the Master Server, and change the user and password accordingly.

#  mysql -u root -p

mysql> slave stop;
mysql> CHANGE MASTER TO MASTER_HOST='172.24.0.1', MASTER_USER='slave_user', MASTER_PASSWORD='yourpassword', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
mysql> slave start;
mysql> show slave status\G

If there is an issue in connecting, you can try starting slave with a command to skip over it:

SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; SLAVE START;

Verifying MySQL Replication on Master and Slave Server

It’s really very important to know that the replication is working perfectly. On Master server create table and insert some values in it.

On Master Server

mysql> create database prakash;
Query OK, 1 row affected (0.00 sec)

mysql> use prakash;
Database changed

mysql> CREATE TABLE employee (c int);
Query OK, 0 rows affected (0.12 sec)

mysql> INSERT INTO employee (c) VALUES (1);
Query OK, 1 row affected (0.07 sec)

mysql> SELECT * FROM employee;
+------+
| c    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

mysql>

On Slave Server
mysql> use prakash;
Database changed
mysql> SELECT * FROM employee;
+------+
| c    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

mysql>

That’s it, finally you’ve configured MySQL Replication in a few simple steps.

If you have any further questions about the specific capabilities of MySQL, feel free to post your questions and I’ll be happy to answer them .

Sunday, 26 September 2010

Memory use by which process Centos/RHEL/Fedora

# ps aux | awk '{if ($5 != 0 ) print $2,$5,$6,$11}' | sort -k2n
[root@microair ~]# ps aux | awk '{if ($5 != 0 ) print $2,$5,$6,$11}' | sort -k2n
PID VSZ RSS COMMAND
1960 4128 640 /usr/sbin/acpid
1706 6208 600 /sbin/portreserve
1781 6820 280 /usr/sbin/mcelog
1828 8404 368 /usr/sbin/fcoemon
396 11372 1408 /sbin/udevd
1815 12420 2636 /sbin/udevd
1816 12420 2408 /sbin/udevd
1803 13600 652 lldpad
2067 14912 596 tgtd
2068 14912 384 tgtd
2015 17856 1028 hald-addon-acpi:
1970 18156 1144 hald-runner
1767 19024 932 rpcbind
1 19408 1508 /sbin/init
2264 20088 408 dbus-launch
2014 20272 888 hald-addon-input:
2212 21544 392 /usr/sbin/atd
1941 23140 392 rpc.idmapd
1871 23396 1352 rpc.statd
1969 26524 5148 hald
2265 29648 912 /bin/dbus-daemon
1841 30080 1488 dbus-daemon
2158 32304 444 /usr/sbin/htcacheclean
144 36016 1352 /bin/plymouthd
1901 45020 488 /usr/sbin/wpa_supplicant
6667 49992 3956 /usr/libexec/polkit-1/polkitd
1856 55880 2320 /usr/sbin/modem-manager
2237 62312 416 /usr/sbin/certmonger
2082 66584 1228 /usr/sbin/sshd
2557 68876 1748 /usr/sbin/saslauthd
2559 68876 1664 /usr/sbin/saslauthd
2560 68876 1664 /usr/sbin/saslauthd
2561 68876 1732 /usr/sbin/saslauthd
2562 68876 1664 /usr/sbin/saslauthd
1852 80188 4416 NetworkManager
2108 93572 1688 /usr/sbin/exim
24965 100328 3984 sshd:
25145 106008 788 awk
2146 108116 804 abrt-dump-oops
2242 108516 1680 /bin/bash
1519 108520 1744 /bin/bash
24969 108520 1888 -bash
2134 110228 996 /usr/sbin/abrtd
25144 110244 1120 ps
2189 117256 1384 crond
2248 127460 16140 /usr/bin/Xorg
2268 131916 4084 /usr/libexec/gconfd-2
25146 155488 836 sort
2173 186424 5252 /usr/sbin/httpd
16817 186556 3684 /usr/sbin/httpd
631 186556 3684 /usr/sbin/httpd
632 186556 3804 /usr/sbin/httpd
633 186556 3756 /usr/sbin/httpd
634 186556 3684 /usr/sbin/httpd
635 186556 3784 /usr/sbin/httpd
636 186556 3684 /usr/sbin/httpd
637 186556 3684 /usr/sbin/httpd
638 186556 3848 /usr/sbin/httpd
1713 242988 1904 /sbin/rsyslogd
2253 251264 8452 /usr/bin/metacity
2251 270292 16956 /usr/bin/python2
2090 289524 196316 clamd
2047 381604 1652 automount
2246 412056 36420 /usr/bin/python2
6669 1031644 2480 /usr/sbin/console-kit-daemon
682 1106792 58480 /usr/bin/python
[root@microair ~]#

Sunday, 19 September 2010

GPT(GUID Partition Table) problem during the linux installation on CentOS5.6

During the installation process of CentOS 5.6 one can face following error

Error: - "Your boot partition is on a disk using the GPT partitioning scheme but this machine cannot boot using GPT".

Reason:- This error mainly arises in the event where the total disk size is more than 2TB, irrespective of the primary partition disk.

Solution:-Enter the rescue mode and delete the MBR on the disk as below:-

#  dd if=/dev/zero of=/dev/sda bs=512 count=1

Reinstall the system again and it should work right.

Monday, 13 September 2010

How To Enable EPEL Repository in RHEL/CentOS 6/5

Why we use EPEL (Extra Packages for Enterprise Linux) repository ?
Provides lots of open source packages to install via Yum.
Epel repo is 100% open source and free to use.
It does not provide any core duplicate packages and no compatibility issues.
All epel packages are maintained by Fedora repo.
First, you need to download the file using Wget and then install it using RPM on your system to enable the EPEL repository. Use below links based on your Linux OS versions. (Make sure you must be root user).
For RHEL/CentOS 6 32-64 Bit
## RHEL/CentOS 6 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
## RHEL/CentOS 6 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
For RHEL/CentOS 5 32-64 Bit
## RHEL/CentOS 5 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm
## RHEL/CentOS 5 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm
For RHEL/CentOS 4 32-64 Bit
## RHEL/CentOS 4 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/4/i386/epel-release-4-10.noarch.rpm
# rpm -ivh epel-release-4-10.noarch.rpm
## RHEL/CentOS 4 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/4/x86_64/epel-release-4-10.noarch.rpm
# rpm -ivh epel-release-4-10.noarch.rpm
How Do I Verify EPEL Repo?
# yum repolist
Loaded plugins: fastestmirror, priorities, refresh-packagekit, security
Loading mirror speeds from cached hostfile
epel/metalink                                            | 5.6 kB     00:00
 * base: centos.aol.in
 * epel: mirror.neu.edu.cn
 * extras: mirrors.digipower.vn
 * remi: fr2.rpmfind.net
 * rpmforge: mir01.syntis.net
 * updates: centos.aol.in
base                                                     | 3.7 kB     00:00
epel                                                     | 4.2 kB     00:03
epel/primary_db                                          | 5.8 MB     01:13
extras                                                   | 3.4 kB     00:00
rpmforge                                                 | 1.9 kB     00:00
updates                                                  | 3.4 kB     00:00
updates/primary_db                                       | 1.3 MB     00:29
repo id        repo name                                               status
base           CentOS-6 - Base                                          6,327+40
epel           Extra Packages for Enterprise Linux 6 - x86_64          9,712+518
extras         CentOS-6 - Extras                                              14
remi           Les RPM de remi pour Enterprise Linux 6 - x86_64        200+1,174
rpmforge       RHEL 6 - RPMforge.net - dag                              4,627+23
updates        CentOS-6 - Updates                                         254+43
repolist: 21,134
How Do I Use EPEL Repo?
You need to use YUM command for searching and installing packages. For example we search for Zabbix package using epel repo, lets see it is available or not under epel.
# yum --enablerepo=epel info zabbix
Sample Output
Available Packages
Name       : zabbix
Arch       : i386
Version    : 1.4.7
Release    : 1.el5
Size       : 1.7 M
Repo : epel
Summary    : Open-source monitoring solution for your IT infrastructure
URL        : http://www.zabbix.com/
License    : GPL
Description: ZABBIX is software that monitors numerous parameters of a network
Let’s install Zabbix package using epel repo option –enablerepo=epel switch.
# yum --enablerepo=epel install zabbix
Note: The epel configuration file is located under /etc/yum.repos.d/epel.repo.
This way you can install as many as high standard open source packages using EPEL repo

Sunday, 15 August 2010

lsof Command Examples (Identify Open Files)

lsof stands for List Open Files.
It is easy to remember lsof command if you think of it as “ls + of”, where ls stands for list, and of stands for open files.
It is a command line utility which is used to list the information about the files that are opened by various processes. In unix, everything is a file, ( pipes, sockets, directories, devices, etc.). So by using lsof, you can get the information about any opened files.
1. Introduction to lsof
Simply typing lsof will provide a list of all open files belonging to all active processes.
#  lsof
COMMAND  PID       USER   FD      TYPE     DEVICE  SIZE/OFF       NODE NAME
init       1       root  cwd       DIR        8,1      4096          2 /
init       1       root  txt       REG        8,1    124704     917562 /sbin/init
init       1       root    0u      CHR        1,3       0t0       4369 /dev/null
init       1       root    1u      CHR        1,3       0t0       4369 /dev/null
init       1       root    2u      CHR        1,3       0t0       4369 /dev/null
init       1       root    3r     FIFO        0,8       0t0       6323 pipe

By default One file per line is displayed. Most of the columns are self explanatory. We will explain the details about couple of cryptic columns (FD and TYPE).
FD – Represents the file descriptor. Some of the values of FDs are,
cwd – Current Working Directory
txt – Text file
mem – Memory mapped file
mmap – Memory mapped device
NUMBER – Represent the actual file descriptor. The character after the number i.e ’1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write.
TYPE – Specifies the type of the file. Some of the values of TYPEs are,
REG – Regular File
DIR – Directory
FIFO – First In First Out
CHR – Character special file
For a complete list of FD & TYPE, refer man lsof.
2. List processes which opened a specific file

You can list only the processes which opened a specific file, by providing the filename as arguments.
#  lsof /var/log/syslog
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
rsyslogd 488 syslog    1w   REG    8,1     1151 268940 /var/log/syslog
3. List opened files under a directory

You can list the processes which opened files under a specified directory using ‘+D’ option. +D will recurse the sub directories also. If you don’t want lsof to recurse, then use ‘+d’ option.
#  lsof +D /var/log/

COMMAND   PID   USER  FD   TYPE DEVICE SIZE/OFF   NODE NAME
rsyslogd  488 syslog   1w   REG    8,1     1151 268940 /var/log/syslog
rsyslogd  488 syslog   2w   REG    8,1     2405 269616 /var/log/auth.log
console-k 144   root   9w   REG    8,1    10871 269369 /var/log/ConsoleKit/history
4. List opened files based on process names starting with

You can list the files opened by process names starting with a string, using ‘-c’ option. -c followed by the process name will list the files opened by the process starting with that processes name. You can give multiple -c switch on a single command line.
#  lsof -c ssh -c init

COMMAND    PID   USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
init         1       root  txt    REG        8,1   124704  917562 /sbin/init
init         1       root  mem    REG        8,1  1434180 1442625 /lib/i386-linux-gnu/libc-2.13.so
init         1       root  mem    REG        8,1    30684 1442694 /lib/i386-linux-gnu/librt-2.13.so
ssh-agent 1528 prakash  1u   CHR        1,3      0t0    4369 /dev/null
ssh-agent 1528 prakash   2u   CHR        1,3      0t0    4369 /dev/null
ssh-agent 1528 prakash    3u  unix 0xdf70e240      0t0   10464 /tmp/ssh-sUymKXxw1495/agent.1495
5. List processes using a mount point

Sometime when we try to umount a directory, the system will say “Device or Resource Busy” error. So we need to find out what are all the processes using the mount point and kill those processes to umount the directory. By using lsof we can find those processes.
#   lsof /home
The following will also work.
#   lsof +D /home/
6. List files opened by a specific user

In order to find the list of files opened by a specific users, use ‘-u’ option.
# lsof -u prakash

COMMAND    PID       USER   FD   TYPE     DEVICE SIZE/OFF       NODE NAME
update-no 1892 prakash   20r  FIFO        0,8      0t0      14536 pipe
update-no 1892 prakash   21w  FIFO        0,8      0t0      14536 pipe
bash      1995  prakash cwd    DIR        8,1     4096     393218 /home/prakash
Sometimes you may want to list files opened by all users, expect some 1 or 2. In that case you can use the ‘^’ to exclude only the particular user as follows
#   lsof -u ^ prakash

COMMAND    PID       USER   FD      TYPE     DEVICE  SIZE/OFF       NODE NAME
rtkit-dae 1380      rtkit    7u     0000        0,9         0       4360 anon_inode
udisks-da 1584       root  cwd       DIR        8,1      4096          2 /
The above command listed all the files opened by all users, expect user ‘prakash’.
7. List all open files by a specific process

You can list all the files opened by a specific process using ‘-p’ option. It will be helpful sometimes to get more information about a specific process.
#  lsof -p 1753

COMMAND  PID       USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
bash    1753 prakash  cwd    DIR    8,1     4096  393571 /home/prakash/test.txt
bash    1753 prakash  rtd    DIR    8,1     4096       2 /
bash    1753 prakash  255u   CHR  136,0      0t0       3 /dev/pts/0

8. Kill all process that belongs to a particular user

When you want to kill all the processes which has files opened by a specific user, you can use ‘-t’ option to list output only the process id of the process, and pass it to kill as follows
#  kill -9 `lsof -t -u prakash`
The above command will kill all process belonging to user ‘prakash’, which has files opened.
Similarly you can also use ‘-t’ in many ways. For example, to list process id of a process which opened /var/log/syslog can be done by
#  lsof -t /var/log/syslog
489
Talking about kill, did you know that there are 4 Ways to Kill a Process?
9. Combine more list options using OR/AND

By default when you use more than one list option in lsof, they will be ORed. For example,
#  lsof -u prakash -c init
COMMAND    PID       USER   FD   TYPE     DEVICE SIZE/OFF       NODE NAME
init         1       root  cwd    DIR        8,1     4096          2 /
init         1       root  txt    REG        8,1   124704     917562 /sbin/init
bash      1995 prakash    2u   CHR      136,2      0t0          5 /dev/pts/2
bash      1995 prakash 255u   CHR      136,2      0t0          5 /dev/pts/2
...
The above command uses two list options, ‘-u’ and ‘-c’. So the command will list process belongs to user ‘prakash’ as well as process name starts with ‘init’.
But when you want to list a process belongs to user ‘prakash’ and the process name starts with ‘init’, you can use ‘-a’ option.
#  lsof -u prakash -c init -a
The above command will not output anything, because there is no such process named ‘init’ belonging to user ‘prakash’.
10. Execute lsof in repeat mode

lsof also support Repeat mode. It will first list files based on the given parameters, and delay for specified seconds and again list files based on the given parameters. It can be interrupted by a signal.
Repeat mode can be enabled by using ‘-r’ or ‘+r’. If ‘+r’ is used then, the repeat mode will end when no open files are found. ‘-r’ will continue to list,delay,list until a interrupt is given irrespective of files are opened or not.
Each cycle output will be separated by using ‘=======’. You also also specify the time delay as ‘-r’ | ‘+r’.
#  lsof -u prakash -c init -a -r5
COMMAND   PID       USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
inita.sh 2971 prakash  cwd    DIR    8,1     4096  393218 /home/prakash
inita.sh 2971 prakash rtd    DIR    8,1     4096       2 /
inita.sh 2971 prakash  txt    REG    8,1    83848  524315 /bin/dash
inita.sh 2971 prakash  mem    REG    8,1  1434180 1442625 /lib/i386-linux-gnu/libc-2.13.so
inita.sh 2971 prakash  mem    REG    8,1   117960 1442612 /lib/i386-linux-gnu/ld-2.13.so
inita.sh 2971 prakash    0u   CHR  136,4      0t0       7 /dev/pts/4
inita.sh 2971 prakash    1u   CHR  136,4      0t0       7 /dev/pts/4
inita.sh 2971 prakash   2u   CHR  136,4      0t0       7 /dev/pts/4
inita.sh 2971 prakash   10r   REG    8,1       20  393578 /home/prakash/inita.sh

In the above output, for the first 5 seconds, there is no output. After that a script named “inita.sh” is started, and it list the output.
Finding Network Connection

Network connections are also files. So we can find information about them by using lsof.
11. List all network connections

You can list all the network connections opened by using ‘-i’ option.
#  lsof -i
COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
avahi-dae  515 avahi   13u  IPv4   6848      0t0  UDP *:mdns
avahi-dae  515 avahi   16u  IPv6   6851      0t0  UDP *:52060
cupsd     1075  root    5u  IPv6  22512      0t0  TCP ip6-localhost:ipp (LISTEN)
You can also use ‘-i4′ or ‘-i6′ to list only ‘IPV4′ or ‘IPV6‘ respectively.
12. List all network files in use by a specific process

You can list all the network files which is being used by a process as follows
# lsof -i -a -p 234
You can also use the following
# lsof -i -a -c ssh
The above command will list the network files opened by the processes starting with ssh.
13. List processes which are listening on a particular port
You can list the processes which are listening on a particular port by using ‘-i’ with ‘:’ as follows
# lsof -i :25

COMMAND  PID        USER   FD   TYPE DEVICE SIZE NODE NAME
exim4   2541 Debian-exim    3u  IPv4   8677       TCP localhost:smtp (LISTEN)
14. List all TCP or UDP connections

You can list all the TCP or UDP connections by specifying the protocol using ‘-i’.
# lsof -i tcp; lsof -i udp;
15. List all Network File System ( NFS ) files

You can list all the NFS files by using ‘-N’ option. The following lsof command will list all NFS files used by user ‘prakash’.

# lsof -N -u prakash -a

Thursday, 5 August 2010

Mount Windows/USB NTFS Partition in RHEL/CentOS/Fedora

First you need to enable EPEL (Extra Packages for Enterprise Linux) Repository. You may refer the article on how to enable EPEL  Repository under RHEL, CentOS and Fedora systems.
To mount any NTFS based filesystem, you need to install a tool called NTFS3G. Before heading up for installation let’s understand NTGS3G.
What is NTFS3G
NTFS3G is an open source cross-platform, stable, GPL licensed, POSIX, NTFS R/W driver used in Linux. It provides safe handling of Windows NTFS file systems viz create, remove, rename, move files, directories, hard links, etc.
Once EPEL is installed and enabled, let’s install ntfs-3g package using the below command with root user.
# yum -y install ntfs-3g
Fuse Install
Next, install and load FUSE driver to mount detected devices with below command. FUSE module is included in the kernel itself in version 2.6.18-164 or newer.
# yum install fuse
# modprobe fuse
Identify NTFS Partition
Once fuse module is loaded, type below command to find out NTFS Partitions in Linux.
# fdisk -l
  Device   Boot      Start    End      Blocks   Id  System
 /dev/sda1   *         1      121602   976760032+   7  HPFS/NTFS
Mount NTFS partition
First create a mount point to mount the NTFS partition.
# mkdir /mnt/usb
Simply run the following command to mount the partition. Replace sda1 with your actual partition found.
# mount -t ntfs-3g /dev/sda1 /mnt/usb
Once it’s mounted on /mnt/ntfs, you may use regular Linux ls -l command to list the content of mounted filesystem.
# ls -l
If you want to make mount point permanent at the boot time, then simple add the following line at the end of /etc/fstab file. This will remain as permanent.
/dev/sda1    /mnt/usb    ntfs-3g        defaults    0    0
Umount NTFS Partition
Simply, use the following command to unmount the mounted partition.
# umount /mnt/usb

Tuesday, 29 June 2010

How to Enable SRIOV of IBM Servers and Blade Servers BIOS

What is SR-IOV? The short answer is that SR-IOV is a specification that allows a PCIe device to appear to be multiple separate physical PCIe devices. The SR-IOV specification was created and is maintained by the PCI SIG, with the idea that a standard specification will help promote interoperability.

Step 1: Power on the system, and press F1 to enter the Setup utility.
Step 2: Select System Settings and then Network.
Step 3: Under the Network Device List, select the device to be configured and press Enter to see all the Network Device options (Figure 1).




















Step 4: Select the device’s description and press Enter to configure the device 
Step 5: From the selection menu, select Advanced Mode and press Enter to change the value.
Step 6: Choose Enable and press Enter.
Step 7: On the same selection menu, select Controller Configuration and press Enter to enter the configuration menu.
Step 8: Select Configure SRIOV and hit Enter.
Step 9: On the Configure SRIOV page, press Enter to toggle the values
Step 10: Select Enable and press Enter
Step 11: Select Save Current Configurations and press Enter.
Step 12: Press Esc to exit the menu. Then, click Save to save the configuration.
Step 13: Reboot the system.

Sunday, 27 June 2010

Setting up an SSL secured Webserver with CentOS

1. Getting the required software
For an SSL encrypted web server you will need a few things. Depending on your install you may or may not have OpenSSL and mod_ssl, Apache's interface to OpenSSL. Use yum to get them if you need them.
# yum install mod_ssl openssl
Yum will either tell you they are installed or will install them for you.
2. Generate a self-signed certificate
Using OpenSSL we will generate a self-signed certificate. If you are using this on a production server you are probably likely to want a key from Trusted Certificate Authority, but if you are just using this on a personal site or for testing purposes a self-signed certificate is fine. To create the key you will need to be root so you can either su to root or use sudo in front of the commands
# Generate private key 
openssl genrsa -out ca.key 1024 
# Generate CSR 
openssl req -new -key ca.key -out ca.csr
# Generate Self Signed Key
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
# Move the files to the correct locations
# mv ca.crt /etc/pki/tls/certs
# mv ca.key /etc/pki/tls/private/ca.key
# mv ca.csr /etc/pki/tls/private/ca.csr
Then we need to update the Apache SSL configuration file
# vi +/SSLCertificateFile /etc/httpd/conf.d/ssl.conf
Change the paths to match where the Key file is stored. If you've used the method above it will be
SSLCertificateFile /etc/pki/tls/certs/ca.crt
Then set the correct path for the Certificate Key File a few lines below. If you've followed the instructions above it is:
SSLCertificateKeyFile /etc/pki/tls/private/ca.key
Quit and save the file and then restart Apache
# /etc/init.d/httpd restart
All being well you should now be able to connect over https to your server and see a default Centos page. As the certificate is self signed browsers will generally ask you whether you want to accept the certificate. Firefox 3 won't let you connect at all but you can override this.
Restart Apache again using 
# /etc/init.d/httpd restart 

Tuesday, 26 January 2010

Recover deleted files using Foremost

Foremost is a console program to recover files based on their headers, footers, and internal data structures. This process is commonly referred to as data carving. Foremost can work on image files, such as those generated by dd, Safeback, Encase, etc, or directly on a drive. The headers and footers can be specified by a configuration file or you can use command line switches to specify built-in file types. These built-in types look at the data structures of a given file format allowing for a more reliable and faster recovery.
Originally developed by the United States Air Force Office of Special Investigations and The Center for Information Systems Security Studies and Research and now foremost has been opened to the general public.
Files types supported by foremost:
jpg, gif, png, bmp
avi, mpg, wav, wmv, mov
pdf, doc, zip, exe, rff, rar, html, cpp
You can tweak /etc/foremost.conf to add support for more file types.
Please note that there's no guarantee that foremost will succeed in recovering your files, but at least there's a chance.
Foremost Installation:
Open the terminal and type following command to install foremost:
               # yum  install  foremost
Foremost isn’t the greatest solution; it recovers every file it sees and doesn’t support very many file types. It is possible to add types to the /etc/foremost.conf file, but it doesn’t look an easy task. However, if you’ve lost a bunch of photos or documents, Foremost could be just what you need.
Using Foremost:
Suppose you want to recover png file, from command line type following commad:
foremost -t png -i /dev/sda1
After completion, you will find a folder called output in the directory from where you executed the foremost, where within you can see the folder 'png' and inside png you can find your lost png file.
There are many more tools that you can use to recover your files:
Recover deleted files from NTFS filesystem from Centos Linux - Ntfsundelete
Recover your deleted jpeg pictures from filesystem or camera memory card - recoverjpeg
Utility to recover deleted files from an ext3 or  ext4 Linux partition - Extundelete