<?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>Never Use This Font &#187; Linux</title>
	<atom:link href="http://neverusethisfont.com/blog/topics/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://neverusethisfont.com/blog</link>
	<description>Aaron Parecki is the co-founder of Geoloqi.com, and specializes in backend systems development.</description>
	<lastBuildDate>Mon, 11 Jul 2011 22:50:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Enabling SSH on the Seagate BlackArmor NAS 220</title>
		<link>http://neverusethisfont.com/blog/2011/07/enabling-ssh-on-the-seagate-blackarmor-nas-220/</link>
		<comments>http://neverusethisfont.com/blog/2011/07/enabling-ssh-on-the-seagate-blackarmor-nas-220/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 01:54:47 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=514</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>I recently acquired a <a href="http://aaron.pk/asin/B0046TSGNE">6 TB Seagate NAS drive</a> which I am using for nightly backups of my servers, as well as <a href="http://neverusethisfont.com/blog/2010/07/how-to-back-up-dropbox-automatically-daily-weekly-monthly-snapshots/">snapshots of several Dropbox accounts</a>.</p>
<p>While the web interface on the device isn&#8217;t too bad, I wanted a little more control over it, as well as the ability to monitor the device&#8217;s health with some custom <a href="https://github.com/aaronpk/Munin-Plugins">munin graphs</a>.</p>
<p>Here&#8217;s how to enable SSH without wiping the drive and installing custom firmware.</p>
<ol>
<li>Set up a new user account on the device from the web interface, and create a password.</li>
<li>Shut down the device, remove both drives, and connect them to a local computer with SATA cables.</li>
<li>Boot your linux computer with the drives attached, it&#8217;s probably safest to boot from some sort of Live CD. I used Fedora.</li>
<li>When you get to a shell, execute the following commands to mount the drives.<br />
<code>$ mdadm -A /dev/md0 /dev/sda1 /dev/sdb1<br />
mdadm: /dev/md0 has been started with 2 drives.<br />
$ mkdir /mnt/md0<br />
$ mount /dev/md0 /mnt/md0<br />
</code></li>
<li>Add the following line to the file <code>/mnt/md0/etc/inetd.conf</code>:<br />
<code>ssh stream tcp nowait root /usr/sbin/dropbear dropbear -i</code><br />
You can do this in one shell command by executing this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ssh stream tcp nowait root /usr/sbin/dropbear dropbear -i&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>md0<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>inetd.conf</pre></div></div>

