Friday, 22 May 2015

Inode usage 100% making the system down

Inode is a data structure that keeps track of all the information about a file. You keep your information in a file and the OS stores the information about a file in an inode. Information about files is sometimes called metadata. We can say that an inode is metadata of the data.


How does the structure of an inode look like?

A directory with it’s corresponding inodes looks like this:

Inodes             Directory/file names

4204851            ./  
4203424            ../ 
4195429            dir1/ 
4205752            dir2/
4205722            file1
4205723            file2
4194941            .hidden_dir/
4205589            .hidden_file1
======================================   
Inode structure of a directory consists of a name to inode mapping of files and directories in that directory.
In the above example, you probably noticed the first two entries of ./ [dot] and ../ [dot dot]. You might have seen them whenever you list the contents of a directory. You might also know that executing the command

cd .   
cd .  will change the directory to the current directory itself and the command

cd ..   
cd ..will take you to the previous directory (the parent directory of the current directory).
Why that happens?
Let’s use an example. Let’s have a look at our test directory:
user@sree ~/tmp/Anchal % ls -i
4204851 ./         4205723 file2
4203424 ../        4195429 folder1/
4205722 file1      4205752 folder2/

Let’s have a look at the inode numbers of . (dot) and .. (dot dot):

. (dot) = 4204851
.. (dot dot) = 4203424

We’ll do the same for ~/tmp/ directory and note the inodes there:
user@sree ~/tmp/Anchal % ls -i
4203424 ./ 
3816836 ../ 
4204851 test/
The inode numbers of ~/tmp/test/ directory and . (dot) from the directory listing of ~/tmp:

. (dot) = 4203424
~/tmp/test/ = 4204851

You can see that inode number of . (dot) inside ~/tmp/test/ directory is equal to inode of test directory – 4204851. And inode of .. (dot dot) inside ~/tmp/test/ is equal to inode of . (dot) inside ~/tmp/ directory – 4203424.


=====================================







How to check Inode Utilization?
===============

user@sree  ~ % df -i
Filesystem                Inodes  IUsed    IFree IUse% Mounted on
rootfs                   5840896 659354  5181542   12% /
udev                      217137    406   216731    1% /dev
tmpfs                     220131    450   219681    1% /run
tmpfs                     220131      6   220125    1% /dev/shm
tmpfs                     220131     11   220120    1% /sys/fs/cgroup
tmpfs                     220131      6   220125    1% /run/lock
tmpfs                     220131     11   220120    1% /run/user
/dev/sda1                 124496    265   124231    1% /boot

=============================
How to access a file using inode?

"ls -i" lists the inode of a file
or
ls -ai
====================================
As you can see, our test directory contains a file with special characters (UNICODE) – µfile¤. You wouldn’t be able to access the file by it’s filename, as your keyboard most definitely doesn’t have the micro character defined. You could access the file in several ways. The harder one, would be to find the UNICODE hex code for the micro sign and this would involve looking for the UNICODE characters table. The easier way would be to use the file inode. However, the most obvious and easiest way to deal with such signs would be to use tab-completion, yet not always a file could be deleted by it’s name. Sometimes the filename contains broken characters, not recognized by the system. Here inode comes in hand. You can access and modify (delete, edit, move, etc.) the file using its inode:

# edit the file with vim
user@sree ~/tmp/test % find ./ -inum 4195034 -exec vim {} \;
# remove the file
user@sree ~/tmp/test % find ./ -inum 4195034 -exec rm {} \;
# change the file name
user@sree ~/tmp/test % find ./ -inum 4195034 -exec mv {} repaired_file \;
# edit the file with vim
user@sree ~/tmp/test % find ./ -inum 4195034 -exec vim {} \;
# remove the file
user@sree  ~/tmp/test % find ./ -inum 4195034 -exec rm {} \;
# change the file name
user@sree  ~/tmp/test % find ./ -inum 4195034 -exec mv {} repaired_file \;

