How to forge a local file system server with IGEPv2 Board

From IGEP - ISEE Wiki

Revision as of 10:38, 31 December 2013 by Pau (talk | contribs) (Software Used)

Jump to: navigation, search

Introduction

Objectives

This project aims to create a local file system server using ARM Platform. It is very useful for this purpose for the next reasons:

  • ARM is designed for low power consumption. This server should be connected to power supply all the day, if you use this architecture, you can lower your electric bill.
  • ARM-Embedded is usually cheaper than a X86-Embedded processor.
  • If you have a good internet broadband connection, is not difficult to configure your server to accept external http requests.
  • Your data are 100% under your control, other services you don't know where are your files.
  • Commercial services offer premium accounts with extra hard disk space, in this project you can use all the space as your HD or SD supports.


When you finish this how-to, you will have your own local web service similar than Dropbox and SugarSync. Your service will powered by Owncloud.org software. I used for this tutorial Owncloud 3 alpha 1 release to prove all new characteristics, but you can follow this tutorial using the stable version, there characteristics are: File management, WebDAV access, sharing, music streaming, calendar, contacts, users & groups, image gallery, online text editor, online task manager and bookmarks. For more information go to Owncloud.org page.

Limitations

When i finished this project, i tested the system performance making some tests. After this i did the next conclusions:

  • If you upload a folder with more than 100 files, i recommend that you compress it before the upload.
  • Don't compress via Web a folder large than 100 MB, use WebDAV for download it.
  • Don't upload more than 750 MB via Web, use WebDAV for this purpose.
  • The Web uses HTML5 technology, it tested with Firefox 7, Google Chrome 14 browser and mobile phone with IOS 4.3.3. Older browsers maybe have problems.

Hardware Used

