Monday 29 August 2016

Configuring Raspberry Pi as NAS,VNC,Samba,Apache server

The Raspberry Pi is a small, credit card sized computer that doesn’t require a lot of power to use.
It can be used for solving many purposes in day to day technical life and building many IOT (Internet Of Things) systems.

Here we are going to discuss about the configurations to be done after you have bought the RPi. It comes without any OS to boot and test the device. First we need a 16 GB Class 10 micro SD card. (Preferably Sandisk Ultra UHS-I)


Creating bootable Raspbian OS image

Download the Raspbian Jessie OS image:
https://www.raspberrypi.org/downloads/raspbian/

For Linux: DD command is use for bit-by-bit copying the image on the memory card
umount /dev/sdx (For unmounting the SD card)
dd bs=10M if=~/2015-02-16-raspbian-jessie.img of=/dev/sdx

For Windows:
Install this software - Win32DiskImager

First thing First!

After installation of Jessie Raspbian first thing should be connecting to RPi via SSH and upgrading Package & Firmware
Default Username/Password : pi / raspberry

sudo apt-get update
sudo raspi-update
sudo raspi-config -> Expand File System (requires reboot)


Configuring Static IP Address on RPi

sudo nano /etc/network/interfaces
Replace iface eth0 inet dhcp with static
auto eth0
iface eth0 inet static
address 192.168.0.2
netmask 255.255.255.0
network 192.168.0.0
gateway 192.168.0.1

(Reboot again)  This will assign the RPi 192.168.0.2 IP everytime it boots.

Automatically connecting to a WiFi network

sudo nano /etc/network/interfaces
on wlan0
# allow-hotplug wlan0
         iface wlan0 inet manual
         wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
         iface default inet dhcp

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add this in the end of file
network={
ssid="WiFi_name"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="wifi_password"
}

(Reboot again)  This is very useful configuration when you don't have access to UI and you have to connect the RPi to a Wireless network everytime it boots. No need to connect it through LAN.



Now the networking part is over, we are ready to install the services on RPI now.

Services you can run on your RPi

Wireless printer using Rpi
Samba share drive on Rpi
VNC server on Rpi
Apache server with PHP & mysql
NAS server
Running boot scripts & commands at startup (Editing /etc/rc.local)

Installing Samba server

sudo apt-get install samba samba-common-bin
sudo vi /etc/samba/smb.conf
Paste in the end of Share Definitions :-

[pihome]
   comment= Pi Home
   path=/home/pi
   browseable=Yes
   writeable=Yes
   only guest=no
   create mask=0777
   directory mask=0777
   public=no

sudo smbpasswd -a pi (Adding a pi share user)
service samba restart

Installing VNC server (Remote Desktop)

sudo apt-get install xrdp

On Windows Run > mstsc (for Remote Desktop connection)

This service is very useful when you don't have a external keyboard/mouse to operate the UI of Raspbian OS, so we utilize laptop's keyboard via RDP connection.

Installing Apache MySql Server

sudo apt-get install apache2
sudo apt-get install mysql-server

verify the verison when installation is done
mysql –version
mysql -u root –p
mysql> show databases;

Install PHP & MySql driver for PHP

sudo apt-get install php5 php5-mysql
Testing PHP : 
sudo nano /var/www/hello.php

Converting Raspberry Pi into a NAS device


Add support to Raspbian for NTFS-formatted disks. To do so type the following command:
sudo apt-get install ntfs-3g (This is present on OS but still to upgrade the package)

Look for the unmounted partitions of the attached external hard drives.
sudo fdisk –l
umount /dev/sda1 (Suppose you external hard disk is sda1)
sudo mkdir /media/USBHDD

sudo mount -t auto /dev/sda1 /media/USBHDD

sudo nano /etc/samba/smb.conf


[NAS HDD]
comment = NAS Drive
path = /media/USBHDD
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no

Creating a Pi share user

sudo useradd nas -m -G users (Adding a user “nas”)
sudo passwd nas

sudo smbpasswd -a nas (Adding “nas” user to smb)

When Rpi restarts it will automatically mount the external hard drives:

sudo nano /etc/fstab

/dev/sda1 /media/USBHDD auto noatime 0 0

No comments:

Post a Comment