July 22nd, 2008

MySQL is a relational database management system (RDBMS) based on SQL (Structured Query Language). First released in January, 1998, MySQL is now one component of parent company MySQL AB’s product line of database servers and development tools. Yes, it really is this easy.run the following command to change the mysql root password

sudo /etc/init.d/mysql reset-password
New MySQL root password:
Verify:
Setting new MySQL root password

July 22nd, 2008

Sometimes you want to restart your Apache server after changing some configuration in your virutual hosts,sites etc, but you have few hundred clients currently downloading files from your server and you don’t want to disconnect them.You need to use the following command

sudo /etc/init.d/apache2 graceful

This will gracefully restart your Apache with new configuration without affecting your client’s connections.

ref :  http://www.ubuntugeek.com/restart-apache-server-without-affecting-existing-connections.html

July 22nd, 2008

1. Telnet using TCP port 25 :
#telnet xxx.xxx.xxx.xxx 25
or
#telnet domain.tld 25

2. Issue the following smtp command sequence

helo <your domain name><enter>
response should be as follows
250 OK

mail from: <your Email Address><enter>
response should be as follows
250 OK - mail from <your Email address>

rcpt to: <recipient address><enter>
response should be as follows
250 OK - Recipient <recipient address>

data<enter>
response should be as follows
354 Send data. End with CRLF.CRLF

To: <recipient’s display name><enter>
From: <your display name><enter>
Subject: <Subject field of Email message><enter>
<Enter you body text><enter><enter> . <enter>
response should be as follows
250 OK

quit<enter>

July 22nd, 2008

fsck is a Unix utility for checking and repairing file system inconsistencies . File system can become inconsistent due to several reasons and the most common is abnormal shutdown due to hardware failure , power failure or switching off the system without proper shutdown . Due to these reasons the superblock in a file system is not updated and has mismatched information relating to system data blocks, free blocks and inodes .

Modes of operation :

fsck operates in two modes interactive and non interactive :

interactive : the fsck examines the file system and stops at each error it finds in the file system and gives the problem description and ask for user response usually whether to correct the problem or continue without making any change to the file system.

noninteractive :fsck tries to repair all the problems it finds in a file system without stopping for user response useful in case of a large number of inconsistencies in a file system but has the disadvantage of removing some useful files which are detected to be corrupt .

If file system is found to have problem at the booting time non interactive fsck fsck is run and all errors which are considered safe to correct are corrected. But if still file system has problems the system boots in single user mode asking for user to manually run the fsck to correct the problems in file system

Running fsck :

fsck should always be run in a single user mode which ensures proper repair of file system . If it is run in a busy system where the file system is changing constantly fsck may see the changes as inconsistencies and may corrupt the file system .

if the system can not be brought in a single user mode fsck should be run on the partitions ,other than root & usr , after unmounting them . Root & usr partitions can not be unmounted . If the system fails to come up due to root/usr files system corruption the system can booted with CD and root/usr partitions can be repaired using fsck.

command syntax:

fsck [ -F fstype] [-V] [-yY] [-o options] special

-F fstype type of file system to be repaired ( ufs , vxfs etc)

-V verify the command line syntax but do not run the command

-y or -Y Run the command in non interactive mode - repair all errors encountered without waiting for user response.

-o options Three options can be specified with -o flag

b=n where n is the number of next super block if primary super block is corrupted in a file system .

p option used to make safe repair options during the booting process.

f force the file system check regardless of its clean flag.

special - Block or character device name of the file system to be checked/repaired - for example /dev/rdsk/c0t3d0s4 .Character device should be used for consistencies check & repair

phases:

fsck checks the file system in a series of 5 pages and checks a specific functionality of file system in each phase.

** phase 1 - Check Blocks and Sizes

** phase 2 - Check Pathnames

** phase 3 - Check Connectivity

** phase 4 - Check Reference Counts

** phase 5 - Check Cylinder Groups

2fsck

e2fsck [options] device fsck.ext2 [options] device

System administration command. Checks and repairs a disk, as does fsck, but specifically designed for ext2 (Linux Second Extended) and ext3 (Third Extended, a journaling version of ext2) filesystems. fsck actually uses this command when checking ext2 and ext3 filesystems. Most often used after a sudden shutdown, such as from a power outage, or when damage to the disk is suspected.
Options

-b superblock
Use superblock instead of the default superblock.

-c
Find bad blocks using the badblocks command. Specify this option twice to perform the scan with a nondestructive read-write test.

-d
Debugging mode.

-f
Force checking, even if kernel has already marked the filesystem as valid. e2fsck will normally exit without checking if the system appears to be clean.

-j file
Use the specified external journal file.

-k

Preserve all previously marked bad blocks when using the -c option.

-l file
Consult file for a list of bad blocks, in addition to checking for others.

-n
Ensure that no changes are made to the filesystem. When queried, answer “no.”

