Sunday, May 6, 2012

Install Python 2.6 on CentOS 5 without affecting yum

Install Python 2.6 on CentOS 5

CentOS 5 is the most common Python hosting environment in the market, but the default version of python it is 2.4 now. As some projects request the python version to be greater than V2.5, in this article, you will see how to install python 2.6 by compiling source code step by step.
======================
1. Download python source from python.org and Uncompress it.
$ wget http://www.python.org/ftp/python/2.6.7/Python-2.6.7.tgz 
$ tar xzvf Python-2.6.7.tgz
 ======================
2. Build & Install.
In the source code folder:
$ ./configure --prefix=/opt/python2.6 --with-threads --enable-shared --with-zlib=/usr/include
$ make
$ make install
 ======================  
 
3. Add Python 2.6 lib to system lib. execute:
$ sudo ln -s /opt/python2.6/lib/libpython2.6.so /usr/lib
$ sudo ln -s /opt/python2.6/lib/libpython2.6.so.1.0 /usr/lib

# Create necessary links and cache
$ sudo /sbin/ldconfig -v

# make a symbolic link to python
$ sudo ln -s /opt/python2.6/bin/python /usr/local/python
 
 ======================  
4. Check python version use "python -V".
If you still see old version of Python, you need to edit /etc/profile (as root), add the following line:
pathmunge /opt/python2.6/bin/
Above setting should be added before the line like:
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
Then re-login system, try "python -V" again.
 ====================== 
5. After install yum, try "yum search php"
This is to make sure we did not accidentally mess up "yum", which is the biggest threat when upgrading Python version. If you see no errors, you should be good to start using Python 2.6.

Tuesday, April 17, 2012

I/OTOP


I/OTOP


Screenshot-root@localhost:-usr-src-iotop-0.3.1
Needs to have Python >= 2.5 and kernel Linux >= 2.6.20 with those options enabled
  • CONFIG_TASKSTATS
  • CONFIG_TASK_DELAY_ACCT
  • CONFIG_TASK_IO_ACCOUNTING

Pre-requisites

1wget http://guichaz.free.fr/iotop/files/iotop-0.3.1.tar.bz2
2tar jxvf iotop-0.3.1.tar.bz2 -C /usr/src
3cd /usr/src/iotop-0.3.1/
To execute the program without installing it, just call via CLI:
1./iotop.py
In case that the following error comes:
1Traceback (most recent call last):
2  File "./iotop.py", line 8, in ?
3    from iotop.ui import main
4  File "/usr/src/iotop-0.3.1/iotop/ui.py", line 12, in ?
5    from iotop.data import find_uids, TaskStatsNetlink, ProcessList
6  File "/usr/src/iotop-0.3.1/iotop/data.py", line 12, in ?
7    from iotop import ioprio, vmstat
8  File "/usr/src/iotop-0.3.1/iotop/ioprio.py", line 1, in ?
9    import ctypes
It’s because you haven’t the python installed os it isn’t the 2.5 version. It’s necessary to install it.

Installing Python 2.5 on Red Hat 5.3 / CentOS 5.3

Red Hat 5 / CentOS 5 comes with python 2.4 by default. It isn’t cool to simply install the new version over the default one, instead, I’m disponibilizing here the RPMs of python 2.5 for Red Hat 5 / CentOS 5 that will be installed in his own directory /usr/bin/python25, so, the scripts that Yum and others scripts made use of python 2.4 won’t get hurt.
The news is, always that you need to use the new version of python 2.5 you’ll have to change the interpretor PATH that call python25. It’s better than the whole system going unstable, isn’t it? ;)

Executing iotop.py

With python25 installed, it’s time to modify the script iotop.py and change the interpreter on the first line, from:
1#!/usr/bin/python
to
1#!/usr/bin/python25
Ok, time to run the script
1./iotop.py
If any of the pre-requisites won’t be safisfied, a message like this one will show informing what is missing
Could not run iotop as some of the requirements are not met:
- Python >= 2.5 for AF_NETLINK support: Found
- Linux >= 2.6.20 with I/O accounting support (CONFIG_TASKSTATS, CONFIG_TASK_DELAY_ACCT, CONFIG_TASK_IO_ACCOUNTING): Not found
Python 2.5 it’s OK, but kernel isn’t.
Simple, compiling kernel with those options:
To compile the new kernel, there’s a post here that explains it, here I’ll show you just which options to be considered, compile and install the kernel it’s with you now ;)
General setup  --->
...
[*] Export task/process statistics through netlink (EXPERIMENTAL)
[*]   Enable per-task delay accounting (EXPERIMENTAL)
[*]   Enable extended accounting over taskstats (EXPERIMENTAL)
[*]     Enable per-task storage I/O accounting (EXPERIMENTAL)
...
Screenshot-3

Kernel 2.6.30.5 (rpm) with process statistics ready to be used with iotop

To install
1rpm -ivh kernel-2.6.30.5fogonacaixadagua-1.i386.rpm
in case you already installed this kernel before, will need to generate again an image initrd and use the flag --force with rpm -ivh --force command.

iotop running

Screenshot-root@localhost:-usr-src-iotop-0.3.1

