Sunday, June 8, 2014

Setting up redundant file- and mediaserver with Debian GNU/Linux 7.5 and RAID-5

This post is effectively a continuation of a saga I started now 5 years ago.

Times have moved on, electricity price has gone up and at some point I changed my Library box setup, swapping out the four 320GB hard drives with total of 960GB of RAID-5 storage for two 500GB hard drives in RAID-1, so retaining 500GB of redundant space.

I though back then that I would make the box consume less power that way. In some ways it worked, the power use went down about a dozen watts. In addition, I removed the videocard, as that motherboard had integrated graphics and I also removed a gigabit network card, as my intention was to put the machine into a closet, where I only had 100Mbit network connection anyway. With all those changes I managed to reduce the power usage from the original 70W down to 50W at idle (and in text mode).

As I now needed more redundant space, I swapped out the hard drives once again. In addition to a 1TB Western Digital Black drive, which I already owned, I bought additional two 1TB Western Digital Green drives (49€ a piece) to set up the system on RAID-5 again, giving me almost 2TB of redundant storage.

The other machine specs remained the same:
  • AMD Athlon 64 3700+ San-Diego (clocks between 1.0 and 2.2GHz)
  • Zalman CNPS7000B-Cu
  • ASRock 939NF6G-VSTA (nForce 430)
  • 1.0 GiB Kingston HyperX
  • Tagan 420W i-Xeye TC PSU
  • Antec Three-Hundred case

Server installation

As before, my choice was Debian GNU/Linux, though this time around the newest version 7.5, "Wheezy".

Partitioning

On each of the drives I created two partitions for software RAID.
The first partition is 998GB for the main data and the remaining 2GB will be used for swap.
NB! It is important to enable the boot flag on all of the three disks!
The bigger partitions were then combined into RAID-5 array to form the root partition of about 2TB using EXT4 and the smaller partitions formed the swap space of about 4GB, also using RAID-5.
This way, not only the data would survive a failure of any one of the drives, but also the whole setup should withstand such a failure.

After partitioning and loading some packages, the Software categories choice came up. I decided to leave the desktop choice, though I will later switch off the automatic boot into graphic mode.
I chose also web server, SQL server, file server and ssh server. I left also the print server, though I'm pretty sure I will not be using it for printer serving.

As I was using a "netinst" image, the installation took quite a while, which was no doubt dependent on my network speed.

When the time came to set up grub, I already knew in advance that the installer only installs grub on the first drive and I also need to install grub on the other two disks.
The necessary commands, to be entered before you allow the installer to install the grub into /dev/sda and call update-grub, are:
chroot /target /bin/bash
grub-install /dev/sdb
grub-install /dev/sdc
The install will finish shortly after that.

Reduce the boot manager delay:

mcedit /etc/default/grub 
and change the timeout value
GRUB_TIMEOUT=5
to something smaller, like 1, and then execute:
update-grub

Enable sudo for the main user:

adduser username sudo
this takes effect only after logging out and back in.

Change Gnome Classic to be default graphical shell:

update-alternatives --config x-session-manager
and selec the fallback line, usually number 2.

Change the IP to be static:

In Gnome Classic, in the right at the upper bar, right-click the network icon and choose Edit to configure the network interface.
In the window that opens, select your network interface and click Edit in the right.
In the following window, at IPv4 settings tab, switch the method from DHCP into Manual, click Add, enter your static IP, netmask and gateway, also enter the DNS below and click Save.

Make Debian boot into console mode

update-rc.d gdm3 disable
This will retain the possibility to start the graphical UI with the startx command.

Setting up the environment:

mcedit ~/.bashrc
add the following lines:
stty -ixon  # enables forward bash command history search CTRL-S
export LC_COLLATE="en_US.UTF-8"  # fixes the broken Estonian character map which breaks regexp [a-z]

File server setup

Creating a directory for the data to be served and group for users:

Create a new group called "share":
addgroup share
Add your user into that new group:
adduser username share 
Create and fix the rights to the /Data directory:
cd /
mkdir Data
chown nobody:share Data
chmod 775 Data

Set up an anonymous readonly Samba account:

mcedit /etc/samba/smb.conf
find the section "Share Definitions" and add the following beneath it:
[library]
   comment = Library
   path = /Data
   browseable = yes
   guest ok = yes
   read only = yes

Set up an NFS share:

mcedit /etc/exports
Add the following line:
/Data 192.168.10.0/24(rw,root_squash,async,no_subtree_check)

Making sure the file owner is displayed correctly over NFS:

mcedit /etc/idmapd.conf
Uncomment the "Domain = xxx" line, and enter your domain.
NB! Be sure to set that same domain name on the client aswell.
Reload the NFS configuration on the server:
/etc/init.d/nfs-kernel-server restart
Probably a better way for all of the changes to take effect is to reboot the machine now.

Media server setup

Setting up Plex Media Server

echo "deb http://shell.ninthgate.se/packages/debian wheezy main" > /etc/apt/sources.list.d/plexmediaserver.list
wget http://shell.ninthgate.se/packages/shell-ninthgate-se-keyring.key | apt-key add -
apt-get update
apt-get install plexmediaserver
This will also add the PMS to be automatically started when the server starts.

Other optional steps

Fixing the locale problem:

Somehow I managed to make all locales, except my own, to disappear. The fix:
dpkg-reconfigure locales

Setting mcedit as the default editor:

update-alternatives --config editor

No comments: