Thursday, July 26, 2012

Rebuilding corrupted RPM database

One of our client reported that he is getting an error and RPM database is corrupted. He is using Red Hat Linux

Sometime it is possible to fix RPM database errors. I am surprised that many admins do not make back up of RPM DB (/var/lib/rpm).

Anyways if you ever messed up with RPM database, here is a quick guide to fix it (you must have rpmdb tools installed):

Take system to single user mode to avoid further damage and to make backup/restore process easy:

# init 1
Method # 1

Remove /var/lib/rpm/__db* files to avoid stale locks:
# cd /var/lib
# rm __db*

Rebuild RPM database:
# rpm --rebuilddb
# rpmdb_verify Packages
Method # 2

If you are still getting errors, then try your luck with following commands:

# mv Packages Packages-BAKUP
# db_dump Packages-BAKUP | db_load Packages
# rpm -qa
# rpm --rebuilddb

apache connection check and error log check

please follow mention step, it may resolve your problem.

date;netstat -ant | grep 80 | grep TIME_WAIT | wc -l

cat /etc/httpd/conf/httpd.conf | grep MaxClients

head /var/log/httpd/error_log

Recovering deleted files with ext3grep


While perusing packages on my Debian 5 host, I came across the ext3grep utility. Ext3grep allows you to poke and prod ext file system metadata structures (superblocks, inode bitmaps, block details, etc.), and has the ability to recover deleted files. To see first hand how file recovery works (this is a useful thing to have in your bag of tricks), I first created an ext3 file system to test this out:
dd if=/dev/zero of=/fstmp bs=512 count=4192
4192+0 records in
4192+0 records out
2146304 bytes (2.1 MB) copied, 0.0218335 s, 98.3 MB/s
mkfs.ext3 /fstmp
mke2fs 1.41.3 (12-Oct-2008)
/tmp/fstmp is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
264 inodes, 2096 blocks
104 blocks (4.96%) reserved for the super user
First data block=1
Maximum filesystem blocks=2359296
1 block group
8192 blocks per group, 8192 fragments per group
264 inodes per group

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

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

mount -o loop /fstmp /mnt


Once the file system was mounted, I copied over and immediately removed a file:
cd /mnt 


cp /etc/services .


ls -la
total 37
drwxr-xr-x 3 root root 1024 2009-03-28 12:43 .
drwxr-xr-x 22 root root 4096 2009-03-28 12:41 ..
drwx------ 2 root root 12288 2009-03-28 12:41 lost+found
-rw-r--r-- 1 root root 18480 2009-03-28 12:43 services
rm -f services
cd /
umount /mnt
After the file was removed, I used the ext3grep utilities “–dump-name” option to display a list of file names:
ext3grep –dump-name /fstmp
Running ext3grep version 0.8.0
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
Number of groups: 1
Minimum / maximum journal block: 60 / 1089
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1238258603 = Sat Mar 28 12:43:23 2009
Number of descriptors in journal: 16; min / max sequence numbers: 2 / 3
Finding all blocks that might be directories.
D: block containing directory start, d: block containing more directory entries.
Each plus represents a directory start that references the same inode as a directory start that we found previously.

Searching group 0: DD+
Writing analysis so far to 'fstmp.ext3grep.stage1'. Delete that file if you want to do this stage again.
Result of stage one:
2 inodes are referenced by one or more directory blocks, 2 of those inodes are still allocated.
1 inodes are referenced by more than one directory block, 1 of those inodes is still allocated.
0 blocks contain an extended directory.
Result of stage two:
2 of those inodes could be resolved because they are still allocated.
All directory inodes are accounted for!

