Thursday, September 27, 2012

Create a Swap File in Linux

Add Additional Swap space for System performance.

Check the size of the disk and create a swap space accordingly.

[root@vmtest02 ~]# free -m
                     total       used       free     shared    buffers     cached
Mem:          2003        437       1565          0         24        307
-/+ buffers/cache:        105       1897
Swap:         4102          0           4102

[root@vmtest02 ~]# df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3     12G  4.1G  6.8G  38% /
/dev/sda6     ext3     20G  3.7G   15G  20% /u01
/dev/sda5     ext3    3.9G  775M  3.0G  21% /tmp
/dev/sda1     ext3     99M   11M   83M  12% /boot
tmpfs        tmpfs   1002M     0 1002M   0% /dev/shm

Create Storage file for 1GB using the below command.

[root@vmtest02 ~]# dd if=/dev/zero of=/u01/swapfile1 bs=1024M count=1
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 68.8808 seconds, 15.6 MB/s

To set the swap area, type

 [root@vmtest02 ~]# mkswap /u01/swapfile1
Setting up swapspace version 1, size = 1073737 kB

 By default the permissions will be

[root@vmtest02 ~]# ls -l /u01/swapfile1
-rw-r--r-- 1 root root 1073741824 Sep 27 13:26 /u01/swapfile1

change it root and set the permissions to 0600 for security reasons

Check the partition size reduced by 1GB

[root@vmtest02 ~]# df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3     12G  4.1G  6.8G  38% /
/dev/sda6     ext3     20G  4.7G   14G  25% /u01
/dev/sda5     ext3    3.9G  775M  3.0G  21% /tmp
/dev/sda1     ext3     99M   11M   83M  12% /boot
tmpfs        tmpfs   1002M     0 1002M   0% /dev/shm

Activate the swap file and cross check the swap size.

[root@vmtest02 ~]# swapon /u01/swapfile1

Verify the swap space.

[root@vmtest02 ~]# free -m
                   total       used       free     shared    buffers     cached
Mem:          2003       1477        525          0         26       1331
-/+ buffers/cache:        120       1883
Swap:         5126          0          5126

Check the details of swap files using the below command.

swapon -s


You can also make the swap  on and off using the below commands.

swapoff -a &&  swapon -a
To make it permanent after reboot , make a entry in /etc/fstab like

 u01/swapfile1 swap swap defaults 0 0





R installation in Linux

        cd  /usr/local/src/
        wget http://linux.softpedia.com/dyn-postdownload.php?p=1182&t=0&i=1

    --> tar -zxvf  R-2.15.tar.gz
   ---> cd R-2.15
   --> ./configure --prefix=/usr/local/R-2.15 --enable-R-shlib
    --> make
    --> make install
    --> Add R path in the bash profile.


  --> open this file /etc/ld.so.conf.d/R-i386.conf and put the following entry /usr/local/R-2.15/lib/R/lib then save and exit.
  --> run the ldconfig command.

It should work fine.

Install for 64 bit architechture.

Download from source, untar
./configure

 Neither an F77 compiler nor f2c found error

If you receive the above error follow the below steps

Yum install gcc*  will fix the issue.


R is now configured for x86_64-unknown-linux-gnu

  Source directory:          .
  Installation directory:    /usr/local/R-2.15

  C compiler:                gcc -std=gnu99  -g -O2
  Fortran 77 compiler:       gfortran  -g -O2

  C++ compiler:              g++  -g -O2
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:            gcc -g -O2

  Interfaces supported:      X11, tcltk
  External libraries:        readline
  Additional capabilities:   PNG, JPEG, iconv, MBCS, NLS
  Options enabled:           shared R library, shared BLAS, R profiling

  Recommended packages:      yes

configure: WARNING: you cannot build DVI versions of the R manuals
configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals


make ; make install

configure: error: --with-x=yes (default) and X11 headers/libs are not available

If you receive the above error , follow the below steps

./configure --prefix=/usr/local/R-2.15 --enable-R-shlib  --with-x=no

export PATH=$PATH:/usr/local/R-2.15/bin

ln /usr/local/R-2.15/lib64/R/lib /usr/local/lib64

export  R path in bash profile

Thursday, September 20, 2012

BOOST Installation in Linux

