You are hereRaspberry Pi Configuration Considerations

Raspberry Pi Configuration Considerations


By steve - Posted on 25 February 2014

The raspberry pi is an awesome little device with an awesome community. Because of what you can do with it and its very low cost, I think it is the current "playground" for future programmers, devops, and other technical professionals. The kids playing with raspberry pi's today are the tech leaders of tomorrow. What I would have done, if I could have built a linux server for $40 when I was a kid! Or even a server FARM! I'm thinking a data center under my twin bed would have been so much more awesome than that yeast experiment gone bad...

I ordered some for my kids as part of their homeschool curriculum and brought the RPi's home. I left them in the shipping box in the kitchen. When I came home that night, both kids had the RPi's running and spent the afternoon learning how to program!

While designed for kids and education, they also make great project boxes and embedded systems. Thousands of software packages available with a simple "apt-get install" command which lets you build a tiny little server capable of anything a big server can do, limited only by 512MB of memory and an overclocked 950mhz processor.

I've deployed a couple RPis as network monitors and remote support boxes and continue to experiment with them.

There is tons of information available about the RPi and getting started with it, so I'm not writing another tutorial. I wanted to document what I had to figure out that was scattered around and took me a while to figure out. Also, some of my best practices.

Here are a couple of recipes for building an RPi useful in these environments...

Getting started

Buy a Pi, power supply, case, SDcard, wireless keyboard/mouse, wireless USB, monitor cable, and get ready for fun!

Specs:

  • Pi: Model B (512MB) or better $35
  • Power supply: I like the Samsung mini cube $5
  • Case: Optional, but recommended--get anything cool looking $6 to $20 or make one out of Legos
  • SDCard: Get a name brand 8GB or larger $8
  • Wireless keyboard/mouse: Tiny one for messing or production nodes, nice big ones for a PC for development $15 to $20
  • Wireless USB: I've used the Edimax with success $10
  • Monitor cable: You'll use the output from the HDMI, so an HDMI monitor is best. If that isn't possible, get an HDMI to DVI cable for a super-easy connection. $10

The keyboard/mouse and monitor cable are only needed for setup, if you are building a headless server.

The wireless is only needed if you need wireless (duh).

Basic Setup

Lots of tutorials on getting the RPi running, but with a Windows box as your main system, the best thing to do is use the latest SDFormatter program to format the SDCard. Then use Win32DiskImager.exe to write your .img file to the SDCard.

When you get started, it is most satisfying to "just get things working" and see what it can do. Download the latest NOOBS image and try out all of the different OSs. When you're done messing around, reformat your SDCard and put Raspian on it. That is the closest to a full Linux experience.

Download the latest (important to get the latest) Raspian image file and put it on the SDCard.

Snap everything together and put the SDCard in the RPi. Plug in the power and watch the screen!

raspi-config

When you boot up, you'll automatically be loaded into the raspi-config program. This lets you set some settings to get you up and running. You can re-run this later on the command line by running: raspi-config

