Tuesday, August 04, 2009

Apache RewriteMap with RewriteLock

Recently I was working with a image gallery site. The site was developed with PHP on Apache which stores images and renders it out.

The photos where stored in a similar path stated below.
/images/photo_id/photos_style/photo_id.jpg

Example:
/images/200/portrait/200.jpg

The requirement was not to show the original path in URL and it should resemble like the below
/<photo_id>/<photo_id>_<_style>.jpg

Example:
/200/200_portrait.jpg

The logic had more complexity than explained here which required a math calculation to get the complete path. To achieve the calculation a perl rewrite rule was introduced.

RewriteMap prg MapType:/path/to/rewrite_rule.pl

The perl script was something similar to below with more logic
#!/usr/bin/perl
$| = 1;
while () {
# ...put here any transformations or lookups...
print $_;
}
The script started working well by redirecting to original directory (internally) with output like
/images/200/portrait/200.jpg

But when the server got loaded heavily with more requests. The output scrambled like
/mages/200/portit/200.jpg
/ramages/200/portrait/200.jpg

etc...

Which was due to the perl script not in sync with Apache. The problem was solved when a RewriteLock was introduced. But still a surprise how this solved it immediately... ;-)

RewriteLock "/path/to/empty/lock/file"
in the global section of httpd.conf

Wednesday, July 29, 2009

Linux: Setting UP DNS Cache server

1. The DNS servers in a network may be with huge traffic or it might have more downtime resulting in failure of resolving domain names.

2. May be a dialup machine has very slow internet connection where resolving a DNS query might take more time.

The solution for both the problems is to have a caching DNS server. Installing a dnsmasq and running it as a service on local host will resolve the issue.

Steps to Setup DNS Cache Server
(Following lines works good in Fedora / Redhat / CentOS)

Install dnsmasq
$ yum install dnsmasq

Make dnsmasq start on boot
$ chkconfig dnsmasq on

Start dnsmasq immediately
$ service dnsmasq start

Change the network setting to work through this cache server


Open the network settings

Add the Primary DNS as localhost by adding 127.0.0.1
Move the primary and secondary to secondary and tertiary.
Click File->Save

Restart the network
$ service network restart

Test the network DNS resolving speed after the first time access to the site. It will be much faster as it comes from local.

Saturday, July 25, 2009

Install & Configure SVN Server

There are many tutorials available to work with SVN and the best of all is the
svnbook.read-bean.com, This article is about making a quick SVN server with very few steps without much issues.

Server Environment: Redhat / CentOS / Fedora

Install SVN
# yum install subversion

Create SVN Directory


# mkdir -p /srv/svn

Start SVN Server
# svnserve -d /srv/svn

Create SVN Repository
# svnadmin create /srv/svn/myproject

Create Users in /srv/svn/myproject/conf/passwd (Add the following lines)

admin = adM!nPassw0rd
developer = password


Grant User Permissions in /srv/svn/myproject/conf/auth (Add the following lines)

[/]
admin = rw
developer =
rw

Test the setup
Checkout from different macine or in same machine with different directory

192.168.1.1 is assumed IP of the SVN server

# svn co http://192.168.1.1/myproject/ myproject

Test SVN Commit

# cd myproject
# echo "Hello World" > test.txt
# svn add test.txt
# svn commit -m "Test Commit"


You can checkout the same project from any machine but now you will find the test.txt.

More details on how to backup and restore svn and structuring to use are explained step by step in TechysPage(SVN-Revision-Control)
It would be good to go through the article in TechysPage.

The recent POST on User friendly SVN will help you to configure SVN with Admin panel

My First Blog for Killer Configurations

After years of this dream to share what I want to...................
After months of this dream to write a blog on what I want to...................

Finally it happened.

To be short to the point this is my first blog post. This blog is going to be more on Configuration Management.

The blog is named as Killer Configurations as configuring any server / application kills our time, we seek for answer days and night killing our self while the answer is always a simple configuration change.

This blog is for saving people by providing the tips / solution on configuration and to reduce the time of problem solving.

To be more in detail it will be on
  • Server Setup
  • Application configuration
  • Installing Tools
  • Optimizing the servers
  • Tricky problem solving in server configurations
  • Task Automations
  • Ease up server / service administration
  • etc........
The topic is not just this will continue more......................
Hope this blog solves the need of the reader ;-)

Wait for upcoming posts.