Writing analysis so far to 'fstmp.ext3grep.stage2'. Delete that file if you want to do this stage again.
lost+found
services
In the output above, we can see that the services file I previously removed is listed. To recover deleted files, you can run ext3grep with the “–restore-file” option to restore individual files, or with the “–restore-all” option to restore all deleted files:
ext3grep –restore-all /fstmp
Running ext3grep version 0.8.0
WARNING: I don't know what EXT3_FEATURE_COMPAT_EXT_ATTR is.
Number of groups: 1
Minimum / maximum journal block: 60 / 1089
Loading journal descriptors... sorting... done
The oldest inode block that is still in the journal, appears to be from 1238260343 = Sat Mar 28 13:12:23 2009
Number of descriptors in journal: 23; min / max sequence numbers: 21 / 25
Loading fstmp.ext3grep.stage2... done
Restoring services
After the restore operation completes, you can change to the RESTORED_FILES directory to view the recovered files:
cd RESTORED_FILES/
ls -la
total 32
drwxr-xr-x 3 root root 4096 2009-03-28 13:15 .
drwxr-xr-x 6 root root 4096 2009-03-28 13:15 ..
drwx------ 2 root root 4096 2009-03-28 12:41 lost+found
-rw-r--r-- 1 root root 18480 2009-03-28 13:12 services
openssl md5 services /etc/services
MD5(services)= b92ef61d6606c6589df9c2c406632457
MD5(/etc/services)= b92ef61d6606c6589df9c2c406632457
his is pretty fricking sweet, though there are a few caveats I should mention. It is possible that blocks will get overwritten between the file removal and recovery steps, which can hinder recovery. It is also possible that an inode may be recycled, which would indeed make recovery a bit more difficult. Additionally, any recovery operation should work off a copy of the original data to avoid tainting the original file system. Those things said, ext3grep is an incredible tool, and Carlo’s write up is a must read for those wanting to understand EXT file system structures and what is takes to recover files. Great work Carlo!

[CentOS] HP Smart Array B110i SATA RAID Controller

There was Problem CentOS installer wasn't detecting the SATA RAID array.

I'm trying to install CentOS 5.8 64bit on a HP ProLiant ML110 G7 with a
HP Smart Array B110i SATA RAID Controller.

One logical drive (RAID 1+0) on the RAID Controller is already build.

CentOS Installation can't find the logical Drive, but it shows me the
zwo physical drives (sda+sdb). After searching the web, I found
following hints: 

Solved it this way:

In order to install correctly initialize an array you need to download from HP website "Driver diskette for HP Smart Array B110i SATA RAID Controller

for Red Hat Enterprise Linux 5" url -
ftp://ftp.hp.com/pub/softlib2/software1/pubsw-linux/p463360858/v66399/hpahcisr-1.2.6-7.rhel5.x86_64.dd.gz,

if it is not done, the Installer sees 2 disks instead of RAID1.

Next you need write the image to a USB flash disk:

dd if=hpahcisr-1.2.1-3.rhel5.x86_64.dd.gz of=/dev/sdc (change to your device)

Booting from the installation CD/DVD, run the installer with the parameter

boot: linux dd

After loading the kernel the installer will ask whether you have driverdisk and asked to indicate which drive.

After the final boot the installation she began to see my RAID1 partitions:

Vendor: HP Model: LOGICAL VOLUME Rev: 0.00

Then install the system.

Read ftp://ftp.hp.com/pub/softlib2/software1/pubsw-linux/p463360858/v66399/hpahcisr-1.2.6-7.rhel5.x86_64.dd.gz.txt and do what they recommend:

Once the OS is installed but before clicking the reboot button do the following.
Failure to do so will cause the system to panic and not boot.

1. press CTRL+ALT+F2

2. cp -a /tmp/ramfs/DD-0 /mnt/sysimage/tmp

3. chroot /mnt/sysimage

4. cd /tmp/DD-0

5. sh ./fix_driver_order

6. cd /

7. press CTRL+ALT+F6 and click reboot

Sunday, July 22, 2012

How to Remove OpenJDK Ubuntu


step 1)Check Version
          #java -version

step 2) First check the current setup before we uninstall Java
            #sudo update-alternatives --display java
           OR
             #sudo update-alternatives --config java

step 3)Check which JDK packages are installed
            #sudo dpkg --list | grep -i jdk

            #Remove Java
            #sudo apt-get purge icedtea-* openjdk-*

Check that all JDK packages have been removed
#sudo dpkg --list | grep -i jdk

Tuesday, July 3, 2012

Mount Points and /etc/fstab

/etc/fstab is referenced each time the system boots.  It consists fields like device name, mount point, file system type, fsck order like 0 = ignore, 1=fist, 2-9 = second, and third, etc.  After the filesystem is created in /etc/fstab, it's important to use the mount-a to mount the filesystem just created to check for errors.  
umount /apps:  To unmount the file system
fuser -v /apps:  For some reasons you cannot mount a filesystem that has open files, you can display
                       information  about the processes using a filesystem.
fuser -km /apps:  To kill all actions on a filesystem
mount -o remount,rw / :  To mount in a single operation.  This is common during recovery operation.

Useful Linux Commands