These are the options you MUST set every time you set up an RPi:

  • Expand Filesystem (use the full capacity of the SDCard)
  • Change User Password (change it to something you can remember)
  • Enable Boot to Desktop (only do this, if you want the desktop to automatically load--if you are running a network probe and will be running "headless", leave it defaulting to boot to the command line)
  • Internationalization (set it up for the USA)
  • Overclock: no faster than 950mhz! The fastest setting always locked my system up
  • Advanced Options:
  • Hostname: set it to something like probe1 or whatever makes sense
  • SSH: enable it
  • Back
  • Finish
  • If you need to re-run this, just get to the command line and type: raspi-config

    Stop the Wireless from Dropping off

    The EdiMax wireless card will go to sleep after awhile, even if actively used. This is bad and frustrating.

    • Get to a command line
    • To get in permanent ROOT mode, type: sudo su
    • Do: nano /etc/network/interfaces
    • Scroll down until you see: iface wlan0 inet manual
    • Insert this line: wireless-power off
    • (This will tell the wireless card to not go to sleep)

    Set up the Wireless Card

    You can use the wifi configuration program on the desktop, if you want, but you can also configure things on the command line. I like using the command line because I've had some problems with passwords that use special characters like the shifted number keys. It took quite a while to figure out that # key I was using in the password was giving me something completely different!

    • nano /etc/wpa_supplicant/wpa_supplicant.conf
    • Add this after anything else already there:
    • ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
      update_config=1
      
      network={
         ssid="your-ssid"
         psk="your-wireless-password"
         proto=RSN
         key_mgmt=WPA-PSK
         pairwise=CCMP
         auth_alg=OPEN
      }
      
    • Reboot. See if your wireless works.

    Make sure you can ssh to the box

    Because you enabled it, just find out your IP address and, from the same network, point a ssh client to it.

    Say yes, you want to connect to that new server.

    Log in with user pi and the password you set previously.

    Update your apt archives

    Command line:

    apt-get update
    apt-get upgrade
    

    Remove Unneeded Packages

    Here's a script you can run to remove unneeded packages:

    #!/bin/sh
    apt-get purge -y dillo midori
    apt-get purge -y mathematica
    apt-get purge -y wolfram-engine
    apt-get purge -y idle idle-python2.7 idle-python3.2 idle3
    apt-get purge -y scratch
    

    I NEVER use these packages, especially since I can get chromium to use as a browser, but you might. There are a lot more installed that I don't need. To build a truly skinny headless server, consider a project like this one to drop all unneeded packages: http://sirlagz.net/tag/raspbian-server-edition/
    Using that script, you can drop all of the desktop related packages and free up space, processor resources, and memory. Don't run it, if you are going to run vnc.

    Desktop System

    You're mostly there. Make sure you set the option with raspi-config to boot directly to the desktop.

    Add chromium web browser:

    apt-get install chromium
    

    Network Probe/Analyzer

    These packages are handy for remote network probing and analyzing:

    #!/bin/sh
    apt-get install -y iperf mrt tcpdump netcat nmap nethogs iptraf
    

    Webserver

    You can install several different web servers. I use apache a lot, but when I want to play with something fast and lightweight, but with PHP support, I tend to go with nginx.

    Run this script to install nginx and php5 along with a test file you can access called test.php.

    #!/bin/sh
    apt-get install -y nginx php5-fpm php-apc
    mkdir /var/www
    unlink /etc/nginx/sites-enabled/default
    MF=/etc/nginx/sites-available/mysite
    echo "server {" > $MF
    echo "   listen 80;" >> $MF
    echo "   root /var/www;" >> $MF
    echo "   index index.php index.html index.htm;" >> $MF
    echo "   location ~ \.php$ {" >> $MF
    echo "     fastcgi_pass unix:/var/run/php5-fpm.sock;" >> $MF
    echo "     fastcgi_index index.php;" >> $MF
    echo "     include fastcgi_params;" >> $MF
    echo "   }" >> $MF
    echo "}"  >> $MF
    ln -s $MF /etc/nginx/sites-enabled
    service php5-fpm restart
    service nginx start
    echo "<?php phpinfo();?>" > /var/www/index.php
    

    Remote Desktop System

    You can set up a remote desktop so that you get an X desktop from any computer while your RPi is headless. One way is to use tightvncserver to set up a vnc server that requires a vnc client to access it. The other is to use xrdp as an RDP server to use from your RDP client (included with all modern Windows versions).

    The one to use is really up to you as the functionality is similar. If you are coming from a Linux client most of the time, vnc makes sense, but the data passed between client and server is not encrypted, so you'll need a stunnel or VPN connection.

    If you are coming from a Windows client, RDP is already there for you to use and has built in encryption, if you fix the default xrdp.ini settings.

    vnc

    apt-get install tightvncserver
    add a start up script for the service like this:

    #! /bin/sh
    # /etc/init.d/tightvncserver
    tightvncserver under
    VNCUSER='pi'
    case "$1" in
    start)
      echo "Starting VNC Server"
      su $VNCUSER -c '/usr/bin/tightvncserver :1'
    ;;
    stop)
      echo "Stopping VNC Server"
      pkill Xtightvnc
    ;;
    *)
      echo "Usage: /etc/init.d/tightvncserver {start|stop}"
      exit 1
    ;;
    esac
    exit 0
    

    Then make it executable:
    chmod 755 /etc/init.d/tightvncserver
    update-rc.d tightvncserver defaults
    reboot

    When the system boots up, answer the questions such as your password
    Remote in to your desktop from "vnc viewer" of your choice and connect to port 5900.

    rdp

    apt-get install xrdp
    nano /etc/xrdp/xrdp.ini
    
    Change this line from:
    crypt_level=low
    to:
    crypt_level=high
    

    Ctrl-x to save it.
    Restart the service:

    /etc/init.d/xrdp restart
    

    Now try using your RDP client to connect and you should see your raspian desktop.

    Network Monitor

    TODO

    Imaging

    If you are going to be making several nodes that are exactly the same, get everything working the way you want, then copy the SDCard image to your own img file, then you can start with that and be 99% done.

    Now you just have to boot up and change the hostname on each system, plus any other node-specific tweaks.

    Did this help you? You can help me!


    Did you find this information helpful? You can help me back by linking to this page, purchasing from my sponsors, or posting a comment!


    +One me on Google:


    Follow me on twitter: http://twitter.com/mojocode







    Comments



    Affiliation Badges