Tuesday 6 November 2012

Setting up my Home Server


Setting up my Home Server


Notes

I do not accept responsibility for any issues arising while using information provided below. There may be errors in what I have typed. If you get stuck, google can help you find solutions, or check out linux forums. These notes are mostly for myself but I am happy to share them with others wanting to try running their own home server.

If you have software raid hard-drives, remove them before installing the operating system – when rebuilding my system, I kept having a very annoying error – the operating system wouldn’t run, until I removed the raid drives and reinstalled the operating system.

Hardware:


  • HP ProLiant N36L MicroServer AMD 1.3GHz CPU, 1GB RAM, 250GB HDD  $250 from Megabuy
  • 2x Western Digital WDC WD20EARX-00P  2 TB hard-drives (this was set up in a raid 1 array using software raid – basically mirroring each other in case of one drive failing)
  • surge protector ($30)
  • Lan cat 5 cable (Jaycar $20)
  • Existing router

Software:


Operating System


1.             Get your operating system image and create a usb boot disk (as the server didn’t have a disk drive)

2.             for UserOS, install third party software and download updates while installing if connected to the internet (UserOS can be upgraded, but don’t allow partial upgrades as it will cause problems)

3.             set timezone, keyboard (mine is US). Set it to log in automatically. Do not allow ‘encrypt home folder’

4.             Wait for install to finish

5.             Unplug usb boot drive, and reboot (force if necessary)

Set up VNC

(for local remote access – not to be used over the internet without tunnelling through SSH as passwords are sent unencrypted)

a)      Applications, settings, remote desktop setup

b)      Set ‘allow other users to access’

c)      Untick ‘you must confirm each access’

d)      Require the user to enter password, then close

e)      Settings, launch remote desktop server.

f)        Add to Applications, settings, settings manager, startup-> “/usr/lib/vino/vino-server &” (without quotes)

g)      reboot

Attempt access to server from another computer on the network using tightVNC (this is assuming you know your server’s IP address – I set up my router to provide a ‘static’ address for my server so it stays the same)

Installing Raid drives

(assuming that they have been already formatted correctly)

1.      Shutdown and install raid drives, reboot. Drives should be autodetected if they’ve been setup previously.

2.      Set raid to automount on boot. From a terminal window->  #sudo leafpad /etc/fstab

3.      The raid on my device was /dev/md127 so I added the line to fstab
/dev/md127   /media/raid   auto   user  0  0

Desktop Preferences

If desktop preferences disappear, remove line ‘only show in GNOME.unity’ from:  #sudo leafpad /usr/share/applications/vino-preferences.desktop   and add line Name=Remote Desktop Setup

Sharing folders

