Tag: debian

My Debian Server favourites

Intro

Whilst you may be running debian as an HTPC (Home Theater PC) connected to your TV running Kodi , the machine can be servered-up do additional tasks.

For instance I would also like it to host my angular app controlling my MQTT devices, or make files accessible though the internet using ssh/ftp/nfs ..

For that reason this blog is a list of addtional services I’ve installed on that machine. No need to waste the resources of buying an extra machine for the server or home automation.

Programs

Samba

Allows the server to share a folder using the smb:// protocol. This makes it’s shares visible to the windows workgroup network. Easy for accessing files between windows-linux from explorer-thunar (in debian XFCE )

The easiest in use and configuration by far is from the gadmin package:

sudo apt-get install gadmin-samba

VNC

Now you may be wondering, why a VNC client when we’ve got teamviewer? Well while Teamviewer is easy to install and use, there are some drawbacks:

  • they’ve been hacked not long ago exposing accounts and passwords
  • it’s commercial soft; the annoying nag screen that comes on the remote computer after disconnecting.. messing up your movie/game experience
  • it prevents some games going fullscreen correctly

Vnc is light and easy to install using the following steps (for debiaan 8 xfce )

su
apt-get install xfce4 xfce4-goodies gnome-icon-theme tightvncserver

Additional tasks

External Access: anywhere through the internet to your server

For most people, the server is on a NAT behind the ISP’s router. In my case, the ISP gives you one dynamic external IP address… Easier would be to link it to a dynamic dns service. Create a free account on no-ip.com , just gotta log in every 30days to keep it alive. The client software can also be found on their site.

cd
wget http://www.noip.com/client/linux/noip-duc-linux.tar.gz
tar zxvf noip-duc-linux.tar.gz
cd noip-2.1.9-1
sudo make
sudo make install

The make install asks for your credentials you credited in the noip account earlier. Don’t forget to setup your account and one hostname first! ( I recommend following the new device configurator). It’s ver straight forward for the average user.

screen-shot-2016-11-01-at-20-35-49

Once you’ve got your connection tested from the noip configuration wizard, you only need to forward your ports on your router that your apps use on the remote server.

HTPC (entertainment + server in one ! )

In my case my debian server will not be head-less. Since the server is sitting near the TV we might as well give it some added functionality like KODI and some simple games

Debian Software Common Packages

This adds the add-apt commands for example making it easier to add repositories:

sudo apt-get install software-properties-common

 Emulation

It’s always fun having the old-school emulators to play games from N64, Sega .. Let’s get our emulators installed first. So let’s get retroarch installed: dependencies for debian 8.7

apt-get -y install build-essential libxkbcommon-dev zlib1g-dev libfreetype6-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev nvidia-cg-toolkit nvidia-cg-dev libavcodec-dev libsdl2-dev libsdl-image1.2-dev libxml2-dev

Then clone the repo so we can make a fresh build.

git clone git://github.com/libretro/libretro-super.git

cd libretro-super

SHALLOW_CLONE=1 ./libretro-fetch.sh

./retroarch-build.sh

NOCLEAN=1 ./libretro-build.sh

Wait a long time for the compilation of all the cores..

mkdir -p ~/ra/cores
cd retroarch
make DESTDIR=~/ra install
cd .. #to libretro-super directory
./libretro-install.sh ~/ra/cores

 

 

Setting up an MQTT server on Debian Jessie

Intro

Today we`re going to be setting up our own home automation server in a dedicated linux server. It’s gonna host our platform using the the Node.Js environment. The different devices around the house are going to be speaking MQTT to this server. I’ve chosen MQTT because of it’s robustness and lightweightness allowing for easy deployment on my favourite controllers: ESP8266. The esp-01, still the cheapest to this date,only sports 4mb of flash, has no trouble at all controlling a couple of relay’s for now. In the future the newer/bigger boards can be used to get more IO and function, but for now I’m going to be using the esp-01’s extensively around the house flexibly (it’s wireless…).

Requirements

The idea is to have the server online 24/7, so consider a computer thats not to power-hungry; like a Raspberry Pi or a small embedded box computer. Alternatively you can boot up a guest in virtual box like I’m doing for developing purposes. I’m still a fan of debian, which can be run on outdated hardware; it`s memory footprint is small, and fast to boot up.

Guide

After installing the base system, (I’ve used the netboot distro , and selected the XFCE environment) we can install the required packages.

Node.js

The setup guide can be found here: nodejs setup

At the time of writing, my machine is running Jessie Debian 8.7. I also wanted to go with the latest nodejs v7 so the commands become:

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential

Check if everything is fine and installed:

node -v
npm -v

Update the npm to the latest version:

sudo npm install npm -g

Mosquitto + Websockets

Is what will be using as an MQTT broker the esp’s can publish an subscribe to. As we’ll be using the websockets for our frontend app later on, we’ll have to build mosquitto with libwebsockets.

sudo apt-get install build-essential python quilt devscripts python-setuptools python3 libssl-dev cmake libc-ares-dev uuid-dev daemon

Next will be downloading and building libwebsockets: (link is updated)

wget https://libwebsockets.org/git/libwebsockets/snapshot/libwebsockets-1.4-chrome43-firefox-36.tar.gz
tar zxvf libwebsockets-1.4-chrome43-firefox-36.tar.gz
cd libwebsockets-1.4-chrome43-firefox-36
mkdir build
cd build
cmake ..
sudo make install
sudo ldconfig
cd

Download, build and install mosquitto (the broker server):

wget http://mosquitto.org/files/source/mosquitto-1.4.2.tar.gz
tar zxvf mosquitto-1.4.2.tar.gz
cd mosquitto-1.4.2

Change the config.mk file with your favorite editor (mousepad in xfce debian) to enable the build with websockets:

sudo mousepad config.mk

Adapt the following code:

WITH_WEBSOCKETS:=yes

Then build:

make
sudo make install
sudo cp mosquitto.conf /etc/mosquitto
sudo adduser mosquitto

Edit the mosquitto.conf file we just copied to enable the webscoket on port 9001.

sudo mousepad /etc/mosquitto/mosquitto.conf

Add this to the config file:

port 1883
listener 9001
protocol websockets
pid_file /var/run/mosquitto.pid
Optional: I'm going to add security by forcing credentials
You can do so by creating as password file:
mosquitto_passwd -c /etc/mosquitto/passwd yourloginname

Also, back in

/etc/mosquitto/mosquitto.conf

set the

allow_anonymous false

Save and Reboot.
After logging launch mosquitto with the config file just modified:

mosquitto -c /etc/mosquitto/mosquitto.conf

This gave a command not found error. The executable was located in the /usr/local/sbin folder.

To solve that were gonna make a link like so:

sudo ln -s /usr/local/sbin/mosquitto /bin/mosquitto

and then:

mosquitto -c /etc/mosquitto/mosquitto.conf

The broker should be listening for websockets on port 9001. The MQTT port remains the default of 1883.

After testing that, we’re gonna want to start it automatically. Using the systemd (Jessie) we can accomplish that easily:

sudo nano /etc/systemd/system/mosquitto.service

Paste in the following:

[Unit]
Description=Mosquitto MQTT Broker daemon
ConditionPathExists=/etc/mosquitto/mosquitto.conf
Requires=network.target

[Service]
Type=simple
ExecStartPre=/usr/bin/rm -f /var/run/mosquitto.pid
ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/run/mosquitto.pid
Restart=on-failure

[Install]
WantedBy=multi-user.target

You can auto start the service by:

sudo systemctl enable mosquitto
sudo systemctl start mosquitto

That’s it! Done.