Saturday, 30 March 2013

Cherokee Web Server on Linux ( Cross-platform Web server ) :

Cherokee is one of the fastest and most flexible web server's available. Cherokee is able to gracefully handle many concurrent connections while maintaining a low memory footprint. It supports a large variety of technologies, features, load balancing capabilities, platforms, and provides an administration interface to configure your server and sites.

Installation:

RPM:

[root@ranjith ~]# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

YUM:

[root@ranjith ~]# yum install cherokee

start Cherokee and add it to the default runlevel (to start at boot time).

[root@ranjith ~]# /etc/init.d/cherokee start
[root@ranjith ~]# chkconfig cherokee on


Configuration

Unlike Apache, Cherokee itself provides an interface for administering the web server. To start the admin interface, run the following command in the shell.

[root@ranjith ~]# cherokee-admin -b

The output of this command will show the login pass, and URL. Similar to the following:

Login:
User: admin
One-time Password: password

Web Interface:
URL: http://localhost:9090/


Cherokee Web Server 1.0.6 (Aug 6 2010): Listening on port ALL:9090, TLS
disabled, IPv6 enabled, using epoll, 4096 fds system limit, max. 2041
connections, caching I/O, single thread

Cherokee's admin will now be listening on port 9090 of your server, web browser on http://your-servers-ip:9090.

Enjoy!!!

Thursday, 28 March 2013

Bash Test Operators

STRINGS:

-------------------------------------
syntax:

if [ "$str1" operator "$str2" ]
then
   command
fi


-------------------------------------

=     is equal to
==     is equal to     if (( $1 == $2 )) [Note: Used within double parentheses]

The == comparison operator behaves differently within a double-brackets test than within single brackets.
[[ $a == z* ]]     True if $a starts with an “z” (pattern matching).
[[ $a == "z*" ]]     True if $a is equal to z* (literal matching).

[ $a == z* ]     File globbing and word splitting take place.
[ "$a" == "z*" ]     True if $a is equal to z* (literal matching).

!=     is not equal to
<     is less than, in ASCII alphabetical order
>     is greater than, in ASCII alphabetical order
-n     string is not “null.”
-z     string is “null, ” that is, has zero length


INTEGERS: 
--------------------------------------------
syntax:

if [ "$string1" operator "$string2" ]
then
   command
fi


---------------------------------------------


-eq     is equal to     if [ $1 -eq 200 ]
-ne     is not equal to if [ $1 -ne 1 ]
-gt     is greater than if [ $1 -gt 15 ]
-ge     is greater than or equal to if [ $1 -ge 10 ]
-lt     is less than     if [ $1 -lt 5 ]
-le     is less than or equal to     if [ $1 -le 0 ]
<     is less than (within double parentheses)
<=     is less than or equal to (within double parentheses)
>     is greater than (within double parentheses)
>=     is greater than or equal to (within double parentheses)


FILES/DIRECTORIES:

-----------------------------------
syntax:

 if [ -operator "$filename" ]
then
   command
fi


-------------------------------------

-e     file exists
-f     file is a regular file (not a directory or device file)
-s      file is not zero size (lowercase ‘s’)
-S     file is a socket
-d     file is a directory
-b     file is a block device (floppy, cdrom, etc.)
-c     file is a character device (keyboard, modem, sound card, etc.)
-p     file is a pipe
-h     file is a symbolic link
-L     file is a symbolic link
-t     file (descriptor) is associated with a terminal device
-r     file has read permission (for the user running the test)
-w     file has write permission (for the user running the test)
-x     file has execute permission (for the user running the test)
-g     set-group-id (sgid) flag set on file or directory
-u     set-user-id (suid) flag set on file
-k     sticky bit set
-O     you are owner of file
-G     group-id of file same as yours
-N     file modified since it was last read
f1 -nt f2     file f1 is newer than f2
f1 -ot f2     file f1 is older than f2
f1 -ef f2     files f1 and f2 are hard links to the same file