You can also change directory using inode.To get the inode numbers of the directories, you can use the command:
===============================
user@machine ~ % tree -a -L 1 --inodes /
/
├── [3276801]  bin
├── [      2]  boot
├── [   1026]  dev
├── [1179649]  etc
├── [3538945]  home
├── [5505025]  lib
├── [     11]  lost+found
├── [2752513]  media
├── [3670017]  mnt
├── [1703937]  opt
├── [      1]  proc
├── [3145729]  root
The inode number for the specified directory in the brackets. To access a directory use the command:
===========================
user@sree ~ % cd $(find / -inum 1572865)
or
user@sree ~ % find -inum 1572865 -exec cd {} \;   

=====================================================




To remove unwanted inode usage by cpanel
======================

Just run the below script
====================



To find the inode usage per location (/ directory here)

for i in /*; do echo $i; find $i |wc -l; done

=====================


/usr/local/cpanel/bin/purge_dead_comet_files
=====================



                                                                                                          By Sreejth Anchal
 

Monday, 4 May 2015

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Demo advrtisement -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9809879499425176"
     data-ad-slot="8740242843"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Update cPanel Failed : /scripts/upcp

Update cPanel Failed : /scripts/upcp
=====================================
[20150311.000907] Preparing... ##################################################
[20150311.000907] rpm_is_working ##################################################
[20150311.000907] Switching to version '11.42.1.31' of updatenow to perform sync.
=> Log closed Wed Mar 11 00:09:07 2015
[20150311.000907] 17% complete
=======

Fix
====

By looking into the error log, you can get the solution >> The RPM is corrupt in the server
===========
=============
[WARN] * /var/cpanel/sysinfo.config: contains 'rpm_dist_ver=unknown'.

Corrected this by running /scripts/gensysinfo, which populates the file with this info:
=============

Run the below comds

#/scripts/gensysinfo
/var/cpanel/sysinfo.config updated.

# cat /var/cpanel/sysinfo.config
# This values in this file are calculated and updated if necessary nightly. If you wish to override
# these values, populate lock= with a comma delimited list of keys you don't want updated.
# This will allow you to change those values to suit your needs.
#
# Example: if you set lock like this, then rpm_dist and rpm_arch will not be updated nightly:
# lock=rpm_dist,rpm_arch
#
ises=2
lock=
release=6.5
rpm_arch=x86_64
rpm_dist=centos
rpm_dist_ver=6
=======================

Now try /scripts/upcp  >> it will work

Monday, 30 March 2015

/script/upcp stuck on `/usr/local/cpanel/scripts/rpmup`

/script/upcp >> stuck on `/usr/local/cpanel/scripts/rpmup`
======================================

It seems the rpm on the server is not responding
=======
>>  ps aux|grep rpm

 --
 Use the "kill" command to terminate any processes that you are not actively running. Then, rebuild the RPM database via:

 --

>>mkdir /root/old_rpm_dbs/
>>mv /var/lib/rpm/__db* /root/old_rpm_dbs/
>>rpm --rebuilddb

Proceed to attempt another cPanel update if this completes successfully:

/scripts/upcp

/scripts/upcp --force

*** have a party day ***

Saturday, 28 March 2015

Restore KVM and OPenvz

Restore an OpenVZ machine to VM 101

vzrestore /mnt/backup/vzdump-openvz-500.tar 101

Restore an Qemu/KVM machine to VM 107

qmrestore /mnt/backup/vzdump-qemu-600.tar 107

Enable root login alert . Send mail alert when anyone login server

1. Login to your server
2. cd /root
3. pico .bashrc
4. Scroll to the end of the file then add the following:

echo 'ALERT - Root Shell Access (YourserverName) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" test123@gmail.com

Fatal error*: Allowed memory size of 41943040 bytes exhausted

If you see the above error in wordpress and the issue persists even after setting memory limit in wp-settings.php and php.ini..

  try the steps below

copy server php.ini to public_html and change the ownership

create a .htaccess in home dir of user

root@server [/home/username]# vi .htaccess
SuPHP_ConfigPath /home/username/public_html/php.ini

replace username with the correct username.

This is how to set php.ini recursively for all directories. This will only work with suphp handler