-p
“Preen.” Repair all bad blocks noninteractively.

-s
Byte-swap the filesystem if necessary to standard (little-endian) byte-order.

-t
Display timing statistics.

-v
Verbose.

-y
When queried, answer “yes.”

-B size
Expect to find the superblock at size; if it’s not there, exit.

-C filedescriptor
Write completion information to the specified filedescriptor. If 0, print a completion bar.

-D
Optimize directories by reindexing, sorting, and compressing them where possible.

-F

Flush buffer caches before checking.

-L file
Consult file for list of bad blocks instead of checking filesystem for them.

-S
Byte-swap the filesystem.

July 1st, 2008

Default package can’t support mysql 5.1.
There are some solutions to solve this problem. For example, You can install the non-RPM packages which can be downloaded from official web(www.mysql.org). But, my choice is to add some other package sources into source.list.

Edit file :
#vi /etc/apt/sources.list

add new line :
deb http://ppa.launchpad.net/monty/ubuntu gutsy main universe restricted multiverse
deb http://ppa.launchpad.net/smurf/ubuntu gutsy main universe restricted multiverse
save and exit

Update & Upgrade
#apt-get update
#apt-get upgrade

Install MySQL 5.1
#apt-get install mysql-server-5.1

June 29th, 2008

Displaying the MySQL version number

select version();

+———–+
| version() |
+———–+
| 3.22.32   |
+———–+
1 row in set (0.00 sec)

Displaying the current date and time

select now();

+———————+
| now()               |
+———————+
| 2001-05-31 00:36:24 |
+———————+
1 row in set (0.00 sec)

Displaying the current Day, Month and Year

SELECT DAYOFMONTH(CURRENT_DATE);
+————————–+
| DAYOFMONTH(CURRENT_DATE) |
+————————–+
|                       28 |
+————————–+
1 row in set (0.01 sec)

SELECT MONTH(CURRENT_DATE);
+———————+
| MONTH(CURRENT_DATE) |
+———————+
|                   1 |
+———————+
1 row in set (0.00 sec)

SELECT YEAR(CURRENT_DATE);
+——————–+
| YEAR(CURRENT_DATE) |
+——————–+
|               2001 |
+——————–+
1 row in set (0.00 sec)

Displaying text strings

select ‘I Love MySQL’;

+————–+
| I Love MySQL |
+————–+
| I Love MySQL |
+————–+
1 row in set (0.00 sec)

ref : http://www.webdevelopersnotes.com/tutorials/sql/a_little_more_on_the_mysql_select_statement.php3

June 29th, 2008

Dowload Source File :
#cd /tmp
#wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.25-rc.tar.gz/from/http://mysql.llarian.net/

Extract Source File :
#tar zxvf /tmp/mysql-5.1.25-rc.tar.gz
#cd /tmp/mysql-5.1.25-rc

Install Pacakge & Development Libralie :
#apt-get install build-essential libncurses5 libncurses5-dev

Add User & Group :
#groupadd mysql
#useradd -g mysql mysql

Configuration :

#./configure \
–prefix=/usr/local/mysql \
–with-mysqld-user=mysql \
–without-debug \
–with-client-ldflags=-all-static \
–with-mysqld-ldflags=-all-static \
–disable-shared \
–localstatedir=/usr/local/mysql/data \
–with-extra-charsets=none \
–enable-assembler \
–with-unix-socket-path=/tmp/mysql.socket

#make
#make install

 Copy my.cnf
#cd /tmp/mysql-5.1.25-rc
#cp support-files/my-medium.cnf /etc/my.cnf


Create GRANT tables
:
#/usr/local/mysql/bin/mysql_install_db –user=mysql

Changing Owners :
#chown -R root  /usr/local/mysql
#chown -R mysql /usr/local/mysql/var
#chgrp -R mysql /usr/local/mysql

Testing:
#/usr/local/mysql/bin/mysqld_safe -user=mysql&

Set a root password for MySQL (does not affect system root’s password) :

#/usr/local/mysql/bin/mysqladmin -u root password new_password

Try to log in!:

#/usr/local/mysql/bin/mysql

You should add /usr/local/mysql/bin to your path so you can always use mysql, mysqldump, mysqladmin and some others right from the shell.

Starting Mysql at boot time :

#cp support-files/mysql.server /etc/init.d/mysql
#chmod +x /etc/init.d/mysql
#update-rc.d mysql defaults

ref : https://help.ubuntu.com/community/MYSQL5FromSource

June 11th, 2008

One of the main requirements for a fast web server is to has efficient and effective SQL statements or queries that are optimized. Any non-optimal SQL (Structured Query Language) commands or statements that take too long or lengthy time to execute will use up a lot of system resources, causing MySQL database to run slower, and then more and more queries backlogs queuing up, and when connection limit is reached, visitors are been denied or refused connection. In worst case scenario, your web server will go down as well, or continuously underperform. The case is especially true when you are using MyISAM table type which uses table-level locking instead of row-level locking in a high traffic website.

