Thursday, June 20, 2013

Setup Raspberry Pi server environment

Update @ 2014/12/27

Install Raspbian "wheezy" image

Download image from Raspberry Pi offical website

Mount HOME to HDD

  • Copy HOME data to disk
    $ sudo mkdir /media/new_home
    $ sudo mount /dev/sda1 /media/new_home
    $ sudo rsync -aXS /home/. /media/new_home/.
    $ sudo umount /media/new_home 
  • fstab
    #get disk UUID
    $ sudo blkid
    /dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="936C-7122" TYPE="vfat"
    /dev/mmcblk0p2: UUID="c1198422-7a7c-4863-8a8f-45a1db26b4f2" TYPE="ext4"
    /dev/sda1: UUID="2cd990b5-6c27-4933-95d0-fd00b000fe77" TYPE="ext4"
    
    #modify fstab
    $ echo "UUID=2cd880b5-6c27-4933-95d0-fd00b000fe77    /home    ext4    defaults    0    2" | sudo tee --append /etc/fstab
    
    #mount HOMW without reboot.
    $ sudo mount -a

Create a sudo user

#create user with HOME directory 
$ sudo useradd -m oopsmonk
#add user to sudo group 
$ sudo adduser oopsmonk sudo 
#set password 
$ sudo passwd oopsmonk 

Install necessary packages

$ sudo aptitude full-upgrade -y
$ sudo aptitude install tmux vim git python-setuptools -y
$ sudo easy_install pip

SAMBA server

$ sudo aptitude install samba
$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
$ sudo vi /etc/samba/smb.conf
enable sucurity user
#   security = user
[rpi]
comment = raspberry-pi
path = /home/oopsmonk/
browseable = yes
writable = yes
read only = no

#add smaba user and restart samba server
$ sudo pdbedit -a -u oopsmonk
$ sudo service samba restart

Configre default editor

$ echo "export EDITOR=vim" >> ~/.bashrc
$ echo "export GIT_EDITOR=vim" >> ~/.bashrc
$ echo "export TERM=screen-256color" >> ~/.bashrc
$ echo "alias tmux='tmux -2'" >> ~/.bashrc
$ source ~/.bashrc

Boot from USB Disk

  1. Use dd or Win32DiskImager dump image to both SD card and USB Disk.
  2. Use gparted to expand root partition to full USB disk.
  3. Change cmdline.txt on sdcard from root=/dev/mmcblk0p2 to root=/dev/sda2
    dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 
    console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline rootwait  
  4. Plug both sdcard and USB disk into Raspberry Pi, bootup system.

exFat support

Defualt cannot mount exFAT filesystem, why exFAT?
  • NTFS performance is so bad.
  • Single file limited to 4GB in FAT32.
Install exFat:
sudo apt-get install exfat-fuse  

FTP server setup

Install vsftpd

$ sudo apt-get install vsftpd  
$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak  

Modify vsftpd.conf

$ sudo vi /etc/vsftpd.conf  
anonymous_enable=NO
local_enable=YES
write_enable=YES
force_dot_files=YES  #Add at bottom  
Invoke configuration
$ sudo service vsftpd restart    
Reference:
http://www.wikihow.com/Make-a-Raspberry-Pi-Web-Server
http://www.vuplus-community.net/board/threads/howto-make-an-ftp-server-with-your-raspberry.7245/
http://www.instructables.com/id/Raspberry-Pi-Web-Server/step9/Install-an-FTP-server/

BT download server setup

Install transmission-daemon
$ sudo apt-get install transmission-daemon  
Modify config file
$ cd /etc/transmission-daemon  
$ sudo cp settings.json settings.json.bak
$ sudo vi settings.json
#Change download folder
"download-dir": "/home/oopsmonk/BT-Download"
#Accept connection from all ip address
"rpc-whitelist": "*.*.*.*"
#Web GUI login account setting
"rpc-username": "oopsmonk"
"rpc-password": "web-login-pwd"
"umask": 2
umask change from 18 to umask: 2. This will enable all users in the transmission group to also write to the file.
Create download folder and change permission for debian-transmission user.
$ mkdir /home/oopsmonk/BT-Download
$ chmod 777 /home/oopsmonk/BT-Download
Reload config
$ sudo service transmission-daemon reload  
Login to Web GUI
http://localhost:9091/transmission