cd /usr/local/src/
wget  boost_1_51_0.tar.gz
tar -zxvf  boost_1_51_0.tar.gz
cd  boost_1_51_0

 ./bootstrap.sh --with-libraries=signals,python --prefix=/usr/local/ --includedir=/usr/local/include/ --libdir=/usr/local/lib

./b2

################################################

mod_wsgi Installation

The aim of mod_wsgi is to implement a simple to use Apache module which can host any Python application which supports the Python WSGI interface. The module would be suitable for use in hosting high performance production web sites, as well as your average self managed personal sites running on web hosting services.

cd /usr/local/src/

wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
tar -zxvf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4

 locate apxs
./configure --with-apxs=/usr/local/apache/bin/apxs  --with-python=/usr/local/bin/python
make
make install

Edit httpd.conf file
LoadModule wsgi_module modules/mod_wsgi.so

For apache 1.3 version
AddModule mod_wsgi.c

/etc/init.d/httpd/ restart

Install python 2.7 using tar file

    cd /usr/local/src/
    wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
    tar -zxvf Python-2.7.2.tgz
    cd Python-2.7.2
    ./configure --prefix=/opt/python2.7 --with-threads --enable-shared
    make
    make install


Once the python is installed separately export LD_LIBRARY_PATH=/usr/local/lib
path of the current python library.

If it doesn't work try locating the libpython and place it in the right path to make it work.

   --> ./configure --prefix=/usr/local/python2.7  --enable-shared
   --> make ; make install
   --> updatedb
   --> locate libpython2.7.so.1.0
   --> cp -r /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib
  -->  Add /usr/lib in /etc/ld.so.conf file
  -->   Type ldconfig command
   --> Add python path in the bash profile.

It works now !!

PHP Installation in Linux

 
cd /usr/local/src
wget http://es.php.net/distributions/php-5.4.1.tar.gz
tar -zxvf  php-.5.4.1.tar.gz
cd php-5.4.1

Run the command updatedb

Find the exact path of the Apache extension tool (apxs) using
 locate apxs 


./configure --with-apxs2=/usr/sbin/apxs --with-mysql=/usr/bin/mysql --with-libdir=lib64 --enable-mbstring --with-mcrypt

you can also use --prefix= (to the location you need the php to be installed)

Error
checking libxml2 install dir… /opt/xml2/
checking for xml2-config path…
configure: error: xml2-config not found. Please check your libxml2 installation.

Solution
yum -y install libxml2-devel
Error
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

Solution
yum install libmcrypt
yum install libmcrypt-devel

Error:
configure: error: Cannot find MySQL header files under /usr/bin/mysql.
Note that the MySQL client library is not bundled anymore!


./configure --with-apxs2=/usr/sbin/apxs --with-mysqli=/usr/bin/mysql_config --enable-mbstring --with-mcrypt


make
make install

generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating main/php_config.h
config.status: executing default commands


PHP installed successfully now.

You can check the installed php using:

rpm -qa  | grep -i php

For more details you can check 

./configure --help


######################################################################################

Wednesday, September 19, 2012

Apache 2 installation

cd /usr/local/src

 Download the latest version of http and run the below commands

wget http://apache.techartifact.com/mirror//httpd/httpd-2.4.3.tar.gz

tar -zxvf httpd-2.4.3.tar.gz

cd httpd-2.4.3

./configure --prefix=/usr/local/apache2 --with-php=/usr/bin/php --with-mysql=/usr/bin/mysql  --
enable-mods-shared=all --with-included-apr

 You may get the below errors,  you can fix it by following the below steps

configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.


cd  /usr/local/src/
wget http://apache.techartifact.com/mirror//apr/apr-1.4.6.tar.gz
tar -zxvf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure
make
make install

cp -r /usr/local/src/apr-1.4.6 /usr/local/src/httpd-2.4.3/srclib/

cd ../httpd-2.4.3/

./configure --prefix=/usr/local/apache2 --with-php=/usr/bin/php --with-mysql=/usr/bin/mysql --enable-mods-shared=all --with-apr=/usr/local/src/httpd-2.4.3/srclib/apr-1.4.6 --with-apr-util=/usr/local/src/apr-util-1.5.1

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/


cd ..

wget pcre

./configure
make
make install

 cd ../httpd-2.4.3/

./configure
configure: error: Did not find pcre-config script at /usr/local/src/pcre-8.31/

yum install pcre-devel

apr-util not found.configure: error: APR-util version 1.3.0 or later is required

wget apr-util1.5.0

./configure --with-apr=/usr/local/src/apr-1.4.6

make
make install

cd httpd

./configure --prefix=/usr/local/apache2 --with-php=/usr/bin/php --with-mysql=/usr/bin/mysql --enable-mods-shared=all --with-apr=/usr/local/src/httpd-2.4.3/srclib/apr-1.4.6 --with-apr-util=/usr/local/src/apr-util-1.5.1

make
make install

 ps -ef | grep httpd

killall -9 httpd

 cd /usr/local/apache2/bin/

./apachectl start

It should work...

Enable User Home directory http://xxx.ip.xxx/~username

All you have to do is editing these example lines in your httpd.conf

#
# UserDir: The name of the directory which is appended onto a user's home
# directory if a ~user request is received.
#
<IfModule mod_userdir.c>
    UserDir public_html
</IfModule>

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory /home/*/public_html>
    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS PROPFIND>
        Order allow,deny
        Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
        Order deny,allow
        Deny from all
</LimitExcept>
</Directory>



Note that the files and all the directories  have to  read permission for the user under which apache runs. That normally means they have to be world readable. Apache does not use the permissions of the refering user.

If it doesn't work, make sure you have mod_userdir installed.


Restricting what users are permitted to use this feature

Using the syntax shown in the UserDir documentation, you can restrict what users are permitted to use this functionality:

UserDir disabled root krish raj

The configuration above will enable the feature for all users except for those listed in the disabled statement. You can, likewise, disable the feature for all but a few users by using a configuration like the following:

UserDir disabled
UserDir enabled sai tester


Enabling a cgi directory for each user

In order to give each user their own cgi-bin directory, you can use a <Directory> directive to make a particular subdirectory of a user's home directory cgi-enabled.


<Directory /home/*/public_html/cgi-bin/>
Options ExecCGI
SetHandler cgi-script
</Directory>

Then, presuming that UserDir is set to public_html, a cgi program example.cgi could be loaded from that directory as:

http://example.com/~tester/cgi-bin/example.cgi

           
Save the file using :wq or x

Restart apache /etc/init.d/httpd restart

It will work

If you find any internal server error there must a permission issues for the files and directories.

Ensure that the directories have 755 permission and files have 644 permission.

you can also run the below command.

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

Try running the above command inside the directory so that other files in the server doesn't get affected.

Restart the apache . It will work.

By default when adding the user, the public_html directory will not be available. I tried by creating the public_html direcotry in /etc/skel .

After this when ever i create a user the public_html directory is created by default to the users home directory.

Wednesday, September 12, 2012

Check the Process id and Process states

 [root@crs2 ~]# ps -aux | less


USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   2040   632 ?        Ss   09:30   0:00 init [5]     
                    
root         2  0.0  0.0      0     0 ?        S    09:30   0:00 [migration/0]
root         3  0.0  0.0      0     0 ?        SN   09:30   0:00 [ksoftirqd/0]
root         4  0.0  0.0      0     0 ?        S    09:30   0:00 [watchdog/0]
root         5  0.0  0.0      0     0 ?        S<   09:30   0:00 [events/0]
root         6  0.0  0.0      0     0 ?        S<   09:30   0:00 [khelper]
root         7  0.0  0.0      0     0 ?        S<   09:30   0:00 [kthread]
root        10  0.0  0.0      0     0 ?        S<   09:30   0:00 [kblockd/0]
root        11  0.0  0.0      0     0 ?        S<   09:30   0:00 [kacpid]
root       180  0.0  0.0      0     0 ?        S<   09:30   0:00 [cqueue/0]
root       183  0.0  0.0      0     0 ?        S<   09:30   0:00 [khubd]
root       185  0.0  0.0      0     0 ?        S<   09:30   0:00 [kseriod]
root       249  0.0  0.0      0     0 ?        S    09:30   0:00 [pdflush]
root       250  0.0  0.0      0     0 ?        S    09:30   0:00 [pdflush]
:



You can check the process id and states of process using the below command and syntax.

[root@crs2 ~]# ps -C init -o pid=,cmd,stat
      CMD                         STAT
    1 init [5]                    Ss

[root@crs2 ~]# ps -C firefox -o pid=,cmd,stat
      CMD                         STAT
 6666 /bin/sh /usr/lib/firefox-1. S

 Processes states that ps indicate are:

D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.

< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group