Ubuntu home server setup steps
If you have a linux box at home that's running 24x7, then there are a few useful things you can do with it, including the following:
Setting up UPS monitoring
Note: Only needed if you have a UPS that you want to montior, and a data cable connecting it to your machine.
Follow these blog instructions for setting up NUT (NUT = network UPS tool).
I was setting this machine up to monitor two UPSes, so the only differences were that my /etc/nut/ups.conf
file looked like this:
[UPSONIC-DS800] driver = megatec_usb port = auto desc = "UPSONIC DS-800 UPS" [APC-BackUPS-ES-500] driver = usbhid-ups port = auto desc = "APC BackUPS ES 500"
... and my /etc/nut/upsmon.conf
file had two monitor lines:
MONITOR APC-BackUPS-ES-500@localhost 1 nickj test master MONITOR UPSONIC-DS800@localhost 1 nickj test master
... other than that it was all as per the blog post.
Enable collection monitoring, including web interface
Commands as follows to install collectd and set up a web interface:
sudo aptitude install collectd librrds-perl lm-sensors sudo nano /etc/collectd/collectd.conf # Uncomment sensors, and nut (if you have a UPS and configured NUT in the above step). # Note: Nut in Ubuntu prior to 9.04 has a bug so that NUT data won't be visible on AMD64 using collectd sudo /etc/init.d/collectd restart # The location of your webroot may differ - the below line is appropriate for # my configuration, but modify as needed: cd /var/www/hosts/ sudo mkdir bling-collectd cd bling-collectd cp /usr/share/doc/collectd/examples/collection.cgi.gz . sudo gunzip collection.cgi.gz sudo chown www-data.www-data collection.cgi .
For the script to work, your apache config will need the AddHandler line for .cgi files, and also "Options +ExecCGI" for the relevant directory. You should get some basic graphs at the appropriate URL, e.g.: http://bling-collectd/collection.cgi
If you want to also monitor hddtemp using the hddtemp daemon, then do this. Personally, I find the some of the "Sensors" output to be far more accurate than the hddtemp output for monitoring system temp:
sudo aptitude install hddtemp # yes to install hddtemp as a daemon sudo dpkg-reconfigure hddtemp * yes suid * 30 seconds between checks * Should the hddtemp daemon be started at boot? yes * Interface to listen on: 127.0.0.1 # then enable the hddtemp module by editing this file: sudo nano /etc/collectd/collectd.conf
If you want to also monitor uptime, and S.M.A.R.T. errors using smartmontools, then do this:
sudo nano /etc/collectd/exec.sh
and paste in the following:
#!/bin/bash HOST=localhost INTERVAL=300 while true do TEMP=`awk '{ print $1/(60*60*24); }' /proc/uptime` if [ $? -ne 0 ] then TEMP="U" fi echo "PUTVAL $HOST/exec-uptime/charge-uptime interval=$INTERVAL N:$TEMP" TEMP=$((sudo smartctl -d ata -A /dev/sda | grep Offline_Uncorrectable | awk '{ print $10; }') 2>/dev/null); if [ $? -ne 0 ] then TEMP="U" fi echo "PUTVAL $HOST/exec-smartmon/charge-offline_uncorrectable interval=$INTERVAL N:$TEMP" sleep $INTERVAL done
.... then do sudo visudo
and add these two lines to the end:
Cmnd_Alias SMARTCTL = /usr/sbin/smartctl -d ata -A /dev/sda nobody ALL = (root) NOPASSWD: SMARTCTL
... then sudo nano /etc/colllectd/collectd.conf
and load the exec module, and make the exec plugin section look like this:
<Plugin exec> Exec "nobody" "/etc/collectd/exec.sh" </Plugin>
.... the above will give you a graph of days uptime, and number of uncorrectable SMART errors. Note that the y axis will be wrong (will be mislabeled as "charge" in "Ah", when for the uptime graph it will be number of days, and for the smartmon graph it will be number of uncorrectable errors), but the information is otherwise correct.
Set up Rtorrent to use your off-peak data allowance
Some ISPs will give you an allowance of peak data, and allowance of off-peak data. Peak is sometimes quite long (e.g. 18 hours), and off-peak can be quite short (e.g. 6 hours) and is usually during the middle of the night. Usually most of that off-peak bandwidth goes to waste. One way to use it efficiently is to use rtorrent to automate downloading during your off-peak times. To do this:
aptitude install rtorrent screen cd mkdir Downloads cd Downloads/ mkdir rtorrent-session rtorrent-inprogress rtorrent-watch rtorrent-completed cp /usr/share/doc/rtorrent/examples/rtorrent.rc ~/.rtorrent.rc nano ~/.rtorrent.rc
... and follow this great guide for modifying the file for your needs. I also make the following changes:
# Global upload and download rate in KiB. "0" for unlimited. download_rate = 0 upload_rate = 97 # Upload rate should be explicitly set to 80% of your max upload rate. Higher than # this, and you will get slower downloads because the link will be too congested. # Move completed torrents downloads, and delete the associated torrent file: on_finished = rm_torrent,"execute=rm,$d.get_tied_to_file=" on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,/home/username/Downloads/rtorrent-completed/ \ ;d.set_directory=/home/username/Downloads/rtorrent-completed/" # Controls if the session torrent is saved when a torrent finishes. We don't want it. session_on_completion = false
To set it up to run regularly as a daemon:
wget http://libtorrent.rakshasa.no/raw-attachment/wiki/RTorrentCommonTasks/rtorrentInit.sh nano rtorrentInit.sh # replace the run as username with your username used in the section above sudo mv rtorrentInit.sh /etc/init.d/rtorrent sudo chown root.root /etc/init.d/rtorrent sudo chmod +x /etc/init.d/rtorrent sudo nano /etc/crontab
... and add two lines like so:
# Start bitorrent downloading at 1 AM every night, and stop at 6:59 AM every morning 00 1 * * * root /etc/init.d/rtorrent start 59 6 * * * root /etc/init.d/rtorrent stop
Rtorrent does not currently have native ipfiltering, so you have to set it up using a firewall. Moblock is very good for this, and there are very good MoBlock setup instructions available. Here's a summary for Ubuntu 8.10:
gpg --keyserver wwwkeys.eu.pgp.net --recv 9072870B gpg --export --armor 9072870B | sudo apt-key add - sudo nano /etc/apt/sources.lst
... and add these lines:
# MoBlock packages: deb http://moblock-deb.sourceforge.net/debian intrepid main deb-src http://moblock-deb.sourceforge.net/debian intrepid main
... then do:
sudo aptitude update sudo aptitude install moblock blockcontrol sudo blockcontrol restart sudo blockcontrol status sudo blockcontrol test
If you need to reconfigure moblock, then use: sudo dpkg-reconfigure blockcontrol