<?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>Ruby, Rails, OSX and Linux fun &#187; linux</title>
	<atom:link href="http://www.frederico-araujo.com/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederico-araujo.com</link>
	<description>Ruby, Rails, OSX and linux sysadmin</description>
	<lastBuildDate>Thu, 02 Sep 2010 08:13:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Server monitoring with gentoo and iStat on the iPhone</title>
		<link>http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/</link>
		<comments>http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 07:00:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[istatd]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=137</guid>
		<description><![CDATA[You can monitor your servers nicely graphs using iStat for iphone.
these are instructions for Gentoo:

1
2
3
4
5
6
7
8
9
wget http://github.com/downloads/tiwilliam/istatd/istatd-0.5.7.tar.gz
tar xpf istatd-0.5.7.tar.gz
cd istatd-0.5.7
./configure
make
make install 
useradd istat
mkdir -p /var/&#123;run,cache&#125;/istat /home/istat
chown istat.istat /var/&#123;run,cache&#125;/istat /home/istat

Create and edit /etc/istat.conf to match your server specs.
This config is for my OpenVZ vps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#
# /etc/istat.conf: Configuration for iStat server
#
&#160;
# IP Address to listen
network_addr     [...]]]></description>
			<content:encoded><![CDATA[<p>You can monitor your servers nicely graphs using iStat for iphone.<br />
these are instructions for Gentoo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>tiwilliam<span style="color: #000000; font-weight: bold;">/</span>istatd<span style="color: #000000; font-weight: bold;">/</span>istatd-0.5.7.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xpf istatd-0.5.7.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> istatd-0.5.7
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> 
useradd istat
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>run,cache<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>istat <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>istat
<span style="color: #c20cb9; font-weight: bold;">chown</span> istat.istat <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>run,cache<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>istat <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>istat</pre></td></tr></table></div>

<p>Create and edit /etc/istat.conf to match your server specs.<br />
This config is for my OpenVZ vps.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># /etc/istat.conf: Configuration for iStat server</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># IP Address to listen</span>
network_addr           77.88.xx.xx
&nbsp;
<span style="color: #666666; font-style: italic;"># choose any port, Default is 5109</span>
network_port           <span style="color: #000000;">55666</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># this is password, 5 digits</span>
server_code            <span style="color: #000000;">12345</span>
&nbsp;
server_user            istat
server_socket          <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>istat<span style="color: #000000; font-weight: bold;">/</span>istat.sock
server_pid             <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>istat<span style="color: #000000; font-weight: bold;">/</span>istat.pid
cache_dir              <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>istat
monitor_net              venet0
monitor_disk             <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>simfs <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<p>Start istatd server:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> istat istatd <span style="color: #660033;">-d</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>istat.conf</pre></td></tr></table></div>

<p>you might add it to /etc/conf.d/local.start to auload on startup</p>
<p>Then download iStat for iphone http://bjango.com/apps/istat/  it&#8217;s only $0.99<br />
and add your server to the list. </p>
<p>Here are some screenshots, first is server and second image is my macbook discovered with bonjour. </p>

<a href='http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/img_0016/' title='IMG_0016'><img width="150" height="150" src="http://www.frederico-araujo.com/wp-content/uploads/2010/06/IMG_0016-150x150.png" class="attachment-thumbnail" alt="" title="IMG_0016" /></a>
<a href='http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/img_0019/' title='IMG_0019'><img width="150" height="150" src="http://www.frederico-araujo.com/wp-content/uploads/2010/06/IMG_0019-150x150.png" class="attachment-thumbnail" alt="" title="IMG_0019" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Really checking the content-type/mime_type of a file in OSX and Linux</title>
		<link>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/</link>
		<comments>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 18:55:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[content_type]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mime_type]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=95</guid>
		<description><![CDATA[I have came across many projects where checking file uploads and content-type (mime-type) is poorly implemented or heavy in resource.
Methods I have seen so far:
1. Checking content-type from file name: this inefficient, a user can just rename a file and you are fooled, or the file can have a different file format and you will [...]]]></description>
			<content:encoded><![CDATA[<p>I have came across many projects where checking file uploads and content-type (mime-type) is poorly implemented or heavy in resource.</p>
<p>Methods I have seen so far:</p>
<p>1. Checking content-type from file name: this inefficient, a user can just rename a file and you are fooled, or the file can have a different file format and you will not get the expected result.</p>
<p>2. Using Rmagick to check if the file is an image. This is so slow and uses so much Ram. You can try to initialize an rmagick object from an image file, then rescue when the file is not an image.</p>
<p>3. Using mini_magick to check if a file. This method is faster than rmagick. Implemen ted same way as rmagick.</p>
<p>A Better method for OSX and Linux,  is to use the command line tool &#8220;file&#8221; included in most UNIX operating systems.</p>
<p>It is very fast and very accurate.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">file = <span style="color:#996600;">&quot;/path/to/file.ext&quot;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> RUBY_PLATFORM.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>darwin<span style="color:#006600; font-weight:bold;">|</span>linux<span style="color:#006600; font-weight:bold;">|</span>unix<span style="color:#006600; font-weight:bold;">|</span>solaris<span style="color:#006600; font-weight:bold;">|</span>bsd<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 content_type = <span style="color:#996600;">`file --raw --brief &quot;#{file}&quot;`</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span>
 <span style="color:#9966CC; font-weight:bold;">case</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>image<span style="color:#006600; font-weight:bold;">|</span>png<span style="color:#006600; font-weight:bold;">|</span>jpg<span style="color:#006600; font-weight:bold;">|</span>jpeg<span style="color:#006600; font-weight:bold;">|</span>gif<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;image&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>pdf<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;pdf&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Microsoft Word|Microsoft Office Document&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;doc&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#008000; font-style:italic;"># This can go on and on</span>
   real_type = <span style="color:#996600;">&quot;Unknown&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Some examples of content types:</p>
<p>.doc =  Microsoft Word document data</p>
<p>.doc = Microsoft Office Document</p>
<p>.pdf = PDF document, version 1.4</p>
<p>.pdf = PDF document, version 1.3</p>
<p>.psd = Adobe Photoshop Image</p>
<p>.png  = PNG image data, 3508 x 4961, 8-bit/color RGBA, non-interlaced</p>
<p>.gif = GIF image data, version 89a, 195 x 109</p>
<p>.jpg = JPEG image data, EXIF standard</p>
<p>etc&#8230;</p>
<p>I hope this can be useful to someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Stop http Pipeline from overloading your server, using connlimit iptables</title>
		<link>http://www.frederico-araujo.com/2009/01/25/stop-http-pipeline-from-overloading-your-server-with-iptables/</link>
		<comments>http://www.frederico-araujo.com/2009/01/25/stop-http-pipeline-from-overloading-your-server-with-iptables/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 08:31:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=79</guid>
		<description><![CDATA[Have you edited or tweaked your pipeline settings in Firefox?
You can do it by typing about:config in your firefox url tab.
Most blogs and tutorial will tell you to set high values to improve the speed, such as this one: www.mydigitallife.info/2007/10/16/speed-up-your-firefox-by-adjusting-your-http-pipelining/
Many people will go crazy and make values even higher such as:
network.http.pipelining.maxrequests 32
network.http.max-persistent-connections-per-proxy 128
network.http.max-persistent-connections-per-server 128
network.http.max-connections-per-server 256
These [...]]]></description>
			<content:encoded><![CDATA[<p>Have you edited or tweaked your pipeline settings in Firefox?</p>
<p>You can do it by typing about:config in your firefox url tab.</p>
<p>Most blogs and tutorial will tell you to set high values to improve the speed, such as this one: <a href="http://www.mydigitallife.info/2007/10/16/speed-up-your-firefox-by-adjusting-your-http-pipelining/">www.mydigitallife.info/2007/10/16/speed-up-your-firefox-by-adjusting-your-http-pipelining/</a></p>
<p>Many people will go crazy and make values even higher such as:</p>
<p>network.http.pipelining.maxrequests 32<br />
network.http.max-persistent-connections-per-proxy 128<br />
network.http.max-persistent-connections-per-server 128<br />
network.http.max-connections-per-server 256</p>
<p>These settings are very high and will create at least 32 connections to your server.</p>
<p>if you have many images and SSI includes, it could overload your apache webserver.<br />
If you use apache2.2 with worker_mpm it will create 1 thread for each connection, thus you will have 32 new threads forked within just a few seconds.</p>
<p>Of course if you have a quad-core server with lots of ram you should not bother to read this.<br />
But for most cheap vps and single core servers, it can really help.</p>
<p>so how you do it? simple, just use iptables conn_limit module</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--syn</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-m</span> connlimit <span style="color: #660033;">--connlimit-above</span>  <span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> REJECT</pre></div></div>

<p>you may need to adjust the order or to insert or append like</p>
<p># to apped to the end of the INPUT chain:<br />
iptables -A input &#8230;<br />
or<br />
# to insert at position 10 of the input chain:<br />
iptables -I input 10 &#8230;</p>
<p>I have tested this schema and work very well with firefox pipeline freaks.</p>
<p>the server will only then take up to 8 simultaneously connections per IP</p>
<p>to test the established connections you can try with netstat from the server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-na</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> esta <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> 127.0.0.1 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-n</span> -t. <span style="color: #660033;">-k2</span></pre></div></div>

<p>Any comments, suggestions are welcome &#8230;</p>
<p>Update:</p>
<p>This can be not so good to legit users behind a proxy or firewall, because the the IP will be unique to all users behind the proxy/firewall.</p>
<p>in this case, you would increase the limit value.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/01/25/stop-http-pipeline-from-overloading-your-server-with-iptables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Easy installing Passenger mod_rails on gentoo Linux</title>
		<link>http://www.frederico-araujo.com/2008/08/06/easy-installing-passenger-mod_rails-on-gentoo/</link>
		<comments>http://www.frederico-araujo.com/2008/08/06/easy-installing-passenger-mod_rails-on-gentoo/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 05:15:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[mod_rails]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=35</guid>
		<description><![CDATA[To install the great Mod_Rails on Gentoo linux it&#8217;s as easy as 5 steps.
Since you are Gentoo user, i don&#8217;t need to go to details. You know what you doing.  
Update: Mod-rails now works with apache mpm-worker
1. Recompile Apache non-threaded
add this to /etc/portage/package.use
www-servers/apache -threads
and this to /etc/make.conf
APACHE2_MPMS="prefork"
2. Re emerge apache
# emerge -va apache
3. Passenger [...]]]></description>
			<content:encoded><![CDATA[<p>To install the great Mod_Rails on Gentoo linux it&#8217;s as easy as 5 steps.</p>
<p>Since you are Gentoo user, i don&#8217;t need to go to details. You know what you doing. <img src='http://www.frederico-araujo.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong><em>Update</em></strong>: Mod-rails now works with apache mpm-worker</p>
<h4><span style="text-decoration: line-through;">1. Recompile Apache non-threaded</span></h4>
<p><span style="text-decoration: line-through;">add this to /etc/portage/package.use</span></p>
<pre><span style="text-decoration: line-through;">www-servers/apache -threads</span></pre>
<p><span style="text-decoration: line-through;">and this to /etc/make.conf</span></p>
<pre><span style="text-decoration: line-through;">APACHE2_MPMS="prefork"</span></pre>
<h4><span style="text-decoration: line-through;">2. Re emerge apache</span></h4>
<pre><span style="text-decoration: line-through;"># emerge -va apache</span></pre>
<h4>3. Passenger is in gentoo portage, but its in testing. Currently Version 2.0.1</h4>
<pre># echo "www-apache/passenger" &gt;&gt; /etc/portage/package.keywords</pre>
<h4>4. Install Passenger</h4>
<pre># emerge -va passenger</pre>
<p>If it tries to install rails 2.2.2, rake, and lots of other gems that you already have installed trough rubygems, then run emerge with &#8211;nodeps option</p>
<pre># emerge -va --nodeps passenger</pre>
<h4>5. Edit /etc/conf.d/apache and add &#8220;-D PASSENGER&#8221; to apache options</h4>
<p>for example mine looks like this:</p>
<pre>APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D PROXY -D PASSENGER"</pre>
<p>That&#8217;s it.</p>
<p>Now just drop a similar vhost config file inside /etc/apache/vhosts.d/</p>
<p>This is a sample vhost file for a rails app.</p>
<pre>&lt;VirtualHost *:80&gt;
  ServerName mydomain.com
  DocumentRoot /myapp/public
  Include /etc/apache2/vhosts.d/deflate.conf
  RailsBaseURI /
  # The maximum number of Ruby on Rails application instances that may be simultaneously active.
  # A larger number results in higher memory usage, but improved ability to handle concurrent HTTP clients.
  # normally 1 to 10. (1 for each 50mb ram)
  RailsMaxPoolSize 1
  # The maximum number of seconds that a Ruby on Rails application instance may be idle.
  # That is, if an application instance hasn't done anything after the given number of seconds,
  # then it will be shutdown in order to conserve memory. ( 1 hour)
  RailsPoolIdleTime 3600
  RailsEnv 'production'
  &lt;Directory /myapp/public&gt;
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre>
<p>My sample deflate.conf,<br />
used to gzip the content</p>
<pre>&lt;Location /&gt;
	SetOutputFilter DEFLATE
	#
	# Netscape 4.x has some problems...
	BrowserMatch ^Mozilla/4 gzip-only-text/html
	#
	# Netscape 4.06-4.08 have some more problems
	BrowserMatch ^Mozilla/4\.0[678] no-gzip
	#
	# MSIE masquerades as Netscape, but it is fine
	BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
	# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
	# the above regex won't work. You can use the following
	# workaround to get the desired effect:
	BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
	# Don't compress images
	SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
	# Make sure proxies don't deliver the wrong content
	Header append Vary User-Agent env=!dont-vary
&lt;/Location&gt;

DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/apache2/deflate_log deflate</pre>
<p>* Update on July 10, 2008.</p>
<p>- Now using gentoo portage to install it. it&#8217;s more smooth.</p>
<p>Note:</p>
<p>Personally I found that Thin + nginx uses less memory(Nginx 4MB + each thin server) than<br />
apache + passenger, which uses quite more. (Apache: 50MB + each rails spawner)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2008/08/06/easy-installing-passenger-mod_rails-on-gentoo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Very low memory VPS Linux for Rails</title>
		<link>http://www.frederico-araujo.com/2008/07/03/very-low-memory-vps-linux-for-rails/</link>
		<comments>http://www.frederico-araujo.com/2008/07/03/very-low-memory-vps-linux-for-rails/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 05:09:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[thin]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=32</guid>
		<description><![CDATA[The other day I had to set up a VPS machine at Slicehost for a client on a tight budget. I paid for 256mb VPS based on Gentoo, my distro of choice.
But 256MB of ram? what can you do with just 256?
Normally a default 256mb linux machine would not handle very well a set of [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I had to set up a VPS machine at Slicehost for a client on a tight budget. I paid for 256mb VPS based on Gentoo, my distro of choice.</p>
<p>But 256MB of ram? what can you do with just 256?</p>
<p>Normally a default 256mb linux machine would not handle very well a set of Apache + Mysql + 1 mongrel/thin/ebb instance. due to the high memory usage of a default configuration, it will swap very often.</p>
<p>After much research and instinct i made it run one thin servers with mysql and nginx, without any swapping, and really fast as it can be.</p>
<p>If your linux start swapping often your performance will go down to the floor&#8230;  Swapping is bad, specially on a XEN VPS.</p>
<p>The trick is to setup Mysql to use MYISAM and use Nginx instead of apache.</p>
<p>Here is the process list with the Resident Memory usage, after 30 days uptime and about 1,800 page views on the website.</p>
<table border="0">
<tbody>
<tr>
<td>Mysqld 5.0.54 :</td>
<td>7.5 MB</td>
</tr>
<tr>
<td>Thin server each :</td>
<td>66.5 MB</td>
</tr>
<tr>
<td>Nginx 0.6.29 :</td>
<td>3.5 MB (1 worker)</td>
</tr>
<tr>
<td>Postfix</td>
<td>4.2 MB</td>
</tr>
</tbody>
</table>
<p>and others, such as sshd, cron, iptables, bash, together about 5mb.</p>
<p>As you can see, total of memory usage of the applications on the server is about 83 MB, thus leaving the server with 170MB of ram for the linux itself and file cache.</p>
<p>this is what #free command tells:</p>
<pre>             total       used       free     shared    buffers     cached
Mem:           256        235         20          0         54         62
-/+ buffers/cache:        128        128
Swap:          511          0        511</pre>
<p>Nice uh?<br />
you can also make use of the nice tool called &#8220;vmstat&#8221;<br />
it&#8217;s very import that &#8217;si&#8217; (swap in) and &#8217;so&#8217; (swap out) stays zero all the time.</p>
<p>i.e. running vmstat 10 times with a 4 seconds interval. (ignore the 1st line)</p>
<pre># vmstat 4 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0    116  14900  56668  62692    1    1     3     3    9    5  0  0 100  0
 0  0    116  14908  56668  62692    0    0     0     0   34   53  0  0 100  0
 0  0    116  14968  56668  62692    0    0     0     0   37   54  0  0 100  0
 0  0    116  14968  56668  62692    0    0     0     0   31   52  0  0 100  0
....</pre>
<h3>Here is the recipe:</h3>
<h3>1. Use MyIsam instead of InnoDB</h3>
<p>You can read about it more in here:<br />
<a href="http://blog.evanweaver.com/articles/2007/04/30/top-secret-tuned-mysql-configurations-for-rails/"></p>
<p>http://blog.evanweaver.com/articles/2007/04/30/top-secret-tuned-mysql-configurations-for-rails/</p>
<p></a></p>
<p>I forgot to add that you need to dump your database first:</p>
<p>mysqldump -u root &#8211;all-databases &gt; dump.sql</p>
<p>then change my.cnf accordingly,</p>
<p>restart mysql and reload the database</p>
<p>mysql -u root &lt; dump.sql</p>
<p>Change only the values for my.cnf as shown below, and delete all innodb related stuff</p>
<pre>
# can be safely set to 1M if you are really tight on Ram
key_buffer 			       = 4M

max_allowed_packet 			= 1M
table_cache 				= 32
sort_buffer_size 			= 512k
net_buffer_length 			= 8K
read_buffer_size 			= 512k
read_rnd_buffer_size 		= 512K

# can be safely set to 1M
myisam_sort_buffer_size 	= 2M  

language 					= /usr/share/mysql/english

# security:
# using "localhost" in connects uses sockets by default
# skip-networking
bind-address				= 127.0.0.1

# No logging,
# make sure you backup your database more often.
#log-bin

server-id 					= 1

# point the following paths to different dedicated disks
tmpdir 						= /tmp/

# Very important to have this here.
# otherwise it will still load InnoDB.
skip-innodb

[mysqldump]
quick
max_allowed_packet 			= 16M

[mysql]
# uncomment the next directive if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer 					= 8M
sort_buffer_size 			= 8M
read_buffer 				= 2M
write_buffer 				= 2M

[myisamchk]
key_buffer 					= 8M
sort_buffer_size 			= 8M
read_buffer 				= 2M
write_buffer 				= 2M

[mysqlhotcopy]
interactive-timeout</pre>
<p>If you get problems reloading the database, stop mysql delete the contents in /var/lib/mysql/* , then run mysql-installdb and start it and reload again the sql dump file.</p>
<p>Actually that&#8217;s the way i most prefer..</p>
<h3>2. Use nginx</h3>
<p>this is an example nginx config file, located at /etc/nginx/nginx.conf</p>
<pre>user nginx nginx;
# set to 2 or 3 if you have more processors or cores.
# it will use about 3MB per worker
worker_processes 1;

error_log /var/log/nginx/error_log info;

events {
	# default is 8192
	worker_connections  1024;
	use epoll;
}

http {
	include		/etc/nginx/mime.types;
	default_type	application/octet-stream;

	log_format main
		'$remote_addr - $remote_user [$time_local] '
       	'"$request" $status $bytes_sent '
		'"$http_referer" "$http_user_agent" '
		'"$gzip_ratio"';

	client_header_timeout	10m;
	client_body_timeout	10m;
	send_timeout		10m;
        client_body_buffer_size    128k;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;

	connection_pool_size		256;
	client_header_buffer_size	1k;
	large_client_header_buffers	4 2k;
	request_pool_size		4k;

	gzip on;
	gzip_http_version 1.1;
        gzip_comp_level 6;
        gzip_proxied any;
        gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        gzip_buffers 16 8k;
        # Disable gzip for certain browsers.
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";
	gzip_min_length	1100;

	output_buffers	1 32k;
	postpone_output	1460;

	sendfile	on;
	tcp_nopush	on;
	tcp_nodelay	on;

	keepalive_timeout	75 20;

	ignore_invalid_headers	on;

	index index.html;

    # The following includes are specified for virtual hosts
    include /var/www/apps/bla.com/shared/config/nginx.conf;

}</pre>
<p>this is an example vhost file</p>
<pre>upstream mongrel_bla_com {
  server 127.0.0.1:8001;
}

server {
	listen 80;
	client_max_body_size 40M;
	server_name bla.com www.bla.com;
	root /var/www/apps/bla.com/current/public;
	access_log  /var/www/apps/bla.com/shared/log/nginx.access.log;

	location / {
                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect false;
                if (-f $request_filename/index.html) {
                        rewrite (.*) $1/index.html break;
                }
                if (-f $request_filename.html) {
                        rewrite (.*) $1.html break;
                }
                if (!-f $request_filename) {
                        proxy_pass http://mongrel_bla_com;
                        break;
                }
	}

	location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ {
		root /var/www/apps/bla.com/current/public;
	}

}</pre>
<h3>3. Remove unnecessary Services you dont need.</h3>
<p>Some linux distros have enabled by default services we dont need.</p>
<p>such as cupsd, apmd, acpid, mdns, samba, nfs, ftpd&#8230; etc&#8230;</p>
<h3>This is my make.conf in case it helps</h3>
<p>Note that I set MAKEOPTS=&#8221;-J1&#8243; , it will only use 1 gcc process at the time, and not disturb the system, (machine has 4 cores)</p>
<p>Also portage_niceness to 18, to make sure it will run smooth and not disturb thin and mysql.</p>
<p>from nice man page: &#8220;Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable).&#8221;</p>
<pre>CFLAGS="-march=athlon64 -O2"
CHOST="x86_64-pc-linux-gnu"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j1"

USE="3dnow 3dnowext apache2 \
     bash-completion bzip2 \
     -cups \
     gzip httpd hpn \
     innodb imagemagick \
     javascript jpeg \
     mmx mmxext mysql \
     nptl nptlonly \
     perl phyton png \
     ruby \
     screen sse sse2 sqlite sqlite3 ssl \
     threads udev unicode utf8 \
     vim-syntax \
     -X -kde -gnome -gtk -bindist \
     xml xml2 zlib "

GENTOO_MIRRORS="http://mirror.datapipe.net/gentoo http://gentoo.cites.uiuc.edu/pub/gentoo/ ftp://gentoo.mirrors.tds.net/gentoo http://ge
APACHE2_MPMS='worker'
PORTAGE_NICENESS=18</pre>
<p>if you want to use mod_rails Passenger, set APACHE2_MPMS=&#8217;prefork&#8217;</p>
<p>note: I am positive you can throw in another thin server instance, and it will still not swap, or swap very little at all.</p>
<p>have fun</p>
<p>**************************</p>
<h3>Updates :</h3>
<p>Wanna know what Slicehost Manager Diagnostics says about my VPS ?</p>
<pre>Diagnostics

    * Your slice is currently running.
    * The host server is up.
    * Your swap IO usage over the last 4 hours is low: 0.0016 reads/s, 0.0 writes/s. (Read more about swap here)
    * Your root IO usage over the last 4 hours is low: 0.038 reads/s, 0.1643 writes/s.
    * The host server's load is nominal: 0.00, 0.03, 0.00.
 <img src='http://www.frederico-araujo.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2008/07/03/very-low-memory-vps-linux-for-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
