IT Setup

Some notes about the Raspberry Pi server

Here some notes & descriptions which packages are installed and what are the important things to be considered.

Packages

It’s based on standard Raspberry Pi packages. The hardware you can buy at amazon.
You have to setup the SD card first.  I don’t use a keyboard and a screen, so SSH must work from the beginning. In the Raspberry Pi image the SSH daemon is enabled by default.
Therefor after downloading the package and installing it on the SD card, only the raspberry Pi image (Raspbian.xz) must be available in the /images folder. This guarantees that the system is booting with the first start into Raspbian Linux system.

You should either define a fixed IP address for the Pi or make sure in the router that it always gets the same IP.
Then you have to configure the port forwarding in the router to the PIs IP address for port 80 (http).

For accessing the Pi from a Windows system with SSH you can use Putty, for file transfer WinSCP.

While I experienced big problems with the SD card, I installed now a hard disk. The SD card is used for booting only. The root file system is on the hard disk. Only with that setup the system can handle the huge amount of file accesses due to the mail server, feed server, contact/calendar server, analytics server.

1.) Format SD

http://elinux.org/RPi_Easy_SD_Card_Setup

Download and install the SD Association’s Formatting tool from https://www.sdcard.org/downloads/formatter_4/eula_windows/
Open the Application you have just installed
Set „FORMAT SIZE ADJUSTMENT“ to ON in the Options menu.
Make sure you have selected the Drive your SD Card is inserted in
Click „Format“

2.) Install Raspian on SD

http://elinux.org/RPi_Easy_SD_Card_Setup
Download the distribution from the raspberrypi.org downloads page or from a mirror or torrent.
Insert the SD card into your SD card reader and check what drive letter it was assigned. You can easily see the drive letter (for example G:) by looking in the left column of Windows Explorer. You can use the SD Card slot (if you have one) or a cheap Adapter in a USB slot.
Download the Win32DiskImager utility http://sourceforge.net/projects/win32diskimager

Extract the executable from the zip file and run the Win32DiskImager utility; you may need to run the utility as Administrator! Right-click on the file, and select ‚Run as Administrator‘
Select the image file you extracted above.
Select the drive letter of the SD card in the device box. Be careful to select the correct drive; if you get the wrong one you can destroy your data on the computer’s hard disk! If you are using an SD Card slot in your computer (if you have one) and can’t see the drive in the Win32DiskImager window, try using a cheap Adapter in a USB slot.
Click Write and wait for the write to complete.
Exit the imager and eject the SD card.

3.) Raspi-Config timezone, password, expand the file system

sudo raspi-config

4.) apt-get update & upgrade

sudo apt-get update
sudo apt-get upgrade

5.) Install HardDisk

http://jankarres.de/2013/01/raspberry-pi-usb-stick-und-usb-festplatte-einbinden/

sudo apt-get -y install ntfs-3g hfsutils hfsprogs
sudo mkdir /media/usbstick
tail -f /var/log/messages
sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda /media/usbstick/
sudo umount /media/usbstick
sudo blkid /dev/sda
sudo nano -Bw /etc/fstab

NTFS
UUID=88740B44740B350A /media/usbhdd/ ntfs-3g defaults,auto,umask=000,users,rw 0

6.) Copy the rootfs to the hard disk

http://c-mobberley.com/wordpress/2013/04/13/moving-raspberry-pi-root-folders-from-sd-card-to-usb-hdd/

sudo umount /dev/sda1
sudo fdisk /dev/sda1
sudo mkfs.ext4 /dev/sda1
sudo e2fsck /dev/sda1
sudo mount /dev/sda1 /media/usbstick
sudo rsync -ahHAX --exclude=media/usbhdd / /media/usbhdd
sudo nano /media/usbstick/etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/sda1       /               ext4    defaults,noatime  0       1

sudo nano /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait

sudo reboot

7.) Dynamic IP

As the IP address from the ISP is switched during the night we need to make the domain available with the help of a dynamic IP service provider.

cd /usr/local/src/
wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar xf noip-duc-linux.tar.gz
cd noip-2.1.9-1/
make install
/usr/local/bin/noip2

Script noip-DUC in /etc/init.d, must run as a boot service
sudo rcupdate.d noip-DUC defaults

For no-ip you can check the status with
sudo /usr/local/bin/noip2 -S
Dynamic IP providers:

8.) Apache, MySql, phpmyadmin, apc

sudo apt-get install apache2 php5 libapache2-mod-php5
Adapt apache config for RPi.
Enable rewrite module for wordpress.

sudo apt-get install mysql-server mysql-client php5-mysql
sudo apt-get install phpmyadmin
sudo apt-get install php-apc

I’m using the standard web server Apache. It also has the possibility to define multiple hosts.

MySql

As I’m owning the server I have the possibility to setup as much databases as I want. For most of the applications it would be possible to set them up together in one database as the tables would get a prefix.
When creating a new database take care to always define the char set utf8_general_ci.

phpmyadmin

It’s sometime much easier to use this as a web based management system of the mysql database.

PHP5

Necessary for most of the server applications.
For performance enhancements it’s very much recommended to use PHP5-apc.
PHP5-curl is necessary for the piwik archive script.

APC

