<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technology: Learn and Share &#187; CentOS</title>
	<atom:link href="http://crazytoon.com/category/centos/feed/" rel="self" type="application/rss+xml" />
	<link>http://crazytoon.com</link>
	<description>Enterprise level solutions, LAMP, Linux, Apache, MySQL, PHP, Perl, Windows, Cache, Optimization</description>
	<lastBuildDate>Thu, 20 Oct 2011 20:56:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[CentOS] OpenVZ &#8211; container based virtualization quick guide.  Part 1 of 2</title>
		<link>http://crazytoon.com/2010/11/30/centos-openvz-container-based-virtualization-quick-guide-part-1-of-2/</link>
		<comments>http://crazytoon.com/2010/11/30/centos-openvz-container-based-virtualization-quick-guide-part-1-of-2/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 23:00:21 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=231</guid>
		<description><![CDATA[This quick guide will walk you through setting up OpenVZ on CentOS.  I followed these steps on CentOS release 5.5 x64 version.  If you want more detail on install via different methods and/or have different flavor of CentOS and run into an issue, you can follow instructions provided by OpenVZ site.  Once [...]]]></description>
			<content:encoded><![CDATA[<p>This quick guide will walk you through setting up OpenVZ on CentOS.  I followed these steps on CentOS release 5.5 x64 version.  If you want more detail on install via different methods and/or have different flavor of CentOS and run into an issue, you can follow instructions provided by <a title="OpenVZ quick installation guide." href="http://wiki.openvz.org/Quick_installation" target="_blank">OpenVZ site</a>.  Once you are done with this guide, you will have CentOS container running for you to play with.</p>
<p>For my purposes,  I started with very basic installation of CentOS 5.5.  I have done this on existing installations of CentOS without any issues as well.  Ok so let&#8217;s start with getting the OpenVZ repository added to our system.  This means that we will be going down &#8220;yum&#8221; path instead of &#8220;rpm&#8221; path.  This is the quickest and easiest way to get OpenVZ installed.</p>
<p><code>cd /etc/yum.repos.d<br />
wget http://download.openvz.org/openvz.repo<br />
rpm --import  http://download.openvz.org/RPM-GPG-Key-OpenVZ</code></p>
<p>Before we move on, let&#8217;s turn off selinux:</p>
<p><code>vi /etc/selinux/config<br />
:0,$s/=enforcing/=disabled/g<br />
:wq</code></p>
<p>Go ahead and reboot the box and check:</p>
<p><code>[root@tooncent ~]# getenforce<br />
Disabled</code></p>
<p>Now since we have the OpenVZ repository added and selinux disabled, we can go ahead and move on with installation part:<br />
<code>yum install vzkernel.x86_64 #install kernel with openvz support</code></p>
<p><code>echo '<br />
# ----------added for OpenVZ installation----------------<br />
# On Hardware Node we generally need<br />
# packet forwarding enabled and proxy arp disabled<br />
net.ipv4.ip_forward = 1<br />
net.ipv6.conf.default.forwarding = 1<br />
net.ipv6.conf.all.forwarding = 1<br />
net.ipv4.conf.default.proxy_arp = 0<br />
# Enables source route verification<br />
net.ipv4.conf.all.rp_filter = 1<br />
# Enables the magic-sysrq key<br />
kernel.sysrq = 1<br />
# We do not want all our interfaces to send redirects<br />
net.ipv4.conf.default.send_redirects = 1<br />
net.ipv4.conf.all.send_redirects = 0<br />
' &gt;&gt; /etc/sysctl.conf</code></p>
<p>Note:  by executing above snippet, you will end up creating duplicate entries.  It&#8217;s always a good idea to clean up duplicates to avoid confusion/mistakes later.</p>
<p>Following step is optional and mostly for clarity.  Edit your grub.conf and change CentOS to say OpenVZ:</p>
<p><code>vi /etc/grub.conf</code></p>
<p>Change the first &#8220;title CentOS&#8221; to &#8220;title OpenVZ&#8221; (without the quotes).  For example:</p>
<p><code>title CentOS (2.6.18-194.17.1.el5.028stab070.7)<br />
root (hd0,0)<br />
kernel /vmlinuz-2.6.18-194.17.1.el5.028stab070.7 ro root=/dev/VolGroup00/LogVol00<br />
initrd /initrd-2.6.18-194.17.1.el5.028stab070.7.img</code></p>
<p>becomes:</p>
<p><code>title OpenVZ (2.6.18-194.17.1.el5.028stab070.7)<br />
root (hd0,0)<br />
kernel /vmlinuz-2.6.18-194.17.1.el5.028stab070.7 ro root=/dev/VolGroup00/LogVol00<br />
initrd /initrd-2.6.18-194.17.1.el5.028stab070.7.img</code></p>
<p>Ok at this point we are ready to reboot and use the new kernel.  Issue a &#8220;reboot&#8221;.  Let&#8217;s install the utilities to manage OpenVZ:<br />
<code>yum install vzctl.x86_64 vzquota.x86_64</code></p>
<p>We need to start up vz manually once.</p>
<p><code>/etc/init.d/vz start</code></p>
<p>Alright!  we got OpenVZ running.  Now, let&#8217;s get a precreated template from <a title="OpenVZ template downloads" href="http://wiki.openvz.org/Download/template/precreated" target="_blank">OpenVZ site</a>.</p>
<p><code>cd /vz/template/cache/<br />
wget http://download.openvz.org/template/precreated/centos-5-x86_64.tar.gz</code></p>
<p>Ok now comes the fun part; let&#8217;s get our first container up and running:<br />
Note: ostemplate name is the file you downloaded minus .tar.gz.  <strong>centos-5-x86_64</strong>.tar.gz</p>
<p><code>[root@tooncent cache]# vzctl create 101 --ostemplate centos-5-x86_64<br />
Creating container private area (centos-5-x86_64)<br />
Performing postcreate actions<br />
Container private area was created<br />
[root@tooncent cache]#</code></p>
<p>Container files are created under /vz/private/101  &lt; &#8211; 101 is the id you give it.  You can put any numeric number above 100.  Documentation says not to use anything below 101 since its a reserved range.</p>
<p>Let&#8217;s set a hostname so there is no confusion:</p>
<p><code>vzctl set 101 --hostname toontest.tooncent.com --save<br />
Set hostname: toontest.tooncent.com<br />
Saved parameters for CT 101</code></p>
<p>To start your new container:</p>
<p><code>[root@tooncent ~]# vzctl start 101<br />
Starting container ...<br />
Container is mounted<br />
Setting CPU units: 1000<br />
Set hostname: toontest.tooncent.com<br />
Container start in progress...<br />
[root@tooncent ~]#</code></p>
<p>To access your container:</p>
<p><code>vzctl enter 101</code></p>
<p>To exit the container, type: exit</p>
<p>To stop the container:</p>
<p><code># vzctl stop 101<br />
Stopping container ...<br />
Container was stopped<br />
Container is unmounted</code></p>
<p>Congratulations!   You have successfully setup a container.</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2010/11/30/centos-openvz-container-based-virtualization-quick-guide-part-1-of-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Bash] Performing array intersection with Bash</title>
		<link>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/</link>
		<comments>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 01:15:51 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=224</guid>
		<description><![CDATA[I am currently working on a project to deploy new website builds to a
small number of servers.  I needed something simple and reliable that could
be built in a very short period of time.  I decided to whip something up in
bash with the intent of refining it in Python later.
As I began to write [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a project to deploy new website builds to a<br />
small number of servers.  I needed something simple and reliable that could<br />
be built in a very short period of time.  I decided to whip something up in<br />
bash with the intent of refining it in Python later.</p>
<p>As I began to write this code, I realized that it probably would have been<br />
quicker to do it in Python from the start.  I decided to stick with bash as<br />
somewhat of an academic exercise.  The vast majority of these deployment<br />
scripts were trivial; check the code out of git, create a manifest, package<br />
it up, spew it to the servers, etc, etc.  The problem came during the last<br />
step.  We decided to use a symlink to point to the active build out of a<br />
number of builds that could be available on the server at any given time.<br />
Since all of our servers should be running the exact same version of the<br />
build, it makes sense that I should only allow a user of my deployment<br />
scripts to link a build which exists on all servers.  But how do you<br />
accomplish this in bash?</p>
<p>In most other languages, you have access to numerous array helping<br />
functions that allow you to perform intersects, uniqs, and merges.  My goal<br />
was to do the same thing in bash without forking out to any external<br />
binary.  So how do you ensure that a particular thing exists on N number of<br />
servers?  Here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> in_array<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 <span style="color: #7a0874; font-weight: bold;">local</span> x
 <span style="color: #007800;">ENTRY</span>=$<span style="color: #000000;">1</span>
 <span style="color: #7a0874; font-weight: bold;">shift</span> <span style="color: #000000;">1</span>
 <span style="color: #007800;">ARRAY</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #ff0000;">&quot;$@&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
 <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ARRAY}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
 <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ENTRY}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
 <span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${ARRAY[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${x}</span>&quot;</span> == <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ENTRY}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
 <span style="color: #000000; font-weight: bold;">done</span>
 <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">MASTER</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">CURRENT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">FIRST</span>=<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">for</span> SERVER <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${SERVERS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
 <span style="color: #666666; font-style: italic;"># collect all builds from server and populate CURRENT list</span>
 <span style="color: #007800;">COMMAND</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${LS}</span> -1fd <span style="color: #007800;">${WEBROOT}</span>/<span style="color: #007800;">${SITE}</span>.*&quot;</span>
 <span style="color: #007800;">BUILDS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #800000;">${SSH}</span> <span style="color: #800000;">${SSHOPTS}</span> root<span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${SERVER}</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${COMMAND}</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
 <span style="color: #000000; font-weight: bold;">for</span> BUILD <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${BUILDS}</span>; <span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #007800;">CURRENT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${CURRENT[@]-}</span> <span style="color: #800000;">${BUILD}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
 <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># if this is our first time around, copy CURRENT to MASTER</span>
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${FIRST}</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #007800;">MASTER</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${CURRENT[@]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #007800;">FIRST</span>=<span style="color: #000000;">0</span>
 <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># now we do a compare between MASTER and CURRENT to see what builds</span>
 <span style="color: #666666; font-style: italic;"># are common</span>
 <span style="color: #007800;">INTERSECT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
 <span style="color: #000000; font-weight: bold;">for</span> ENTRY <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${CURRENT[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
   in_array <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ENTRY}</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${MASTER[@]}</span>&quot;</span>
   <span style="color: #007800;">RET</span>=<span style="color: #007800;">$?</span>
   <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${RET}</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
     <span style="color: #007800;">INTERSECT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${INTERSECT[@]-}</span> <span style="color: #800000;">${ENTRY}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #000000; font-weight: bold;">fi</span>
 <span style="color: #000000; font-weight: bold;">done</span>
 <span style="color: #007800;">MASTER</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${INTERSECT[@]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># clear the CURRENT array</span>
 <span style="color: #007800;">CURRENT</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>Let me take a moment to explain the code above:</p>
<ul>
<li> In order to check for array intersection, you need an in_array()<br />
function</p>
<ul>
<li>The first argument as the &#8220;needle&#8221; and the second is the<br />
&#8220;haystack&#8221;</li>
<li>We verify that both parameters were passed</li>
<li>We simply loop through the haystack checking for the needle</li>
<li>If we find it, return success.  Otherwise, eventually return<br />
false</li>
</ul>
</li>
<li>We need to loop through each server eventually, but we&#8217;ll start with<br />
the first one</p>
<ul>
<li>Run an SSH command to get a listing of builds</li>
<li>Populate an array ($CURRENT) with the builds that were found</li>
</ul>
<ul>
<li>Since the first server has no previous server to compare with, so we<br />
just copy it to $MASTER</li>
</ul>
</li>
<li>We then loop to the 2nd server, and put the result of getting builds<br />
into $CURRENT</p>
<ul>
<li>Now that we have the first server&#8217;s builds in $MASTER, we perform an<br />
intersect with $CURRENT</li>
<li>We realize the need for an $INTERSECT array to hold the intersections<br />
found above</li>
<li>$INTERSECT becomes $MASTER since it only contains similar builds from<br />
the 1st and 2nd server</li>
</ul>
</li>
<li>Looping to the 3rd server, we get the builds and put them in $CURRENT
<ul>
<li>Since $MASTER contains only the similar builds thus far, we again<br />
compare it with $CURRENT</li>
<li>The intersect can now be used to compare against builds on the 4th<br />
server, and so on</li>
</ul>
</li>
<li>Once you finish looping through all servers, your $MASTER should<br />
contain only similar builds</li>
</ul>
<p>There are a few guides out there which show you how to do this via<br />
forking, but I thought someone may appreciate the elegance of using 100%<br />
bash to accomplish this.  I hope this helps someone else out there!</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do you print number of files for each folder in a directory [Linux]</title>
		<link>http://crazytoon.com/2010/04/05/get-file-counts-for-folders-linux/</link>
		<comments>http://crazytoon.com/2010/04/05/get-file-counts-for-folders-linux/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 20:37:06 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=208</guid>
		<description><![CDATA[I have been annoyed by the fact that I couldn&#8217;t easily print file count for all of the folders in certain directory.  Most of the time I just want to see what space each folder is using (du -hs *) but there are times when I need to know how many files are in each [...]]]></description>
			<content:encoded><![CDATA[<p>I have been annoyed by the fact that I couldn&#8217;t easily print file count for all of the folders in certain directory.  Most of the time I just want to see what space each folder is using (du -hs *) but there are times when I need to know how many files are in each folder (checking cache folder, session folders etc).   So I whipped together a command line which does just that for me:</p>
<p><code>for i in `find -maxdepth 1 -type d`; do  echo -n $i " ";find $i|wc -l; done</code></p>
<p>I am sure there are many different ways to show file count for each folder in a directory and I am curious to see what people do so please do post comments with what you do.</p>
<p>Above command is pretty simple and can be expanded to do whatever you need.  For example, you can throw it into a bash script and be able to pass parameters.  For example:  count_files /home/  In this case your command line would look like:</p>
<p><code>for i in `find /home/ -maxdepth 1 -type d`; do  echo -n $i " ";find $i|wc  -l; done</code></p>
<p>only difference would be that /home/ would be argument you passed and therefore will be $1.  Here is a sample script for above example:</p>
<p><code>#!/bin/bash<br />
for i in `find $1 -maxdepth 1 -type d`; do<br />
echo -n $i " ";<br />
find $i|wc -l;<br />
done</code></p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet  carefully. Make backups often. And yeah.. last but not least.. I am not  responsible for any damage caused by this posting. <strong>Use at your  own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2010/04/05/get-file-counts-for-folders-linux/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP: Curl being slow from php call on CentOS 5.4</title>
		<link>http://crazytoon.com/2010/01/19/php-curl-being-slow-from-php-call-on-centos-5-4/</link>
		<comments>http://crazytoon.com/2010/01/19/php-curl-being-slow-from-php-call-on-centos-5-4/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 22:12:28 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=204</guid>
		<description><![CDATA[I ran into an issue where curl request run within few ms from command line but same url fetch was taking over 10 secs.  After doing some debugging and research it turned out that call to check (getaddr ipv6 was timing out.  Obviously you can do multiple things to fix this (including enabling [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into an issue where curl request run within few ms from command line but same url fetch was taking over 10 secs.  After doing some debugging and research it turned out that call to check (getaddr ipv6 was timing out.  Obviously you can do multiple things to fix this (including enabling ipv6 support) but since I did not have a need for ipv6 (it is disabled in my network configuration), I decided to recompile curl and disable ipv6.  Here is the command for recompiling curl and installing into /usr/local/curl directory with ipv6 disabled.</p>
<p>./configure &#8211;prefix=/usr/local/curl &#8211;disable-ipv6</p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2010/01/19/php-curl-being-slow-from-php-call-on-centos-5-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sshfs: How do you install sshfs and fuse? [CentOS/Linux/Redhat]</title>
		<link>http://crazytoon.com/2008/10/07/sshfs-how-do-you-install-sshfs-and-fuse-centoslinuxredhat/</link>
		<comments>http://crazytoon.com/2008/10/07/sshfs-how-do-you-install-sshfs-and-fuse-centoslinuxredhat/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 23:06:50 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[fuse]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[sshfs]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=84</guid>
		<description><![CDATA[One may wonder what is sshfs and why would you want it?  Well simply put, sshfs allows you to mount another server&#8217;s filesystem into a folder on your local system which in the background is doing ssh commands and transfers.  As a mounted folder, you are able to move about and copy files back and [...]]]></description>
			<content:encoded><![CDATA[<p>One may wonder what is sshfs and why would you want it?  Well simply put, sshfs allows you to mount another server&#8217;s filesystem into a folder on your local system which in the background is doing ssh commands and transfers.  As a mounted folder, you are able to move about and copy files back and forth as everything was on local server.  As you can see this makes it very easy for you to work with files on multiple servers.</p>
<p><strong>Note</strong>:  you only have to do the following installations on the server where you are doing the mounts on.</p>
<p>Let us download and install the filesystem framework which is a requirement for sshfs called fuse.</p>
<p><code>wget http://voxel.dl.sourceforge.net/sourceforge/fuse/fuse-2.7.4.tar.gz<br />
tar zxpfv fuse-*.gz<br />
cd fuse*<br />
./configure</code></p>
<p>If you get the following error, you will either have to point to the location of the kernel source or install it if needed.</p>
<p><code>checking kernel source directory... Not found<br />
configure: error:<br />
*** Please specify the location of the kernel source with<br />
*** the '--with-kernel=SRCDIR' option<br />
configure: error: ./configure failed for kernel</code></p>
<p>In our case here, we will be installing the source using yum.</p>
<p><code>yum -y install kernel-devel</code></p>
<p>Once installed, you will have to find out the directory it is installed in</p>
<p><code>ls -l /usr/src/kernels/<br />
total 4.0K<br />
drwxr-xr-x 18 root root 4.0K Oct  7 14:50 <strong>2.6.18-92.1.13.el5-x86_64</strong>/</code></p>
<p><code>./configure --with-kernel=/usr/src/kernels/<strong>2.6.18-92.1.13.el5-x86_64</strong><br />
make &amp;&amp; make install<br />
cd ..</code></p>
<p>Now let us get sshfs source and install it.</p>
<p><code>wget http://voxel.dl.sourceforge.net/sourceforge/fuse/sshfs-fuse-2.1.tar.gz<br />
tar zxpfv sshfs*<br />
cd sshfs-fuse-*<br />
./configure</code></p>
<p>If you get the following error:</p>
<p><code>checking for SSHFS... configure: error: The pkg-config script could not be found or is too old.  Make sure it<br />
is in your PATH or set the PKG_CONFIG environment variable to the full<br />
path to pkg-config.</code></p>
<p>OR</p>
<p><code>checking for SSHFS... configure: error: Package requirements (fuse &gt;= 2.2 glib-2.0 gthread-2.0) were not met:</code></p>
<p>No package &#8216;glib-2.0&#8242; found<br />
No package &#8216;gthread-2.0&#8242; found</p>
<p>You need to install glib2.  Do the following:</p>
<p><code>yum install glib2-devel</code></p>
<p>Once installation is done, continue with configure.</p>
<p><code>./configure<br />
make &amp;&amp; make install</code></p>
<p>After installation is done, we can move on with testing the installation:</p>
<p><code>cd /mnt<br />
mkdir test<br />
sshfs 10.0.0.2:/ test</code></p>
<p>If you get the following error,<br />
<code>sshfs: error while loading shared libraries: libfuse.so.2: cannot open shared object file: No such file or directory</code><br />
execute this:  NOTE:  this is for x64 system.  If you have 32 bit system, you have to symlink to /lib instead.<br />
<code>ln -s /usr/local/lib/libfuse.so.2 /lib64/</code><br />
Let us try mounting again:<br />
<code>sshfs 10.0.0.2:/ test</code><br />
At this point it would be like if you were making a ssh connection to 10.0.0.2  You will have to type in a password to get the mount to happen.  You may get the following error:  <code>fuse: device not found, try 'modprobe fuse' first</code></p>
<p>If you do &#8216;modprobe fuse&#8217;, as they tell you to, and you get:<br />
<code>modprobe fuse<br />
FATAL: Module fuse not found.</code></p>
<p>That means your running kernel is not the same version as the one you compiled with.  You have two options here:<br />
1) you can upgrade your kernel by typing:  yum update kernel<br />
2) find the source files for the kernel you have running and recompile fuse.</p>
<p>I went with option 1.  Once you do the update, reboot and try doing <em>modprobe fuse</em> again.</p>
<p>At this point we can try doing the mount again.<br />
<code>cd /mnt<br />
sshfs 10.0.0.2:/ test</code></p>
<p>If you do not get any errors, do df -h to see the mount:<br />
<code>...<br />
sshfs#10.0.0.2:/  1000G     0 1000G   0% /mnt/test<br />
...</code></p>
<p>At this point you can browse 10.0.0.2 server filesystem as it was local on your server.</p>
<p>————————————-</p>
<p><small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/10/07/sshfs-how-do-you-install-sshfs-and-fuse-centoslinuxredhat/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Linux: How do you find out what your server&#8217;s outgoing ip is?</title>
		<link>http://crazytoon.com/2008/09/04/linux-how-do-you-find-out-what-your-servers-outgoing-ip-is/</link>
		<comments>http://crazytoon.com/2008/09/04/linux-how-do-you-find-out-what-your-servers-outgoing-ip-is/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 14:27:05 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[Notes for self]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=110</guid>
		<description><![CDATA[There are many times when I needed to find out my outgoing (or external) IP for the servers which are behind load balancers or firewalls.  I used to just login to another external server from the server in question and find out by looking at &#8220;who&#8221; what my external ip is.  Even though it works [...]]]></description>
			<content:encoded><![CDATA[<p>There are many times when I needed to find out my outgoing (or external) IP for the servers which are behind load balancers or firewalls.  I used to just login to another external server from the server in question and find out by looking at &#8220;<a title="man who - manpage for who" href="http://www.lamp-tips.com/man-pages/who/" target="_blank">who</a>&#8221; what my external ip is.  Even though it works and I am so used to it, today I decided to figure out a more graceful way of finding my outgoing ip.  As most of us already know, whatismyip.com is the quickest way to find out your outgoing ip from the browser.  So I decided to use the same way on the servers.  So I issued a wget:</p>
<p><code>wget http://www.whatismyip.org</code></p>
<p>Well that does the trick.  But being lazy as I am, I did not want to have to cat the output file to find out the ip (plus there is no point of creating extra files and doing extra work to remove them).  So if you are ssh&#8217;ed in, you can issue following command (I am sure there is another way of doing it, but this is the quickest way I could think of):</p>
<p><code><a title="man wget - manpage for wget" href="http://www.lamp-tips.com/man-pages/wget/" target="_blank">wget</a> -q -O - http://www.whatismyip.org</code></p>
<p>-O tells wget to redirect output to the following file (- being the standard out ).  So it basically echo&#8217;s output to our console.</p>
<p>-q makes wget run in  quiet mode so you do not see all of the connection/download/etc output.</p>
<p>That is it!  I am curious to know what other ways people use to get the same information.  Please share your way if possible.</p>
<p>————————————-</p>
<p><small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/09/04/linux-how-do-you-find-out-what-your-servers-outgoing-ip-is/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Quick tip:  how do you rename all files so spaces are converted to underscores?</title>
		<link>http://crazytoon.com/2008/08/25/quick-tip-how-do-you-rename-all-files-so-spaces-are-converted-to-underscores/</link>
		<comments>http://crazytoon.com/2008/08/25/quick-tip-how-do-you-rename-all-files-so-spaces-are-converted-to-underscores/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 23:36:13 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[man tr]]></category>
		<category><![CDATA[rename files]]></category>
		<category><![CDATA[spaces to underscores]]></category>
		<category><![CDATA[uppercase to lowercase]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=97</guid>
		<description><![CDATA[My friend today asked me how to convert all spaces in filenames under a specified directory to underscores.  Also, at the same time lowercase all of the filenames.  Here is a quick script to do what is needed.  Let us start with creating some test data in a temp directory:
mkdir temp
cd temp
touch [...]]]></description>
			<content:encoded><![CDATA[<p>My friend today asked me how to convert all spaces in filenames under a specified directory to underscores.  Also, at the same time lowercase all of the filenames.  Here is a quick script to do what is needed.  Let us start with creating some test data in a temp directory:</p>
<p><code>mkdir temp<br />
cd temp<br />
touch Foo FooO "Foo Bar" "FOO BAaR"<br />
\ls | while read -r FILENAME<br />
do<br />
mv -v "$FILENAME" `echo $FILENAME| tr ' ' '_'| tr '[A-Z]' '[a-z]'`<br />
done</code></p>
<p>Note:  I intentionally have slash in front of ls (\ls).  \ls means that we want to make sure there is no ls alias overwriting our command.  This is needed if your system has alias setup to display ls in a different way instead of default listing.  mv -v shows us the filenames being renamed as your script goes through the whole dir.  Your output should be like:</p>
<p><code>`Foo' -&gt; `foo'<br />
`FOO BAaR' -&gt; `foo_baar'<br />
`Foo Bar' -&gt; `foo_bar'<br />
`FooO' -&gt; `fooo'</code></p>
<p>One of the very powerful commands in this post is the &#8220;tr&#8221; command.  This command is not as popular as sed or awk but it is very useful and simple to use (<a title="man tr - man page for tr" href="http://www.lamp-tips.com/man-pages/tr/" target="_blank">read more about tr</a>).</p>
<p>If you only needed to convert spaces to underscores and you are using CentOS/Fedora/Redhat, you can use this simpler method.  <strong>NOTE</strong>:  this command is not available on all distributions:  <code>rename " " "_" *</code></p>
<p>Learn more about <a title="man rename - man page for rename" href="http://www.lamp-tips.com/man-pages/rename/" target="_blank">rename </a>command<br />
————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/08/25/quick-tip-how-do-you-rename-all-files-so-spaces-are-converted-to-underscores/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Apache/http monitoring:  monitor http traffic in realtime using httptop</title>
		<link>http://crazytoon.com/2008/08/12/apachehttp-monitoring-monitor-http-traffic-in-realtime-using-httptop/</link>
		<comments>http://crazytoon.com/2008/08/12/apachehttp-monitoring-monitor-http-traffic-in-realtime-using-httptop/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 20:05:59 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Server load]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[apache monitoring]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[realtime monitoring]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=86</guid>
		<description><![CDATA[Server monitoring is a big part of running a solid web site.  As an admin, you must know what is going on your server.  One of the tools most Linux/Unix admins are used to is called &#8220;top&#8221;.  &#8220;top&#8221; by itself is a very powerful tool.  Here is a quick guide on how to read output [...]]]></description>
			<content:encoded><![CDATA[<p>Server monitoring is a big part of running a solid web site.  As an admin, you must know what is going on your server.  One of the tools most Linux/Unix admins are used to is called &#8220;top&#8221;.  &#8220;<a title="Introduction to load averages under &quot;top&quot;" href="http://crazytoon.com/2007/01/29/what-is-this-load-average-i-keep-hearing-about/" target="_blank">top</a>&#8221; by itself is a very powerful tool.  Here is a quick guide on how to read output from top:  <a title="Introduction to load averages under &quot;top&quot;" href="http://crazytoon.com/2007/01/29/what-is-this-load-average-i-keep-hearing-about/">introduction to load averages under top</a>.  It just makes sense that somebody went and created http<strong>top</strong> to monitor http traffic.</p>
<p>Install perl modules:</p>
<p><code>install Term::ReadKey<br />
install File::Tail<br />
install Time::HiRes<br />
</code><br />
Now copy paste the script below and save it in a location and set +x attribute on it so you can execute it.  On my setup, I have the script under /usr/bin/httptop:</p>
<p><code>#!/usr/bin/perl -w<br />
use Time::HiRes qw( time );<br />
use File::Tail (  );<br />
use Term::ReadKey;<br />
use Getopt::Std;<br />
use strict;<br />
### Defaults you might be interested in adjusting.<br />
my $Update = 2; # update every n secs<br />
my $Backtrack = 250; # backtrack n lines on startup<br />
my @Paths = qw(<br />
%<br />
/title/%/logs/access_log<br />
/var/log/httpd/%/access_log<br />
/usr/local/apache/logs/%/access_log<br />
);<br />
my $Log_Format = "combined";<br />
my %Log_Fields = (<br />
combined =&gt; [qw/ Host x x Time URI Response x Referer Client /],<br />
vhost =&gt; [qw/ VHost Host x x Time URI Response x Referer Client /]<br />
);<br />
### Constants &amp; other thingies. Nothing to see here. Move along.<br />
my $Version = "0.4.1";<br />
sub by_hits_per (  ) { $b-&gt;{Rate} &lt;=&gt; $a-&gt;{Rate} }<br />
sub by_total (  ) { $b-&gt;{Total} &lt;=&gt; $a-&gt;{Total} }<br />
sub by_age (  ) { $a-&gt;{Last} &lt;=&gt; $b-&gt;{Last} }<br />
my $last_field = "Client";<br />
my $index = "Host";<br />
my $show_help = 0;<br />
my $order = \&amp;by_hits_per;<br />
my $Help = "htlwufd?q";<br />
my %Keys = (<br />
h =&gt; [ "Order by hits/second" =&gt; sub { $order = \&amp;by_hits_per } ],<br />
t =&gt; [ "Order by total recorded hits" =&gt; sub { $order = \&amp;by_total } ],<br />
l =&gt; [ "Order by most recent hits" =&gt; sub { $order = \&amp;by_age } ],<br />
w =&gt; [ "Show remote host" =&gt; sub { $index = "Host" } ],<br />
u =&gt; [ "Show requested URI" =&gt; sub { $index = "URI" } ],<br />
f =&gt; [ "Show referring URL" =&gt; sub { $index = "Referer" } ],<br />
d =&gt; [ "Show referring domain" =&gt; sub { $index = "Domain" } ],<br />
'?' =&gt; [ "Help (this thing here)" =&gt; sub { $show_help++ } ],<br />
q =&gt; [ "Quit" =&gt; sub { exit } ]<br />
);<br />
my @Display_Fields = qw/ Host Date URI Response Client Referer Domain /;<br />
my @Record_Fields = qw/ Host URI Referer Domain /;<br />
my $Max_Index_Width = 50;<br />
my $Initial_TTL = 50;<br />
my @Months = qw/ Jan Feb Mar Apr May Jun Jul Aug Sep Nov Dec /;<br />
my %Term = (<br />
HOME =&gt; "\033[H",<br />
CLS =&gt; "\033[2J",<br />
START_TITLE =&gt; "\033]0;", # for xterms etc.<br />
END_TITLE =&gt; "\007",<br />
START_RV =&gt; "\033[7m",<br />
END_RV =&gt; "\033[m"<br />
);<br />
my ( %hist, %opt, $spec );<br />
$SIG{INT} = sub { exit };<br />
END { ReadMode 0 };<br />
### Subs.<br />
sub refresh_output<br />
{<br />
my ( $cols, $rows ) = GetTerminalSize;<br />
my $show = $rows - 3;<br />
my $count = $show;<br />
my $now = (shift || time);<br />
for my $type ( values %hist ) {<br />
for my $peer ( values %$type ) {<br />
# if ( --$peer-&gt;{_Ttl} &gt; 0 ) {<br />
my $delta = $now - $peer-&gt;{Start};<br />
if ( $delta &gt;= 1 ) {<br />
$peer-&gt;{ Rate } = $peer-&gt;{ Total } / $delta;<br />
} else {<br />
$peer-&gt;{ Rate } = 0<br />
}<br />
$peer-&gt;{ Last } = int( $now - $peer-&gt;{ Date } );<br />
# } else {<br />
# delete $type-&gt;{$peer}<br />
# }<br />
}<br />
}<br />
$count = scalar( values %{$hist{$index}} ) - 1 if $show &gt;= scalar values %{$hist{$index}};<br />
my @list = ( sort $order values %{$hist{$index}} )[ 0 .. $count ];<br />
my $first = 0;<br />
$first = ( $first &lt;= $_ ? $_ + 1 : $first ) for map { $_ ? length($_-&gt;{$index}) : 0 } @list;<br />
$first = $Max_Index_Width if $Max_Index_Width &lt; $first;<br />
print $Term{START_TITLE}, "Monitoring $spec at: ", scalar localtime, $Term{END_TITLE} if $ENV{TERM} eq "xterm"; # UGLY!!!<br />
my $help = "Help/?";<br />
my $head = sprintf( "%-${first}s %6s %4s %4s %s (%d total)",<br />
$index, qw{ Hits/s Tot Last }, $last_field,<br />
scalar keys %{$hist{$index}}<br />
);<br />
#<br />
# Truncate status line if need be<br />
#<br />
$head = substr($head, 0, ($cols - length($help)));<br />
print @Term{"HOME", "START_RV"}, $head, " " x ($cols - length($head) - length($help)), $help, $Term{END_RV}, "\n";<br />
for ( @list ) {<br />
# $_-&gt;{_Ttl}++;<br />
my $line = sprintf( "%-${first}s %6.3f %4d %3d %s",<br />
substr( $_-&gt;{$index}, 0, $Max_Index_Width ), @$_{(qw{ Rate Total Last }, $last_field)} );<br />
if ( length($line) &gt; $cols ) {<br />
substr( $line, $cols - 1 ) = "";<br />
} else {<br />
$line .= " " x ($cols - length($line));<br />
}<br />
print $line, "\n";<br />
}<br />
print " " x $cols, "\n" while $count++ &lt; $show;<br />
}<br />
sub process_line<br />
{<br />
my $line = shift;<br />
my $now = ( shift || time );<br />
my %hit;<br />
chomp $line;<br />
@hit{@{$Log_Fields{$Log_Format}}} = grep( $_, split( /"([^"]+)"|\[([^]]+)\]|\s/o, $line ) );<br />
$hit{ URI } =~ s/HTTP\/1\S+//gos;<br />
$hit{ Referer } = "&lt;unknown&gt;" if not $hit{Referer} or $hit{Referer} eq "-";<br />
( $hit{Domain} = $hit{Referer} ) =~ s#^\w+://([^/]+).*$#$1#os;<br />
$hit{ Client } ||= "&lt;none&gt;";<br />
$hit{ Client } =~ s/Mozilla\/[\w.]+ \(compatible; /(/gos;<br />
$hit{ Client } =~ s/[^\x20-\x7f]//gos;<br />
# if $now is negative, try to guess how old the hit is based on the time stamp.<br />
if ( $now &lt; 0 ) {<br />
my @hit_t = ( split( m![:/\s]!o, $hit{ Time } ))[ 0 .. 5 ];<br />
my @now_t = ( localtime )[ 3, 4, 5, 2, 1, 0 ];<br />
my @mag = ( 3600, 60, 1 );<br />
# If the hit didn't parse right, or didn't happen today, the hell with it.<br />
return unless $hit_t[2] == ( $now_t[2] + 1900 )<br />
and $hit_t[1] eq $Months[ $now_t[1] ]<br />
and $hit_t[0] == $now_t[0];<br />
splice( @hit_t, 0, 3 );<br />
splice( @now_t, 0, 3 );<br />
# Work backward to the UNIX time of the hit.<br />
$now = time;<br />
$now -= (shift( @now_t ) - shift( @hit_t )) * $_ for ( 3600, 60, 1 );<br />
}<br />
$hit{ Date } = $now;<br />
for my $field ( @Record_Fields ) {<br />
my $peer = ( $hist{$field}{$hit{$field}} ||= { Start =&gt; $now, _Ttl =&gt; $Initial_TTL } );<br />
@$peer{ @Display_Fields } = @hit{ @Display_Fields };<br />
$peer-&gt;{ Total }++;<br />
}<br />
}<br />
sub display_help {<br />
my $msg = "httptop v.$Version";<br />
print @Term{qw/ HOME CLS START_RV /}, $msg, $Term{END_RV}, "\n\n";<br />
print " " x 4, $_, " " x 8, $Keys{$_}[0], "\n" for ( split "", $Help );<br />
print "\nPress any key to continue.\n";<br />
}<br />
### Init.<br />
getopt( 'frb' =&gt; \%opt );<br />
$Backtrack = $opt{b} if $opt{b};<br />
$Update = $opt{r} if $opt{r};<br />
$Log_Format = $opt{f} if $opt{f};<br />
$spec = $ARGV[0];<br />
die &lt;&lt;End unless $spec and $Log_Fields{$Log_Format};<br />
Usage: $0 [-f &lt;format&gt;] [-r &lt;refresh_secs&gt;] [-b &lt;backtrack_lines&gt;] &lt;logdir | path_to_log&gt;<br />
Valid formats are: @{[ join ", ", keys %Log_Fields ]}.<br />
End<br />
for ( @Paths ) {<br />
last if -r $spec;<br />
( $spec = $_ ) =~ s/%/$ARGV[0]/gos;<br />
}<br />
die "No access_log $ARGV[0] found.\n" unless -r $spec;<br />
my $file = File::Tail-&gt;new(<br />
name =&gt; $spec,<br />
interval =&gt; $Update / 2,<br />
maxinterval =&gt; $Update,<br />
tail =&gt; $Backtrack,<br />
nowait =&gt; 1<br />
) or die "$spec: $!";<br />
my $last_update = time;<br />
my ( $line, $now );<br />
# Backtracking.<br />
while ( $Backtrack-- &gt; 0 ) {<br />
last unless $line = $file-&gt;read;<br />
process_line( $line, -1 );<br />
}<br />
$file-&gt;nowait( 0 );<br />
ReadMode 4; # Echo off.<br />
print @Term{"HOME", "CLS"}; # Home &amp; clear.<br />
refresh_output;<br />
### Main loop.<br />
while (defined( $line = $file-&gt;read )) {<br />
$now = time;<br />
process_line( $line, $now );<br />
while ( $line = lc ReadKey(-1) ) {<br />
$show_help = 0 if $show_help;<br />
$Keys{$line}[1]-&gt;(  ) if $Keys{$line};<br />
}<br />
if ( $show_help == 1 ) {<br />
display_help;<br />
$show_help++; # Don't display help again.<br />
} elsif ( $now - $last_update &gt; $Update and not $show_help ) {<br />
$last_update = $now;<br />
refresh_output( $now );<br />
}<br />
}</code></p>
<p>Save/exit and make sure you make it executable by setting it to +x (<a title="man chmod - man page for chmod" href="http://www.lamp-tips.com/man-pages/chmod/" target="_blank">chmod </a>+x httptop)</p>
<p>Now you can run httptop by typing:  <code>httptop -f combined -r 1 /usr/local/apache2/logs/access_log</code></p>
<p>NOTE:  Your access_log file might be in different location.  Point to the right location.  This sets the refresh rate to 1 sec (-r 1).  Now you can run httptop any time you want to checkout how your http traffic is doing.  Remember to press &#8220;?&#8221; to get help once you are in.</p>
<p>—————</p>
<p><small>DISCLAIMER: As always, if you find any inaccurate information, please comment and let me know. When you do comment, make sure you give me some references to confirm.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/08/12/apachehttp-monitoring-monitor-http-traffic-in-realtime-using-httptop/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do you enable sphinxse (Sphinx Storage Engine) in your mysql installation?</title>
		<link>http://crazytoon.com/2008/08/05/mysql-how-do-you-enable-sphinxse-sphinx-storage-engine-in-your-mysql-installation/</link>
		<comments>http://crazytoon.com/2008/08/05/mysql-how-do-you-enable-sphinxse-sphinx-storage-engine-in-your-mysql-installation/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 22:21:32 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[fulltext search]]></category>
		<category><![CDATA[open source full text search engine]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[RHEL]]></category>
		<category><![CDATA[sphinx]]></category>
		<category><![CDATA[sphinx storage engine]]></category>
		<category><![CDATA[sphinxse]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=88</guid>
		<description><![CDATA[As you may know mysql fulltext search is not highly scalable.  One of the options to get around this scalability limitation, which I prefer, is to use Sphinx.   You can use Sphinx with out having to alter your mysql installation.  But, if you would like to use from within mysql and not have to [...]]]></description>
			<content:encoded><![CDATA[<p>As you may know mysql fulltext search is not highly scalable.  One of the options to get around this scalability limitation, which I prefer, is to use <a title="Sphinx Homepage" href="http://www.sphinxsearch.com/" target="_blank">Sphinx</a>.   You can use Sphinx with out having to alter your mysql installation.  But, if you would like to use from within mysql and not have to worry about how to pass data between Sphinx and MySQL, you can enable sphinxse (sphinx storage engine).  It is not included with mysql by default so you will have to compile it yourself.</p>
<p>Here are the instructions on how to get sphinxse compiled with your mysql installation on CentOS x64.  I am sure same instructions will work for other flavors but I have not tested it.  I will be compiling the most current version of sphinx (0.9.8) with most current stable version of mysql (5.0.51b) at the time of the writing.  Let&#8217;s get the appropriate packages first:</p>
<p><code>wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8.tar.gz<br />
wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51b.tar.gz/from/http://mysql.he.net/<br />
tar zxpf sphinx*<br />
tar zxpf mysql*</code></p>
<p>You will also need &#8220;bison&#8221;, &#8220;patch&#8221;, &#8220;automake&#8221; and &#8220;libtool&#8221; installed.  Let us just do a yum install for it.</p>
<p><code>yum -y install bison patch automake libtool</code></p>
<p><strong>NOTE</strong>:  if you don&#8217;t install bison, you will get the following error:<br />
<code>sed '/^#/ s|y\.tab\.c|sql_yacc.cc|' y.tab.c &gt;sql_yacc.cct &amp;&amp; mv sql_yacc.cct sql_yacc.cc<br />
sed: can't read y.tab.c: No such file or directory<br />
make[2]: *** [sql_yacc.cc] Error 2</code></p>
<p>Let us continue with patching mysql source with sphinx storage engine (sphinxse) code and compile/install our new binaries.</p>
<p><code>cd mysql*<br />
patch -p1 &lt; ../sphinx-0.9.8/mysqlse/sphinx.5.0.37.diff #Make sure everything succeeded.<br />
BUILD/autorun.sh<br />
mkdir sql/sphinx<br />
cp ../sphinx-0.9.8/mysqlse/* sql/sphinx<br />
./configure --prefix=/usr/local/mysql --with-sphinx-storage-engine<br />
make<br />
make install</code></p>
<p>Now start your mysql installtion and check if engine support is compiled in:</p>
<p><code>mysql&gt; show engines\G<br />
Engine: SPHINX<br />
Support: YES<br />
Comment: Sphinx storage engine 0.9.8</code></p>
<p>To read more about how to use Sphinx storage engine, please refer to:  <a title="Sphinx Documentation for using Sphinx Storage Engine" href="http://www.sphinxsearch.com/doc.html#sphinxse-using" target="_blank">Sphinx documentation for using sphinx storage engine</a></p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/08/05/mysql-how-do-you-enable-sphinxse-sphinx-storage-engine-in-your-mysql-installation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Linux:  yum options you may not know exist.</title>
		<link>http://crazytoon.com/2008/06/16/linux-yum-options-you-may-not-know-exist/</link>
		<comments>http://crazytoon.com/2008/06/16/linux-yum-options-you-may-not-know-exist/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 15:18:17 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=85</guid>
		<description><![CDATA[Most of the users who work with distributions such as: centos, fedora, redhat, etc use yum as a package update/installer.  Most of them know how to do &#8220;yum update [packagename]&#8221; (to update all or [certain packages]) or they do &#8220;yum install packagename&#8221; to install certain package(s).  But yum can do so much more. [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the users who work with distributions such as: centos, fedora, redhat, etc use yum as a package update/installer.  Most of them know how to do &#8220;yum update [packagename]&#8221; (to update all or [certain packages]) or they do &#8220;yum install packagename&#8221; to install certain package(s).  But yum can do so much more.  Here are some options you may find useful:</p>
<p>Following command will search for the string you specified.   Generally this will give you all of the packages which has specified string in title or description.  Most of the time you will have to look through a lot of output to find what you are looking for.</p>
<p><code>yum search string</code></p>
<p>Probably one of the most important options for yum is provides/whatprovides.  If you know what command you need, you can find out what package you have to install in order to have that command available to you.</p>
<p><code>yum provides (or whatprovides) command</code><br />
<code></code></p>
<p>Following command is same as above but with less output.</p>
<p><code> yum -d 1 provides command</code></p>
<p>So for example if you are trying to figure out what you need to install to use bunzip2, type:</p>
<p><code>yum -d 1 provides bunzip2</code></p>
<p>you will get a similar output as below.</p>
<p><code># yum -d 1 provides bunzip2<br />
bzip2.x86_64                             1.0.2-13.EL4.3         base<br />
bzip2.x86_64                             1.0.2-13.EL4.3         base<br />
man-pages-fr.noarch                      0.9.7-13.el4           base<br />
man-pages-ja.noarch                      20050215-2.EL4.3       base<br />
man-pages-pl.noarch                      0.23-5                 base</code></p>
<p>As you can see bunzip2 is part of bzip2 package.  So now you can you just install bzip2.x86_64 to get bunzip2.</p>
<p>To learn more about what else is available, <a title="man yum - man page for yum" href="http://www.lamp-tips.com/man-pages/yum/" target="_blank">read man yum</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/06/16/linux-yum-options-you-may-not-know-exist/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do I dump each record from a table to a separate files in csv format?</title>
		<link>http://crazytoon.com/2008/05/12/mysql-how-do-i-dump-export-each-record-from-table-separate-files-in-csv-format/</link>
		<comments>http://crazytoon.com/2008/05/12/mysql-how-do-i-dump-export-each-record-from-table-separate-files-in-csv-format/#comments</comments>
		<pubDate>Mon, 12 May 2008 08:45:14 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=70</guid>
		<description><![CDATA[I honestly do not know why somebody would want to export each record from a table in to its&#8217; own files in a csv format.  I am sure people have their own reasons.  But since I got request from couple people, I figure I would post a solution here.  Same script can [...]]]></description>
			<content:encoded><![CDATA[<p>I honestly do not know why somebody would want to export each record from a table in to its&#8217; own files in a csv format.  I am sure people have their own reasons.  But since I got request from couple people, I figure I would post a solution here.  Same script can be used to dump the whole table in to one csv file as well, with little tweaking.  I will start with creating database with a table.  I then insert three rows with test data into the table just to show three separate files creation.</p>
<p><code>mysql&gt; CREATE DATABASE testdump;<br />
mysql&gt; USE testdump<br />
mysql&gt; CREATE TABLE `testtable` (<br />
`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,<br />
`testfield` VARCHAR( 15 ) NOT NULL ,<br />
`testfield2` VARCHAR( 15 ) NOT NULL<br />
) ENGINE = innodb COMMENT = 'test table for dumping each row to file';<br />
mysql&gt; INSERT INTO `testtable` values ('','test1','test2'),('','test3','test4'),('','test5','test6');<br />
mysql&gt; select * from testtable;<br />
+----+-----------+------------+<br />
| id | testfield | testfield2 |<br />
+----+-----------+------------+<br />
|  1 | test1     | test2      |<br />
|  2 | test3     | test4      |<br />
|  3 | test5     | test6      |<br />
+----+-----------+------------+<br />
3 rows in set (0.00 sec)</code></p>
<p>Now we create a php script which we can use to select data from MySQL database and save it to a file under /tmp directory.  You can easily modify this script to save it somewhere else, pull from multiple tables and/or save with different delimiter.</p>
<p><code>&lt;?php<br />
$link = mysql_connect('localhost', 'username', 'password');<br />
if (!$link) {<br />
die('Could not connect: ' . mysql_error());<br />
}<br />
$db = mysql_select_db('testdump',$link);<br />
//specify what query to use to pull data.<br />
$select = "SELECT * FROM `testtable`";<br />
$result = mysql_query($select);<br />
while($myrow = mysql_fetch_array($result))<br />
{<br />
extract($myrow);<br />
//specify what query to use for create text files with csv data<br />
//in our case we create files with testtable_ and ID which is unique<br />
//per row.  We use the same ID in where clause to limit one record at a time<br />
//modify this part to your needs.  Eg change delimiter from , to - or something else<br />
$export = "<br />
SELECT * INTO OUTFILE '/tmp/testtable_$id.txt'<br />
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'<br />
LINES TERMINATED BY '\n'<br />
FROM testtable where id=$id";<br />
mysql_query($export);<br />
}//loop until we are done exporting all records.<br />
mysql_close($link);<br />
?&gt;</code></p>
<p>You can run this script from command line if you have php cli installed by issuing:  <code>php filename.php</code></p>
<p>Above example is a very simple example. t is merely a proof of concept.  You can modify it to do whatever you need it to do.  I would also put some error checking, not use extract() function, etc before using it in production environment.</p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/05/12/mysql-how-do-i-dump-export-each-record-from-table-separate-files-in-csv-format/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linux:  How do you rename a user account in linux?</title>
		<link>http://crazytoon.com/2008/05/09/linux-how-do-you-rename-a-user-account-in-linux/</link>
		<comments>http://crazytoon.com/2008/05/09/linux-how-do-you-rename-a-user-account-in-linux/#comments</comments>
		<pubDate>Fri, 09 May 2008 11:13:19 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=69</guid>
		<description><![CDATA[In Linux, there is no command which will rename a user account. If you make a mistake creating a user account, user changes their name or if user does not like his user name, there is no real easy way of going and making the change.  Only thing I know you can do is [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: line-through;">In Linux, there is no command which will rename a user account.</span> If you make a mistake creating a user account, user changes their name or if user does not like his user name, there is no real easy way of going and making the change.  Only thing I know you can do is to go through some files and rename user manually.  Let us say that we have a user who is named joe and we want to rename him to john.</p>
<p>Note:  you must be logged in as root to do following.</p>
<p>vi /etc/passwd<br />
find joe and change it to john, save/exit</p>
<p>vi /etc/group<br />
find joe and change it to john, save/exit</p>
<p>vi /etc/shadow<br />
find joe and change it to john.  This file is read only and you have to force overwrite it.  In vi it is :w!  once saved, quit.</p>
<p>cd /home<br />
mv joe john</p>
<p>And that should do the trick.</p>
<p>[Edited] Right after I posted this post, I was contacted and was told to look at utility called usermod.  Read more about it <a title="Man usermod:  man page for usermod" href="http://www.lamp-tips.com/man-pages/usermod/" target="_blank">man usermod</a>.  Got to love the quick responses.  </p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/05/09/linux-how-do-you-rename-a-user-account-in-linux/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do you use symlinks with MySQL tables?</title>
		<link>http://crazytoon.com/2008/05/02/mysql-how-do-you-use-symlinks-with-mysql-tables/</link>
		<comments>http://crazytoon.com/2008/05/02/mysql-how-do-you-use-symlinks-with-mysql-tables/#comments</comments>
		<pubDate>Fri, 02 May 2008 07:48:34 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql table symlinks]]></category>
		<category><![CDATA[symlinks]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=66</guid>
		<description><![CDATA[Creating table symlinks in MySQL is very easy and it is probably one of the features a lot of MySQL users overlook or never think about.  You may ask, why would I want to use symlinks? Some of the reasons you would want symlinks is if you are running low on disk space on [...]]]></description>
			<content:encoded><![CDATA[<p>Creating table symlinks in MySQL is very easy and it is probably one of the features a lot of MySQL users overlook or never think about.  You may ask, why would I want to use symlinks? Some of the reasons you would want symlinks is if you are running low on disk space on the partition where your data generally is and/or you want to move one (or more) table(s) on to a different disk/partition for performance reasons.</p>
<p>One of the things worth mentioning is that MySQL documentation states:  &#8220;Symlinks are fully supported only for MyISAM tables. For files used by tables for other storage engines, you may get strange problems if you try  to use symbolic links.&#8221;  Keeping that in mind, if you have a innodb table and would like to create symlinks for, you should change the engine type to myisam before symlinking. Although, I have heard and personally used symlinks for innodb databases with no side affects.</p>
<p>First let us find out if your MySQL configuration allows symlinks:</p>
<p><code class="literal">mysql&gt; SHOW VARIABLES LIKE 'have_symlink'\G<br />
*************************** 1. row ***************************<br />
Variable_name: have_symlink<br />
Value: YES</code></p>
<p>I am going to make following assumptions:</p>
<ul>
<li>MySQL installation is in /usr/local/mysql.</li>
<li>You want to create new tables under /mnt/another_partition/mysql/var
<ol>
<li>you must create the dir: mkdir /mnt/another_partition/mysql/var -p</li>
<li>Make it owned by mysql user:  chown mysql /mnt/another_partition/mysql/var</li>
</ol>
</li>
</ul>
<p>We will create some test data.  Following are the steps:</p>
<p><code>mysql&gt; create database db1;<br />
Query OK, 1 row affected (0.05 sec)<br />
mysql&gt; use db1;<br />
Database changed<br />
mysql&gt; CREATE TABLE `users` ( `id` int(11) default NULL, `name` varchar(255) default NULL ) ENGINE=myisam, <strong>data directory="/mnt/another_partition/mysql/var", index directory="/mnt/another_partition/mysql/var"</strong>;<br />
Query OK, 0 rows affected (0.09 sec)<br />
mysql&gt; show tables;<br />
+---------------+<br />
| Tables_in_db1 |<br />
+---------------+<br />
| users         |<br />
+---------------+</code></p>
<p>Drop back to command prompt and &#8220;ls&#8221; your db1 directory as shown below.  Here you can see that users table&#8217;s data file (users.MYD) is a symbolic link to the location we specified.  You can see that users index file (users.MYI) is symlinked to the location we specified as well.<br />
<code><br />
# ls -al /usr/local/mysql/var/db1/<br />
total 24K<br />
drwx------   2 mysql mysql 4.0K May  2 00:03 ./<br />
drwx------  23 mysql mysql 4.0K May  1 23:59 ../<br />
-rw-rw----   1 mysql mysql   65 May  1 09:33 db.opt<br />
-rw-rw----   1 mysql mysql 8.4K May  2 00:03 users.frm<br />
lrwxrwxrwx   1 mysql mysql   42 May  2 00:03 users.MYD -&gt; /mnt/another_partition/mysql/var/users.MYD<br />
lrwxrwxrwx   1 mysql mysql   42 May  2 00:03 users.MYI -&gt; /mnt/another_partition/mysql/var/users.MYI</code></p>
<p>Here are the real files which above symlinks are pointing to:</p>
<p><code># ls -al /mnt/another_partition/mysql/var/<br />
total 12K<br />
drwxr-xr-x  2 mysql root  4.0K May  2 00:03 ./<br />
drwxr-xr-x  3 root  root  4.0K May  1 23:39 ../<br />
-rw-rw----  1 mysql mysql    <strong>0</strong> May  2 00:03 users.MYD<br />
-rw-rw----  1 mysql mysql 1.0K May  2 00:03 users.MYI</code></p>
<p>If you go back in to mysql prompt and insert couple rows, you can see the size of users.MYD increase:</p>
<p><code>mysql&gt; insert into db1.users values (1,"test1");<br />
Query OK, 1 row affected (0.01 sec)<br />
mysql&gt; insert into db1.users values (2,"test2");<br />
Query OK, 1 row affected (0.01 sec)<br />
# ls -al /mnt/another_partition/mysql/var/<br />
total 16K<br />
drwxr-xr-x  2 mysql root  4.0K May  2 00:03 ./<br />
drwxr-xr-x  3 root  root  4.0K May  1 23:39 ../<br />
-rw-rw----  1 mysql mysql   <strong>40</strong> May  2 00:08 users.MYD<br />
-rw-rw----  1 mysql mysql 1.0K May  2 00:08 users.MYI</code></p>
<p>If you already have data file and index file you would like to move, I recommend shutting down your MySQL server and moving the files manually and create symbolic links by using &#8220;ln -s&#8221; command.  You can read more about ln by doing <a title="man ln:  man page for ln" href="http://www.lamp-tips.com/man-pages/ln/" target="_blank">man ls</a></p>
<p><strong>NOTE: </strong>Even though MySQL documentation says this is only supported 100% for myisam tables, I  have read few posts where people say they have done this with innodb tables without any problems.  If anybody else can comment on this, I would greatly appreciate it.</p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/05/02/mysql-how-do-you-use-symlinks-with-mysql-tables/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>MySQL: Solution for ERROR 1442 (HY000): Can&#8217;t update table &#8216;t1&#8242; in stored function/trigger because it is already used by statement which invoked this stored function/trigger.</title>
		<link>http://crazytoon.com/2008/03/03/mysql-error-1442-hy000-cant-update-table-t1-in-stored-functiontrigger-because-it-is-already-used-by-statement-which-invoked-this-stored-functiontrigger/</link>
		<comments>http://crazytoon.com/2008/03/03/mysql-error-1442-hy000-cant-update-table-t1-in-stored-functiontrigger-because-it-is-already-used-by-statement-which-invoked-this-stored-functiontrigger/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 02:42:02 +0000</pubDate>
		<dc:creator>Tracy</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL Triggers]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2008/03/03/mysql-error-1442-hy000-cant-update-table-t1-in-stored-functiontrigger-because-it-is-already-used-by-statement-which-invoked-this-stored-functiontrigger/</guid>
		<description><![CDATA[Here is a sample table you can create to test following problem/solution on:
CREATE TABLE `t1` (
`a` char(1) default NULL,
`b` smallint(6) default NULL
);
insert into t1 values ('y','1');
I have a table t1 which has column a and b, I want column a to be updated to &#8216;n&#8217; when column b = 0. Here is the first version [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a sample table you can create to test following problem/solution on:</p>
<p><code>CREATE TABLE `t1` (<br />
`a` char(1) default NULL,<br />
`b` smallint(6) default NULL<br />
);<br />
insert into t1 values ('y','1');</code></p>
<p>I have a table t1 which has column a and b, I want column a to be updated to &#8216;n&#8217; when column b = 0. Here is the first version I created:</p>
<p><code>DELIMITER |<br />
CREATE TRIGGER trigger1 AFTER UPDATE ON t1<br />
FOR EACH ROW UPDATE t1 SET a= 'n' WHERE b=0;<br />
|<br />
DELIMITER ;</code></p>
<p>The trigger created successfully but I got this error when I tried to do an update on column b on table t1:<br />
<code>mysql&gt; update t1 set b=0;<br />
ERROR 1442 (HY000): Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.<br />
</code></p>
<p>After searching online for a while and trying different solutions, I finally found a way to update the table which has trigger on it:<br />
<code><br />
drop trigger trigger1;<br />
DELIMITER |<br />
CREATE TRIGGER trigger1 BEFORE UPDATE ON t1<br />
FOR EACH ROW<br />
BEGIN<br />
IF NEW.b=0 THEN<br />
SET NEW.a = 'n';<br />
END IF;<br />
END<br />
|<br />
DELIMITER ;</code></p>
<p>After the new trigger is in, I issued the same update query and &#8220;<small>ERROR 1442 (HY000): Can&#8217;t update table &#8216;t1&#8242; in stored function/trigger because it is already used by statement which invoked this stored function/trigger.</small>&#8221;  didn&#8217;t show up and it updated the col a value to &#8220;n&#8221; as it suppose to.</p>
<p><code>mysql&gt; update t1 set b=0;<br />
Query OK, 1 row affected (0.01 sec)<br />
Rows matched: 1  Changed: 1  Warnings: 0<br />
mysql&gt; select * from t1\G<br />
*************************** 1. row ***************************<br />
a: <strong>n</strong><br />
b: 0</code></p>
<p>Therefore, if you want to create a trigger on the table which will update itself, make sure you use the NEW.column_name to refer to the row after it&#8217;s updated and don&#8217;t do the full update statement!</p>
<p>However, if you are updating some other table, then you can use the regular update statement:</p>
<p><code>DELIMITER |<br />
CREATE TRIGGER trigger1 AFTER UPDATE ON <strong>t1 </strong><br />
FOR EACH ROW UPDATE<strong> t2 </strong>SET a= 'n' WHERE b=0;<br />
|<br />
DELIMITER ;</code></p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/03/03/mysql-error-1442-hy000-cant-update-table-t1-in-stored-functiontrigger-because-it-is-already-used-by-statement-which-invoked-this-stored-functiontrigger/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>MySQL: How do you set up master-master replication in MySQL? (CentOS, RHEL, Fedora)</title>
		<link>http://crazytoon.com/2008/02/29/mysql-how-do-you-set-up-mastermaster-replication-in-mysql-centos-rhel-fedora/</link>
		<comments>http://crazytoon.com/2008/02/29/mysql-how-do-you-set-up-mastermaster-replication-in-mysql-centos-rhel-fedora/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 21:40:02 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL cluster]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2008/02/29/mysql-how-do-you-set-up-mastermaster-replication-in-mysql-centos-rhel-fedora/</guid>
		<description><![CDATA[Setting up master-master replication in MySQL is very similar to how we set up master/slave replication.  You can read up about how to setup master/slave replication in my previous post: How to set up master/slave replication in MySQL.  There is obviously pros and cons about using master/master replication.  But this is not [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up master-master replication in MySQL is very similar to how we <a href="http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/">set up master/slave replication</a>.  You can read up about how to setup master/slave replication in my previous post: <a href="http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/" title="How to set up master/slave replication in MySQL" target="_blank">How to set up master/slave replication in MySQL</a>.  There is obviously pros and cons about using master/master replication.  But this is not a post which discuses advantages and disadvantages for using master/master replication. One of the differences between master/master set up and master/slave is that in master/master set up, you have true redundancy.  If one server dies, second server can take all the inserts/selects.  In master/slave setup, if master dies, you will have to go through steps to make slave become the master.  Master/master set up we are going to set up is essentially master/slave and slave/master.  Meaning, if you had two servers, db0 and db1, your setup will be db0(master)/db1(slave) and also db0(slave)/db1(master).  Here are some assumptions:</p>
<p><code>Master1 server ip:  10.0.0.1<br />
Master2 server ip:  10.0.0.2<br />
Slave username:  slaveuser<br />
Slave pw:  slavepw<br />
Your data directory is:  /usr/local/mysql/var/</code></p>
<p>Let us go through the steps you must take on Master1 to enable it to act as master and slave by using following configuration which goes  under [mysqld] section:</p>
<p><code># let's make it so auto increment columns behave by having different increments on both servers<br />
auto_increment_increment=2<br />
auto_increment_offset=1<br />
# Replication Master Server<br />
# binary logging is required for replication<br />
log-bin=master1-bin<br />
binlog-ignore-db=mysql<br />
binlog-ignore-db=test<br />
# required unique id between 1 and 2^32 - 1<br />
server-id       = 1<br />
#following is the slave settings so this server can connect to master2<br />
master-host = 10.0.0.2<br />
master-user = slaveuser<br />
master-password = slavepw<br />
master-port = 3306</code></p>
<p>Following is the configuration which goes on master2 under [mysqld] section:</p>
<p><code># let's make it so auto increment columns behave by having different increments on both servers<br />
auto_increment_increment=2<br />
auto_increment_offset=2<br />
# Replication Master Server<br />
# binary logging is required for replication<br />
log-bin=master2-bin<br />
binlog-ignore-db=mysql<br />
binlog-ignore-db=test<br />
# required unique id between 1 and 2^32 - 1<br />
server-id       = 2<br />
#following is the slave settings so this server can connect to master2<br />
master-host = 10.0.0.1<br />
master-user = slaveuser<br />
master-password = slavepw<br />
master-port = 3306</code></p>
<p>On master1 server, go to mysql&gt; prompt and add the appropriate user:</p>
<p><code>mysql&gt; grant replication slave on *.* to slaveuser@'10.0.0.2' identified by 'slavepw';</code></p>
<p>On master2 server do the same but allow right ip:</p>
<p><code>mysql&gt; grant replication slave on *.* to slaveuser@'10.0.0.1' identified by 'slavepw';</code></p>
<p>Restart both of the master servers and check slave status:</p>
<p><code>mysql&gt; show slave status\G</code></p>
<p>That is all you have to do to set up the replication.  Of course there are a lot more configuration options but this should get your replication going and you can tweak from here on.</p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/02/29/mysql-how-do-you-set-up-mastermaster-replication-in-mysql-centos-rhel-fedora/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do you set up master-slave replication in MySQL? (CentOS, RHEL, Fedora)</title>
		<link>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/</link>
		<comments>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 03:12:57 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[MySQL cluster]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/</guid>
		<description><![CDATA[Before we go into how to set up master-slave replication in MySQL, let us talk about some of the reasons I have set up master-slave replication using MySQL.
1)    Offload some of the queries from one server to another and spread the load:  One of the biggest advantages to have master-slave set [...]]]></description>
			<content:encoded><![CDATA[<p>Before we go into how to set up master-slave replication in MySQL, let us talk about some of the reasons I have set up master-slave replication using MySQL.</p>
<p>1)    Offload some of the queries from one server to another and spread the load:  One of the biggest advantages to have master-slave set up in MySQL is to be able to use master for all of the inserts and send some, if not all, select queries to slave.  This will most probably speed up your application without having to diving into optimizing all the queries or buying more hardware.</p>
<p>2)    Do backups from slave:  One of the advantages people overlook is that you can use MySQL slave to do backups from.  That way site is not affected at all when doing backups.  This becomes a big deal when your database has grown to multiple gigs and every time you do backups using mysqldump, site lags when table locks happen.  For some sites, this could mean that site goes down for few secs to minutes.  If you have slave, you just take slave out of rotation (should be built into code) and run backups off the slave.  You can even stop slave MySQL instance and copy the var folder instead of doing mysqldump.</p>
<p>Ok let us dive into how to setup master-slave replication under MySQL.  There are many configuration changes you can do to optimize your MySQL set up.  I will just touch on very basic ones to get the replication to work.  Here are some assumptions:</p>
<blockquote><p>Master server ip:  10.0.0.1<br />
Slave server ip:  10.0.0.2<br />
Slave username:  slaveuser<br />
Slave pw:  slavepw<br />
Your data directory is:  /usr/local/mysql/var/</p></blockquote>
<p>Put the following in your master my.cnf file under [mysqld] section:</p>
<p><code># changes made to do master<br />
server-id           = 1<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
log-bin             = /usr/local/mysql/var/mysql-bin<br />
# end master</code></p>
<p>Copy the following to slave&#8217;s my.cnf under [mysqld] section:</p>
<p><code># changes made to do slave<br />
server-id           = 2<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
# end slave setup</code></p>
<p>Create user on master:<br />
<code>mysql&gt; grant replication slave on *.* to slaveuser@'10.0.0.2' identified by 'slavepw';</code></p>
<p>Do a dump of data to move to slave<br />
<code>mysqldump -u root --all-databases --single-transaction --master-data=1 &gt; masterdump.sql</code></p>
<p>import dump on slave<br />
<code>mysql &lt; masterdump.sql</code></p>
<p>After dump is imported go in to mysql client by typing mysql.  Let us tell the slave which master to connect to and what login/password to use:<br />
<code>mysql&gt; CHANGE MASTER TO MASTER_HOST='10.0.0.1',  MASTER_USER='slaveuser', MASTER_PASSWORD='slavepw';</code></p>
<p>Let us start the slave:<br />
<code>mysql&gt; start slave;</code></p>
<p>You can check the status of the slave by typing<br />
<code>mysql&gt; show slave status\G</code></p>
<p>The last row tells you how many seconds its behind the master.  Don’t worry if it doesn’t say 0, the number should be going down over time until it catches up with master (at that time it will show Seconds_Behind_Master: 0)  If it shows NULL, it could be that slave is not started (you can start by typing:  start slave) or it could be that it ran into an error (shows up in Last_errno: and Last_error under show slave status\G).</p>
<p>Related posts:</p>
<ul>
<li><a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" title="How do I dump all tables in a database into separate files?" target="_blank">How do I dump all tables in a database into separate files?</a></li>
<li><a href="http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/" title="How do I import individual table dump files in to MySQL using shell script?" target="_blank">How do I import individual table dump files in to MySQL using shell script?</a></li>
<li><a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL backups using mysqldump" target="_blank">MySQL backups using mysqldump</a></li>
</ul>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Memcached:  How do you install memcached?  (CentOS 64 bit, Linux, Redhat, Fedora)</title>
		<link>http://crazytoon.com/2008/01/20/memcached-how-do-you-install-memcached-centos-64-bit-linux-redhat-fedora/</link>
		<comments>http://crazytoon.com/2008/01/20/memcached-how-do-you-install-memcached-centos-64-bit-linux-redhat-fedora/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 22:52:32 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Caching]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2008/01/20/memcached-how-do-you-install-memcached-centos-64-bit-linux-redhat-fedora/</guid>
		<description><![CDATA[ [updated 5/16/2010]
Memcached is a very popular open source object caching server.  It was developed to speed up livejournal.com by Danga Interactive.  We use memcached for a lot of our sites.  We use it for different purposes but one main purpose is to cache query results so we don&#8217;t have to keep hitting database.  [...]]]></description>
			<content:encoded><![CDATA[<p> [updated 5/16/2010]</p>
<p>Memcached is a very popular open source object caching server.  It was developed to speed up livejournal.com by Danga Interactive.  We use memcached for a lot of our sites.  We use it for different purposes but one main purpose is to cache query results so we don&#8217;t have to keep hitting database.  As most of the people who work with databases know it is costly to keep hitting database for same information over and over.</p>
<p>When you run the Memcached daemon, it runs and listens on a specific port.  One of the things Memcached does lack is security.  Memcached will let anybody who can make a connection to its port have full access to all objects.  So you would have to run a firewall to block unauthorized access.  It is usually wise to do put firewall on it even if you trust everybody on the same network since accidents do happen.  That said, let&#8217;s get memcached installed!</p>
<p>Let&#8217;s get libevent which is required by Memcached:</p>
<p>wget http://monkey.org/~provos/libevent-1.3e.tar.gz<br />
tar zxpfv libevent*<br />
cd libevent*<br />
./configure<br />
make install</p>
<p>Now let&#8217;s download the newest Memcached source (at time of update to this post 1.4.5 was the latest)</p>
<p>wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz<br />
tar zxpfv memcached*<br />
cd memcached*<br />
./configure<br />
make install</p>
<p>Let&#8217;s add Memcached user to run daemon as since we don&#8217;t need it to run as root privileges.</p>
<p>adduser memcached</p>
<p>We will start the server to use 48 megs of ram (-m 48), listen on ip 10.0.0.2 (-l 10.0.0.2) and run on port 11211 (-p 11211) as user memcached (-u memcached)</p>
<p>./memcached -u memcached -d -m 48 -l 10.0.0.2 -p 11211</p>
<p>If you get the following error (which you will get if you are doing this under CentOS 64 bit):</p>
<p>./memcached: error while loading shared libraries: libevent-1.3e.so.1: cannot open shared object file: No such file or directory</p>
<p>You can fix this by simply doing this:</p>
<p>ln -s /usr/local/lib/libevent-1.3e.so.1 /lib64/</p>
<p>That is all there is to it.  You can see if daemon is running by telneting to the port.</p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/01/20/memcached-how-do-you-install-memcached-centos-64-bit-linux-redhat-fedora/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>PHP:  How do I install phpsh, interactive shell prompt for php under CentOS or Fedora?</title>
		<link>http://crazytoon.com/2007/12/11/php-how-do-i-install-phpsh-interactive-shell-prompt-for-php-under-centos-or-fedora/</link>
		<comments>http://crazytoon.com/2007/12/11/php-how-do-i-install-phpsh-interactive-shell-prompt-for-php-under-centos-or-fedora/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 08:26:48 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/12/11/php-how-do-i-install-phpsh-interactive-shell-prompt-for-php-under-centos-or-fedora/</guid>
		<description><![CDATA[phpsh requires readline support built into python.  It also requires python version 2.4+. You can check which version of python you have installed by typing:
python -V
Let us download and install readline:
wget ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz
tar zxf readline-5.2.tar.gz
cd readline-5.2
./configure
make install
Now let us install python with readline support:

wget http://www.python.org/ftp/python/2.5.1/Python-2.5.1.tgz
tar zxf Python-2.5.1.tgz
cd Python-2.5.1

I had some problems on one of the [...]]]></description>
			<content:encoded><![CDATA[<p>phpsh requires readline support built into python.  It also requires python version 2.4+. You can check which version of python you have installed by typing:</p>
<p><code>python -V</code></p>
<p>Let us download and install readline:</p>
<p><code>wget ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz<br />
tar zxf readline-5.2.tar.gz<br />
cd readline-5.2<br />
./configure<br />
make install</code></p>
<p>Now let us install python with readline support:<br />
<code><br />
wget http://www.python.org/ftp/python/2.5.1/Python-2.5.1.tgz<br />
tar zxf Python-2.5.1.tgz<br />
cd Python-2.5.1<br />
</code></p>
<p>I had some problems on one of the servers where it would not compile readline support in to python.  I was able to compile reading support in to python by:</p>
<p><code>echo "readline readline.c -lreadline -ltermcap" &gt;&gt; Modules/Setup.local</code></p>
<p>Now let us continue with python installation.</p>
<p><code>./configure --prefix=/usr/local/python-2.5.1 --enable-readline<br />
make -i install</code></p>
<p>If you do not do &#8220;make -i install&#8221;, install may fail with following error (-i means ignore any errors):<br />
<code>Compiling /usr/lib/python2.5/zipfile.py ...<br />
make: *** [libinstall] Error 1</code></p>
<p>If you scroll up, you will find following error which seems to be the root cause:</p>
<p><code>Compiling /usr/lib/python2.5/test/test_multibytecodec.py ...<br />
Sorry: UnicodeError: ("\\N escapes not supported (can't load unicodedata module)",)</code></p>
<p>Once you do python install with make -i install, that library (unicodedata.so which is not built until later stage of build process) gets installed.  If you want, you can type make install once again (without ignoring errors) and it will complete without errors.</p>
<p>Once you have python installed, you would want to use the new version.  I like to keep a backup of old files in case I have to use older version for any reason.  Run following which creates symbolic links and makes backups of current files:</p>
<p><code>for binaries in `find /usr/local/python-2.5.1/bin/*` ; do<br />
mv /usr/bin/`basename ${binaries}` /usr/bin/`basename ${binaries}`.bak<br />
ln -s ${binaries} /usr/bin/`basename ${binaries}`<br />
done</code></p>
<p>Now let us get phpsh and try it out:</p>
<p><code>wget http://www.phpsh.org/phpsh-latest.tgz<br />
tar zxf phpsh-latest.tgz<br />
cd ../phpsh<br />
chmod +x phpsh<br />
./phpsh</code></p>
<p>At this point you should be at the shell:  php&gt;</p>
<p>Following is a snippet from README file which comes with phpsh.  You should take a look since it has more details on how to use phpsh:</p>
<p><code>Type php commands and they will be evaluated each time you hit enter. Ex:<br />
php&gt; $msg = "hello world"<br />
Put = at the beginning of a line as syntactic sugar for return. Ex:<br />
php&gt; = 2 + 2<br />
If you end a line with a backlash (\), you can enter multi-line input.<br />
For example,<br />
php&gt; print "like \<br />
... this"<br />
like   this<br />
php&gt;</code></p>
<p>There we go.  Now you have a great interactive php shell prompt.  Note that there is interactive mode built into php as well.  I personally do not like it as much but you can try it out for yourself by typing:</p>
<p><code>php -a<br />
Interactive mode enabled<br />
echo "Hello world";<br />
Hello world</code></p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/12/11/php-how-do-i-install-phpsh-interactive-shell-prompt-for-php-under-centos-or-fedora/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do I import individual table dump files in to MySQL using shell script?</title>
		<link>http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/</link>
		<comments>http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 03:35:49 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[Notes for self]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/</guid>
		<description><![CDATA[After I wrote the post: How do I dump all tables in a database into separate files? I got emails from couple people asking how to import the individual table files back in to MySQL.  First way to import each sql file created by  the post is to import each file individually by [...]]]></description>
			<content:encoded><![CDATA[<p>After I wrote the post: <a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" rel="bookmark" title="MySQL:  How do I dump all tables in a database into separate files?">How do I dump all tables in a database into separate files?</a> I got emails from couple people asking how to import the individual table files back in to MySQL.  First way to import each sql file created by  <a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" rel="bookmark" title="MySQL:  How do I dump all tables in a database into separate files?">the post</a> is to import each file individually by typing:<code>mysql db_name &lt; table1.sql</code>  This will work as long as you are only importing few files.  But if you need to import all of the files in the directory, which could be in 100&#8217;s, this method does not scale well.  To achieve this I wrote a shell script which does the work for me.  Of course, there are other ways to do this and I am only showing you one way of doing it.  This works for me so here it is:</p>
<p><code>#!/bin/bash<br />
db=$1<br />
if [ "$db" = "" ]; then<br />
echo "Usage: $0 db_name"<br />
exit 1<br />
fi<br />
mkdir done<br />
clear<br />
for sql_file in *.sql; do<br />
echo "Importing $sql_file";<br />
mysql $db&lt; $sql_file;<br />
mv $sql_file done;<br />
done</code></p>
<p>Related posts:</p>
<ul>
<li><a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" title="How do I dump all tables in a database into separate files?" target="_blank">How do I dump all tables in a database into separate files?</a></li>
<li><a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL backups using mysqldump" target="_blank">MySQL backups using mysqldump</a></li>
</ul>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Linux:  How do I mass find and replace text in files under linux using perl?</title>
		<link>http://crazytoon.com/2007/10/29/linux-how-do-i-mass-find-and-replace-text-in-files-under-linux-using-perl/</link>
		<comments>http://crazytoon.com/2007/10/29/linux-how-do-i-mass-find-and-replace-text-in-files-under-linux-using-perl/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 07:00:08 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/10/29/linux-how-do-i-mass-find-and-replace-text-in-files-under-linux-using-perl/</guid>
		<description><![CDATA[Few friends have asked me how to do mass find and replace text in files under linux.  There are quite a bit of options in linux to achieve mass replacing of text in files.  If you are doing it file by file, you can achieve that in vi by opening, running replace and [...]]]></description>
			<content:encoded><![CDATA[<p>Few friends have asked me how to do mass find and replace text in files under linux.  There are quite a bit of options in linux to achieve mass replacing of text in files.  If you are doing it file by file, you can achieve that in vi by opening, running replace and closing and going to next file.  But sometimes that can be very tedious and you would rather do mass replacement on all files containing certain extension.  We can do this by using sed or perl.  Since most people are familiar with perl (at least most system admins and programmers), I will show you a perl way of doing it which you can use with sed as well if you wish.  First step is to get perl to do what we want on one file</p>
<p><code>perl -w -i -p -e "s/search_text/replace_text/g" filename</code></p>
<p>-w turns warnings on<br />
-i  makes Perl operate on files in-place (if you would like to make backups, use -i.bak, this will save filename.bak files)<br />
-p loops over the whole input<br />
-e specifies Perl expression<br />
filename  works on one file at a time</p>
<p>Once we get the results we want, we can now pass it multiple files by doing something like:</p>
<p><code>perl -w -i -p -e "s/search_text/replace_text/g" *.php</code></p>
<p>This will search and replace within all php files in the directory you are in.</p>
<p>Now, let us say you want to go through your whole web directory and replace every place where you have &#8220;Perl is good&#8221; to &#8220;Perl is great&#8221;, you would use following command:</p>
<p><code>find /www_root -name "*.php"|xargs  perl -w -i -p -e "s/Perl is good/perl is great/g"</code></p>
<p>find will start at /www_root, look for filenames which have .php extension, xargs takes that filename and passes it to perl as an arguement.</p>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/10/29/linux-how-do-i-mass-find-and-replace-text-in-files-under-linux-using-perl/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Linux virus scan:  How do I check my linux installation for viruses using ClamAV? (CentOS, Linux, Redhat)</title>
		<link>http://crazytoon.com/2007/10/19/linux-virus-scan-how-do-i-check-my-linux-installation-for-viruses-using-clamav-centos-linux-redhat/</link>
		<comments>http://crazytoon.com/2007/10/19/linux-virus-scan-how-do-i-check-my-linux-installation-for-viruses-using-clamav-centos-linux-redhat/#comments</comments>
		<pubDate>Sat, 20 Oct 2007 03:50:32 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/10/19/linux-virus-scan-how-do-i-check-my-linux-installation-for-viruses-using-clamav-centos-linux-redhat/</guid>
		<description><![CDATA[There are quite a bit of antivirus software exist for Linux nowadays.  One of the popular antivirus software is ClamAV.  We will install Clam AntiVirus software from source and install it to a custom directory.  We will also install gmp-devel package which installs GMP library.  GMP library is used to verify [...]]]></description>
			<content:encoded><![CDATA[<p>There are quite a bit of antivirus software exist for Linux nowadays.  One of the popular antivirus software is <a href="http://www.clamav.org/" title="ClamAV website" target="_blank">ClamAV</a>.  We will install Clam AntiVirus software from source and install it to a custom directory.  We will also install gmp-devel package which installs GMP library.  GMP library is used to verify the digital signature of the virus database.</p>
<p><code>yum -y install gmp-devel<br />
wget http://freshmeat.net/redir/clamav/29355/url_tgz/clamav-0.91.2.tar.gz<br />
adduser -M -s /bin/false clamav<br />
tar zxf clamav-0.91.2.tar.gz<br />
cd clamav-0.91.2<br />
./configure --prefix=/usr/local/clamav<br />
make install<br />
for binaries in `find /usr/local/clamav/bin/*` ; do ln -s ${binaries} /usr/bin/; done</code></p>
<p>At this point Clam AntiVirus is installed and ready for use.   Edit the configuration file and remove the line which says: Example  It is there to ensure.  If you want, you can look at other options but we don&#8217;t need to change anything else here to make ClamAV work for us.</p>
<p><code>vi /usr/local/clamav/etc/freshclam.conf #remove Example</code></p>
<p>Now let us run the <em>freshclam </em>which will download virus database and bring our virus database up to date.   We should do this manually and make sure it didn&#8217;t give any errors.  If this works, you will a lot of &#8220;downloading&#8221; messages.</p>
<p><code>/usr/bin/freshclam</code></p>
<p>If everything checks out, let us add this to our crontab to ensure our virus database is updated hourly.  I chose to be updated every 9 minutes in to every hour.  You can change to fit your needs or leave it as it is.<br />
<code><br />
crontab -e</code></p>
<p>9 * * * *       /usr/bin/freshclam &#8211;quiet</p>
<p>At this point our ClamAV virus database is up to date and now we can scan whichever directory we want.  Go to the directory you want to scan and type:</p>
<p><code>clamscan -r -i</code></p>
<p>Once it is done scanning, it will display something similar to below.<br />
-r parameter tells clamscan to recurse into directories<br />
-i will print out infected filenames</p>
<p><code>----------- SCAN SUMMARY -----------<br />
Known viruses: 159855<br />
Engine version: 0.91.2<br />
Scanned directories: 1437<br />
Scanned files: 8836<br />
Infected files: 0<br />
Data scanned: 464.83 MB<br />
Time: 103.678 sec (1 m 43 s)</code></p>
<p>Happy scanning!<br />
————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/10/19/linux-virus-scan-how-do-i-check-my-linux-installation-for-viruses-using-clamav-centos-linux-redhat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL:  Slave lag behind master and data corruption.</title>
		<link>http://crazytoon.com/2007/10/15/mysql-slave-lag-behind-master-and-data-corruption/</link>
		<comments>http://crazytoon.com/2007/10/15/mysql-slave-lag-behind-master-and-data-corruption/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 00:09:10 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/10/15/mysql-slave-lag-behind-master-and-data-corruption/</guid>
		<description><![CDATA[I am reaching out to mysql experts out there!  We just inherited a site which uses MySQL master/slave replication.  We set up the master and slaves per MySQL documents and did some of our own tweaking in my.cnf to get things working.  Things were great when we were testing the site but [...]]]></description>
			<content:encoded><![CDATA[<p>I am reaching out to mysql experts out there!  We just inherited a site which uses MySQL master/slave replication.  We set up the master and slaves per MySQL documents and did some of our own tweaking in my.cnf to get things working.  Things were great when we were testing the site but than after we put it up, we started to notice missing data on slaves.  At first, we thought maybe we missed something with the import of data on slaves, so we re-imported.  All tables in our db, at that time, were myisam.  After a day or so, we started to see data corruption on some of the slaves.   We went through and repaired all the tables.  Few hours after the repair, we checked row counts and the repaired tables didn&#8217;t have same count as master did.   Eventually most of our slaves were at the same state so we decided to re-import data from master again.</p>
<p>Before we went ahead and re-imported, we made a decision to move to innodb for *most* of our crucial tables.  After altering on master, we did a dump/import.  Converting tables to innodb got rid of our data corruption problem but our missing rows issue is still there.  Hardware on the master is 4&#215;1.86Ghz, 8 gigs of ram; slaves hardware is: 4&#215;1.86, 4 gigs of ram.</p>
<p>Here is the config running on our master:<br />
<code>&lt; some of the part of the config has been cut off to keep it short/simple and to the point &gt;<br />
skip-locking<br />
ft_min_word_len=2<br />
long_query_time=30<br />
max_connect_errors=10000<br />
max_connections=1000<br />
#skip-grant-tables<br />
skip-bdb<br />
delay-key-write=ALL<br />
key_buffer = 1G<br />
read_buffer_size = 2M<br />
read_rnd_buffer_size = 8M<br />
myisam_sort_buffer_size = 64M<br />
thread_concurrency = 8<br />
skip-name-resolve<br />
max_allowed_packet = 32M<br />
#low-priority-updates<br />
table_cache = 1024<br />
thread_cache = 8<br />
query_cache_size = 64M<br />
#<br />
# added by sunny &gt;<br />
wait_timeout = 120<br />
tmp_table_size = 128M<br />
sort_buffer_size = 128M   # Sort buffer is used to perform sorts for some ORDER BY and GROUP BY queries.<br />
read_rnd_buffer_size = 8M # Read the rows in sorted order by using the row<br />
# pointers in the result file. To optimize this,<br />
# we read in a big block of row pointers, sort them,<br />
# and use them to read the rows in sorted order into a row buffer.<br />
thread_cache_size = 8<br />
#<br />
# Try number of CPU's*2 for thread_concurrency<br />
thread_concurrency = 16<br />
log_slow_queries<br />
log_long_format<br />
#<br />
# INNODB Settings<br />
innodb_additional_mem_pool_size = 32M # was 16<br />
innodb_buffer_pool_size = 4G<br />
innodb_file_per_table<br />
innodb_log_file_size = 50M<br />
innodb_log_buffer_size = 8M<br />
innodb_flush_log_at_trx_commit = 0<br />
innodb_lock_wait_timeout = 50<br />
innodb_flush_method=O_DIRECT</code></p>
<p>Here is the config running on our slave:</p>
<p><code># The MySQL server<br />
[mysqld]<br />
port                = 3306<br />
socket              = /tmp/mysql1.sock<br />
pid-file            = /usr/local/mysql/var/mysql.pid<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
server-id           = 31<br />
skip-slave-start<br />
skip-locking<br />
skip-name-resolve<br />
ft_min_word_len=2<br />
long_query_time=30<br />
max_connect_errors=10000<br />
max_connections=1000<br />
#skip-grant-tables<br />
skip-bdb<br />
delay-key-write=ALL<br />
key_buffer = 512M<br />
max_allowed_packet = 1M<br />
table_cache = 512M<br />
myisam_sort_buffer_size = 64M<br />
thread_cache_size = 4<br />
read-only<br />
#slave-skip-errors=all<br />
#<br />
# added by sunny &gt;<br />
wait_timeout = 120<br />
tmp_table_size = 128M<br />
read_buffer_size = 2M<br />
sort_buffer_size = 128M   # Sort buffer is used to perform sorts for some ORDER BY and GROUP BY queries.<br />
read_rnd_buffer_size = 8M # Read the rows in sorted order by using the row<br />
# pointers in the result file. To optimize this,<br />
# we read in a big block of row pointers, sort them,<br />
# and use them to read the rows in sorted order into a row buffer.<br />
thread_cache_size = 8<br />
query_cache_size =  16M # changed to 16 3/1/07<br />
#<br />
# Try number of CPU's*2 for thread_concurrency<br />
thread_concurrency = 8<br />
log_slow_queries<br />
log_long_format<br />
#<br />
# INNODB Settings<br />
default_table_type = INNODB<br />
innodb_additional_mem_pool_size = 32M # was 16<br />
innodb_buffer_pool_size = 2G<br />
innodb_file_per_table<br />
innodb_log_file_size = 50M<br />
innodb_log_buffer_size = 8M<br />
innodb_flush_log_at_trx_commit = 0<br />
innodb_lock_wait_timeout = 50<br />
innodb_flush_method=O_DIRECT</code></p>
<p>Please feel free to comment/scrutinize any of these settings.  If you think they should be different, please give quick summary about why they should be different.  Some of these settings were inherited from old setup of mysql (where they had it hosted before).</p>
<p>Right now we are just trying to find out why we have missing rows and why our slaves lag behind constantly.  We have refreshed data almost every day for last two weeks.  We barely have load average above 1 or 2.  What can we do to track down the problem?   What are the things we should be looking out for?</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/10/15/mysql-slave-lag-behind-master-and-data-corruption/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do I reset MySQL to have only the databases when I first installed it? (CentOS, Redhat, Fedora, Linux)</title>
		<link>http://crazytoon.com/2007/09/13/mysql-reset-mysql-have-only-databases-when-first-installed-centos-redhat-fedora-linux/</link>
		<comments>http://crazytoon.com/2007/09/13/mysql-reset-mysql-have-only-databases-when-first-installed-centos-redhat-fedora-linux/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 06:44:07 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/09/13/mysql-how-do-i-reset-mysql-to-have-only-the-databases-when-i-first-installed-it-centos-redhat-fedora-linux/</guid>
		<description><![CDATA[One of my clients asked me today to make their MySQL installation go back to default database install.  Basically they wanted me to get rid of all their databases (in this case test databases) so they can start fresh and go live with only the databases they needed.  So here are the steps [...]]]></description>
			<content:encoded><![CDATA[<p>One of my clients asked me today to make their MySQL installation go back to default database install.  Basically they wanted me to get rid of all their databases (in this case test databases) so they can start fresh and go live with only the databases they needed.  So here are the steps I followed.</p>
<p>Note:  I have installed their MySQL from source and installed MySQL in to /usr/local/mysql folder.  Your installation path might be different.</p>
<p><code>service mysql stop<br />
cd /usr/local/mysql<br />
mv var var.bak<br />
mkdir var<br />
bin/mysql_install_db<br />
chown -R mysql.mysql  var<br />
chmod 700 -R var<br />
service mysql start<br />
</code><br />
At this point we should have fresh MySQL db setup.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/09/13/mysql-reset-mysql-have-only-databases-when-first-installed-centos-redhat-fedora-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Subversion (SVN):  How do you set up backup for your Subversion repositories?</title>
		<link>http://crazytoon.com/2007/08/16/subversion-svn-how-do-you-set-up-backup-for-your-subversion-repositories/</link>
		<comments>http://crazytoon.com/2007/08/16/subversion-svn-how-do-you-set-up-backup-for-your-subversion-repositories/#comments</comments>
		<pubDate>Fri, 17 Aug 2007 01:00:51 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/08/16/subversion-svn-how-do-you-set-up-backup-for-your-subversion-reposiotries/</guid>
		<description><![CDATA[Subversion is becoming more and more popular every day.  To get quick installation guide, see my post on installing Subversion.  Once you have Subversion set up, make sure you have backups of repository setup!  This is one of those things most people forget to do.  If you followed the installation guide [...]]]></description>
			<content:encoded><![CDATA[<p>Subversion is becoming more and more popular every day.  To get quick installation guide, see my post on <a href="http://crazytoon.com/2007/06/01/subversion-how-do-you-install-and-set-up-subversion-for-revision-control/" title="How do you install Subversion?">installing Subversion</a>.  Once you have Subversion set up, make sure you have backups of repository setup!  This is one of those things most people forget to do.  If you followed the installation guide and did source install, you already have a tool available to you.  You can find <span><strong class="command">hot-backup.py </strong></span>tool in the         <tt class="filename">tools/backup/</tt> directory of the Subversion         source distribution.   One thing about this script is that it doesn&#8217;t backup all your repositories.  Which might be an issue if you create more repositories but forget to create a script to backup that particular repository.  Here is a very simple shell script to help you backup all of your subversion repositories.  You can edit it to point to different /svn location if you didn&#8217;t install to default location.  Make sure you copy hot-backup.py to a location which is included in your path so your scripts will work.</p>
<p><code>mkdir /backups/repos -p<br />
for repostobackup in `ls /svn/` ; do<br />
filename=`basename ${repostobackup}`<br />
if [ ! $filename = "" ]; then<br />
hot-backup.py --archive-type=bz2 /svn/${filename} /backups/repos<br />
fi<br />
done</code></p>
<p>This will create your backup files and compress them using bzip2.  You can also use zip or gz if you prefer.  Another thing you should do is to edit the hot-backup.py script and change num_backups to be whatever you think is a good number.  I personally use:  num_backups = 10</p>
<p>That&#8217;s all there is to it.  Just add this script to your crons and your backups will be automated.  You may want to consider moving your backups to another server by adding ftp, scp or rsync at the end of the script.</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/08/16/subversion-svn-how-do-you-set-up-backup-for-your-subversion-repositories/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>MySQL:  InnoDB: ERROR: the age of the last checkpoint is [number]</title>
		<link>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/</link>
		<comments>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 21:32:59 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/</guid>
		<description><![CDATA[One of the mysql database servers I manage started to have issues with doing backups yesterday.  mysqldump was running but nothing was happening on the backup side.  I started to investigate to see why our full backups were failing.  I opened up the mysql error log file (mine is at:  /usr/local/mysql/var/hostname.err) [...]]]></description>
			<content:encoded><![CDATA[<p>One of the mysql database servers I manage started to have issues with doing backups yesterday.  mysqldump was running but nothing was happening on the backup side.  I started to investigate to see why our full backups were failing.  I opened up the mysql error log file (mine is at:  /usr/local/mysql/var/hostname.err) and notice there were many instances of following error.</p>
<p><code>070815 15:31:46  InnoDB: ERROR: the age of the last checkpoint is 9433957,<br />
InnoDB: which exceeds the log group capacity 9433498.<br />
InnoDB: If you are using big BLOB or TEXT rows, you must set the<br />
InnoDB: combined size of log files at least 10 times bigger than the<br />
InnoDB: largest such row.</code></p>
<p>I poked around and found out our log files were set to default (5 mb) and they needed to be increased.  After doing some calculations and research, I decided going to 50 mb at this point would be a good way to go.   So I made the change in my.cnf file and added:  <code>innodb_log_file_size = 50M </code></p>
<p>I then stopped our mysql server and restarted it.  And to my horror I saw following error messages show up in the mysql error logs:</p>
<p><code>070815 17:37:40 [ERROR] /usr/local/mysql/libexec/mysqld: Incorrect information in file: './dbname/table_name.frm'<br />
070815 17:37:40 [ERROR] /usr/local/mysql/libexec/mysqld: Incorrect information in file: './dbname/table_name.frm'</code></p>
<p>I stopped the mysql server right away.  I then remember, by help of a friend, that I have to remove the old log files if I change the size by changing <code>innodb_log_file_size</code>.  So I issued a command:  <code>mv ib_logfile? ..</code></p>
<p>This command moves both ib_logfile1 and ib_logfile2 down one directory.  I didn&#8217;t want to just remove &#8216;em so instead I moved them.  After that, I restarted mysql again and to my comfort, everything came back up without errors.  So lesson learned:  if you change ib_logfile size by using  <code>innodb_log_file_size</code> setting, make sure you move existing log files before you start mysql again.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