To view System Resource Information
uname --help
uname -r
grep model /proc/cpuinfo
grep MemFree /proc/meminfo
sudo -u root lastcomm -f /var/account/pacct
cat /proc/version
# cat /proc/cpuinfo
# cat /proc/meminfo
# cat /proc/zoneinfo
# cat /proc/mounts
cat /etc/redhat-release
grep MemTotal /proc/meminfo
grep SwapTotal /proc/meminfo
df -k /tmp
grep "model name" /proc/cpuinfo
ifconfig (/sbin/ifconfig)
uaname -r
lshal:detected hardware
rpm -qa:  display pakage
rpm -qa | less
Linux Kernel Information:
cat /etc/sysctl.conf
cat /etc/hosts
/sbin/ifconfig
Uname -r
cat /etc/security/limits.conf
cat /proc/sys/kernel/sem
cat /proc/sys/kernel/shmmax
cat /proc/sys/kernel/shmall
cat /proc/sys/kernel/shmmni
cat /proc/sys/fs/file-max
cat /proc/sys/net/ipv4/ip_local_port_range
/sbin/lsmod
cat /etc/issue
sysctl -a | grep shm
sysctl -a | grep ip_local_port_range
/etc/inittab:  init process determines which runlevel it should be 
w, ps -a, ps -Alf, ps -AlFH, ps -AlLm
ps -u oracle, ps -u anguyen
Commands to monitor bottlenecks such as Disk, Memory / CPU/Network, or System Activity:
top ? t, m, A: top consumer, r: renice, o: interactively select
vmstat 3, vmstat -m:memority slab info, vmstat -a
w, ps -a, ps -Alf, ps -AlFH, ps -AlLm
ps -u oracle, ps -u attunity
uptime
free
fee -s 2
watch -n 3 -d free
watch -d cat /proc/meminfo
sar -B -f /var/log/sa/sa14
sar -W -f /var/log/sa/sa14
vmstat -m
vmstat -a
ipcs -sm
ipcs -lms
sar -n DEV | more
sar 4 5
mpstat -P ALL
MEMORY intensive process:
ps -e -o pmem,pid,user,tty,args | grep -i oracle | sort -n -k 1 -r | head
watch -n 3 -d free
watch -d cat /proc/meminfo
CPU intensive process
top
ps -e -o pcpu,pid,user,tty,args | sort -n -k 1 -r | head
mpstat -P 0 2 20 (processor 0
mpstat -P ALL
sar -u -f

Disk Storage
************************************
iostat -d 3, iostat 2 15
iostat -xd 10

sorting files by size
***********************
ls -alS | head -5
mpstat -P ALL
sar 4 5
****************************************************
Network
**************************************************
lsmod | grep -i bonding
cat /etc/sysconfig/network-scripts/ifcfg-eth0 (check bonding)..the difference NETWORK, IPADDRESS, NETMASK
netstat -s | less
netstat --interfaces eth0
netstat -ptc
sar -n DEV
netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq
tcpdump -n -i eth1 -s 0 -w output.txt src or dst port 80
iptraf - Real-time Network Statistics
Network traffic
netstat -ptc
sar -n DEV
sar - Collect and Report System Activity
*************************************************
Oracle
***************************************************
cpio -idmv < 10201_database_linux_x86_64.cpio
id oracle
id nobody
pgrep sshd
env | grep PATH
detected hardware lshal:
init process determines which runlevel it should be /etc/inittab
shutdown
shutdown -t3 -r now
mount /dev/hda4 /data/oracle/bkup1:
 grep ‘Ashley Nguyen’ /etc/passwd
find / -name install.log
sed ‘s/anguyen/lvu/’ /etc/passwd > /tmp/test
ps aux | grep nfs
free: 
Ifconfig -a
To determine the amount of shared memory available, enter the following command:automatic memory management
# df -k /dev/shm/
To determine the distribution and version of Linux installed, enter the following command:
# cat /proc/version
To determine whether the required packages are installed, enter commands similar to the following:
# rpm -q package_name
Add group
# /usr/sbin/groupadd oper
Modify user:  usermod -g oinstall -G dba oracle
Create disks:
fdisk -l
give password to oracle user
passwd oracle
change ownership in linux
chown
clear screen
clear
TAR - backup / restore
tar -cf myfiles.tar *.trc (create)
tar xvf myfiles.tar (extract)
tar tvf myfiles.tar (show the details)