Installing iotop

Into the directory you extracted iotop-0.3.1 run the command
./setup.py install
1cd /usr/src/iotop-0.3.1
2./setup.py install
How it was installed python 2.5, if you run /usr/bin/iotop the following error will be gracefuly show to you
Traceback (most recent call last):
File "/usr/bin/iotop", line 4, in
import pkg_resources
ImportError: No module named pkg_resources
To resolve that one, it’s quite simple, into directory where you extracted iotop, in this case /usr/src/iotop-0.3.1 copy the entire directory iotop to /usr/lib/python-2.5
1cd /usr/src/iotop-0.3.1
2cp -Rp iotop /usr/lib/python2.5/
And after that, edit the file /usr/bin/iptop and modify the line of interpreter
from
1#!/usr/bin/python
to
1#!/usr/bin/python25
Ok, iotop running!

Git 1.7.6.1 on CentOS 5.6

Git 1.7.6.1 on CentOS 5.6

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

I’ve been hearing good things about git lately, with many projects which used to use subversion converting to it, so I’ve decided to try it out myself. RPMForge only has version 1.5, so like the other software I’ve been using, I’ve converted Fedora 11′s rpm to CentOS and put it in the Webtatic repository.
Update 2010-02-14 – Updated Git 1.6.6 to 1.7.0
Update 2010-04-05 – Updated to 1.7.0.4, included all dependencies in the repository to remove any dependencies on other repositories
Update 2011-04-09 – Emacs support is back in, with the emacs-git package
If you haven’t set up the Webtatic repository in yum, then add it in the command-line as following:
rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
Now install git:
yum install --enablerepo=webtatic git-all
=========================================================
 

Thursday, March 29, 2012

Postfix Flush the Mail Queue

Postfix Flush the Mail Queue

by Vivek Gite on October 25, 2007 · 20 comments
Traditionally you use the "sendmail -q" command to flush mail queue under Sendmail MTA. Under Postfix MTA, just enter the following command to flush the mail queue:
# postfix flush
OR
# postfix -f
To see mail queue, enter:
# mailq
To remove all mail from the queue, enter:
# postsuper -d ALL
To remove all mails in the deferred queue, enter:
# postsuper -d ALL deferred

postfix-delete.pl script

Following script deletes all mail from the mailq which matches the regular expression specified as the first argument (Credit: ??? - I found it on old good newsgroup)
#!/usr/bin/perl
 
$REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!";
 
@data = qx;
for (@data) {
  if (/^(\w+)(\*|\!)?\s/) {
     $queue_id = $1;
  }
  if($queue_id) {
    if (/$REGEXP/i) {
      $Q{$queue_id} = 1;
      $queue_id = "";
    }
  }
}
 
#open(POSTSUPER,"|cat") || die "couldn't open postsuper" ;
open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;
 
foreach (keys %Q) {
  print POSTSUPER "$_\n";
};
close(POSTSUPER);
 
For example, delete all queued messages from or to the domain called fackspamdomain.com, enter:
./postfix-delete.pl fackspamdomain.com
Delete all queued messages that contain the word "xyz" in the e-mail address:
./postfix-delete.pl xyz
Updated for accuracy.






Use the following command to view the current postfix MTA queue:
# postqueue -p

Tuesday, March 27, 2012

Install unrar command

Install unrar command

Under Debian or Ubuntu Linux, you need to type apt-get command as follows to install unrar program:
# apt-get install unrar
If you are using Fedora core Linux / CentOS / RHEL, use yum command as follows (see discussion below for more):
# yum install unrar
If you are using FreeBSD, enter:
# pkg_add -v -r unrar
If any of above, methods is not working for you, download binary package from official rarlab site:
$ cd /tmp
$ wget http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz

Next, untar file, enter:
$ tar -zxvf rarlinux-3.6.0.tar.gz
Both unrar and rar commands are located in rar sub-directory. Just cd to rar directory, type:
$ cd rar
$ ./unrar

Now copy rar and unrar file to /bin directory, type:
# cp rar unrar /bin

HowTo: Use unrar Command

The unrar command supports various options, below are common options that you need to for extracting files.

Task: Exreact rar (unpack) File

To extract file.rar file into the current directory, enter:
$ unrar e file.rar

Task: List (l) file inside rar archive:

$ unrar l file.rar

Task: To extract (x) files with full path type command:

$ unrar x file.rar
(D) To test (t) integrity of archive, file type command:
$ unrar t file.rar

Rewrite Rule to redirect the access for a IP to another URL.

 Rewrite Rule to redirect the access for a IP to another URL.

#RewriteEngine on
#RewriteCond %{REMOTE_ADDR} ^172\.16\.107 [OR]
#RewriteCond %{REMOTE_ADDR} 172.16.107.58
#RewriteCond %{REMOTE_ADDR} 172.16.110.35
#RewriteRule /node/64$ https://xxxxxxxxxxxxx.com/node/65 [R=301,L]

Thursday, March 22, 2012

libMagickCore.so.5: cannot open shared object file:

libMagickCore.so.5: cannot open shared object file:

======================
ldconfig /usr/local/lib
 ======================