Monday, 25 March 2013

Zombie Processes in Linux

What is a zombie?

Zombie is a process state when the child dies before the parent process. In this case the structural information of the process is still in the process table. Since this process is not alive, it cannot react to signals. Zombie state can finish when the parent dies. All resources of the zombie state process are cleared by the kernel.

Causes of Zombie Processes:

When a subprocess exits, its parent is supposed to use the "wait" system call and collect the process's exit information. The subprocess exists as a zombie process until this happens, which is usually immediately. However, if the parent process isn't programmed properly or has a bug and never calls "wait," the zombie process remains, eternally waiting for its information to be collected by its parent.

Killing Zombie Processes:

Zombie processes persist until their parent process ends, at which point they are adopted by the "init" system process and shortly cleaned up. However, there's no way to get rid of a zombie process without ending its parent process. If you have a lot of zombie processes, close and restart the parent process or service. Init adopts and cleans up the orphaned zombie processes. If you can't close the parent process, don't worry, zombies won't affect the performance of your computer unless a very large amount are present. However, bear in mind that, if a process is creating a lot of zombies, it has a programming bug or error in its code and isn't working correctly.
Viewing Zombie Processes

The Execute the "top" command in a Terminal window. The top command shows the number of zombie processes at the upper-right side of its output, in the Tasks: row.

You can also list running processes by executing the "ps aux" command. Zombie processes have a "z" listed in their Stat column in the output of the 'ps aux" command.

Risks of Zombie Processes:

While zombie processes aren't a problem in and of themselves and take up very little resources, there is one concern. Linux systems have a maximum amount of processes and thus process ID numbers. If a computer has enough zombie processes, the maximum amount is reached and new processes can't be launched.

The maximum amount of processes can be listed by typing the "cat /proc/sys/kernel/pid_max" in a Terminal window and is usually 32768. Thus, zombie processes are usually not a concern.

However, if the parent process creating zombie processes is server software that isn't written properly, a large amount of zombies could be created under load. Or, zombies could gradually accumulate over long periods of time until the maximum process limit is reached.

Thursday, 21 March 2013

swap partition VS swap file

Swap File:

1. If the hard disk is full or corrupted,swap file will get damaged.

2. System speed get decrease as soon the hard disk space is full.

3. It should be on a particular location where it should not get damaged or accidentally copied with other files.

4. It have advantage to increase the swap space on a system that have already installed with linux.

5. In any case if we need to increase the swap space of the system immediately we can do it.

6. We can able to create and keep the swap file on external device.

7. New kernel have nearly achieved to make both swap partitions and swap file speed closer.

8. Swap file will get fragmented.

Swap Partition:

1. Reside on a separate hard disk space.

2. Multiple Os on a single machine can share the same partition.

3. Fragmentation is less compare to swap file.

4. If hard disk is corrupted the swap partition would not be functioning.

5. Reduce accident loss or corruption.

What is Swap Space?


 Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.

Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.

Swap Space Calculation

Wednesday, 20 March 2013

How to echo colored text in linux shell script:

Colored text in Linux shell script:

 

Having a colourful display on shell script is something that’d beautify your experience. Using colour text and echos will help you to highlight and distinguish the shell output on a linux prompt.

Try following command on you bash:

syntax:

echo -e "\033[COLOR1;COLOR2m sample text\033[0m"