The hardware used for this project is:

  • IGEPv2 Board
  • 5 V power supply.
  • MicroSD card 2GB at least with SD card adapter.
  • IGEPv2 Serial Debug cable (it isn't necessary later).
  • Ethernet cable.
  • Switch or Router.
  • External USB Hard Disk with USB cable.

Software Used

I used the following software:

NOTE: Tested using Owncloud version 2

Installing Linaro Headless

Use this tutorial(microSD) and this other(IGEPxloader) to install Linaro Headless in your SD card. It runs well with the software detailed above.  You can compile the IGEPxloader and Kernel, but is not necessary.

NOTE: Use FAT16 for boot partition and EXT3 for rootfs partition.

Create a new plan text file into the boot partition named igep.ini with these content and save it.

[kernel]
; Kernel load address, NOT Modify
kaddress=0x80008000
; RAM disk load Address, NOT Modify
;rdaddress=0x84000000
; Board Serial ID
serial.low=00000001
serial.high=00000000
; Board Revision
revision=0003
; Kernel Image Name
kImageName=zImage
; Kernel RAM Disk Image Name
;kRdImageName=initrd.img-2.6.35-1010-linaro-omap
MachineID=2344
; Where Machine ID = 2344 for IGEPv2 and ID = 2717 for IGEP Module
 
[kparams]
;buddy=igep0022
;buddy=base0010
; Setup the Kernel console params
console=ttyS2,115200n8
; Enable early printk
;earlyprintk=serial,ttyS2,115200
; Setup the Board Memory Configuration
;mem=430M
mem=512M
; Setup the Boot Delay
boot_delay=0
; Setup the ARM Processor Speed
;mpurate=800
; Setup the loglevel
;loglevel=7
; Enable Kernel Debug Output
;debug=1
; Fix RTC Variable
;fixrtc=1
; Configure nocompcache variable
nocompcache=1
; Configure Frame Buffer Configuration
;omapfb.mode=dvi:1280x720MR-16@60
;omapfb.mode=dvi:hd720-16@60
; Configure Video Ram assigned
vram=40M
; Configure Video RAM assigned to every frame buffer
omapfb.vram=0:12M,1:16M,2:12M
; Configure frame buffer debug output
;omapfb.debug=1
; Configure DSS Video Debug option
;omapdss.debug=1
; Configure the Board Ethernet Mac Address
smsc911x.mac=0xb2,0xb1,0x1f,0xb5,0xcd,0xdf
;  --- Configure UBI FS boot --- 
;ubi.mtd=2 
;root=ubi0:igep0020-rootfs 
;rootfstype=ubifs
;  --- Configure NFS boot --- 
;ip=192.168.2.123:192.168.2.129:192.168.2.1:255.255.255.0::eth0:
;root=/dev/nfs
;nfsroot=192.168.2.129:/srv/nfs/igep_rootfs
;  --- Configure MMC boot --- 
root=/dev/mmcblk0p2 rw rootwait
; Assign Init program
;init=/bin/bash

NOTE: Check MAC address is not used for avoid conflicts.

Set up internet connection

Login as root via serie, and use "vi" editor to add the following lines to the bottom of /etc/network/interfaces

auto eth0
iface eth0 inet dhcp

NOTE: Some routers give a static IP via Dhcp identifying the MAC address, others give a free IP when we send Dhcp request. Also you can configure /etc/network/interfaces to get a static IP with the following lines:

auto eth0
iface eth0 inet static
address <type your address>
netmask <normally: 255.255.255.0>
gateway <where send Dhcp request>

Save changes and restart the system with via "reboot" command.
After reboot, if you don't know private ip of your server, find it typing:

ifconfig

Search in eth0: "inet addr:X.X.X.X", where X.X.X.X is the private IP server.

Test your server connection sending a ping request:

ping X.X.X.X 

After this, upgrade your system via "apt-get".

Installing Open SSH Server

Login as root via serie, type:

apt-get install openssh-server

Change root password typing:

passwd root

Enter new password, i recommend use letters, numbers and symbols like:?¿!...

Search in eth0: inet addr:X.X.X.X, where X.X.X.X is the server private IP. We are going to prove it login as root via ssh:

ssh root@X.X.X.X

Now we be able to connect to server via SSH, using the password typed above.

The next steps are not necessary use serial communication .

Creating and editing Server Users

Using root user can be dangerous, for this reason we are going to create a new user named adminserver to access server. Create new user typing:

adduser adminserver
The next steps are not necessary use serial communication . 

Follow the assistant entering a password and your user data.

Once adminserver user was create, we are going to give sudoers privileges. Type:

visudo

Go to: # User privilege specification, and add below:

adminserver ALL=(ALL) ALL

Defaults:adminserver    timestamp_timeout=0, runaspw, passwd_tries=1

The first line says that adminserver user can access like root with sudo command.

The second line, configure some paremetres to adminserver sudo access: adminserver needs root's password to run sudo (runaspw), the password will not be remembered (timestamp_timeout) and he gets only one chance to enter it (passwd_tries).
NOTE: Is important use visudo editor because it can detect spelling errors before write sudoers file.

Installing LAMP

Apache

The Apache HTTP Server is an open-source HTTP server for modern operating systems including UNIX, Microsoft Windows, Mac OS/X and Netware.

We are going to install it:

sudo apt-get install apache2 apache2-mpm-prefork

After installation, we are going to make some configurations:

mkdir /home/adminserver/web/

We create that folder called web to store all the web files.

Now we are going to change some basic Apache configuration, edit: /etc/apache2/sites-available/default

Search line:

DocumentRoot /var/www/

Replace by:

DocumentRoot /home/<user>/web/

DocumentRoot is the root folder that contains our web pages.

Search line:

Directory /var/www/

Options Indexes FollowSymLinks MultiViews

Replace by:

Directory /home/<user>/web/ 

Options FollowSymLinks

For security reasons, we are going to hide our files and folders.

Search line:

AllowOverride None

Replace by:

AllowOverride all

Allows a file .htaccess to override the options for the respective directory

Save and exit.

Add the following lines to the bottom of /etc/apache2/apache2.conf

ServerSignature Off
ServerTokens Prod

For security reasons, this lines hide the version of Apache and Linux Distro.

Restart Apache:

sudo /etc/init.d/apache2 restart

Now we have a Apache with basic improved configuration.

PHP

Now we are going to install, the required packages to run Owncloud, if you want to install more Webs like Wordpress, Joomla, etc. Maybe you need install others. Type:

sudo apt-get install php5 php5-sqlite php5-common

Restart Apache:

sudo /etc/init.d/apache2 restart

MySQL + PHPmyAdmin

sudo apt-get install mysql-server mysql-client phpmyadmin

When we are installing MySQL, we configure it entering password for root MySQL database. Also when we are installing phpmyadmin we should choose: configure database for phpmyadmin with dbconfig-common, type root MySQL password again,  type phpmyadmin password database and choose apache2 confiuration .

Restart Apache:

sudo /etc/init.d/apache2 restart

Make a simbolic link to phpmyadmin:

sudo ln -s /usr/share/phpmyadmin /home/adminserver/web/phpmyadmin

With phpmyadmin you can handle your mysql databases (managing databases, tables, fields, relations, indexes, users, permissions, etc) via web browser. It is useful for Owncloud or another program than uses MySQL.

Enabling Automatic Updates

Automatic updates can be used to automatically install updated packages. You can configure it to update all packages or just security packages. Install the following package:

sudo apt-get install unattended-upgrades

To configure unattended-upgrades, edit:/etc/apt/apt.conf.d/50unattended-upgrades and adjust the following to fit your needs:

The double “//” serve as comments, so whatever follows "//" will not be evaluated. Coment/uncoment the repositoris that you prefe, i recommend this configuration:

Unattended-Upgrade::Allowed-Origins {
        "${distro_id} stable";
        "${distro_id} ${distro_codename}-security";
//      "${distro_id} ${distro_codename}-updates";
//      "${distro_id} ${distro_codename}-proposed-updates";
};

You can blacklisted some packeges, you can enable automatic removes, autoremove orphans packages,etc.

To set everything first create a file: /etc/apt/apt.conf.d/10periodic and edit it with your favorite editor, my configuration is:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";

The above configuration updates the package list, downloads, and installs available upgrades every day. The local download archive is cleaned every week.

For more information go to here.

Set up a External HD

External HD is useful to get more space for our project. In this part we are going to set up our HD when it is connected to server.

Format your HD with a EXT3 Filesystem.

Create the following script: /etc/udev/rules.d/50-mount-external.rules, and paste this:

KERNEL!= "sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"

# Global mount options
ACTION=="add", ENV{mount_options}="relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"

# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"

# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"

# Exit
LABEL="media_by_label_auto_mount_end"

Stop/start the udev deamon:

/etc/init.d/udev stop
/etc/init.d/udev start

Connect your HD to server. Use "mount" command to see External HD information.

/dev/root on / type ext3 (rw)
none on /proc type proc (rw,noexec,nosuid,nodev)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/kernel/debug type debugfs (rw)
none on /dev type tmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
/dev/sda1 on /media/usbhd-sda1 type ext3 (rw,relatime)

Where our HD isi mounted in media folder, and its name is u"sbhd-sda1"

Set up Owncloud.org Software

Installing Owncloud.org

Owncloud software need some extra packages:

For improved scanning of music files:

sudo apt-get install mp3info

For downloading multiple files:

sudo apt-get install zip

For the OpenID plugin

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

This how-to uses the lastest release of Ownlcoud but if you use stable version it would be similar. Download Owncloud in your root Apache folder.

sudo apt-get install wget
cd /home/adminserver/web/
wget http://gitorious.org/owncloud/owncloud/archive-tarball/master

Uncompres it:

tar -zxvf master

Make Root file folder in External HD:

cd /media/usbhd-sda1
sudo mkdir DATA
sudo chown -R www-data:www-data DATA

Make ownCloud directory accessible to Apache:

cd /home/adminserver/web/
sudo chown -R www-data:www-data owncloud-owncloud/

The estable version, the folder is named owncloud.
Previewowncloudinstallation1.png

Open your web browser and finish your Owncloud installation. Go to: http://<IP PRIVATE SERVER>/owncloud-owncloud/ Put your personal information and select MySQL Database. once finish, click Finish Setup.






Configuring Apache and PHP for Owncloud

PHP and Apache have a standard configuration, we need to change it to improve performance  of our project and server.

Edit <span style="font-family: monospace;" />/etc/apache2/apache2.conf

LockFile ${APACHE_LOCK_DIR}/accept.lock
PidFile ${APACHE_PID_FILE}
Timeout 700
KeepAlive On
MaxKeepAliveRequests 500
KeepAliveTimeout 600
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients           10
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          10
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_event_module>
    StartServers          2
    MaxClients          10
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
AccessFileName .htaccess
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>
DefaultType text/plain
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
Include mods-enabled/*.load
Include mods-enabled/*.conf
Include httpd.conf
Include ports.conf
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
Include conf.d/
Include sites-enabled/
ServerSignature Off
ServerTokens Prod

I reduce the number of clients and increased the persistent connection time.

Edit: /etc/php5/apache2/php.ini.

max_file_uploads = 20            max_file_uploads = 100
upload_max_filesize = 2M         upload_max_filesize = 750M
post_max_size = 8M               post_max_size = 800M
default_socket_timeout = 60      default_socket_timeout = 600
max_execution_time = 30          max_execution_time = 500
max_input_time = 60              max_input_time = 600
memory_limit = 128M              memory_limit = 1025M
mysql.connect_timeout = 60       mysql.connect_timeout = 600

I configure it for a local connection.

Edit Owncloud .htaccess and erase the following lines:

php_value upload_max_filesize 512M
php_value post_max_size 512M

Now .htacces don't limit the upload filesize and post size.

Restart Apache service:

sudo /etc/init.d/apache2 restart

Configuring WebDAV for Owncloud

Owncloud development team are creating a native client to manage files more easyly, but is not release yet. Although we can set up a WebDAV protocol to solve it. I tested with a Ubuntu 10.04 laptop, but can be use in other paltforms, see this page for more information.

Install the WebDAV support:

sudo apt-get install davfs2

Reconfigure davfs2 to allow access to normal users:

<code>sudo dpkg-reconfigure davfs2</code>

Select Yes when prompted

Add the users you want to be able to mount the share to the davfs2 group:

sudo usermod -aG davfs2 <userclient>

Edit /etc/fstab, and add the following line for each user who wants to mount the folder (with your details where appropriate)

http://<IPPRIVATE>/owncloud-owncloud/files/webdav.php /home/<username>/owncloud davfs user,rw,noauto 0 0

Create the folders owncloud & .davfs2 in your home directory Create the file named secrets inside .davfs2 folder, fill it with the following (with your credentials where appropriate)

http://<IPPRIVATE>/owncloud-owncloud/files/webdav.php <yourowncloudusername> <yourowncloudpassword>

Ensure the file is only writable by you either through the file manager:

chmod 600 ~/.davfs2/secrets

Mount your Virtual Owncloud Hardrive with the command: mount ~/owncloud You can automatically mount the folder on login, add the last command to ~/.bashrc