Sometime, a single SQL query may be the cause of all the server’s problems. MySQL has built-in functionality to capture slow query log or identify queries that are not optimal and take a long time to finish, which allows you to log all slow running queries which took over defined number of seconds to execute by MySQL database engine to a file. Slow query log is not activated or on by default MySQL installation, thus it is one of the less-used logs.

To enable slow query log, simply add the following line to MySQL configuration file (my.cnf or my.ini), and then restart the MySQL server:

log-slow-queries

or

log-slow-queries = [path to the log file]

Replace [path to the log file] with actual path to the slow query log file you want the MySQL to write the log to, which is the optional value.

Or you can start mysqld with with the –log-slow-queries[=file_name] option to enable the slow query log. In both syntaxes, if not log file name is specified, the default name is host_name-slow.log, stored in the MySQL data file directory. If a filename is given, but not as an absolute pathname, the server writes the file in the data directory too.

After enabling slow query log, MySQL will create, capture and log to the log file with all SQL statements that took more than long_query_time seconds to execute, which is by default set to 10 seconds. The time to acquire the initial table locks is not counted as execution time. mysqld writes a statement to the slow query log after it has been executed and after all locks have been released, so log order might be different from execution order.

You can then examine all the SQL queries that took longer than the pre-defined number of seconds (10 seconds by default) in the host_name-slow.log, and then take the necessary steps to optimize the SQL statements. The slow query log will tell you about what was time the query completed, how long the query took to run, how long it took to secure its locks, how many rows were sent back as a result, how many rows were examined to determine the result, which database was used, and the actual query itself. But bear in mind that a SQL query contained in the log may have already optimum, but executed slowly due to the system resources been used up by the actual slow statement that need to be fine tuned.

ref : http://www.mydigitallife.info/2007/01/22/enable-logging-of-slow-queries-slow-query-log-in-mysql-database/

May 16th, 2008

Recently we’ve been converting an ISP’s servers from Debian Linux to Ubuntu Server. Ubuntu is heavily based on Debian so most things are the same. The most limiting factor so far has been that Ubuntu’s Main software package repository contains far fewer packages than Debian.

One Apache module we like to use on production servers is mod_evasive, a simple denial of service detection tool that helps prevent miscreants from hammering a server to death with requests. It won’t stop a determined attacker who has a few hundred bots under his control from flooding you offline, but mod_evasive is useful additional layer of defense for a production web server.

If you enable Ubuntu’s “universe” repository you can access almost the same number of packages as provided by Debian. However, those packages are not supported, meaning timely security fixes may not be released and they may break the ability to perform a seamless upgrade to subsequent releases of Ubuntu. A package for mod_evasive is available in Universe, but it’s only for Apache 1.3.x. The supported version of Apache in Ubuntu 6.06 is 2.0.55 (there goes our dream of being able to avoid compiling things from source).

All the support libraries and utilities needed to compile Apache modules from source are available in Main, so it’s possible to download mod_evasive and install it yourself for Apache 2. Here’s how:

To compile any Apache module in Ubuntu, install the development package that corresponds to the Apache Multi-processing Module (MPM) you are using. Apache 2 gives you a choice of MPMs but if the server is running PHP5, Apache will be using the default “Prefork MPM”. For that MPM, install package apache2-prefork-dev:

apt-get install apache2-prefork-dev

Download the mod_evasive source tarball and unpack into a temporary directory. To allow sending of email alerts when activity is blocked, edit the file mod_evasive20.c to change the #define MAILER to “/usr/bin/mail %s”.

Compile and install the module with the following command:

/usr/bin/apxs2 -i -c mod_evasive20.c

Normally the module would be enabled by added a LoadModule directive to file httpd.conf. However on Ubuntu the directive is specified in a file located in /etc/apache2/mods-available. Create a file named “evasive.load” in that directory containing the following:

LoadModule evasive20_module /usr/lib/apache2/modules/mod_evasive20.so

Directives controlling the behavior of mod_evasive should be specified in a file created in directory /etc/apache2/conf.d. Create a file named “evasive” in that directory and add the mod_evasive directives you want for your server. For example:

<ifmodule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSEmailNotify you@example.com
</ifmodule>

Finally, enable the module and restart Apache:

en2mod evasive

/etc/init.d/apache2 force-reload

Some Linux distributions make it very difficult to add your own customizations such as Apache modules. Ubuntu (and of course Debian) make it fairly straightforward.

ref : http://advosys.ca/viewpoints/2006/08/installing-mod_evasive-in-ubuntu/

May 14th, 2008

#apt-get install curl libcurl3 libcurl3-dev php5-curl

ref : http://codehunter.net/category/ubuntu/