<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4337142345946287269</id><updated>2011-11-27T17:28:56.906-06:00</updated><category term='Squid'/><category term='Tcpdump'/><category term='Yum'/><category term='Apache Tomcat'/><category term='GNU/Linux'/><category term='Scripts'/><category term='Load Balancing'/><category term='Bash'/><category term='Mantis'/><category term='Scaling'/><category term='RPM'/><category term='Apache HTTPD'/><category term='LDAP'/><category term='Utilities'/><title type='text'>Intrigue</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ksutaria.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ksutaria.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Kalpesh</name><uri>http://www.blogger.com/profile/11789170660994069564</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4337142345946287269.post-6056357742825530708</id><published>2009-04-20T11:26:00.024-05:00</published><updated>2009-04-20T16:06:23.439-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Apache HTTPD'/><category scheme='http://www.blogger.com/atom/ns#' term='Scaling'/><category scheme='http://www.blogger.com/atom/ns#' term='Apache Tomcat'/><category scheme='http://www.blogger.com/atom/ns#' term='GNU/Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Load Balancing'/><category scheme='http://www.blogger.com/atom/ns#' term='Squid'/><title type='text'>Load Balancing and Scaling with Squid-HTTPD-Tomcat</title><content type='html'>One of our clients host a content management system built on top of technology I use at work. The technology is a custom server that stacks on top of the J2EE application servers like &lt;a href='http://www.jboss.org'&gt;JBoss&lt;/a&gt; or a servlet container like &lt;a href='http://tomcat.apache.org'&gt;Apache Tomcat&lt;/a&gt;. Our standard stack that we prescribe to clients is the MySQL-Apache Tomcat stack. &lt;br /&gt;&lt;br /&gt;Over a period of few weeks, the needs of this client grew well beyond the standard stack. Considering the amount of static content being served by the Content Management System, a caching server such as &lt;a href='http://www.squid-cache.org'&gt;Squid&lt;/a&gt; was a logical choice. Soon it was apparent, that this wouldn't scale either. Hence as the next iteration, we prescribed a solution with three Apache Tomcat instances running on 32-bit JVM instances of 1.5GB memory each, being load balanced by Apache HTTPD using &lt;a href='http://tomcat.apache.org/connectors-doc'&gt;mod-jk connnector&lt;/a&gt;, and front-ended with a Squid caching server. Since the public side had only read requests, a single &lt;a href='http://www.mysql.org'&gt;MySQL server&lt;/a&gt; as the back-end was sufficient. &lt;br /&gt;&lt;br /&gt;Being a unique stack in itself, not to mention the abundant complexities involved in between versions and dependencies, I thought it would be great to document the setup for future reference. As of now the stack is working well for the client, with the added ability to bring down one or even two Apache Tomcat instances for maintenance and leaving the site unaffected. The architecture is depicted in Figure 1 below:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_0qBYX65R2_A/SezcOUWvSAI/AAAAAAAAAAU/sUTr4QFwa-0/s1600-h/Squid-HTTPD-Tomcat-1.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 220px;" src="http://3.bp.blogspot.com/_0qBYX65R2_A/SezcOUWvSAI/AAAAAAAAAAU/sUTr4QFwa-0/s400/Squid-HTTPD-Tomcat-1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5326874597812815874" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The versions for softwares used are:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;[root@1233797-app45 ~]# /usr/share/tomcat/bin/version.sh &lt;br /&gt;Using CATALINA_BASE:   /usr/share/tomcat&lt;br /&gt;Using CATALINA_HOME:   /usr/share/tomcat&lt;br /&gt;Using CATALINA_TMPDIR: /usr/share/tomcat/temp&lt;br /&gt;Using JRE_HOME:       /usr/java/jdk1.5.0_17&lt;br /&gt;Server version: Apache Tomcat/5.5.17&lt;br /&gt;Server built:   Apr 14 2006 02:08:29&lt;br /&gt;Server number:  5.5.17.0&lt;br /&gt;OS Name:        Linux&lt;br /&gt;OS Version:     2.6.9-67.0.22.ELsmp&lt;br /&gt;Architecture:   i386&lt;br /&gt;JVM Version:    1.5.0_17-b04&lt;br /&gt;JVM Vendor:     Sun Microsystems Inc.&lt;br /&gt;[root@183787-app9 ~]# rpm -q httpd squid mysql-server&lt;br /&gt;httpd-2.0.52-41.ent.4&lt;br /&gt;squid-2.5.STABLE14-4.el4&lt;br /&gt;mysql-server-5.0.77-1.rs.el4&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Following are the steps to setup the servers with reference to Figure 1. Customize it for your local setup.&lt;br /&gt;&lt;br /&gt;Edit the /etc/httpd/conf/httpd.conf. Change the IP and port that HTTPD listens on:&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;Listen 192.168.1.139:8084&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Download the mod_jk connector from &lt;a href=http://tomcat.apache.org/download-connectors.cgi&gt;Apache Tomcat Connectors Download&lt;/a&gt;. Since I ran into issues finding pre-packaged RPM for RHEL, I used one of the binaries available from their binaries link on that page. Save the "mod_jk-*.so" file along-with other modules for HTTPD. Append the following lines to the /etc/httpd/conf/httpd.conf&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;LoadModule jk_module modules/mod_jk.so&lt;br /&gt;&lt;br /&gt;&lt;Location /jkmanager/&gt;&lt;br /&gt;  JkMount jkstatus&lt;br /&gt;  order deny,allow&lt;br /&gt;  allow from 127.0.0.1&lt;br /&gt;  deny from all&lt;br /&gt;&lt;/Location&gt;&lt;br /&gt;&lt;br /&gt;&lt;IfModule mod_jk.c&gt;&lt;br /&gt;  JkWorkersFile conf/workers.properties&lt;br /&gt;  JkShmFile /var/cache/httpd/mod_jk.shm&lt;br /&gt;  JkLogFile /var/log/httpd/mod_jk.log&lt;br /&gt;  JkLogLevel info&lt;br /&gt;  JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "&lt;br /&gt;  JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories&lt;br /&gt;  JkRequestLogFormat "%w %V %T"&lt;br /&gt;&lt;br /&gt;  SetEnvIf Request_URI "/webmail/*" no-jk&lt;br /&gt;  SetEnvIf Request_URi "/mailman/*" no-jk&lt;br /&gt;  SetEnvIf Request_URI "/awstatsclasses/*" no-jk&lt;br /&gt;  SetEnvIf Request_URI "/awstatscss/*" no-jk&lt;br /&gt;  SetEnvIf Request_URI "/awstatsicons/*" no-jk&lt;br /&gt;  SetEnvIf Request_URI "/awstats/*" no-jk&lt;br /&gt;&lt;br /&gt;  JkMount  /* router&lt;br /&gt;  JkMount  /jkmanager/* jkstatus&lt;br /&gt;&lt;/IfModule&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a /etc/httpd/conf/workers.properties file as shown under:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;# Define some properties&lt;br /&gt;workers.apache_log=/var/apache/logs&lt;br /&gt;workers.tomcat_home=/usr/share/tomcat&lt;br /&gt;workers.java_home=/usr/java/jrockit-R27.4.0-jdk1.5.0_12&lt;br /&gt;ps=/&lt;br /&gt;&lt;br /&gt;# The advanced router LB worker&lt;br /&gt;worker.list=router,tomcat1,tomcat2,tomcat3,jkstatus&lt;br /&gt;&lt;br /&gt;# Set properties for tomcat1 (ajp13)&lt;br /&gt;worker.tomcat1.type=ajp13&lt;br /&gt;worker.tomcat1.host=192.168.1.140&lt;br /&gt;worker.tomcat1.port=8010&lt;br /&gt;worker.tomcat1.lbfactor=1&lt;br /&gt;&lt;br /&gt;# Set properties for tomcat2 (ajp13)&lt;br /&gt;worker.tomcat2.type=ajp13&lt;br /&gt;worker.tomcat2.host=192.168.1.140&lt;br /&gt;worker.tomcat2.port=8011&lt;br /&gt;worker.tomcat2.lbfactor=1&lt;br /&gt;&lt;br /&gt;# Set properties for tomcat3 (ajp13)&lt;br /&gt;worker.tomcat3.type=ajp13&lt;br /&gt;worker.tomcat3.host=192.168.1.140&lt;br /&gt;worker.tomcat3.port=8012&lt;br /&gt;worker.tomcat3.lbfactor=1&lt;br /&gt;&lt;br /&gt;# Define the LB worker&lt;br /&gt;worker.router.type=lb&lt;br /&gt;worker.router.balance_workers=tomcat1,tomcat2,tomcat3&lt;br /&gt;&lt;br /&gt;worker.jkstatus.type=status&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;On each of the workers (tomcat1,tomcat2,tomcat3) make the following changes to the /usr/share/tomcatXX/conf/server.xml file where XX indicates the number of tomcat:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Change the connector configuration so that the port numbers are 8081, 8082, 8083 for tomcat1, tomcat2 and tomcat3 respectively. This helps validate individual tomcat instances.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;    &lt;Connector port="8081" maxhttpheadersize="8192" maxthreads="150" minsparethreads="25" maxsparethreads="75" enablelookups="false" redirectport="8443" acceptcount="2000" connectiontimeout="60000" disableuploadtimeout="true" /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;The mod_jk connector talks to the worker instances on the AJP connector port. This port can be specified in the server.xml file as shown below. We picked ports 8010-8012 for tomcat1-tomcat3&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;    &lt;!-- Define an AJP 1.3 Connector on port 8010 --&gt;&lt;br /&gt;    &lt;Connector port="8010" enablelookups="false" redirectport="8081" protocol="AJP/1.3" /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Uncomment the lines that set the jvmRoute or append if necessary. Note that the value for the jvmRoute should be the same as that used in the workers.properties file for the respective tomcat instance.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;  &lt;!-- You should set jvmRoute to support load-balancing via AJP ie : --&gt;&lt;br /&gt;  &lt;Engine name="Standalone" defaulthost="localhost" jvmroute="tomcatXX" /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;To change the root context ensure that the “Context” directive is updated as under:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;  &lt;Host name="localhost" appbase="webapps" unpackwars="true" autodeploy="false" xmlvalidation="false" xmlnamespaceaware="false"&gt;&lt;br /&gt;     &lt;Context path="" docbase="./myFavApp"&gt;&lt;br /&gt;      &lt;Valve classname="org.apache.catalina.valves.FastCommonAccessLogValve" directory="weblogs/myFavApp" prefix="myFavApp_" suffix=".log" pattern="combined" resolvehosts="false" /&gt;&lt;br /&gt;     &lt;/Context&gt;&lt;br /&gt;  &lt;/Host&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;Restart the Apache HTTPD Server and the individual Apache Tomcat Servers and validate the Load-Balancing configuration works as expected. Use the following log files to isolate the problem if any:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;tail -f /var/log/httpd/access.log&lt;br /&gt;tail -f /var/log/httpd/mod_jk.log&lt;br /&gt;tail -f /usr/share/tomcatXX/logs/catalina.out&lt;br /&gt;tail -f /var/log/httpd/error_log&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Assuming the load balancing setup is working as expected, lets move on to the Squid as a Reverse Proxy. There have been changes between versions 2.5 and 2.6 that affect the configuration file options for the setup. Following are the instructions for version 2.5. Set the IP-Port on which Squid listens. Next, configure the cache-peer of Squid to be Apache HTTPD at port 8084.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;http_port 192.168.1.139:80&lt;br /&gt;cache_peer 192.168.1.139 parent 8084 0 no-query&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Since, we wanted to cache the pages with parameters as well, we commented the no_cache option. The hierarchy stoplist option was also commented out as shown.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;#hierarchy_stoplist cgi-bin ?&lt;br /&gt;#acl QUERY urlpath_regex cgi-bin \?&lt;br /&gt;#no_cache deny QUERY&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Depending on your cache size requirements, tweak the following parameters:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;cache_mem 512 MB&lt;br /&gt;maximum_object_size 8192 KB&lt;br /&gt;maximum_object_size_in_memory 256 KB&lt;br /&gt;cache_dir ufs /var/spool/squid 1024 16 256&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Define access control lists for the destination and trusted networks. This is followed by http_access rules that allow or deny as per security requirements. Note how the rule 'filter_admin_portal' uses a regular expression match to filter access for the admin portal.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;acl our_networks src 192.168.1.0/24 10.20.30.0/24&lt;br /&gt;acl dst_mywebapp dst 192.168.1.0/255.255.255.0&lt;br /&gt;acl filter_admin_portal urlpath_regex -i ^/[^/]*admin[^/]*&lt;br /&gt;&lt;br /&gt;http_access deny filter_admin_portal&lt;br /&gt;http_access allow dst_mywebapp&lt;br /&gt;http_access allow our_networks&lt;br /&gt;http_access deny all&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Squid needs to know the 'Real' HTTP server for which it acts as an accelerator. The parameters httpd_accel_host and httpd_accel_port should point to the Apache HTTPD server setup earlier.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;httpd_accel_host 192.168.1.139&lt;br /&gt;httpd_accel_port 8084&lt;br /&gt;&lt;br /&gt;httpd_accel_single_host on&lt;br /&gt;httpd_accel_with_proxy on&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Once Squid has been restarted, the entire setup should be ready for some testing. Use the log files described above and the following log files to iron out discrepancies, if any.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;tail -f /var/log/squid/squid.out&lt;br /&gt;tail -f /var/log/squid/access.log&lt;br /&gt;tail -f /var/log/squid/cache.log&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Along the way, we used JMeter for load/stress testing, JConsole for viewing the JVM health in real time, and WireShark/Fiddler to look at HTTP headers and packets. These tools helped find find bottlenecks, tweak parameters and re-architect the solution.&lt;br /&gt;&lt;br /&gt;Although, there are multiple points of failure in this architecture, the primary aim was load balancing. Fault tolerance and reliability weren't the primary concerns at this point of time. In a future iteration, the plan is to address these concerns as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4337142345946287269-6056357742825530708?l=ksutaria.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ksutaria.blogspot.com/feeds/6056357742825530708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4337142345946287269&amp;postID=6056357742825530708' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/6056357742825530708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/6056357742825530708'/><link rel='alternate' type='text/html' href='http://ksutaria.blogspot.com/2009/04/load-balancing-and-scaling-with-squid.html' title='Load Balancing and Scaling with Squid-HTTPD-Tomcat'/><author><name>Kalpesh</name><uri>http://www.blogger.com/profile/11789170660994069564</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_0qBYX65R2_A/SezcOUWvSAI/AAAAAAAAAAU/sUTr4QFwa-0/s72-c/Squid-HTTPD-Tomcat-1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4337142345946287269.post-4287633300974499433</id><published>2009-04-07T15:03:00.004-05:00</published><updated>2009-04-20T16:06:56.496-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RPM'/><category scheme='http://www.blogger.com/atom/ns#' term='Yum'/><category scheme='http://www.blogger.com/atom/ns#' term='GNU/Linux'/><title type='text'>Corrupt RPM Database</title><content type='html'>The other day I was on a client machine which happened to give me the following exception when looking up an RPM package using yum. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;[root@staging ~]# yum search vnc&lt;br /&gt;Loading "rhnplugin" plugin&lt;br /&gt;rpmdb: Lock table is out of available locker entries&lt;br /&gt;rpmdb: Unknown locker ID: 8470&lt;br /&gt;error: db4 error(22) from db-&gt;close: Invalid argument&lt;br /&gt;error: cannot open Packages index using db3 - Cannot allocate memory (12)&lt;br /&gt;error: cannot open Packages database in /var/lib/rpm&lt;br /&gt;Traceback (most recent call last):&lt;br /&gt;  File "/usr/bin/yum", line 29, in ?&lt;br /&gt;    yummain.main(sys.argv[1:])&lt;br /&gt;  File "/usr/share/yum-cli/yummain.py", line 85, in main&lt;br /&gt;    base.getOptionsConfig(args)&lt;br /&gt;  File "/usr/share/yum-cli/cli.py", line 163, in getOptionsConfig&lt;br /&gt;    disabled_plugins=self.optparser._splitArg(opts.disableplugins))&lt;br /&gt;  File "/usr/lib/python2.4/site-packages/yum/__init__.py", line 164, in _getConfig&lt;br /&gt;    self._conf = config.readMainConfig(startupconf)&lt;br /&gt;  File "/usr/lib/python2.4/site-packages/yum/config.py", line 685, in readMainConfig&lt;br /&gt;    yumvars['releasever'] = _getsysver(startupconf.installroot, startupconf.distroverpkg)&lt;br /&gt;  File "/usr/lib/python2.4/site-packages/yum/config.py", line 755, in _getsysver&lt;br /&gt;    idx = ts.dbMatch('provides', distroverpkg)&lt;br /&gt;TypeError: rpmdb open failed&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Apparently, this is the case of a corrupt RPM database and can be fixed by rebuilding the database as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;[root@staging ~]# rm /var/lib/rpm/__db.*&lt;br /&gt;rm: remove regular empty file `/var/lib/rpm/__db.000'? y&lt;br /&gt;rm: remove regular file `/var/lib/rpm/__db.001'? y&lt;br /&gt;rm: remove regular file `/var/lib/rpm/__db.002'? y&lt;br /&gt;rm: remove regular file `/var/lib/rpm/__db.003'? y&lt;br /&gt;[root@staging ~]# rpm --rebuilddb&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4337142345946287269-4287633300974499433?l=ksutaria.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ksutaria.blogspot.com/feeds/4287633300974499433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4337142345946287269&amp;postID=4287633300974499433' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/4287633300974499433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/4287633300974499433'/><link rel='alternate' type='text/html' href='http://ksutaria.blogspot.com/2009/04/corrupt-rpm-database.html' title='Corrupt RPM Database'/><author><name>Kalpesh</name><uri>http://www.blogger.com/profile/11789170660994069564</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4337142345946287269.post-8227928301727592513</id><published>2009-02-02T17:41:00.016-06:00</published><updated>2009-04-20T16:07:32.268-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Utilities'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripts'/><category scheme='http://www.blogger.com/atom/ns#' term='GNU/Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Bash'/><title type='text'>Check Available Disk Space and Notify</title><content type='html'>Here's some handy bash script to notfiy support when we are running low on disk space.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;#&lt;br /&gt;# Description:Checks the available space for the disk mounted as / (root)&lt;br /&gt;#             If disk space is less than 10GB it will send out a notification&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;# Send emails to these people&lt;br /&gt;EMAILID=support@mydomain.com&lt;br /&gt;&lt;br /&gt;# Min Free Space&lt;br /&gt;MINSPACE=10485760&lt;br /&gt;&lt;br /&gt;# Get the space available&lt;br /&gt;FREESPACE=`df / | awk '{ if( NR == 2) print $4 }'`&lt;br /&gt;&lt;br /&gt;# Send email if required&lt;br /&gt;if [ $FREESPACE -le $MINSPACE ];&lt;br /&gt;then&lt;br /&gt; logger "Warning: Root Drive Running Out Of Disk Space [${FREESPACE}KB]"&lt;br /&gt; mail -s 'My Favourite Production Server Disk Space' ${EMAILID} &lt;&lt; EOF&lt;br /&gt;My Favourite Production server root drive is running out of disk space. Current free space is ${FREESPACE} KB @ $(date)&lt;br /&gt;EOF&lt;br /&gt;fi&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4337142345946287269-8227928301727592513?l=ksutaria.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ksutaria.blogspot.com/feeds/8227928301727592513/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4337142345946287269&amp;postID=8227928301727592513' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/8227928301727592513'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/8227928301727592513'/><link rel='alternate' type='text/html' href='http://ksutaria.blogspot.com/2009/02/check-available-disk-space-and-notify.html' title='Check Available Disk Space and Notify'/><author><name>Kalpesh</name><uri>http://www.blogger.com/profile/11789170660994069564</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4337142345946287269.post-829139487173415052</id><published>2008-05-23T16:49:00.013-05:00</published><updated>2009-04-20T16:08:00.197-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LDAP'/><category scheme='http://www.blogger.com/atom/ns#' term='Mantis'/><category scheme='http://www.blogger.com/atom/ns#' term='GNU/Linux'/><title type='text'>Mantis + LDAP Authentication</title><content type='html'>Mantis is one of the many bug tracking softwares available out there (&lt;a href="http://www.google.com/Top/Computers/Software/Configuration_Management/Bug_Tracking"&gt;http://www.google.com/Top/Computers/Software/Configuration_Management/Bug_Tracking&lt;/a&gt;). For an internal project at work, I needed a bug tracker and Mantis was the logical choice due to prior experience within the development team. The machine at hand was running on CentOS Release 4.4 and required the following rpm packages:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="bash"&gt;&lt;br /&gt;&lt;br /&gt;[root@eclipse html]# rpm -q httpd mysql-server php php-mysql php-ldap&lt;br /&gt;&lt;br /&gt;httpd-2.0.52-28.ent.centos4&lt;br /&gt;&lt;br /&gt;mysql-server-4.1.20-1.RHEL4.1&lt;br /&gt;&lt;br /&gt;php-4.3.9-3.22.9&lt;br /&gt;&lt;br /&gt;php-mysql-4.3.9-3.22.9&lt;br /&gt;&lt;br /&gt;php-ldap-4.3.9-3.22.9&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;There were issues with using the community-server rpms for MySQL 5.0.51 as the php-mysql and php-ldap packages weren't compatible. Since, this was going to be an internal bug tracker, and we weren't expecting to use any of the 5.0 features, it was a fair compromise for the power of Apache-PHP-LDAP-Mantis.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have an existing LDAP server which stores the authentication credentials companywide. Out of the box, Mantis allows for new user sign-up but this would mean that every user in the organization would have to keep track of another set of credentials. Hence, LDAP integration was a must. I expected LDAP authentication to work out of the box but it turned out to be a little more involved. I am a novice when it comes to PHP and it took a little bit of searching and reading manuals to wade my way through the Mantis-PHP maze of code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In order to help people who want to walk down the same path, I aim to simplify their life by providing steps to achieve this feat:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1. Download Mantis and unzip at &lt;span style="font-family:courier new;"&gt;/var/www/html&lt;/span&gt; (or whatever your DocumentRoot is at in &lt;span style="font-family:courier new;"&gt;/etc/httpd/conf/httpd.conf&lt;/span&gt;) and rename the folder to mantis. As of writing this post, the stable version was mantis-1.1.1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. A bunch of global Mantis settings are listed in the &lt;span style="font-family:courier new;"&gt;mantis/config_defaults_inc.php&lt;/span&gt;. I tried to override the ones that were relevant to this integration. Here's the file:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;# --- database variables ---------&lt;br /&gt;&lt;br /&gt;# set these values to match your setup&lt;br /&gt;$g_hostname = "10.0.0.4";&lt;br /&gt;$g_db_username = "mantisuser";&lt;br /&gt;$g_db_password = "password";&lt;br /&gt;$g_database_name = "mantis";&lt;br /&gt;$g_db_type = "mysql";&lt;br /&gt;&lt;br /&gt;# --- email variables -------------&lt;br /&gt;&lt;br /&gt;$g_administrator_email = 'admin@mycompany.com';&lt;br /&gt;$g_webmaster_email = 'webmaster@mycompany.com';&lt;br /&gt;&lt;br /&gt;# the "From: " field in emails&lt;br /&gt;$g_from_email = 'noreply@mycompany.com';&lt;br /&gt;&lt;br /&gt;# the return address for bounced mail&lt;br /&gt;$g_return_path_email = 'admin@mycompany.com';&lt;br /&gt;&lt;br /&gt;# --- file upload settings --------&lt;br /&gt;# This is the master setting to disable *all* file uploading functionality&lt;br /&gt;#&lt;br /&gt;# The default value is ON but you must make sure file uploading is enabled&lt;br /&gt;# in PHP as well. You may need to add "file_uploads = TRUE" to your php.ini.&lt;br /&gt;$g_allow_file_upload = ON;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# LDAP&lt;br /&gt;$g_login_method = LDAP;&lt;br /&gt;$g_ldap_server = 'ldap://10.0.0.4/';&lt;br /&gt;$g_ldap_port = '389';&lt;br /&gt;$g_ldap_root_dn = 'dc=mycompany,dc=com';&lt;br /&gt;$g_ldap_organization = 'objectClass=*'; # e.g. '(organizationname=*Traffic)'&lt;br /&gt;$g_ldap_uid_field = 'uid'; # Use 'sAMAccountName' for Active Directory&lt;br /&gt;$g_ldap_bind_dn = 'uid=root,ou=Users,dc=mycompany,dc=com';&lt;br /&gt;$g_ldap_bind_passwd = 'cleartextsecret';&lt;br /&gt;# Should we send to the LDAP email address or what MySql tells us&lt;br /&gt;$g_use_ldap_email = OFF;&lt;br /&gt;&lt;br /&gt;# The LDAP Protocol Version, if 0, then the protocol version is not set.&lt;br /&gt;$g_ldap_protocol_version = 3;&lt;br /&gt;&lt;br /&gt;# --- signup ----------------------&lt;br /&gt;&lt;br /&gt;$g_allow_signup = OFF;&lt;br /&gt;$g_lost_password_feature = OFF;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;3. In the file &lt;span style="font-family:courier new;"&gt;'mantis/core/authentication.php'&lt;/span&gt;, change the lines in the function &lt;span style="font-family:courier new;"&gt;'auth_attempt_login'&lt;/span&gt; begining "&lt;span style="font-family:courier new;"&gt;if ( false === $t_user_id ) {&lt;/span&gt;" as follows&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;if ( false === $t_user_id ) {&lt;br /&gt;  if ( BASIC_AUTH == $t_login_method \\ LDAP == $t_login_method ) {&lt;br /&gt;    # attempt to create the user if using BASIC_AUTH&lt;br /&gt;    if ( BASIC_AUTH == $t_login_method) {&lt;br /&gt;      $t_cookie_string = user_create( $p_username, $p_password );&lt;br /&gt;    } elseif ( LDAP == $t_login_method ) {&lt;br /&gt;      $t_cookie_string = user_create( $p_username, '', &lt;br /&gt;        ldap_email_from_username( $p_username ) );&lt;br /&gt;    }&lt;br /&gt;    if ( false === $t_cookie_string ) {&lt;br /&gt;      # it didn't work&lt;br /&gt;      return false;&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;4. Restart your Apache HTTPD server and validate.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4337142345946287269-829139487173415052?l=ksutaria.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ksutaria.blogspot.com/feeds/829139487173415052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4337142345946287269&amp;postID=829139487173415052' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/829139487173415052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/829139487173415052'/><link rel='alternate' type='text/html' href='http://ksutaria.blogspot.com/2008/05/mantis-ldap-authentication.html' title='Mantis + LDAP Authentication'/><author><name>Kalpesh</name><uri>http://www.blogger.com/profile/11789170660994069564</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4337142345946287269.post-3384229524561345321</id><published>2008-04-09T09:37:00.006-05:00</published><updated>2009-04-20T16:08:55.206-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Utilities'/><category scheme='http://www.blogger.com/atom/ns#' term='GNU/Linux'/><title type='text'>Truncate a file</title><content type='html'>While setting up Apache HTTP Server to rotate logs I came across an interesting problem. How would you truncate a file? The trivial solution that I came up with was&lt;br /&gt;&lt;br /&gt;&lt;pre name='code' class='bash'&gt;&lt;br /&gt;[root@lambda ~]# rm -f /var/log/httpd/foo.log&lt;br /&gt;[root@lambda ~]# touch /var/log/httpd/foo.log&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Unfortunately this doesn't work. The HTTP Server ceases logging to the file unless there is a server restart. After prying around the web I came across some interesting tricks but the one that stood out was:&lt;br /&gt;&lt;br /&gt;&lt;pre name='code' class='bash'&gt;&lt;br /&gt;[root@lambda ~]# :&gt; /var/log/httpd/foo.log&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4337142345946287269-3384229524561345321?l=ksutaria.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ksutaria.blogspot.com/feeds/3384229524561345321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4337142345946287269&amp;postID=3384229524561345321' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/3384229524561345321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/3384229524561345321'/><link rel='alternate' type='text/html' href='http://ksutaria.blogspot.com/2008/04/truncate-file.html' title='Truncate a file'/><author><name>Kalpesh</name><uri>http://www.blogger.com/profile/11789170660994069564</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4337142345946287269.post-1999650556932993973</id><published>2008-04-09T09:37:00.005-05:00</published><updated>2009-04-20T16:08:27.387-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Utilities'/><category scheme='http://www.blogger.com/atom/ns#' term='Tcpdump'/><category scheme='http://www.blogger.com/atom/ns#' term='GNU/Linux'/><title type='text'>TCP Dump</title><content type='html'>A very convenient way to find out traffic content on a particular port.&lt;br /&gt;&lt;br /&gt;&lt;pre name='code' class='bash'&gt;&lt;br /&gt;tcpdump -l -i eth0 -w - src or dst port 3306 | strings&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4337142345946287269-1999650556932993973?l=ksutaria.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ksutaria.blogspot.com/feeds/1999650556932993973/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4337142345946287269&amp;postID=1999650556932993973' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/1999650556932993973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4337142345946287269/posts/default/1999650556932993973'/><link rel='alternate' type='text/html' href='http://ksutaria.blogspot.com/2008/04/tcp-dump.html' title='TCP Dump'/><author><name>Kalpesh</name><uri>http://www.blogger.com/profile/11789170660994069564</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