Nginx proxy setup for BT server

Why should use proxy??
Some firewall allow connect to internet using 80 port only.
In this case, we can use proxy redirect 9091 to 80 port.
$ sudo install nginx
$ sudo service nginx stop  
$ sudo vi /etc/nginx/sites-available/default
server{
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
...
        location /bt {
                proxy_pass http://127.0.0.1:9091/transmission;
        }
...
}

$ sudo service nginx start  
Test connection:
http://localhost/bt/web/
Do not forget the / in end of URL.
Reference:
Setting Up Transmission’s Web Interface
Linux防健忘日誌No.69-Ubuntu 12.04 安裝及設定transmission-daemon

USB Wifi setup

Check USB wifi driver

$ sudo lsusb  
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0b05:1786 ASUSTek Computer, Inc. USB-N10 802.11n Network Adapter [Realtek RTL8188SU]
Bus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 006: ID 0bc2:5061 Seagate RSS LLC
Here my wifi dongle is ASUS USB-N10.
Supported wifi dongle list can find at http://elinux.org/RPi_VerifiedPeripherals#USB_Wi-Fi_Adapters

Wifi scan test

$ sudo iwlist wlan0 scan | grep ESSID  
                ESSID:"CH_Lee"
                ESSID:"iHome01"
                ESSID:"WALL-E"
                ESSID:"AndyStella"
                ESSID:"My home wifi"
                ESSID:"HC-SY"
                ESSID:"default"  

Configure /etc/network/interfaces

auto wlan0

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
wpa-ssid "XXXXXX"
wpa-psk "YYYYYY"
iface default inet dhcp

PPPoE setup

Install pppoeconf

$ sudo apt-get install pppoeconf  
$ sudo pppoeconf
Input account and password to config PPPoE.
Satrt DSL connection
$ sudo pon dsl-provider  
Terminate connection
$ sudo poff  
Connection status
$ sudo plog  
or  
$ ifconfig ppp0  

Run MOC issue

Update: 2013/08/14
When run moc get an error as bellow:
$ mocp
Running the server...
Trying JACK...
Trying ALSA...
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM default
Trying OSS...

FATAL_ERROR: No valid sound driver!


FATAL_ERROR: Server exited!
Check if audio driver(snd_bcm2835) is not loaded
$ lsmod
Module                  Size  Used by
xt_TCPMSS               3119  1 
xt_tcpmss               1301  1 
xt_tcpudp               2087  1 
iptable_mangle          1467  1 
ip_tables              11482  1 iptable_mangle
x_tables               16865  5 ip_tables,xt_tcpmss,xt_tcpudp,xt_TCPMSS,iptable_mangle
pppoe                  11317  2 
pppox                   2445  1 pppoe
ppp_generic            25397  6 pppoe,pppox
slhc                    5679  1 ppp_generic
snd_bcm2835            16304  0 
snd_pcm                77560  1 snd_bcm2835
snd_page_alloc          5145  1 snd_pcm
snd_seq                53329  0 
snd_seq_device          6438  1 snd_seq
snd_timer              19998  2 snd_pcm,snd_seq
snd                    58447  5 snd_bcm2835,snd_timer,snd_pcm,snd_seq,snd_seq_device
leds_gpio               2235  0 
led_class               3562  1 leds_gpio
Check device permission.
$ sudo ls -al /dev/snd/*            
crw-rw---T 1 root audio 116,  0 Aug 14 10:49 /dev/snd/controlC0
crw-rw---T 1 root audio 116, 16 Aug 14 10:49 /dev/snd/pcmC0D0p 
crw-rw---T 1 root audio 116,  1 Aug 14 10:49 /dev/snd/seq      
crw-rw---T 1 root audio 116, 33 Aug 14 10:49 /dev/snd/timer
Ha! it's a permission issue.
Change permission:
$ sudo chmod 666 /dev/snd/*
Solved!

No comments:

Post a Comment