</li>
<li>Edit <code>/mnt/md0/etc/shadow</code> with a text editor, and replace the hashed password for &#8220;root&#8221; with the hashed password of the user you created. The hashed password is the characters between the second two colons, and begins with <code>$1$$</code>.</li>
<li>Unmount the drives and shut down the array:<code><br />
$ cd<br />
$ umount /mnt/md0<br />
$ mdadm -S /dev/md0<br />
mdadm: stopped /dev/md0</code></li>
<li>Put the drives back in the NAS device and turn it back on!</li>
<li>After it boots, you&#8217;ll be able to ssh in as <code>root</code> with the password you set from the web interface.</li>
</ol>
<p><img src="http://neverusethisfont.com/blog/wp-content/uploads/2011/07/2011-07-10_1850.png" alt="" title="SSH" width="414" height="152" class="aligncenter size-full wp-image-523" /></p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2011/07/enabling-ssh-on-the-seagate-blackarmor-nas-220/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tracking typos of your domain name in Google Analytics</title>
		<link>http://neverusethisfont.com/blog/2010/12/tracking-typos-of-your-domain-name-in-google-analytics/</link>
		<comments>http://neverusethisfont.com/blog/2010/12/tracking-typos-of-your-domain-name-in-google-analytics/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 17:41:53 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[redirection]]></category>
		<category><![CDATA[tracking]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=279</guid>
		<description><![CDATA[Say you want to register a couple different typos of your domain name, and redirect everyone seamlessly to the correct site. This can be done quite easily in Apache using ServerAlias and a simple RewriteRule. I just registered geoloqui.com after noticing a couple articles linking to it instead of geoloqi.com. But then I thought, wouldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Say you want to register a couple different typos of your domain name, and redirect everyone seamlessly to the correct site. This can be done quite easily in Apache using ServerAlias and a simple RewriteRule. I just registered geoloqui.com after noticing a couple articles linking to it instead of geoloqi.com. But then I thought, wouldn&#8217;t it be useful if I could track these typos and see which ones are most common? Turns out it&#8217;s not difficult! </p>
<p>Here is a snippet of my virtual hosts definition for geoloqi.com:</p>
<pre>
&lt;VirtualHost *:80&gt;
	ServerName geoloqi.com
	ServerAlias *.geoloqi.com
	ServerAlias geoloqui.com
	ServerAlias *.geoloqui.com

	RewriteEngine on
	RewriteCond %{HTTP_HOST} !^geoloqi.com
	RewriteRule ^/(.*)$ http://geoloqi.com/$1?utm_source=DomainRedirect&#038;utm_medium=%{HTTP_HOST} [R=permanent,L]
...
</pre>
<p>This will make domain typos visible in Google Analytics under the &#8220;All Traffic Sources&#8221; section. You can clearly see the referrals from the typo&#8217;d domain name at the bottom of this list.</p>
<p><img src="http://neverusethisfont.com/blog/wp-content/uploads/2010/12/referrers_-_fake.png" alt="" title="geoloqi.com traffic sources" width="522" height="348" class="aligncenter size-full wp-image-282" /></p>
<p>You could also use the filter box to search for &#8220;DomainRedirect&#8221; and see only the typos. </p>
<p>I&#8217;d be curious to know if anybody else has other suggestions for tracking this type of thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2010/12/tracking-typos-of-your-domain-name-in-google-analytics/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to back up Dropbox automatically &#8211; daily, weekly, monthly snapshots</title>
		<link>http://neverusethisfont.com/blog/2010/07/how-to-back-up-dropbox-automatically-daily-weekly-monthly-snapshots/</link>
		<comments>http://neverusethisfont.com/blog/2010/07/how-to-back-up-dropbox-automatically-daily-weekly-monthly-snapshots/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 21:42:48 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[ownyourdata]]></category>
		<category><![CDATA[snapshots]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=248</guid>
		<description><![CDATA[Dropbox is great. Most of the time. It&#8217;s great when I need to easily share files with people while working on a project together. It keeps files in sync between multiple computers, and is the only solution I&#8217;ve found so far which works seamlessly and instantaneously. If you don&#8217;t already use it, I highly recommend [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://aaron.pk/dropbox">Dropbox</a> is great. Most of the time. It&#8217;s great when I need to easily share files with people while working on a project together. It keeps files in sync between multiple computers, and is the only solution I&#8217;ve found so far which works seamlessly and instantaneously. If you don&#8217;t already use it, I <a href="http://aaron.pk/dropbox">highly recommend it</a>.</p>
<div id="attachment_254" class="wp-caption alignright" style="width: 300px"><a href="http://aaron.pk/dropbox"><img src="http://neverusethisfont.com/blog/wp-content/uploads/2010/07/dropbox_logo_home.png" alt="Dropbox - Online file backup and sharing" title="Dropbox - Online file backup and sharing" width="290" height="75" class="size-full wp-image-254" /></a><p class="wp-caption-text">Dropbox - Online file backup and sharing</p></div>
<p>I&#8217;ve recently been having problems with <a href="http://aaron.pk/dropbox">Dropbox</a> ever since joining a shared folder which overflowed my quota. Completely unrelated files mysteriously disappeared. Luckily I had a snapshot from before I had joined the folder and was able to restore the files.</p>
<p>This prompted me to set up a proper backup system which makes snapshots daily, weekly and monthly.</p>
<p>This guide assumes you have a Linux server somewhere with no GUI.</p>
<p>First, follow the <a href="http://wiki.dropbox.com/TipsAndTricks/TextBasedLinuxInstall">Dropbox wiki instructions</a> for installing Dropbox on Linux. The process is relatively painless, and seems to just work. At the end, you&#8217;ll end up with a &#8220;Dropbox&#8221; folder in your home folder. This folder will always have the latest version of your files.</p>
<p>The next step is to take snapshots of that folder at regular intervals. I chose to keep 7 days of daily snapshots, 4 snapshots taken weekly, and 12 taken monthly. In theory, this should give me access to any files I&#8217;ve accidentally deleted within the past year.</p>
<p>This script will run rsync to clone the Dropbox folder into snapshot folders which will be overwritten over time, so you will only end up with 7+4+12 copies of your Dropbox folder. Save this code to a file called backup.sh or whatever you want, and make it executable (chmod 755 backup.sh).</p>
<p>backup.sh:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Makes daily snapshots in folders like &quot;daily-4-Thu&quot;, &quot;daily-5-Fri&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> == <span style="color: #ff0000;">&quot;daily&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">path</span>=daily-<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>u-<span style="color: #000000; font-weight: bold;">%</span>a<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Makes weekly snapshots in folders like &quot;weekly-1&quot; where 1 is the day of the month</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> == <span style="color: #ff0000;">&quot;weekly&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">path</span>=weekly-<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Makes  monthly snapshots in folders like &quot;monthly-04-Apr&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> == <span style="color: #ff0000;">&quot;monthly&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">path</span>=monthly-<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>b<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Run with &quot;go&quot; as the second CLI parameter to actually run the rsync command, otherwise prints the command that would have been run (useful for testing)</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$2&quot;</span> == <span style="color: #ff0000;">&quot;go&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
        rsync <span style="color: #660033;">-avz</span> <span style="color: #660033;">--delete</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aaron<span style="color: #000000; font-weight: bold;">/</span>Dropbox <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aaron<span style="color: #000000; font-weight: bold;">/</span>aaron<span style="color: #000000; font-weight: bold;">/</span>Dropbox-Backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$path</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> rsync <span style="color: #660033;">-avz</span> <span style="color: #660033;">--delete</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aaron<span style="color: #000000; font-weight: bold;">/</span>Dropbox <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aaron<span style="color: #000000; font-weight: bold;">/</span>Dropbox-Backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$path</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Add these lines to your crontab to run the backup script at the appropriate intervals. This will run the daily script every night at 1am, the weekly script on the 4th, 12th, 20th and 28th days of the month at 1:30am, and the monthly script on the 1st of the month at 2am.</p>
<p>crontab:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aaron<span style="color: #000000; font-weight: bold;">/</span>backup.sh daily go
<span style="color: #000000;">30</span> <span style="color: #000000;">1</span> <span style="color: #000000;">4</span>,<span style="color: #000000;">12</span>,<span style="color: #000000;">20</span>,<span style="color: #000000;">28</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aaron<span style="color: #000000; font-weight: bold;">/</span>backup.sh weekly go
<span style="color: #000000;">0</span> <span style="color: #000000;">2</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aaron<span style="color: #000000; font-weight: bold;">/</span>backup.sh monthly go</pre></div></div>

<p>Hopefully this saves you some headaches down the road when <a href="http://aaron.pk/dropbox">Dropbox</a> decides to play tricks on you.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2010/07/how-to-back-up-dropbox-automatically-daily-weekly-monthly-snapshots/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Linux Software RAID and LVM</title>
		<link>http://neverusethisfont.com/blog/2009/08/linux-software-raid-and-lvm/</link>
		<comments>http://neverusethisfont.com/blog/2009/08/linux-software-raid-and-lvm/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 17:48:48 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>
		<category><![CDATA[ext3]]></category>
		<category><![CDATA[LVM]]></category>
		<category><![CDATA[mdadm]]></category>
		<category><![CDATA[RAID 5]]></category>
		<category><![CDATA[Terabyte]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=97</guid>
		<description><![CDATA[I wanted to create a RAID 5 array with four 1tb drives. I only have three, but I have a 750gb and 320gb drive lying around. I figured there was probably a way to combine them into a 1tb drive that I could use with the others. Using Linux&#8217;s LVM, I can create a logical [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to create a RAID 5 array with four 1tb drives. I only have three, but I have a 750gb and 320gb drive lying around. I figured there was probably a way to combine them into a 1tb drive that I could use with the others.</p>
<p>Using Linux&#8217;s LVM, I can create a logical partition from the two smaller drives as big as the 1tb drive.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pvdisplay</pre></div></div>

<p>Lists all physical volumes managed by LVM. First we have to create the physical volumes for LVM. I prefer to create the volumes out of partitions, although you can do it from raw drives too.</p>
<p>First let&#8217;s use fdisk to create &#8220;Linux LVM&#8221; partitions on the two drives.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ fdisk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb
Press <span style="color: #ff0000;">&quot;n&quot;</span> to create a new partition
Press <span style="color: #ff0000;">&quot;t&quot;</span> to <span style="color: #000000; font-weight: bold;">set</span> the partition <span style="color: #7a0874; font-weight: bold;">type</span>, and enter <span style="color: #ff0000;">&quot;8e&quot;</span> <span style="color: #000000; font-weight: bold;">for</span> Linux LVM.</pre></div></div>

<p>When creating the partition, accepting the defaults will make it use the whole drive. I want to use the entire 750 drive and only part of the 320 drive, so that in total it has the same number of blocks as the 1tb drives. So I first created the &#8220;Linux RAID&#8221; partitions on the 1tb drives so I could see how many cylinders it listed, which ended up being <b>121601</b>. So I created a partition the full size of the 750 drive (91201 cylinders), then created a 121601-91201 cylinder partition on the 320 drive.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ fdisk <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb
Disk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb: <span style="color: #000000;">320.0</span> GB, <span style="color: #000000;">320072933376</span> bytes
<span style="color: #000000;">255</span> heads, <span style="color: #000000;">63</span> sectors<span style="color: #000000; font-weight: bold;">/</span>track, <span style="color: #000000;">38913</span> cylinders
   Device Boot      Start         End      Blocks   Id  System
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1               <span style="color: #000000;">1</span>       <span style="color: #000000;">30400</span>   <span style="color: #000000;">244187968</span>+  8e  Linux LVM
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb2           <span style="color: #000000;">30401</span>       <span style="color: #000000;">38913</span>    <span style="color: #000000;">68380672</span>+  <span style="color: #000000;">83</span>  Linux
&nbsp;
$ fdisk <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj
Disk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj: <span style="color: #000000;">750.1</span> GB, <span style="color: #000000;">750156374016</span> bytes
<span style="color: #000000;">255</span> heads, <span style="color: #000000;">63</span> sectors<span style="color: #000000; font-weight: bold;">/</span>track, <span style="color: #000000;">91201</span> cylinders
   Device Boot      Start         End      Blocks   Id  System
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj1               <span style="color: #000000;">1</span>       <span style="color: #000000;">91201</span>   <span style="color: #000000;">732572001</span>   8e  Linux LVM</pre></div></div>

<p>Now that I have the two partitions ready, I moved on to LVM setup.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pvcreate <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1
$ pvcreate <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj1</pre></div></div>

<p>This sets up the two partitions as physical volumes for LVM.</p>
<p>Next is creating a logical volume group:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ vgcreate vg_tb <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj1</pre></div></div>

<p>This creates a volume group called &#8220;vg_tb&#8221; using the two physical volumes sdb1 and sdj1.</p>
<p>Let&#8217;s take a look at what we have so far:</p>
<pre>
$ pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               vg_tb
  PV Size               232.88 GB / not usable 832.50 KB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              59616
  Free PE               59616
  Allocated PE          0
  PV UUID               70hPKX-n11U-RcB6-0Kyt-1SOP-ni7E-2Y9hcE

  --- Physical volume ---
  PV Name               /dev/sdj1
  VG Name               vg_tb
  PV Size               698.64 GB / not usable 2.34 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              178850
  Free PE               178850
  Allocated PE          0
  PV UUID               PzFb9b-lapG-KdT3-78nh-Gq75-F0Lo-I3xCrl

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               111.60 GB / not usable 2.86 MB
  Allocatable           yes
  PE Size (KByte)       32768
  Total PE              3571
  Free PE               1
  Allocated PE          3570
  PV UUID               1wM65Z-3QGd-vDiq-mq1R-YhEE-Ackp-hh3g13

$ vgdisplay
  --- Volume group ---
  VG Name               vg_tb
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               931.51 GB
  PE Size               4.00 MB
  Total PE              238466
  Alloc PE / Size       0 / 0
  Free  PE / Size       238466 / 931.51 GB
  VG UUID               olg9GP-x1sC-sFAD-TgWY-KIIx-YWNt-kL763n

  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               111.59 GB
  PE Size               32.00 MB
  Total PE              3571
  Alloc PE / Size       3570 / 111.56 GB
  Free  PE / Size       1 / 32.00 MB
  VG UUID               IZ25LV-oMOG-DwKK-QuFN-bqqp-ClUe-d71k5l
</pre>
<p>So far so good. The next step is to create a logical volume in the new volume group:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ lvcreate vg_tb <span style="color: #660033;">-n</span> onetb <span style="color: #660033;">-l</span> <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span>VG
  Logical volume <span style="color: #ff0000;">&quot;onetb&quot;</span> created</pre></div></div>

<p>This creates a new logical volume called &#8220;onetb&#8221; in the &#8220;vg_tb&#8221; group using 100% of the group&#8217;s available space. Now let&#8217;s take a look at the list of logical volumes:</p>
<pre>
$ lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_tb/onetb
  VG Name                vg_tb
  LV UUID                sQKaq9-D6Mv-p8it-vWGW-O7DX-FGmC-cl5FSh
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                931.51 GB
  Current LE             238466
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                G5hlbb-tA3S-qhTS-03us-f9dl-1Vxy-9vDSU5
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                109.62 GB
  Current LE             3508
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                7NZrY9-1wSJ-4fRp-VPnM-V07u-9rj8-vmtxTx
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
</pre>
<p>You can ignore all of the VolGroup00 things, those are the auto-created volumes from when I installed Fedora. </p>
<p>At this point, I have a new device at /dev/vg_tb/onetb which is the same size as my 1tb drives, and I can use it exactly as I would use the 1tb partition at /dev/sdf1.</p>
<p>Now it&#8217;s time to create the RAID 5 array from these four volumes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ mdadm <span style="color: #660033;">-v</span> <span style="color: #660033;">--create</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md1 <span style="color: #660033;">--chunk</span>=<span style="color: #000000;">128</span> <span style="color: #660033;">--level</span>=<span style="color: #000000;">5</span> <span style="color: #660033;">--raid-devices</span>=<span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdf1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdh1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdi1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vg_tb<span style="color: #000000; font-weight: bold;">/</span>onetb
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: <span style="color: #c20cb9; font-weight: bold;">size</span> <span style="color: #000000; font-weight: bold;">set</span> to 976756608K
mdadm: array <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md1 started.</pre></div></div>

<p>The array will begin syncing, and you can watch it by running:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">watch</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1</span> <span style="color: #ff0000;">&quot;cat /proc/mdstat&quot;</span>
Personalities : <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid6<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid5<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid4<span style="color: #7a0874; font-weight: bold;">&#93;</span>
md1 : active raid5 dm-<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdi1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdh1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdf1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
      <span style="color: #000000;">2930269824</span> blocks level <span style="color: #000000;">5</span>, 128k chunk, algorithm <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>UUU_<span style="color: #7a0874; font-weight: bold;">&#93;</span>
      <span style="color: #7a0874; font-weight: bold;">&#91;</span>=<span style="color: #000000; font-weight: bold;">&gt;</span>...................<span style="color: #7a0874; font-weight: bold;">&#93;</span>  recovery =  <span style="color: #000000;">5.5</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">54017536</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">976756608</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">finish</span>=593.1min <span style="color: #007800;">speed</span>=25925K<span style="color: #000000; font-weight: bold;">/</span>sec
&nbsp;
md0 : active raid5 sdg1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdc1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sde1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdd1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
      <span style="color: #000000;">2197715712</span> blocks level <span style="color: #000000;">5</span>, 64k chunk, algorithm <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>UUUU<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
unused devices: <span style="color: #000000; font-weight: bold;">&lt;</span>none<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>While this is syncing, we can create the ext3 filesystem.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ mke2fs <span style="color: #660033;">-j</span> <span style="color: #660033;">-b</span> <span style="color: #000000;">4096</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-E</span> <span style="color: #007800;">stride</span>=<span style="color: #000000;">32</span>,stripe-width=<span style="color: #000000;">96</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md1</pre></div></div>

<p>This creates an ext2 filesystem with journaling (ext3), the block size is 4kb, and 0% of the blocks are reserved for the superuser. The stride is calculated as the raid block size / ext2 block size (128k / 4k = 32). The stripe width is calculated as the stride value times the number of data disks in the array. In a 4-disk RAID 5 array, there are three data disks, one being for the parity data. </p>
<p>This will take some time, and will significantly slow down the sync process. Mine dropped from 25mb/s to around 1mb/s. I figure I&#8217;ll let it create the filesystem so I can start copying data to it right away, and let it finish its sync on its own time.</p>
<p>While you&#8217;re at it, you should set up <a href="http://munin.projects.linpro.no/">munin</a> to monitor the SMART data from all the drives as well as the status of the array using my <a href="http://aaronparecki.com/GitHub">munin-raid-monitor</a> plugin.</p>
<p>Additional Reading:</p>
<div style="font-size:10px">
<ul>
<li><a href="http://linux-raid.osdl.org/index.php/RAID_setup">http://linux-raid.osdl.org/index.php/RAID_setup</a></li>
<li><a href="http://bfish.xaedalus.net/2006/11/software-raid-5-in-ubuntu-with-mdadm/">http://bfish.xaedalus.net/2006/11/software-raid-5-in-ubuntu-with-mdadm/</a></li>
<li><a href="http://www.linuxquestions.org/questions/linux-hardware-18/how-can-i-override-the-5.00-reserved-for-the-super-user-mkfs.ext3-creates-616546/">http://www.linuxquestions.org/questions/linux-hardware-18/how-can-i-override-the-5.00-reserved-for-the-super-user-mkfs.ext3-creates-616546/</a></li>
<li><a href="http://www.linuxconfig.org/Linux_lvm_-_Logical_Volume_Manager">http://www.linuxconfig.org/Linux_lvm_-_Logical_Volume_Manager</a></li>
<li><a href="http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/LV_create.html">http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/LV_create.html</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2009/08/linux-software-raid-and-lvm/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Workaround for Comcast blocking port 25</title>
		<link>http://neverusethisfont.com/blog/2009/07/workaround-for-comcast-blocking-port-25/</link>
		<comments>http://neverusethisfont.com/blog/2009/07/workaround-for-comcast-blocking-port-25/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 14:01:32 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=71</guid>
		<description><![CDATA[Comcast just started blocking port 25 outgoing. I have several computers at home configured to send email reports of cron jobs. Of course they do this by trying to send mail on port 25 from inside the house to my mail server outside. Now that Comcast is blocking that, I need some other way for [...]]]></description>
			<content:encoded><![CDATA[<p>Comcast just started blocking port 25 outgoing. I have several computers at home configured to send email reports of cron jobs. Of course they do this by trying to send mail on port 25 from inside the house to my mail server outside. Now that Comcast is blocking that, I need some other way for my emails to be delivered.</p>
<p>The easiest solution I could come up with was to tell my mail server to listen on another port such as 587, and have my firewall route requests for port 25 to port 587. Here is the iptables rule to do that!</p>
<p><code>iptables -t nat -A PREROUTING -p tcp -i eth0 -d xx.xx.xx.xx --dport 25 -j DNAT --to-destination :587</code></p>
<p>Where xx.xx.xx.xx is the IP address of my mail server. Now all the computers inside think they are communicating with my mail server on port 25, but the firewall secretly passes the request on to port 587 instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2009/07/workaround-for-comcast-blocking-port-25/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>SSHfs on OS X via Samba</title>
		<link>http://neverusethisfont.com/blog/2008/11/sshfs-on-os-x-via-samba/</link>
		<comments>http://neverusethisfont.com/blog/2008/11/sshfs-on-os-x-via-samba/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 19:39:03 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X/Apple]]></category>
		<category><![CDATA[Server Software]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=62</guid>
		<description><![CDATA[Why, you ask? Because sshfs on OSX&#8217;s version of sshfs is wonky. My solution is to use an intermediate linux server which does the sshfs mount, then serves that to os x over a samba share. Another benefit to this is that you only need one samba share to mount all your sshfs connections, since [...]]]></description>
			<content:encoded><![CDATA[<p>Why, you ask?</p>
<p>Because sshfs on OSX&#8217;s version of sshfs is wonky.</p>
<p><a href="http://neverusethisfont.com/blog/wp-content/uploads/2008/11/osx-samba-sshfs.jpg"><img class="aligncenter size-full wp-image-64" title="osx-samba-sshfs" src="http://neverusethisfont.com/blog/wp-content/uploads/2008/11/osx-samba-sshfs.jpg" alt="" width="500" height="166" /></a></p>
<p>My solution is to use an intermediate linux server which does the sshfs mount, then serves that to os x over a samba share. Another benefit to this is that you only need one samba share to mount all your sshfs connections, since the linux server will be taking care of those. Also if you had a windows computer you wanted to use this with, it would also be able to mount the samba share from the linux server.</p>
<p>Let&#8217;s get started.</p>
<p>I ran into a couple tricky config issues while setting this up. This post is here mostly for me to remember them for next time I need to do them. If anybody else happens to stumble across this and finds it useful, then that&#8217;s a bonus.</p>
<p>On the linux server, you&#8217;ll need to install fuse-sshfs as well as samba. In Fedora, this can be done like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> samba
$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> fuse-sshfs</pre></div></div>

<p>You need to add the linux user to the fuse group, and create a samba user account.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ usermod <span style="color: #660033;">-a</span> <span style="color: #660033;">-G</span> fuse aaron
$ smbpasswd <span style="color: #660033;">-a</span> aaron</pre></div></div>

<p>Here&#8217;s something that isn&#8217;t normally covered in fuse tutorials. In order to allow samba to access the fuse mount, you need to create a file, /etc/fuse.conf with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user_allow_other</pre></div></div>

<p>If you don&#8217;t do that, the mounted folder just disappears from the samba share.</p>
<p>You need to make some changes to /etc/samba/smb.conf file in order for symlinks to be shared to os x. I&#8217;m not sure if this is required for fuse to work, but it&#8217;s nice to have anyway:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">unix extensions = no  <span style="color: #7a0874; font-weight: bold;">&#40;</span>add this outside of a share definition<span style="color: #7a0874; font-weight: bold;">&#41;</span>
follow symlinks = <span style="color: #c20cb9; font-weight: bold;">yes</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>add this inside a share definition<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Of course, you need to configure the firewall to allow access to samba, (tcp and udp ports 445, 137, 138, 139 should do). And, you&#8217;ll need to make sure samba starts when the machine boots.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ chkconfig smb on</pre></div></div>

<p>We&#8217;re almost there.</p>
<p>To actually mount the sshfs folder, you&#8217;ll run a command which looks something like this. Note the extra option at the end:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sshfs username<span style="color: #000000; font-weight: bold;">@</span>example.com:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>username mount_target <span style="color: #660033;">-o</span> allow_other</pre></div></div>

<p>Now you can mount your home folder on the linux server over samba, and you&#8217;ll see a folder mount_target, which is the sshfs mount.</p>
<p>Note: you&#8217;ll probably want to set up your ssh server with public key authentication so you don&#8217;t have to enter your password every time you connect. This is not the topic of this post, so I won&#8217;t bother mentioning how. There&#8217;s <a href="http://sial.org/howto/openssh/publickey-auth/">plenty</a> of <a href="http://www.ssh.com/support/documentation/online/ssh/adminguide/32/Public-Key_Authentication-2.html">other</a> <a href="http://www.onlamp.com/pub/a/onlamp/excerpt/ssh_8/">tutorials</a> on the Internet.</p>
<p>I hope this covers it, but feel free to comment if I&#8217;ve left anything out.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2008/11/sshfs-on-os-x-via-samba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redundant web &amp; database servers on a budget using Virtual Private Servers</title>
		<link>http://neverusethisfont.com/blog/2008/09/redundant-web-database-servers-on-a-budget-using-virtual-private-servers/</link>
		<comments>http://neverusethisfont.com/blog/2008/09/redundant-web-database-servers-on-a-budget-using-virtual-private-servers/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 03:33:41 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>
		<category><![CDATA[Website Development]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=55</guid>
		<description><![CDATA[Background First let me just say that I have been struggling with this problem for quite some time now. The problem is to provide redundancy for a website so that the website continues to run even if there is a problem with one of the servers it&#8217;s running on. In a typical simple server setup, [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>First let me just say that I have been struggling with this problem for quite some time now. The problem is to provide redundancy for a website so that the website continues to run even if there is a problem with one of the servers it&#8217;s running on.</p>
<p>In a typical simple server setup, there is a single machine running the web and mysql servers. The machine can be either a dedicated server, or as I have been using, a <a href="http://en.wikipedia.org/wiki/Virtual_private_server">VPS</a>. I have been running my websites off of VPSs for several years now, with minimal trouble. This works most of the time, but the having a site on must one machine means a Single Point Of Failure. If something is wrong with that server, the websites are non-functional until it is fixed. The trouble I have run in to falls under a few categories:</p>
<ol>
<li>A problem with the physical host</li>
<li>A problem at the VPS level (operating system, Apache or MySQL errors, etc)</li>
<li>A problem at the network level</li>
</ol>
<h3>Problems with the physical host</h3>
<p>Problems with the physical host do occur. With a VPS, these are completely out of your control, and are the responsibility of the hosting provider. Some examples of things I&#8217;ve encountered include a failed RAID array, a corrupted filesystem on the host, requiring a several-hour-long fsck, or an unplugged power cord. The worst issue I&#8217;ve had was when the provider said they had lost 2 drives in a RAID 5 array, and all the VPSs on that host were completely gone. Luckily I had a backup of the system and was up and running on a new VPS within a couple hours.</p>
<h3>Problems at the application level</h3>
<p>I haven&#8217;t actually run in to many problems at the VPS level compared to the other types of problems. However the latest issue I&#8217;m having does fall in to this category. Apache periodically starts crashing part way through serving a page with the error &#8220;[notice] child pid 21106 exit signal Segmentation fault (11)&#8221;. Visitors see a completely blank page some of the time.</p>
<h3>Problems at the nework level</h3>
<p>By far the most frequently occurring problem I encounter is network-related. These problems are usually out of both my and the hosting provider&#8217;s control. If there is a problem with the network, the downtime can vary greatly, anywhere from 5 minutes to 12 hours. It can be caused by a <a href="http://en.wikipedia.org/wiki/Denial-of-service_attack">Denial of Service</a> attack on a completely different server in the same datacenter, or it could just be a routing issue somewhere along the path from me to the server.</p>
<p>A typical redundant setup will cover both #1 and #2. Typical setups may include one or more load balancers in front of multiple application servers. If a machine goes down, the load balancers can stop sending requests to it. This works great if you&#8217;re trying to protect against servers failing. However if the load balancers are all on the same network, unless the network has multiple redundant paths, the whole system is still vulnerable to network issues.</p>
<h2>My Solution</h2>
<p>Since I most frequently encounter network issues, I can&#8217;t get away with a just a typical load-balancing solution. What I really need is a copy of the entire website in a geographically different location. Here is my solution:</p>
<p>One VPS in Dallas, TX (called triton), and another VPS in Newark, NJ (called proteus). (Yes, I name my servers after Greek mythology.) Triton holds the master copies of the websites&#8217; php files, and proteus gets a copy of them via rsync. If I ever need to update the site, I edit the files on triton and then rsync them to proteus. Here is where the redundancy comes in. My DNS entries point the domain to both IP addresses. This means during normal operation, visitors will be more or less distributed between the two hosts evenly. If one server goes down, I can stop resolving DNS queries to it, and the worst that will happen is some dead pages for as long as the TTL on the domain.</p>
<p>This works as long as you&#8217;re just serving static content. Serving dynamic content, such as from a database, gets a little more complicated. MySQL&#8217;s NDB clusters are apparently only effective when run within a high speed network, with at least a 10 MBPS connection between them. Replication turns out to be more along the lines of what I&#8217;m looking for.</p>
<h2>Replication to the rescue!</h2>
<p>Replication is designed for a one-way sync between a master and slave. However, it is possible to configure two servers to be both a master and a slave. They will both notify each other of changes made to their databases. There is one trick you need to do in order to prevent primary key conflicts if rows are written to both databases while the link is down. It involves setting the auto_increment offset and increment, so that one server will only create even keys, and the other creates only odd keys.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>my.cnf
    auto_increment_increment = <span style="color: #000000;">2</span>
    auto_increment_offset = <span style="color: #000000;">1</span></pre></div></div>

<p>Here&#8217;s some dry reading on <a href="http://dev.mysql.com/doc/refman/5.0/en/replication.html">replication</a> from the MySQL manual. Here is a <a href="http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html">slightly clearer guide to replication</a> which sums everything up pretty nicely. Overall, replication was pretty easy to set up. It seems to be pretty robust as well. I simulated network problems by adding firewall rules to block the servers from each other. I was able to continue to interact with each database, and the changes were all carried over when the link came back up.</p>
<p>Feel free to comment if you have any experience or insights into configuring web and database servers! I&#8217;m curious to hear what other people have done.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2008/09/redundant-web-database-servers-on-a-budget-using-virtual-private-servers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Another raid5 scare, and how to recover an apparently trashed array</title>
		<link>http://neverusethisfont.com/blog/2008/08/another-raid5-scare-and-how-to-recover-an-apparently-trashed-array/</link>
		<comments>http://neverusethisfont.com/blog/2008/08/another-raid5-scare-and-how-to-recover-an-apparently-trashed-array/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 17:52:12 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[mdadm]]></category>
		<category><![CDATA[raid]]></category>
		<category><![CDATA[raid5]]></category>

		<guid isPermaLink="false">http://blog.neverusethisfont.com/2008/08/another-raid5-scare-and-how-to-recover-an-apparently-trashed-array/</guid>
		<description><![CDATA[This morning after waking up to lots of thunder and lightning, I got a text message saying my raid5 array had failed. Only this time, 2 of the 3 drives were missing. Since both of those drives were actually mounted via a vblade share (on a different physical machine), I assumed that the other server [...]]]></description>
			<content:encoded><![CDATA[<p>This morning after waking up to lots of thunder and lightning, I got a text message saying my raid5 array had failed. Only this time, 2 of the 3 drives were missing. Since both of those drives were actually mounted via a vblade share (on a different physical machine), I assumed that the other server had freaked out during a power surge. I quickly rebooted the machine to bring back the vblade shares, but then the trouble started.</p>
<p>At some point, the array was &#8220;started&#8221; but had two faulty drives. I tried &#8211;remove and &#8211;add to remove and re-add the &#8220;faulty&#8221; drives. This had the effect of bringing the array back &#8220;online&#8221; with all the drives as spares. I removed the drives again, and tried the trick I used last time:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mdadm <span style="color: #660033;">--assemble</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md0 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda2 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>etherd<span style="color: #000000; font-weight: bold;">/</span>e4.1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>etherd<span style="color: #000000; font-weight: bold;">/</span>e4.2</pre></div></div>

<p>However, this also didn&#8217;t work. It showed the array with /dev/sda2 and /dev/etherd/e4.2 as spares, and e4.1 was nowhere to be seen. At this point I was a little more than worried that I had done something to trash the array. That&#8217;s when a google search led me to this handy command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mdadm <span style="color: #660033;">-E</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda2</pre></div></div>

<p>This prints out the superblock information that is present on the hard drive. This told me that the e4.2 drive had not been damaged, since I was able to see information there. Also, the UUIDs on all three drives still matched. However, the bottom section of the report differed on all the drives.</p>
<p>A few google searches later, and I came across this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mdadm <span style="color: #660033;">--create</span> <span style="color: #660033;">--assume-clean</span> <span style="color: #660033;">--level</span>=<span style="color: #000000;">5</span> <span style="color: #660033;">--raid-devices</span>=<span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md0 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda2 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>etherd<span style="color: #000000; font-weight: bold;">/</span>e4.2 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>etherd<span style="color: #000000; font-weight: bold;">/</span>e4.1</pre></div></div>

<p>Using the &#8211;assume-clean flag tells mdadm not to write any data to the drives, or to start initializing the array. However, what I didn&#8217;t realize was that it would reset the UUIDs. That command brought the array back online, at least according to /proc/mdstat, but when I tried to mount it, it couldn&#8217;t figure out the filesystem.</p>
<p>That&#8217;s when I realized that the *order* in which you specify the drives to the &#8211;create command actually matters. I re-ran the command like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mdadm <span style="color: #660033;">--create</span> <span style="color: #660033;">--assume-clean</span> <span style="color: #660033;">--level</span>=<span style="color: #000000;">5</span> <span style="color: #660033;">--raid-devices</span>=<span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md0 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda2 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>etherd<span style="color: #000000; font-weight: bold;">/</span>e4.1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>etherd<span style="color: #000000; font-weight: bold;">/</span>e4.2</pre></div></div>

<p>The array came back online, and I was able to mount it!</p>
<p>So while RAID 5 protects against a single hard drive failing, it does not protect against me running stupid commands on the array. I&#8217;m going to have to start backing up my raid arrays onto other drives&#8230;</p>
<p><strong>Useful Links</strong></p>
<ul>
<li><a href="http://ubuntuforums.org/archive/index.php/t-410136.html">http://ubuntuforums.org/archive/index.php/t-410136.html</a></li>
<li><a href="http://www.linuxdevcenter.com/pub/a/linux/2002/12/05/RAID.html?page=2">http://www.linuxdevcenter.com/pub/a/linux/2002/12/05/RAID.html?page=2</a></li>
<li><a href="http://www.amazon.com/Managing-RAID-Linux-Derek-Vadala/dp/1565927303/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1219078238&amp;sr=8-1">Managing RAID on Linux (Amazon.com)</a></li>
<li><a href="http://episteme.arstechnica.com/eve/forums/a/tpc/f/96509133/m/697004072931">http://episteme.arstechnica.com/eve/forums/a/tpc/f/96509133/m/697004072931</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2008/08/another-raid5-scare-and-how-to-recover-an-apparently-trashed-array/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Treasure Hunt &#8211; Question 2</title>
		<link>http://neverusethisfont.com/blog/2008/05/google-treasure-hunt/</link>
		<comments>http://neverusethisfont.com/blog/2008/05/google-treasure-hunt/#comments</comments>
		<pubDate>Tue, 20 May 2008 03:35:12 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[google cis programming bash]]></category>

		<guid isPermaLink="false">http://blog.neverusethisfont.com/2008/05/google-treasure-hunt/</guid>
		<description><![CDATA[I just stumbled across Google&#8217;s Treasure Hunt. They&#8217;re always doing neat things, so I checked it out. It&#8217;s a series of four problem-solving puzzles released one week at a time. I found out about it after the first question was already over, so I jumped in starting with the second question. Question 2: File sum [...]]]></description>
			<content:encoded><![CDATA[<p>I just stumbled across Google&#8217;s <a href="http://google-au.blogspot.com/2008/05/google-treasure-hunt.html">Treasure Hunt</a>. They&#8217;re always doing neat things, so I checked it out. It&#8217;s a series of four problem-solving puzzles released one week at a time. I found out about it after the first question was already over, so I jumped in starting with the second question.</p>
<p><strong>Question 2</strong>: File sum and multiplication problem</p>
<p>In this problem you are given a zip folder with hundreds of text files nested in folders an arbitrary number of levels deep. The question asks to find the sum of the nth line of all files with abc in their path, ending in .xyz. You do this twice, then calculate the product of the two sums. You can download the file I got from them at the link below.<br />
<a href="http://blog.neverusethisfont.com/wp-content/uploads/2008/05/googletreasurehunt08_9334957515161249657.zip">googletreasurehunt.zip</a></p>
<p>My question is below:</p>
<blockquote><p>Sum of line 3 for all files with path or name containing jkl and ending in .rtf<br />
Sum of line 5 for all files with path or name containing stu and ending in .rtf<br />
Multiply all the above sums together and enter the product below.</p></blockquote>
<p>I thought this would be a good chance to practice my bash scripting, so I decided to give it a shot.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-wholename</span> <span style="color: #ff0000;">&quot;*jkl*\.rtf&quot;</span></pre></div></div>

<p>-type f restricts the search to files, not directories. -wholename searches for files matching that pattern. Once we run this, we get a list of all the files we&#8217;ll need to process. Now we need to create a running total of the values in the nth line in each file. This is where a bash &#8216;for&#8217; loop and &#8216;awk&#8217; come in handy.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-wholename</span> <span style="color: #ff0000;">&quot;*jkl*\.rtf&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>The &#8216;$&#8217; tells bash to execute that command and return the result. The &#8216;for&#8217; loop looks at the output line by line, and the variable x will contain each filename.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'NR==3'</span> filename.txt</pre></div></div>

<p>This is an awk command that prints the 3rd line of filename.txt. If we can stick this into the &#8216;for&#8217; loop, we can get a running total.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">sum1</span>=<span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-wholename</span> <span style="color: #ff0000;">&quot;*jkl*\.rtf&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">sum1</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'NR==3'</span> <span style="color: #007800;">$x</span><span style="color: #000000; font-weight: bold;">`</span> + <span style="color: #007800;">$sum1</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$sum1</span></pre></div></div>

<p>Now we just repeat for the other pattern, and we end up with our sum in two variables. Calculating the product is simple.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$sum1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #007800;">$sum2</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Personally, I thought this puzzle was a little bit simplistic. I would have expected them to throw in some tricks, so that a poorly written search command would return some other files that would mess with your result. Now that I&#8217;ve said that, I hope I got it right! I find out in 10 hours if my answer is correct.</p>
<p>Feel free to comment if you have a different and/or better solution to this problem!</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2008/05/google-treasure-hunt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to keep a MySQL connection alive</title>
		<link>http://neverusethisfont.com/blog/2007/05/how-to-keep-a-mysql-connection-alive/</link>
		<comments>http://neverusethisfont.com/blog/2007/05/how-to-keep-a-mysql-connection-alive/#comments</comments>
		<pubDate>Sun, 27 May 2007 06:36:12 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>

		<guid isPermaLink="false">http://blog.neverusethisfont.com/2007/05/how-to-keep-a-mysql-connection-alive/</guid>
		<description><![CDATA[Ok, so I wasted about 3 hours on this, and have only sort of found a solution. I have a PHP script which is going to be running 24/7 checking a message queue and then interacting with a database when a message is received. It was mostly working, until it sat there for a day [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so I wasted about 3 hours on this, and have only sort of found a solution. I have a PHP script which is going to be running 24/7 checking a message queue and then interacting with a database when a message is received. It was mostly working, until it sat there for a day and I tried to use it the next day. The PHP script had quit, with the error &#8220;MySQL server has gone away.&#8221; I figured there must be some sort of time limit that the mysql server will keep an idle connection alive. I couldn&#8217;t find it, but luckily I was talking to <a href="http://nickmudge.info" >nick</a>, and he did! He found <a href="http://viconflex.blogspot.com/2006/11/how-to-keep-db-connections-alive-in.html" >this</a> blog entry. So I changed the my.cnf file to set the timeout to one week:</p>
<blockquote><p>wait_timeout=604800<br />
interactive_timeout=604800</p></blockquote>
<p>That&#8217;ll do for now. The other alternative would be to check if the connection is alive before running a query, and connecting if it isn&#8217;t. I couldn&#8217;t get that one to work, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2007/05/how-to-keep-a-mysql-connection-alive/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

