Monday, January 14, 2013

Using FreeNAS to build a DIY home server


Using FreeNAS to build a DIY home server

We haven’t checked in with FreeNAS, the FreeBSD-based DIY NAS OS, in quite some time. The OS has been completely overhauled, plugin support has been added, and it now works with even more hardware.
Since the last time we built a FreeNAS box, back in January 2010, the OS has been through some changes. It switched developers, nearly switched platforms, removed media streaming, added it back in via plugins, added better ZFS management, and more. FreeNAS promises near-endless customization and hardware support, enabling nearly anyone to build a highly moddable NAS from off-the-shelf parts. I’ve been promising an updated FreeNAS build for quite a while, and now’s the time to deliver. I assembled a cream-of-the-crop batch of hardware, got the latest version of FreeNAS, and got cracking.

Choosing the Hardware

The beauty of FreeNAS is that it’ll work with just about any old hardware you have lying around—you don’t need to build a special box for it. This “build” is more about exploring the new version of FreeNAS than it is about the hardware itself. I took the opportunity to build a pretty powerful system, but you don’t have to take my hardware choices as your minimum recommended specs or anything like that. I just wanted to see what would happen if I gave it beefy hardware to play with.
I chose a Fractal Array R2 chassis, which has six drive bays and an integrated PSU. I had a Mini-ITX FM1 board and an AMD A8 APU lying around and decided to use those, because a more capable CPU in your NAS means better transcoding and streaming. You could just as easily use any Mini-ITX board with a PCIe slot, maybe one with an integrated Atom or Brazos chip, if you want to save some money.
Four Western Digital Caviar Red NAS drives at 3TB each give me a theoretical 12TB of capacity if I were just going to make a RAID 0, which I’m not. Because I’ll be using a filesystem called ZFS, which does all its volume management in software, I want a good host-bus adapter that doesn’t insist on imposing its own hardware RAID over it—just something to pass the commands from the OS to the drives. I picked LSI’s SAS-9207-8i, which can control up to eight 6Gb/s drives and runs on a x8 PCIe 3.0 bus. Because I want to use the case’s SATA power connectors, I also bought a HighPoint Mini-SAS-to-SATA breakout cable rather than use the included connectors, which run on Molex power.
Because ZFS loves RAM and wants as much as you can throw at it (the specs recommend at least 1GB per TB of storage), I used two 8GB DDR3 DIMMs from G.Skill.
FreeNAS won’t mount any storage on the boot drive, and only takes up about 2GB total (with another 2GB swap), so there’s no point wasting a hard drive on it. It’s perfectly happy booting from a flash drive. I just used an 8GB drive left over from a CES press kit.

Set it Up

Since this is a very straightforward build but a complicated software install, I’ll skip the step-by-step build entirely, and start with the software configuration. It’s a bit of a doozy. Thankfully, I have the excellent instructions on Freenas.org and the FreeNas Quick Start Guide to help. Here’s how to set up FreeNAS; create volumes; set up users, groups, and sharing; and install a few streaming plugins.

1. Install the OS

To create the bootable OS image (from a Windows machine), you’ll need the aforementioned USB drive, the programs 7-Zip and Win32 Disk Imager, and the img.xz file for your install. We’re using FreeNAS 8.2.0 Release 1. Download the FreeNAS-8.2.0-RELEASE-p1-x64.img.xz file fromSourceForge. Extract the img.xz file using 7-Zip to turn it into an .img file, then burn that file onto your USB key with Win32 Disk Imager. This might take a few minutes. Once it’s ready, plug the USB key into one of the FreeNAS box’s rear USB ports and turn on the machine. You’ll need a keyboard and a monitor for this, but only for a few minutes. Make sure the FreeNAS box is connected to your network via Ethernet. Make sure the system is set to boot from USB. The system will spend a few minutes doing a self-test and then dump you at a screen called Console Setup. At this point, under a list of 11 options, you should see the phrase “You may try the following URLs to access the web user interface,” followed by an IP address. Go to another computer on your network and enter that address into the web browser; you should be able to get right into the web console, which will make this whole process a lot easier (image A).
INGREDIENTS
PARTURLPrice
Case/PSUFractal Array R2 w/300W SFX PSUwww.fractal-design.com$200
MoboAsus F1A75-I Deluxewww.asus.com$175
CPUAMD A8-3850 2.9GHz APUwww.amd.com$100
CoolerStock AMDwww.amd.com$0
RAMG.Skill RipjawsXwww.gskill.com$105
Boot Drive8GB Flash Drivevarious$8
Hard Drives3TB WD Red NAS drive (x4)www.wdc.com$880
Drive ControllerLSI SAS 9207-8iwww.lsi.com$305
SAS-to-SATA cableHighPoint Int-MS-1M4Swww.highpoint-tech.com$10
OSFreeNAS 8.2 Releasewww.freenas.org$0
Total$1,783

You’ll notice a blinking Alert light on the upper right. Click it and you’ll see that you need to change the admin password. Hit the Account button to the left of the Alert button, then select Change Password. Changing the admin username from “admin” can help with security too. You should also set up an email address for the root account, so FreeNAS can email you with admin alerts. Go to Account, then Users, then View Users, and click Change Email on the root account. You should also set up console logging by going to System > Settings > Advanced and selecting Show Console messages in footer.


2. Set Up Storage

Now for the fun part: volume management. Thousands of words can be and have been written about the relative merits of the various traditional RAID levels, as well as ZFS-specific types like RAIDZ1 and RAIDZ2. Any choice will be a trade-off between performance, capacity, and robustness. I’m going with RAID-Z2, which will allow me to tolerate up to two disk failures without data loss.
Go to Storage > Volumes > Volume Manager. Create a volume name (I used “mpcstore”), then hold Ctrl and select the drives to use—I used all four drives. For filesystem type, select ZFS, then RAIDZ2. Select Add Volume. My four 3TB drives created a volume of 6TB; I’m sacrificing space for redundancy.
Inside the volume, I’ll create individual ZFS datasets so I can set granular permissions on each of them. Because I’m the first user, I’ll create a dataset within mpcstore for myself. In the left navigation pane I’ll go to Storage > Volumes >
/mnt/mpcstore and select Create ZFS Dataset. I’ll call it “nedstore” and give it an unlimited quota (image B).



3. Add Users and Groups

FreeNAS can be configured to inherit users from an Active Directory or LDAP, but I’m assuming that this device will be used in an unmanaged home network, so we’ll assign users with the same names as the Windows login names they use, per FreeNAS’s instructions.
I’ve created a user named Nathan (for myself), and selected “Create a new primary group for the user,” which will let me fine-tune permissions. I set my home directory to the dataset I created earlier, i.e., /mnt/mpcstore/nedstore.

4. Configure Permissions

Go back into Volumes and find the dataset you created earlier—in my case, that’s nedstore. Click Change Permissions and select the user you just created. Here you can control which users and groups have read/write access to the dataset (image C). Repeat the dataset, user, and permission steps for any users you create.


5. Set Up a Media Share

I’m going to set up a media dataset so I can share my music and movies with the rest of the Windows computers in my network. Follow the procedure above for setting up a new dataset (I called it Media), then browse in the navigation pane to Sharing > Windows (CIFS) > Add Windows (CIFS) Share. Create a new share and point it to the dataset you’ve just created (image D).
You can either restrict it to specific users or groups, or enable an anonymous Guest Mode. If you have Apple computers on your network, you should also turn on AFP; if you have Linux, enable NFS. You can also enable SSH, rsync (for replication), iSCSI, and more, all from the Services panel.

6. Map the Drive

Now you can map the Windows share you’ve just created. Go to My Computer, right-click, and select Add Network Location. Plug in the IP (the same one in your web console) and share name, as shown in the image (image E). Give it a fancy name. Note that you’ll have to configure permissions so that users have write access if you want to be able to add files and folders via Explorer.


7. Set Up the Plugins Jail

Earlier versions of FreeNAS contained robust streaming options, such as iTunes, uPnP, and BitTorrent clients. FreeNAS version 8.2 restored that functionality via the use of plugins. The word “plugin,” however, dramatically overstates the ease of using these. To install and set up these plugins, first go to your storage volume and create two ZFS datasets, one of at least 2GB called Jail and another called Software (image F). The plugin system basically creates a virtualized FreeBSD system inside your FreeNAS system, and by this point if you’re tearing your hair out, you’re not alone.
Next, go back to SourceForge and find the plugins_Jail.pbi file for the release you’re running. In our case, that’s at http://sourceforge.net/projects/freenas/files/FreeNAS-8.2.0/RELEASE/x64/plugins/. Download the PBI file to your computer. Now click the little wrench icon next to Plugins in the Services menu. That’ll put you through a three-part setup screen. The first one will give you a temporary place to store the PBI you’re about to upload. I just used the root of my mpcstore. The second lets you set up the paths to your jail and software datasets. Point the plugins jail path to the jail dataset and the archive path to the software dataset (image G). The third step is to upload the plugins jail PBI file from your desktop.
You’ll also need to create a separate pingable IP address for the software jail, distinct from your FreeNAS IP address (image H).




8. Install Plugins

Now you should be able to slide the Plugins slider to On and click the Plugins menu at the top. Go back to SourceForge and download the PBI files for the plugins you want to install. Right now the ones available are Transmission (a BitTorrent client), MiniDLNA (a, yes, DLNA client), and Firefly, a no-longer-maintained iTunes-library service. Once you’ve downloaded them, hit the Install Plugin button and browse to the PBI file and upload it. You’ll see it appear in the Plugins list, with service status set to Off. Create a mount point within the jail pointing to a folder outside the jail (image I). I directed it to the same dataset I’m using for my Windows share, so I can drag-and-drop media that can then be broadcast over MiniDLNA and Firefly. Easy, right?
Now go to the left-side navigation tree and go to Services > Plugins, and select the plugin you just installed. I’ll use MiniDLNA as an example. Give it a friendly name and a media directory. Note that your media directory should use a relative path within your software jail, so it’s best to just type it in manually. I used /media again (image J). Save your changes and turn the plugin on. Make sure the IP address you picked for your software jail is working and you should see the DLNA server show up in your list of UPnP devices (I used VLC to check).


Paddling in the Shallow End

So now you know how to set up users, groups, datasets, and sharing, and you’ve got your plugins ready to go. We’ve only scratched the surface of what FreeNAS has to offer. Fortunately, there’s a robust community that loves documentation and has its own forum with discussions and FAQs for every part of the FreeNAS experience, from hardware to software to plugins to fine-tuning, and more (bit.ly/OosjiB).
One note: Be sure to back up your NAS data to an external drive. Even with two-disk loss tolerance, you never know when disaster will strike. You can use FreeNAS’s built‑in rsync to make sure you have all your data synched to an external drive.
As for the specific hardware I used, it’s probably overkill for most home users. It did enable large-file read and write speeds of over 90MB/s, which is quite nice.
FreeNAS’s greatest strength is also its greatest weakness: It’s incredibly complex and granular, with myriad configuration options, plugins, services, and so forth. The average home user may be better off buying an off-the-shelf NAS from Qnap or Synology, which are easier to configure and often include mobile access apps. But if you have the patience and the inclination, there’s nothing like building your own.
NOTE: This article was taken from the Novembe issue of the magazine.



0 comments:

Post a Comment