To share a folder (samba is required to share folders with Windows computers), right click on the folder and select ‘sharing options (eg, I allow guest access to my raid drive. May need to type #sudo nautilus into a terminal window to get enough privileges

Lock on boot

(screensaver setup). Applications, settings, settings manager, screensaver. Tick ‘lock screen after 0mins’, set screensaver to kick in after a few minutes of non use. Then Sessions & Startup, Add to application on autostart   “xscreensaver –nosplash”  without the quotes and “xscreensaver-command –lock” 

Power off button

To switch off when power button is pressed, in Session & Startup, ensure ‘log off required’ is unticked. Also in Settings Manager, Power Manager, click the down arrow next to ‘when power button is pressed’ to show ‘shutdown’

BackupPC


1.      BackupPC used to automatically back up other computers documents. Default location is accessed via LAN internet browser pointing to http://server-ip-address/backuppc  where server-ip-address is the local address of your server. Username is backuppc and password is backuppc (this can be changed)

2.      If backup (using backuppc) already exists on another drive, set up a soft link from /var/lib/backuppc after renaming the existing backuppc folder to backuppc-old (backuppc server needs to be stopped first though)

3.      #sudo /etc/init.d/backuppc stop

4.      #sudo cp –dpR /var/lib/backuppc/. /media/raid/backuppc (or wherever you have your backup files – this copies the required files from the existing backuppc folder)
#sudo mv /var/lib/backuppc  /var/lib/backuppc.orig  (rename the existing backuppc folder)
#sudo ln –s /media/raid/backuppc  /var/lib/backuppc  (link from the backuppc folder to your backup on another drive)

5.      Create a non-admin user called backuppc on the computer you want to allow backups from. Create a password for the account. You can hide the account from other users – just google ‘disable or enable user account in Vista’ (or whatever your operating system. Vista64 has a good tutorial for Vista users.

6.      Share the folder that you want to backup and add backuppc as a user with access permissions.

7.      Then at http://your-server-ip/backuppc   create a host at the IP address of the computer you want to have backed up (I set up my computers with a static IP address using the settings in my router). Edit the config for the host. Click on xfer. Change smbshare name to the name of folder on the pc that you shared and want to backup.

8.      Change SmbShareName to backuppc and passwd to the password you want it to use to access the share (what you set up on the pc)

9.      Change schedule if you want – period is in days. Click on name links for more info. Click Save to keep any changed settings.

Optirain

(irrigation controller program available from quicksmart.com )

  1. To set up Optirain, a LAMP server is required. Specifics are:
    1. PHP 5.25+
    2. PDO support
    3. PDO driver for sqlite3 enabled
    4. Sqlite support enabled
    5. Sockets support enabled
  2. to test if your server is set up correctly, create a file called phpinfo.php and place in your /var/www folder. In the file, type in “” without the quotes. Access the file using an internet browser, pointed to http://your-server-ip/phpinfo.php
  3. If it is not, type #sudo apt-get install php5-sqlite
  4. Copy the Optirain files to your /var/www folder
  5. set ownership on the folder #sudo chown –R www-data:www-data /var/www
  6. set permissions #cd /var/www     then
    #sudo find . –type f –exec chmod 664 {} \;
    #sudo find . –type d –exec chmod 775 {} \;
  7. Access via http://your-server-ip/   You should be presented with the Optirain window. If not, check your server settings and file locations.
  8. Click ‘continue’. Setup EtherRain (edit device) – it should automatically appear if it is found on your network. Try rebooting the device if Optirain can’t find it). Select the device. Password is pw
  9. Give each zone a name (if you leave a zone with a blank name, it will ignore any after it)
  10. Submit, and test with a Quick Cycle
  11. Setup weather using codes found at weather.yahoo.com – the code is found on the rss link. The code for Ellendale was ASXX0329 – and uses the weather station info at Bushy Park – not exactly local, but local enough.
  12. Setup schedules from Home – show schedule, setup.

MediaTomb

(UPnP MediaServer): setup is at http://your-server-ip:49152 

Mail setup

(any cron jobs having problems will be emailed to you)

  1. #sudo apt-get install ssmtp
  2. #sudo leafpad /etc/ssmtp/ssmtp.conf
  3. type in: 
    root=youremail@address.com
    mailhob=smtp.mailserver.com:465 (whatever your smtp mailserver is eg bigpond or gmail)
    rewrite domain=address.com  (gmail, etc)
    Authuser = username (your username for email)
    Authpass = password (your password for email)
  4. test your email (see https://wiki.archlinux.org/index.php/SSMTP )

Some useful linux commands using a terminal window


sudo command --- where command is the action you want, sudo elevates the command to root user for elevated privileges (for when the command requires it)

ps aux | less ---- displays all running processes
 
leafpad --- a text editor (there are several – use in place of nano)

nautilus --- file manager (type in sudo nautilus from the command line to get root privileges on the file manager)

sudo su  --- all commands are now elevated to root user. Can be dangerous if you don’t know what you are doing.

sudo !!  --- gives root permission to the previously entered (and denied) command

ls --- list files in a directory

Irrigation system

I thought I would share my cool irrigation system. It has a few advantages over manually turning on the tap (especially when I forget to turn the tap off again!), or even one of those irrigation controllers that you can buy from the hardware shop.

It can
  • run a 'master valve' which ensures that even if there are problems down the line, I won't lose too much water.
  • stop irrigatation if rain is detected
  • delay irrigation if rain is predicted (as in the local weather forcast).
  • start irrigation if the weather forcast is a very hot day
  • can be operated remotely via my phone (or any computer) from anywhere

This is the irrigation controller that I chose. It requires a home network (LAN) with an always on computer to control it and a 24V AC power supply (available from any irrigation store for about $30)


I had my EtherRain 7P controller and ER-RD-NW rain sensor shipped to Australia from the US. The cost for the EtherRain-7P controller was $US 162 and a ER-RD-NW Rain Sensor was $US 9. Shipping was $US 17


This is my home server running a 'flavour' of Ubunutu server (linux) with an Xfce desktop. It stores and streams my media (movies, photos, music), does automatic backups of my computers, and runs my irrigation system. I have since found a $38 computer (Raspberry pi) that could also control the EtherRain.

{UPDATE} I have now since transferred control of the EtherRain to my Raspberry Pi running Raspian (Wheezy) - just SSH into it, updated using raspi-config and update, create the LAMP stack (with mysqlite), transfer the files into my Home directory using winscp, set permissions, redirected Apache to use the local folder instead of /var/www ( http://drndivoje.wordpress.com/2010/03/30/easy-change-apache-root-web-folder-www/ ), set up OptiRain, and it just works!  Though I've realised that because it doesn't have an onboard clock that it doesn't really know the time unless you tell it what time (and date) it is - which will be lost if the power is lost or it gets rebooted....there is a fix but maybe later)



This is the master controller. It turns on for all irrigation programs. If I bust a pipe below this point, then at least I can cut the flow until it is fixed. This solenoid cost $80 from Irrigation Tasmania

Another solendoid - this one is for my orchard

Some smaller solenoids (25mm). These are for my vege garden and my hothouse. They were $25 each.

This is the sprinkler in the vege garden. Because I have tank water with low pressure, I need to have a pressure pump running for this sprinkler to work properly.


My pressure pump has a relay attached, so when the solenoid for the vege garden is activated, the relay for the pressure pump is also activated, turning on the pressure pump for when I need it (and not have it running constantly when I don't)

The hothouse does well when it is regularly irrigated. These are an abundance of tomatoes. Yum!
I have a valve in the hothouse to switch from overhead sprays to drippers if it is getting too damp in there.


Control of the EtherRain is done using a web browser. This is a free Linux program they provide called OptiRain. Here I can set schedules, or turn on a cycle for a set time. They also have a windows version.


This is the latest addition to the irrigation system. It's a $25 hothouse from Bunnings. If the irrigation system didn't kick in, the seedlings would get cooked !

I wanted to be able to operate my irrigation system via my phone which I can do using an internet page connected to my server using my wireless network. However, my wireless network doesn't quite reach to the lower parts of my garden. As I have a dynamically assigned IP address for my internet, I set up a free account using no-ip.com  - a program running on my server updates my IP address with no-ip.com and I can just log on to my server using a sub-domain of no-ip.com  - the only catch is I have to log into my account with no-ip once a month, but I have set a task scheduler to remind me to do this. I haven't set it up with a password yet, so anyone with the address could turn on my sprinkler system. If it starts going off at random times, I guess I would have to address this.