My Home Server

From Jorg Bosman
Jump to: navigation, search

My Apple Time-Capsule just died, the disk of my AppleTV is starting to make weird noises, my time-lapse recorder needs more storage and cpu-power, and i haven't been creating anything new for too long now :) Guess it's time for a new project...

  • QNAP TNS-459Pro+
  • 2x Western Digital Caviar Green 2TB, model WD20EARS
  • 1x OCZ Onyx SATA-II 30GB SSD Disk

Contents

Basic configuration

  • Install Optware IPKG from the admin web interface
  • Update ipkg: ipkg update
  • Install vim as a texteditor: ipkg install vim
  • Install Coreutils: ipkg install coreutils

Power management

The disks won't spin down, because system files keep writing to the /share/MD0_DATA/.locks dir. Move the locks dir to the SSD disk:

  • /etc/init.d/services.sh stop
  • cp -rp /share/MD0_DATA/.locks /share/HDC_DATA/.locks
  • mv /share/MD0_DATA/.locks /share/MD0_DATA/.locks_old
  • ln -s ../HDC_DATA/.locks /share/MD0_DATA/.locks
  • /etc/init.d/services.sh start

Transmission

i installed a Bittorrent downloader on the NAS: (Instructions from http://wiki.qnap.com/wiki/Transmission)

  • Install transmission: ipkg install transmission
  • It is not advised to run a BitTorrent client as root. Therefore you should create a new user named transmission: adduser -DH transmission
  • Add startup script:
mkdir /share/MD0_DATA/System
mkdir /share/MD0_DATA/System/transmission
vi /share/MD0_DATA/System/transmission/transmission_start.sh
#!/bin/sh
#
# start script for transmission/clutch
#
# jorg@bosman.tv - 29 january 2011

TORRENTFOLDER=/share/MD0_DATA/Multimedia/Movies
TRANSMISSION_BIN=/opt/bin/transmission-daemon
TRANSMISSION_HOME=/opt/etc/transmission
TRANSMISSION_USER=transmission
TRANSMISSION_PORT=6888

REMOTE_USER=<username>
REMOTE_PASS=<password>

echo -n "Starting Transmission Daemon..."
su $TRANSMISSION_USER -c "EVENT_NOEPOLL=0 $TRANSMISSION_BIN --blocklist --auth --username $REMOTE_USER --password $REMOTE_PASS --config-dir $TRANSMISSION_HOME --download-dir $TORRENTFOLDER"

#Wait a while till the daemon has started...
sleep 20

#Set a few settings
transmission-remote -n $REMOTE_USER:$REMOTE_PASS --portmap --port $TRANSMISSION_PORT --pex --encryption-preferred
chmod +x /share/MD0_DATA/System/transmission/transmission_start.sh

After a reboot, this script still needs to be started manually. Need to fix that later.

Timelapse

Script to fetch a snapshot from the webcam, every minute, during working hours:

mkdir /share/MD0_DATA/System/timelapse
vi /share/MD0_DATA/System/timelapse/fetch_image.sh

Nagios

  • Install some extra dependencies
ipkg install gcc make perl libgd
  • Create a user "nagios" via the web interface
  • Download and extract nagios-3.3.1.tar.gz
./configure --prefix=/share/nagios --with-nagios-group=everyone
make all
  • Comment out these lines, since they break the installation:
vi html/Makefile
  • Change these:
for file in includes/rss/*; \
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/includes/rss; done
for file in includes/rss/extlib/*; \
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/includes/rss/extlib; done

Into:

chmod 775 /share/nagios/share/includes/rss
for file in includes/rss/*; \
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/includes/rss; done
chmod 775 /share/nagios/share/includes/rss/extlib
for file in includes/rss/extlib/*; \
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/includes/rss/extlib; done
  • Install nagios:
make install
make install-commandmode
  • Remove the '-b' from the 'install -b' lines, since that option isn't available:
vi Makefile
make install-config
  • Copy startup script and remove the "su" from it:
cp ~/src/nagios/daemon-init ~/bin/daemon
chmod +x ~/bin/daemon
vi ~/bin/daemon
#su - $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile"
touch $NagiosVarDir/nagios.log $NagiosRetentionFile
  • Make the scripts accessible:
ln -s ~/share/cgi-bin ../sbin

pnp4nagios

  • Install some extra dependencies
ipkg install rrdtool grep diffutils sudo
  • Download and extract pnp4nagios-0.6.14.tar.gz
./configure --prefix=/share/nagios/pnp4nagios --with-nagios-group=everyone --with-base-url=/nagios/pnp4nagios --with-httpd-conf=/share/nagios/pnp4nagios/etc
make all
  • Add this line to /usr/local/apache/conf/apache.conf
Include /share/nagios/pnp4nagios/etc/httpd.conf
  • Setup sudo
vi /opt/etc/sudoers.d/nagios
  nagios ALL=(ALL) NOPASSWD: ALL
chmod 440 /opt/etc/sudoers.d/nagios
  • Add a root useraccount after the original admin username. (sudo admin remains the default root account)
vi /etc/passwd 
  root:x:0:0:administrators:/share/homes/admin:/bin/sh
Personal tools