<?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>Kerry D. Wong &#187; Apache</title>
	<atom:link href="http://www.kerrywong.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kerrywong.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Sep 2010 00:51:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Apache2 Logrotate</title>
		<link>http://www.kerrywong.com/2010/08/11/apache2-logrotate/</link>
		<comments>http://www.kerrywong.com/2010/08/11/apache2-logrotate/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 00:14:04 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Linux/BSD]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Logrotate]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/?p=2422</guid>
		<description><![CDATA[Whenever I setup a new web server, I always like the idea of keeping the Apache logs roated on a daily basis. While the procedures for changing the log rotate frequency is pretty straight forward, I have seen a lot of people having problems with it so I decided to document it. To change the [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I setup a new web server, I always like the idea of keeping the <a href="http://www.apache.org">Apache</a> logs roated on a daily basis. While the procedures for changing the log rotate frequency is pretty straight forward, I have seen a lot of people having problems with it so I decided to document it.<span id="more-2422"></span></p>
<p>To change the Apache log rotate frequency, you would want to change the apache2 configuration file located under /etc/logrotate.d. Configurations located in this directory overrides the default settings in /etc/logrotate.conf (the configurations in /etc/logrotate.d are included in logrotate.conf)</p>
<p>Here&#8217;s what my settings look like (note that I had commented out compress option so that all the logs can be easily browsed):</p>
<blockquote><p>
/var/log/apache2/*.log {<br />
        daily<br />
        missingok<br />
        rotate 365<br />
        #compress<br />
        #delaycompress<br />
        notifempty<br />
        create 640 root adm<br />
        sharedscripts<br />
        postrotate<br />
                if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then<br />
                        /etc/init.d/apache2 reload > /dev/null<br />
                fi<br />
        endscript<br />
}
</p></blockquote>
<h3>Common problem</h3>
<p>A common problem after changing the log rotate frequency is that the Apache logs do not appear to be rotating daily even though the configuration file had been changed correctly.</p>
<p>This seems to be a known issue with logrotate. If you read the manual for logrotate you&#8217;d see the following explanation:</p>
<blockquote><p>
       -f, &#8211;force<br />
              Tells logrotate to force the rotation, even if it doesn&#8217;t  think<br />
              this  is  necessary.   Sometimes this is useful after adding new<br />
              entries to a logrotate config file, or if  old  log  files  have<br />
              been removed by hand, as the new files will be created, and<br />
              logging will continue correctly.
</p></blockquote>
<p>Since the default cron daily job does not force the log rotation, you may want to add -f parameter to /etc/cron.daily/logrotate:</p>
<blockquote><p>
#!/bin/sh</p>
<p>test -x /usr/sbin/logrotate || exit 0<br />
/usr/sbin/logrotate -f /etc/logrotate.conf
</p></blockquote>
<p>With this change, the logs will be forced to rotate daily according to the setup.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2010/08/11/apache2-logrotate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing Apache Server Log for Unique IPs</title>
		<link>http://www.kerrywong.com/2009/02/01/parsing-apache-server-log-for-unique-ips/</link>
		<comments>http://www.kerrywong.com/2009/02/01/parsing-apache-server-log-for-unique-ips/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 16:41:01 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Linux/BSD]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Server Log]]></category>
		<category><![CDATA[Unique IP]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/?p=531</guid>
		<description><![CDATA[I created this short Perl script to tally the number of unique IPs from the Apache server log. Since by default, the logrotate daemon compresses Apache logs, we need to disable the compression option for the Apache log configuration. In Ubuntu, this setting can be changed in /etc/logrotate.d/apache2. To disable compression, just comment out the [...]]]></description>
			<content:encoded><![CDATA[<p>I created this short Perl script to tally the number of unique IPs from the Apache server log.<span id="more-531"></span> Since by default, the logrotate daemon compresses Apache logs, we need to disable the compression option for the Apache log configuration. In Ubuntu, this setting can be changed in /etc/logrotate.d/apache2. To disable compression, just comment out the following lines:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #compress<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #delaycompress</p>
<p>The Perl script is quite straight forward: it basically builds a hash table and use the IP address as the key:</p>
<div>#!/usr/bin/perl</div>
<div>
$apacheLogDir = &quot;/var/log/apache2&quot;;</div>
<div>
opendir(DIR, $apacheLogDir);</div>
<div>@files = grep(/^access/, readdir(DIR));</div>
<div>closedir(DIR);</div>
<div>
%hashTable=();</div>
<div>$uniqueIP = 0;</div>
<div>foreach $file (@files) {</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; open FILE, &quot;$apacheLogDir&quot; . &quot;/&quot; . &quot;$file&quot; or die $!;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @lines = &lt;FILE&gt;;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach $line (@lines) {</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #print &quot;$resolved&quot;;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;$IP[0]\n&quot;;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close(FILE);</div>
<div>}</div>
<div>
print &quot;Total unique IPs: $uniqueIP.\n&quot;;</div>
<p>&nbsp;</p>
<p>The two lines commented out:</p>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #$resolved = qx{resolveip $IP[0]};<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #print &quot;$resolved&quot;;</div>
<p>can be used to identify the domain name the IP is associated with. Since reverse DNS lookup is a rather slow process, it will take a long time to resolve all the IPs. I may change it to use multiple threads to speed up the DNS lookup in the further.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2009/02/01/parsing-apache-server-log-for-unique-ips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache Log Rotation on Ubuntu Server</title>
		<link>http://www.kerrywong.com/2007/10/03/apache-log-rotation-on-ubuntu-server/</link>
		<comments>http://www.kerrywong.com/2007/10/03/apache-log-rotation-on-ubuntu-server/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 01:57:50 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Server Log]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/2007/10/03/apache-log-rotation-on-ubuntu-server/</guid>
		<description><![CDATA[Interestingly, the log rotation utility rotatelogs which came with Apache does not work with Ubuntu 7.04 installation. At least not when the Apache is installed via apt-get. By default, Ubuntu server utilizes logrotate not rotatelogs to rotate all its server logs. Appache access and error logs are rotated on a weekly basis when first installed. [...]]]></description>
			<content:encoded><![CDATA[<p>Interestingly, the log rotation utility <a href="http://httpd.apache.org/docs/2.0/programs/rotatelogs.html">rotatelogs</a> which came with Apache does not work with Ubuntu 7.04 installation. At least not when the Apache is installed via apt-get.<span id="more-225"></span></p>
<p>By default, Ubuntu server utilizes logrotate not rotatelogs to rotate all its server logs. Appache access and error logs are rotated on a weekly basis when first installed. To change the log rotation frequency, you will need to change the following file:&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; /etc/logrotate.d/apache</p>
<p>The main difference between logrotate and rotatelogs is that logrotate is triggered by a cron job whereas rotatelogs runs in the background as a daemon. In Ubuntu, cron jobs are neatly organized into&nbsp; cron.hourly, cron.daily, cron.weekly and cron.monthly folders. This makes creating ad-hoc cron jobs a very easy task.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2007/10/03/apache-log-rotation-on-ubuntu-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