The semicolon separated numbers "COLOR1" and "COLOR2" specify a
foreground and a background color.The order of the numbers does not
matter, since the foreground and background numbers fall in non-
overlapping ranges."m" terminates the escape sequence, and the text
begins immediately after that.Although setting the colors separately
also work (i.e. \033[44m\033[32m).


echo -e "\033[33;31m Color Text" - red

echo -e "\033[33;32m Color Text" - green

echo -e "\033[33;33m Color Text" - yellow

echo -e "\033[33;34m Color Text" - blue

echo -e "\033[33;35m Color Text" - Magenta

echo -e "\033[33;30m Color Text" - Gray

echo -e "\033[33;36m Color Text" - Cyan


Enjoy!!!

Tuesday, 19 March 2013

Shell Script To Display Logged in Users and Load:

To know current users and server load while login:

Place the below code in /root/.bashrc file,

a=$(cat /proc/loadavg | awk '{print $1}')
echo -e "\033[33;34m"
echo -e "Server load average is : $a\n"
b=$(who | awk '{print $1}' | wc -l)
echo -e "Current users : $b"
echo -e "\033[33;m"


Hereafter, You can find the load and current user info in each login.

Monday, 18 March 2013

Table './mysql/user' is marked as crashed and should be repaired

How to make mysql service online from crash!


mysqld started
[ERROR] /usr/sbin/mysqld: Table './mysql/user' is marked as crashed and should be repaired
[ERROR] /usr/sbin/mysqld: Table './mysql/user' is marked as crashed and should be repaired
[ERROR] Fatal error: Can't open and lock privilege tables: Table './mysql/user' is marked as crashed and should be repaired
mysqld ended

Which means DB: /var/lib/mysql/mysql table: "user" has been crashed.

To resolve this issue, please perform the commands below:

root@ranjith [/var/lib/mysql/mysql]# service mysql start --skip-grant-tables

now with mysql started, you can repair the mysql/user table

root@ranjith [/var/lib/mysql/mysql]# mysqlcheck -r mysql user

or

Repair ALL database tables thorugh:

http://techietent.blogspot.in/2013/02/how-repair-all-database-tables.html

After that,

root@ranjith [/var/lib/mysql/mysql]# service mysql stop

Shutting down MySQLs [ OK ]
root@ranjith [/var/lib/mysql/mysql]# service mysql start
Starting MySQL [ OK ]
root@ranjith [/var/lib/mysql/mysql]#

cheers!!!

Wednesday, 13 March 2013

URL redirection using .htaccess

.htaccess



     The .htaccess file is a small text document that generally sits in the 
same location as your index.php or index.htm pages. It gives you the 
ability to interact with Apache on an individual domain-to-domain and 
directory-to-directory basis.

# This will allow to Redirect index page in site like
(http://domain.com/index.html):

Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.yoursite.com/$1 [R=301,L]

# This will allow you the Redirection on New Domain:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] 

# This will allow you to make All http request to https request for a Domain:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
 
# For PHPFox script:
RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://yourdomain/$1 [R,L]  


NOTE:
The reason you should save the file as htaccess.txt is because many operating systems and FTP applications are unable to read or view .htaccess files by default. Once uploaded to the server you can rename the file to .htaccess.

Saturday, 9 March 2013

Command Aliases

Command Aliases

If you always run a command with the same set of options, you can have bash create an alias for it. This alias will incorporate the required options, so that you don't need to remember them or manually type them every time. For example, if you always run ls with the -l option to obtain a detailed directory listing, you can use this command:

root@server # alias ls='ls -l'

To create an alias that automatically includes the -l option. Once this alias has been created, typing ls at the bash prompt will invoke the alias and produce the ls -l output.
You can obtain a list of available aliases by invoking alias without any arguments, and you can delete an alias with unalias.

Quickly jump to frequently-used directories

You probably already know that the $PATH variable lists bash's "search path" - the directories it will search when it can't find the requested file in the current directory. However, bash also supports the $CDPATH variable, which lists the directories the cd command will look in when attempting to change directories. To use this feature, assign a directory list to the $CDPATH variable, as shown in the example below:


root@server # CDPATH='.:~:/usr/local/apache/htdocs:/disk1/backups'

root@server # export CDPATH

Now, whenever you use the cd command, bash will check all the directories in the $CDPATH list for matches to the directory name.