QNAP TS-459 Pro+ with Ubuntu

Server specifications

Not a lot of memory, but just enough for the basics. An SSD as primary disk, for added silence. And 2 large HDDs for the extra space.

Create install disk (using MacOSX)

Download Ubuntu iso from http://www.ubuntu.com/

Install the OS

Network

vi /etc/network/interfaces

auto eth0
iface eth0 inet static
    address 192.168.0.1
    netmask 255.255.255.0
    gateway 192.168.0.1
    dns-nameservers 192.168.0.254
    dns-search domain.eu

and activate: ifdown eth0; ifup eth0

Power management

By default the fan is running fairly loud. With fancontrol you can let them run at half speed, assuming the temperature stays within limits.

You might need to install a kernel which includes the needed modules:

ls /lib/modules/4.10.0-40-generic/kernel/drivers/hwmon/coretemp.ko
apt-file find coretemp.ko

apt-get install lm-sensors
sensors-detect
service kmod restart

Either configure fancontrol manually by running "pwmconfig" or edit /etc/fancontrol: vi /etc/fancontrol

# Configuration file generated by pwmconfig, changes will be lost
INTERVAL=10
DEVPATH=hwmon1=devices/platform/it87.2576
DEVNAME=hwmon1=it8718
FCTEMPS=hwmon1/device/pwm1=hwmon1/device/temp3_input
FCFANS= hwmon1/device/pwm1=hwmon1/device/fan1_input
MINTEMP=hwmon1/device/pwm1=20
MAXTEMP=hwmon1/device/pwm1=60
MINSTART=hwmon1/device/pwm1=150
MINSTOP=hwmon1/device/pwm1=0

Restart to activate:

service fancontrol restart

LCD Panel

Configure the lcd panel like this:

stty -F /dev/ttyS1 1200

And then execute these commands to control the LCD (Switch on, Switch off, Set text in line 1, Set text in line 2):

echo -e "M^\x1" > /dev/ttyS1
echo -e "M^\x0" > /dev/ttyS1
echo -e "M\f\x0 HELLO WORLD 1234" > /dev/ttyS1
echo -e "M\f\x1 HELLO WORLD 1234" > /dev/ttyS1

The text has to be exactly 16 characters.

NFS

NFS has little network overhead, making it ideal for streaming video from the server to the mediaplayer.

apt-get install nfs-kernel-server

vi /etc/exports

/home           192.168.0.0/24(ro,fsid=0,nohide,insecure,no_subtree_check,async)
/home/movies    192.168.0.0/24(ro,nohide,insecure,no_subtree_check,async)

PostgreSQL

apt-get install postgresql94-server postgresql94 python27-psycopg2
service postgresql-9.4 initdb en_GB.UTF8

vi /var/lib/pgsql/9.4/data/pg_hba.conf

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             192.168.0.0/24          md5

vi /etc/postgresql/9.4/main/postgresql.conf

listen_addresses = '*'
port = 5432
max_connections = 1500
shared_buffers = 2048MB
checkpoint_segments = 100
log_filename = 'postgresql.log'
log_truncate_on_rotation = off
log_rotation_age = 0
log_line_prefix = '%m [%p]: [%l-1] (%a) db=%d user=%u sId=%c tId=%x - '
log_min_duration_statement = 1000

and activate:

service postgresql-9.4 restart

Create users/database/permissions:

sudo su - postgres
psql
\password postgres
# <setup main password>
CREATE ROLE <your-username> LOGIN ENCRYPTED PASSWORD '<your-password>';
CREATE DATABASE <your-database>;
\c <your-database>
GRANT ALL ON ALL TABLES IN SCHEMA public TO <your-username>;
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO <your-username>;

Mediawiki

Basic packages to support mediawiki:

apt-get install nginx php5-fpm

Add packages for caching and thumbnails:

apt-get install php-apc imagemagick

The mediawiki version which comes with Ubuntu is too old, just download the latest stable version from mediawiki.org:

mkdir /home/www/website
cd /home/www/website
wget http://download.wikimedia.org/mediawiki/1.20/mediawiki-1.20.2.tar.gz
tar xvzf mediawiki-1.20.2.tar.gz
ln -s mediawiki-1.20.2 wiki
chown -R www-data:www-data /home/www/website/wiki/images

Go to the website and walk through the installation wizard, including copying the LocalSettings.php (Keep rewrite rules disabled in apache config, while going through the installation wizard)

vi /etc/php5/fpm/php.ini

upload_max_filesize = 10M
open_basedir = /tmp:/home/www/website/wiki:/home/www/otherwebsite/wiki
extension=gd.so
extension=intl.so
extension=iconv.so
session.save_path = "/var/lib/php5/sessions"

Friendly urls

vi LocalSettings.php

$wgScriptPath = "";
$wgScriptExtension = ".php";
$wgArticlePath = "/$1";
$wgUsePathInfo = true;

vi /etc/nginx/sites-available/website.conf

server {
        server_name website.eu www.website.eu;

        root /home/www/website/wiki;
        index index.php index.html index.htm;

        access_log /var/log/nginx/access-website.log;
        error_log /var/log/nginx/error-website.log;

        location ~ \.htaccess {
                deny all;
        }

        location / {
                try_files $uri $uri/ @rewrite;
        }

        location @rewrite {
                rewrite ^/(.*)$ /index.php;
        }

        location ^~ /maintenance/ {
                return 403;
        }

        location ~ \.php$ {
                include /etc/nginx/fastcgi_params;

                fastcgi_pass  unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;

                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

                try_files $uri @rewrite;
        }
}

Torrents

Transmission: apt-get install transmission-daemon

vi /etc/transmission-daemon/settings.json

"download-dir": "/home/movies",
"rpc-port": 12345,
"rpc-username": "<yourusername>",
"rpc-whitelist-enabled": false,

NOTE: stop the daemon before modifying the file. it overwrites the file upon exit.

Bittorrent Sync:

sudo sh -c 'echo "deb http://linux-packages.getsync.com/btsync/deb btsync non-free" > /etc/apt/sources.list.d/btsync.list'
wget -qO - http://linux-packages.getsync.com/btsync/key.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install btsync
sudo vi /etc/btsync/config.json
    "listen" : "0.0.0.0:12346"

and activate:

cd && mkdir shared_folder
sudo chown YOUR_USER:btsync shared_folder
sudo chmod 2775 shared_folder
sudo usermod -a -G btsync YOUR_USER
sudo service btsync start

Webbased SSH

git clone https://github.com/liftoff/GateOne.git
cd GateOne
python3.5 setup.py install

vi /etc/rc.local

/usr/bin/gateone &

Unifi / mFi

Download unifi_sysvinit_all.deb from http://www.ubnt.com/

apt-get install binutils jsvc mongodb-server default-jre-headless
apt-get -f install
dpkg -i unifi_sysvinit_all.deb

vi /var/lib/system.properties