For the WordPress cache W3C the PHP cache APC is necessary.

 

9.) WordPress

http://de.wordpress.org/txt-download/
Needs apache2, php, apc, mysql with a db.

The wordpress standard is installed with the standard theme, so far.
The following plugins are important:

  • Anti-Spam
  • WP-piwik: Includes the javascript code for the piwik analytics.
    Needs the API code provided by piwik.
  • W3C Cache, speeding up the system
  • Awesome Flickr gallery

Nice to have plugins:

  • NextGen Gallery, for picture galeries
  • CaptionPix, to set a nice caption under an image
  • Social Icons, to give the users to share on social networks

Some folder rights must be set by hand.

10.) Mail server

It’s not a real mail server, as one still needs a mail account at any provider, where the e-mails are originally are sent to and also that is addressed for the outgoing mails. Nevertheless it’s quite a nice solution to store the e-mails on your own server, although you also have to care for a backup then.

The solution consists of a few components as layed out in an article of the c’t magazine.

Mail transfer agent, exim4

sudo apt-get install exim4
sudo dpkg-reconfigure exim4-config

Configure as Smarthost, add RPi IP address to incoming IP adresses.
Machines to relay from: 192.168.178.0/24.
Mail format: mbox format in /var/mail
In /etc/exim4/passwd.client:
mail.example.com:username:password

In /etc/exim4/exim4.conf.localmacros:
MAIN_TLS_ENABLE = 1

Test with
echo „Smarthost-Test“ | mail Smarthost-Test user@example.com

IMAP server dovecot

Issue
sudo modprobe ipv6

otherwise dovecot will not install.

For diasabling IPV6 add in the file /etc/dovecot/dovecot.conf
listen = *

Very important is the format of the mailbox, defined in /etc/dovecot/conf.d/10-mail.conf with
mail_location = mbox:~/mail:LAYOUT=maildir++:INBOX=/var/mail/%u:CONTROL=~/mail/control

Otherwise you can not create folders in your mailbox!

Fetchmail

Grab your mails from different e-mail hosters and setup either a local or a central /etc/fetchmailrc file with:

poll imap.gmail.com proto IMAP user "mm@gmail.com" there is mmuster here password "123456" folder INBOX ssl
mda 'formail -c >> ~/mail/.INBOX.Gmail'
keep

Remove the „keep“ option when everything works.

Either run it with a daemon or configure a cron job.
Adapt  /etc/default/fetchmailrc to run fetchmail as daemon.

Webmailer roundcube

sudo apt-get install roundcube-core roundcube-mysql

For https you need SSL enabled in apache.
In the file /etc/apache2/conf.d/roundcube

enter the two alias
Alias /roundcube/program/js/tiny_mce/ /usr/share/tinymce/www/
Alias /roundcube /var/lib/roundcube

On Windows I use the thunderbird client, on Android the K9.

11.) Baikal contact & calendar server

http://baikal-server.com/
Read INSTALL.
Adapt the httpd.conf.

You can use the following clients:

If I once really need file sharing and collaboration seafile sounds like a very good option.

12.) tt-rss feed reader

Tiny tiny RSS is an open source RSS feed aggregator and news reader.

You have to enable the API so that mobile apps can access it. There is an app from the developer, and also a fork now. And it works with the greader app. All are only available for Android.

Install the cronjob for automatic update within another user, not for root.

*/30 * * * * /usr/bin/php /var/www/tt-rss/update.php --feeds --quiet

13.) Piwik

Piwik is an open source analytics software. You put a javascript code on all your pages, and when a page is loaded the information is send to the piwik server. Of course there must be no add/script blocker activated in the browser, otherwise it’s not working.

Important: As the raspberry pi server has low performance you have to switch off the „on the fly calculations“ in „Preferences/General Preferences/Archiv in Browser: Off“
Set „Reports“ to 3600 seconds.

It can happen that the server is too slow and the PHP maximum execution time is reached. So first you have to set this to „0“ in php.ini and restart apache with „sudo service apache2 restart“.

To make the calculations in the background configure a cron job with:
sudo crontab -e
5 * * * * /usr/bin/php5 /var/www/piwik/misc/cron/archive.php -- url=http://hardy.no-ip.biz/piwik/ > /var/log/piwik-archive.log

Then you can check the log file at /var/log/piwik-archive.log if it’s running correctly every hour + 5min.

14.) URL setting

The URL that the Dynamic IP service provider delivers must be set in the following files/packages

  • WordPress: In the General preferences, WordPress URL
  • No-Ip: Configure with sudo /usr/local/bin/noip2 -C
  • Piwik: In the GUI at general preferences/web sites and in the cron job
  • tt-rss: In the file config.php file at define('SELF_URL_PATH', 'http://your.domain.org/tt-rss/');

15.) Port forwarding

For HTTPS forward the TCP port 443, for secure IMAP the TCP port 993.

16.) Backup

Two backups are done automatically, the file system with rsync to another hard disk and the mysql database.

 

 

 

 

 

3 Antworten auf „IT Setup“

Hi,
super idea, all hints very helpful
c’t magazine 3/2014 hat a topic title raspberry Pi &Co.
I think this will be my next project 🙂
Thanx a lot

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert