Archive for the ‘linux’ Category
Kill Zombie Process
Written by Navjeet on October 16, 2008 – 5:29 pm -Zombie process or defunction process is a process that has completed execution but still has an entry in the process table. The term zombie process derives from the common definition of zombie—an undead person.
Zombie processes are mostly harmless: they are a process which has finished and is sticking around because their parent hasn’t reaped their exit status. Normally it will do no harm to your system except resource waste.
You can use below command to kill zombie processes:
for i in `ps ax | grep Z | awk {’print $1?}`;do kill -9 $(cat /proc/${i}/status | grep PPid | awk {’print $2?});done
Tags: Zombie
Posted in Dedicated Server Hosting, linux, Linux VPS Hosting, Plesk For Linux, VPS hosting | No Comments »
Installation of Tomcat 6
Written by Mike on October 16, 2008 – 5:25 pm -Download and Install JAVA
Download j2sdk-1.4.2 from Sun Download center http://developers.sun.com/downloads/ Here I have used j2sdk-1_4_2_18-linux-i586-rpm.bin which will install j2sdk using RPMS and set the Path of JAVA_HOME automatically
#chmod +x j2sdk-1_4_2_09-linux-i586.bin
#./j2sdk-1_4_2_09-linux-i586.bin
Now Check if Java is installed on the server using command java -version
[root@vps907 ~]# java -version
java version “1.6.0_07″
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
Download Tomcat
Now Download Tomcat from Apache Website and exract it
#cd /usr/local/
#wget http://bluedogfan.com/mirrors/apache/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
#tar -zxvf apache-tomcat-6.0.18.tar.gz
Create Symlink for the Tomcat Folder
#ln -s /usr/local/apache-tomcat-6.0.18 /usr/local/apache/tomcat
Install Tomcat
#cd apache-tomcat-6.0.18
#cd bin
#tar xvfz jsvc.tar.gz
#cd jsvc-src
#chmod +x configure
#./configure
#make
#cp jsvc ..
#cd ..
Start Tomcat
Use Following script to start Tomcat Service on the Server
#/usr/local/apache/tomcat/bin/startup.sh
Running Tomcat as non root user
Due to security reasons always run tomcat as non-root user i.e. tomcat. To run it as tomcat first you will have to change the ownership of the tomcat folder
#chown tomcat.tomcat /usr/local/apache-tomcat-6.0.18 -R
Now Tomcat can be stopped and started under user tomcat using following commands:
#su -l tomcat -c /usr/local/apache/tomcat/bin/startup.sh
#su -l tomcat -c /usr/local/apache/tomcat/bin/shutdown.sh
Test Tomcat installation
open a browser and browse website http://xx.xx.xx.xx:8080 where xx.xx.xx.xx will be your Server IP and If you get following output than Tomcat has been installed properly on the Server.
Creating Script to start, stop and restart Tomcat
The above installation step will not create tomcat service so that user can restart tomcat using command service tomcat restart. Create a new file in /etc/init.d as tomcat and copy following contenents into it.
#vi /etc/init.d/tomcat
#
# Startup script for Tomcat
#
# chkconfig: 345 84 16
# description: Tomcat jakarta JSP server
#Necessary environment variables
export CATALINA_HOME=”/usr/local/tomcat”
if [ ! -f $CATALINA_HOME/bin/catalina.sh ]
then
echo “Tomcat not available…”
exit
fi
start() {
echo -n -e ‘\E[0;0m'"\033[1;32mStarting Tomcat: \033[0m \n"
su -l tomcat -c $CATALINA_HOME/bin/startup.sh
echo
touch /var/lock/subsys/tomcatd
sleep 3
}
stop() {
echo -n -e '\E[0;0m'"\033[1;31mShutting down Tomcat: \033[m \n"
su -l tomcat -c $CATALINA_HOME/bin/shutdown.sh
rm -f /var/lock/subsys/tomcatd
echo
}
status() {
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start” | awk ‘{printf $1 ” “}’ | wc | awk ‘{print $2}’ > /tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
echo -n “tomcatd ( pid ”
ps ax –width=1000 | grep “[o]rg.apache.catalina.startup.Bootstrap start” | awk ‘{printf $1 ” “}’
echo -n “) is running…”
echo
else
echo “Tomcat is stopped”
fi
}
case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo “Usage: tomcatd {start|stop|restart|status}”
exit 1
esac
Save and exit from the file. Now assign executable permission to this file
#chown 755 /etc/init.d/tomcat
Enable it for all the Run-levels
#chkconfig –add tomcat
#chkconfig tomcat on
Now you can restart tomcat service using following commands (you can check the screenshot too)
#service tomcat restart <<< To restart tomcat
#service tomcat stop <<< To stop Tomcat
#service tomcat start <<< To start Tomcat
#service tomcat Status <<< to check the status of Tomcat
Tags: Download j2sdk-1.4.2, Download Tomcat, Install Tomcat6, Script for to start, stop and restart Tomcat, Test Tomcat installation, Tomcat as non root user
Posted in linux, Linux VPS Hosting | 2 Comments »
What is DomainKeys
Written by AlanV on October 16, 2008 – 5:51 am -DomainKeys is an e-mail authetication mechanism designed for verifying the identity of an email sender. It is one of cryptographic authentication method to verify sender’s identity and the integrity of email content. It also verify DNS records of domain of an email sender and the message integrity. DomainKeys has implemented standard of Identified Internet Mail to create enhanced protocol called DomainKeys Identified Mail (DKIM)
How it works and mail is identified as spam or legitimate.
Technically DKIM provides a method for validating a domain name identity that is associated with a message through cryptographic authentication. Basically mailservers generate a public and private key pair and sign outgoing messages with the private key and published the public key as part of their DNS record. The public key published by mailservers can be used to confirm that the sender of the email has not been spoofed.
Email without headers can be used as part of the process of identifying spam.
You can install and use DomainKeys on all cPanel server as cPanel has included this feature for email authentication.
Type the following command on server to enable domainkeys.
#/usr/local/cpanel/bin/domain_keys_installer username (username=cPanel account like alan etc.)
So enjoy the emails without spam
Tags: domainkeys, install domainkeys on cPanel server, mailserver with domainkeys, prevent spams using domainkeys, spam+doaminkeys, what dkim, what is domain key
Posted in Dedicated Server Hosting, linux, Linux VPS Hosting, Plesk For Linux, VPS hosting | 1 Comment »
ISPConfig
Written by Pravin on October 16, 2008 – 4:30 am -Licensed under BSD license, ISPConfig is an open source control panel for hosting on Linux. Internet services like DNS servers, FTP servers, Web servers, Database servers are managed by ISPConfig. Configuration of anti-virus, shell users, spam filters, quotas, autoresponders & firewall can be configured through ISPConfig.
ISPConfig is supported on CentO, Debian, Fedora Core, Ubuntu, Red Hat Linux, Mandrake & Mandriva. Services like Mailscanner, Shell-access, IP-addresses, SSL, SSI, Traffic limits, Mail-Quota, Harddisk quota, Webalizer statistics, Bin, POP3 are also managed on ISPConfig.
Tags: Add new tag, control panel, cpanel, Plesk, Plesk For Linux
Posted in Dedicated Server Hosting, linux | No Comments »
How To Use Netstat To Find Out Number Of Connections To Server
Written by Jahangir on October 13, 2008 – 2:04 pm -Netstat :- Netstat is the most frequent tool used for monitoring network connections on a Linux servers. Netstat returns a variety of information on active connections such as their current status, what hosts are involved, and which programs are involved. You can also see information about the routing table and even get statistics on your network interfaces. Netstat is a good all-around utility and it is an essential tool for the Linux administrators.
If you just type netstat, it would display a long list of information that’s usually more than you want to go through at any given time. The trick is that how to keeping the information useful and what you’re looking for and how to tell netstat to only display that information.
Below is some of the command to find out number of connections to server using netstat, grep, cut, awk, uniq, sort.
To find out the number of connections from an IP.
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | uniq -c | sort -n
In the above command AWK print out the 5th column of netstat output, the CUT part cuts every line at the first space character and take the first piece, than we just have to SORT the results and take the UNIQUE values.
To find out the largest number of established connections.
netstat -na | grep ‘ESTABLISHED’ | awk ‘{print $4}’ | cut -d: -f1 | uniq -c | sort -rn
In the above command GREP is been used to find the line containing “ESTABLISHED“, AWK print out the 4th column of netstat output. CUT part cuts every line at the first space character and take the first piece, than we just have to SORT the results and take the UNIQUE values.
To check max number of connections to server.
netstat -nap |grep ‘tcp\|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n | tail
In the above command GREP is been used to find the line containing “tcp/udp” [ if you want to sort such lines which are matching two or more different pattern then simply define all patterns in single quote and separate them using \|] , AWK print out the 5th column of netstat output. CUT part cuts every line at the first space character and take the first piece, than we just have to SORT the results and take the UNIQUE values. TAIL command print the last part (10 lines) of the output.
To find out the largest number of established connections with port number.
netstat -na | grep ‘ESTABLISHED’ | awk ‘{print $4}’ | uniq -c | sort -rn
To find out the number of connections to port 80 [http] from each IP.
netstat -plan|grep :80|awk {‘print $5′}|cut -d: -f 1|sort|uniq -c|sort -n
Similarly, you can find out the number of connections to port 25 from each IP as.
netstat -plan|grep :25|awk {‘print $5′}|cut -d: -f 1|sort|uniq -c|sort -n
NETSTAT is the most useful tool to detect and determine whether a server is under DoS or DDoS attack (Distributed Denial of Service).
Tags: awk, cut, grep, monitoring network connections on a Linux servers, netstat, Netstat To Find Out Number Of Connections, server is under DoS or DDoS attack, sort., uniq
Posted in Dedicated Server Hosting, linux, Linux VPS Hosting, Plesk For Linux | No Comments »
COMMPRESSION – How Does Data Compression Work?
Written by Mike on October 13, 2008 – 12:55 pm -Compression is widely used to save storage space and for faster data transmission over networks and the Internet. A large file (or a number of files) is shrunk into a compact file that can be “expanded” later to get back the original files. In the case of lossy compression (we’ll come to that in a minute), you get a much smaller MP3 file from a huge WAV file (for example). So the question is: how does data compression work?
Lossless Compression
Let’s talk about lossless compression first, basically what happens when a number of files are zipped. Here, you get back all the original data when you unzip it. The simple fact is that data files have redundancy—the same information is represented repetitively.
For example, in a text file, pronouns, prepositions, punctuations, and such are repeated throughout the document. The redundancy can be removed through compression by listing the bits of repeated information or common elements (for example, patterns or shapes in the case of image files) once, instead of listing them again and again.
One of the simplest ways to understand the working of compression is by considering a text file. In the phrase “A penny saved is a penny earned,” each letter, space and punctuation mark occupies one unit of space in the storage media. This file would occupy 32 units of space—comprising 25 letters, 6 spaces, and 1 full stop. If we look for redundancies, the words “a” and “penny”, which are repeated twice each, can be replaced with the numbers 1 and 2 using a coding scheme. So this scheme is: A=1, Penny=2. The coding scheme thus consists of 8 characters (6 letters and 2 numbers). This scheme itself has to be saved in the resulting compressed file so the compression program knows how to unzip the data. The phrase, after applying the coding scheme, would read “1 2 saved is 1 2 earned,” which would occupy 23 units of space. This is saved by the compression program along with the coding scheme to form a compressed file. The size of this file would be 31 units, which consist of 23 characters (with spaces) of the new coded phrase and 8 characters (numbers and letters) of the coding scheme.
So, as compared to the original file size, that is, 32 units, the compressed file size now requires 31 units of space. Here, the dictionary takes up comparatively more space since the original phrase is small. But in the case of a much larger text file, the overhead will reduce: the dictionary will be comparatively smaller, and there will be more repeated patterns in the data. For instance, in the above example, if the next sentence were “So don’t waste a penny!”, we add only 3 items to the dictionary instead of 5. Lossless Compression uses a number of algorithms such as run length coding, the Burrows-Wheeler transform, dictionary coders, prediction by partial matching, context mixing, and entropy coding. Of these, Lempel and Ziv’s (LZ) dictionary-based algorithm for data compression is the most popular and widely-used.
Lossy Compression
When you’re talking to someone on the phone, what matters more—the clarity with which you can hear their words, or whether the phone line reproduces the deep baritone of his voice? It’s this same premise that gave people the idea of lossy compression—compressing files in a way that eliminates some of the “frills” from the file, but keeping its heart intact.
A good example is JPEG compression—tries saving a JPEG at maximum compression through a program like IrfanView—it looks awful, but you can still tell that it’s a dog or a pig or whatever.
The advantage of lossy compression over lossless is the fact that with the freedom of destroying some information from the file itself, you can achieve smaller file sizes. Such stunts aren’t tried with things like text compression, of course—all the data is essential! Lossy compression finds itself used most with images, audio and video—all one needs to do is provide a threshold beyond which all information will be destroyed. Once compressed, you can’t regain the quality of the original file, and if you compress an already compressed file, you lose even more quality, no matter how generous you are with the threshold.
Tags: How Does Data Compression Work?, Lossless Compression, Lossy Compression
Posted in Dedicated Server Hosting, linux, Linux VPS Hosting, VPS hosting, Windows VPS | No Comments »
Some Linux Tricks
Written by AlanV on October 12, 2008 – 6:26 am -Some Linux Tricks
To do simple calculation you can use command ((…))
$ echo $(( 20 + 10 ))
30
Following are the basic math operator use in Linux.
+ perform addition
/ divide last two numbers
* perform multiplication
- perform substration
For more complex math , like floating point etc. use bc command
$ echo "scale=5; 5/3" | bc
1.66666
You can use ((…)) or bc command to convert hex values to decimal
$ echo $((0xff))
255
$ echo 'obase=10; ibase=16; FF' | bc
255
You should always use uppercase letters while using bc command
To convert decimal to hex:
$ echo 'obase=16; ibase=10; 255' | bc
FF
One of the most important command ‘units’you can use to do conversion
$ units -t '1mile' 'km'
1.609344
Hope you will enjoy this
Tags: addition in linux, conversion in linux, hexadecimal in linux, math operators in linux, unit conversion in linux
Posted in Dedicated Server Hosting, linux, Linux VPS Hosting, Plesk For Linux, VPS hosting | No Comments »
How To Split A Large Files To Multiple Parts Using “tar”.
Written by Jahangir on October 10, 2008 – 7:26 am -Process to split file
Here you have to use two extra command line options to split the file over multiple parts. The standard syntax are -M (–multi-volume) which tells Tar you want to split the file over multiple files. Then you need to tell Tar how big that file is, so that it can create files of the correct size. To do this you use the –tape-length option, where the value you pass is number x 1024 bytes.
The example below shows the syntax to used tar to split large file in to multiple parts. Let’s say the large file name trulymanaged.tgz is of 3 GB and we need to fit this file on to the parts of 700 Meg files.
# tar -c -M -v –tape-length=716800 –file=file1.tar trulymanaged.tgz
v :- Output in verbose mode.
M :- Option to split the file over multiple files.
c :- Option to create the tar file.
The value 716800 is 700 x 1024, which will create a 700 Meg file called file1.tar and then Tar will prompt for volume 2 like below :-
Prepare volume #2 for ‘file1.tar’ and hit return:
We have to fire the following command to continue the writing :-
n file2.tar
This instructs Tar to continue writing the remaining of trulymanaged.tgz to a file named file2.tar. You will then be prompted with the line below, and you can now hit return to continue.
Prepare volume #2 for `file2.tar’ and hit return:
You have to continue this process until your large file has been splited completely, increase the file number in the filename each time you are prompted.
Below screen shot demonstrate this process.

Putting the File Back Together
The process is similar like creating files, putting the large files back together from its split-up files. Following is the syntax used to re-create the large file from the file1.tar and file2.tar and the number of files which is been created at the time of splitting.
# tar -x -M -v –file=file1.tar trulymanaged.tgz
trulymanaged.tgz
Prepare volume #2 for `file1.tar’ and hit return: n file2.tar
Prepare volume #2 for `file2.tar’ and hit return:
Below screen shot demonstrate this process.

Tags: Is there a way to split a larger file into multiple chunks using tar, split big file, Split Big File Using "tar", Split files using tar, split tar file into two (or more) files, Split the file in tar, split the file over multiple parts
Posted in Dedicated Server Hosting, linux, Linux VPS Hosting | 3 Comments »
Manage MySQL Databases
Written by AlanV on October 10, 2008 – 6:48 am -
Some MySQL commands are given below to manage your MySQL databases
Step 1
Create database
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_specification] ...
create_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
Create database db_name;
Step 2
Create user CREATE USERuser[IDENTIFIED BY [PASSWORD] 'password'] [,user[IDENTIFIED BY [PASSWORD] 'password']] ... Create user db_user identified by ‘db_passswd’; Step 3
Grant privileges
GRANT priv_type [(column_list)]
[, priv_type [(column_list)]] …
ON [object_type]
{
*
| *.*
| db_name.*
| db_name.tbl_name
| tbl_name
| db_name.routine_name
}
TO user [IDENTIFIED BY [PASSWORD] ‘password’]
GRANT ALL ON *.* TO ‘someuser’@'somehost’;
GRANT SELECT, INSERT ON *.* TO ‘someuser’@'somehost’;
Step 4
Remove database user
DROP USER user;
Step 5
Set password for database users
SET PASSWORD FOR ‘alan’@'%.loc.gov’ = PASSWORD(‘newpass’);
That is equivalent to the following statements:
UPDATE mysql.user SET Password=PASSWORD(‘newpass’)
WHERE User=’alan’ AND Host=’%.loc.gov’;
FLUSH PRIVILEGES;
Tags: Add new tag, create, create database user, create mysql database, grant priviliges on database, how to add user in database, how to create mysql datbase, how to grant priviliges, how to manage mysql database, mysql database, mysql.user, remove database user, set, set password for database
Posted in Dedicated Server Hosting, linux, Linux VPS Hosting, Plesk For Linux, VPS hosting, Windows VPS | No Comments »
Optimize MySQL database
Written by AlanV on October 10, 2008 – 5:18 am -
Optimization is an integral part of database administration. When database is heavily used having too many records and hence there are too many inserts/deletes or retrievals from the database in that case MySQL uses most of system resources.
There are two many options you have to optimize the query or MySQL databases.
Those options are illustrated in this article.
If querying is taking lot of time, and database connections and backlogs are growing, then site performance as well as server performance goes down causing high load sometimes or database crashed which indicate that it is time to optimize your database.
mysqladminpr command is used to check which mysql queries are responsible for heavy system resources.
You can modify MySQL configuration file (my.cnf) to log slow queries. It will check the slow running queries and the possible causes.
This could be related to indexes like no index or improper index for database columns. Here is an attempt to describe which commands and concepts we can use to optimize MySQL so that it will improve the performance.
Step 1:
Use of indexes
Using indexes makes the query faster in the same way as an index in a book helps in looking for a particular word.
To know how and which indexes are used in a given query, use EXPLAIN command as a prefix to select query.
EXPLAIN SELECT employee_code FROM emp WHERE dept = ‘IT’;
This command returns following information:
Table – Which table(s) are used in the query
Type – JOIN type. Values can be system, const, eq_ref, ref, range, index, all
Possible Keys – All keys which can be used for indexes
Key – The key actually used for index
Key Length – Shorter keys are better
Ref – Other Columns used with key to get the results
Rows – Number of rows from where data will come
Extra – Extra information. Some possible values can be using index, using where, using temporary, using filesort
You should reconsider your table structure if Possible Keys contain NULL value.
A NULL value in Key field indicates no index is being used. Using no indexes will deter the performance if there are too many records in the table because, for any query, all the records will be searched for the given condition.
Use ALTER command to add index as given below:
ALTER TABLE table_name ADD INDEX (column_name);
You can do indexing on multiple columns using:
ALTER TABLE table_name ADD INDEX (column_name1,..,column_nameN);
MySQL uses leftmost prefixing, so automatically indexes will be added for column_name1, (column_name1,column_name2),…(column_name1,..,column_NameN-1). This is quite helpful in situations like searching based on surname so an index on (surname, firstname, middlename) will automatically add multiple indexes used in faster querying.
Points to remember:
- Choose the column(s) for indexing very carefully.
- Indexed fields should be used for searching and query should be re-framed if any calculation is performed on indexed fields.
- Index itself takes storage space.
- Each operation on database requires updating index as well.
- A smaller Key Length reported by EXPLAIN command is better. Smaller key length means lesser storage space is required by index file and also that time to search in index is less. For this, indexes can be set on part of columns. For example, INDEX(col1(10),col2(20)). Again, you have to judiciously decide what length of columns to be used for indexing.
Step 2:
Using ANALYZE command
ANALYZE command is used to generate key distribution for the table to be used by MySQL query optimizer to decide which indexes are best to use in a query.
ANALYZE TABLE table_name;
Step 3:
Using OPTIMIZE command
If there are too many inserts/deletes in a table then OPTIMIZE command must be frequently used to optimize disk head movement during retrieval. This is particularly useful if variable size columns are used like varchar, text, blob etc. OPTIMIZE command does defragmentation of the fragmentation caused by variable length fields like VARCHAR.
OPTIMIZE TABLE table_name;
Step 4:
Using special functions for loading data
For loading data from a file into a database table, using LOAD DATA INFILE is much faster than reading data from file iteratively and using INSERT command. The syntax for this command is:
LOAD DATA INFILE ‘impdata.dat’ INTO TABLE table_name (col1,col2,…,colM) FIELDS TERMINATED BY ‘|’”);
Step 5:
Setting PRIORITY of commands
If there are more queries than data insertions, you may lower priority of INSERT command using:
INSERT LOW_PRIORITY or SELECT HIGH_PRIORITY
If client is not interested in results of INSERT, then it can be immediately freed using following command:
INSERT DELAYED.
This makes the system faster by batching insertions.
Step 6:
DELETE vs. TRUNCATE
DELETE command use to deletes row by row, while TRUNCATE use to deletes all rows at once. So, if you are not interested in number of rows deleted from a table as result of DELETE command, then use TRUNCATE with following syntax:
TRUNCATE TABLE table_name;
Step 7:
Lowering permission checking overhead
Simpler permissions reduce permission checking overhead. Use GRANT command to set the permissions. General syntax for GRANT is:
GRANT priv_type [(column_list)]
[, priv_type [(column_list)]] …
ON [object_type]
{
*
| *.*
| db_name.*
| db_name.tbl_name
| tbl_name
| db_name.routine_name
}
TO user [IDENTIFIED BY [PASSWORD] ‘password’]
For example:
GRANT SELECT,UPDATE ON emp_sal TO hr@localhost IDENTIFIED BY ’password’;
If user account ‘hr’ is not there, then it will be created on localhost (although user can access data from any workstation) and password ‘password’ will be assigned to it.
Step 8:
Use BENCHMARK() function
To know how much a given MySQL function or expression is taking time, use MySQL built-in function:
BENCHMARK(loop_count, expression)
It always returns 0 but also prints time taken by the expression.
Step 9:
Synchrozing data types
If columns in tables contain identical information, then make their data types also same so that joins can be performed faster.
Step 10:
Database optimization is not one time job. You have to optimize it every after 2-3 months.
Tags: dataabase, mysql, mysql database optimization, optimization, query optimize
Posted in Dedicated Server Hosting, linux, Linux VPS Hosting, Plesk For Linux, VPS hosting, Windows VPS | No Comments »







