Saturday, 4 August 2012

Raspberry Pi - how to get ssh and Tomcat running

Finally got my Raspberry Pi! The cheap $25/$35 board with 700Mhz ARM cpu, GPU, 256 mb RAM, dual USB, ethernet and a bunch of general purpose IO pins. Looking awesome in its bare metal and firing it up is no problem. I flashed an SD card with the Raspbian “wheezy” Linux distribution. To write the image to the SD card I used Win32DiskImager from a PC with SD card slot.

After attaching USB keyboard, network cable and HDMI  it comes to life by using a micro USB as power supply. The diods flashes and even X runs quite smooth on this limited hardware.

However, after playing around I soon realised I will be much more comfortable working on a distance from my ordinary desktop machine. So how to enable ssh?
A lot of tutorials talks about something as simple as this to enable ssh daemon on boot.
sudo mv /boot/boot_enable_ssh.rc /boot/boot.rc

Sorry, I have no such files in my /boot directory. Furthermore, when trying to start the ssh daemon with
/etc/init.d/ssh start
it refuses to start. Clues in the startup log are

Could not load host key: /etc/ssh/ssh_host_rsa_key Could not load host key: /etc/ssh/ssh_host_dsa_key

Why these are corrupt I don't know, but it's easy to regenerate them.

ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key

Make ssh daemon start permanent

sudo update-rc.d ssh defaults

sudo reboot and everything seems ok.

Now, my mission for tonight was to get a web server running on the chipset. Here's what you need to do to make Tomcat 7 run.

Tomcat obviously need Java:
sudo apt-get install openjdk-6-jdk

And you obviously need a potent editor
sudo apt-get install vim

Clean up your installs to save some space on the SD card
sudo apt-get clean

Now, download, unpack and install Tomcat
wget http://mirrors.axint.net/apache/tomcat/tomcat-7/v7.0.28/bin/apache-tomcat-7.0.28.tar.gz
tar xzf apache-tomcat-7.0.28.tar.gz
cd apache-tomcat-7.0.28/conf
vim tomcat-users.xml

Add a user to the authorization file, directly below <tomcat-users> add
<user username="system" password="raspberry" roles="manager-gui"/>

Now start Tomcat
cd ../bin
sudo sh startup.sh

Nice! From your PC (or via a browser on the Pi) surf against the Tomcat console.
http://192.168.1.90:8080/

(Figure out the ip address via for example ifconfig)

It takes a short while to warm up the server but then you can login via Manager App. Now, it's business as usual. Upload a war archive and you have a nifty web server running you web application, for $35!

29 comments:

  1. Works like a charm!
    Thanks! It saved me an evening.

    ReplyDelete
  2. What about performance?
    Does it work (fine), for example, running a little webservice?

    Thx!

    ReplyDelete
  3. Good post!
    You wrote: "I flashed an SD card with the Raspbian “wheezy” Linux distribution". I've readed, this version of the OS doesn't support Oracle JVM, you have to install the Soft-float Debian “wheezy”.
    But you have installed the openJDK. The Raspbian wheezy version works fine in this case? Thanx in advance!

    ReplyDelete
  4. Yeah, I haven't noticed any problems with OpenJDK. I'm not an expert, but isn't the codebase pretty similar these days? Most differences are in the proprietary codecs etc which you can't GPL?

    On performance: The performance is decent. Can't imagine any problems running an standard webservice.

    ReplyDelete
  5. Thanks for the post! I flashed the SD with the Soft-float Debian “wheezy” image and installed the Oracle Java Embedded Runtime 1.7.0_10, but other than that followed this post.

    ReplyDelete
  6. The sshd setup was easy with "sudo raspi-config", but the TomCat part of this worked like a charm. Now that I've figured this out and have a door chain position sensor chosen for the Arduino controller, my garage automation project is progressing. Thank you for saving me some time. Now I need to order some MCP23008s for lighting and sprinkler control - Jy@

    ReplyDelete
  7. had a problem downloading tomcat? - version 28 is no longer available.

    change 28 to 35 or whatever number is available

    wget http://mirrors.axint.net/apache/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.tar.gz
    tar xzf apache-tomcat-7.0.35.tar.gz
    cd apache-tomcat-7.0.35/conf
    vim tomcat-users.xml

    ReplyDelete
  8. I found the answer. update & upgrade the system first

    sudo apt-get update
    sudo apt-get upgrade

    ReplyDelete
  9. If my localhost works outside my home network, but localhost/8080 doesnt, do i need to open more ports for tomcat on my router ?

    ReplyDelete
    Replies
    1. mean localhost:8080

      Delete
    2. If you intend to access the Pi outside your LAN you must surf against the router with the external IP/hostname of the router. You can use whatever port, so you could use standard 80 if you want. The important thing is to create a port forwarding rule in the router that redirect traffic on that external port to the ip address of the Pi on the internal network, and to use port 8080. So example of forwarding rule: 234.123.123.123:80 -> 192.168.1.5:8080

      Delete
  10. Thnx, I'll update the versions soon!

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Hello,

    Thanks very much for the good description. All steps had worked at the frist run. Now i try to deploy a web applicaton and install firefox (iceweasle) and try to run some addons. What a great stuff!.

    Mike

    ReplyDelete
  13. Thanks for the tutorial. It is a little slow (startup time: 12 seconds ;-) but works ;-)

    ReplyDelete
  14. Great tutorial. Note: Oracle are aiming to bring out a SE8 JDK that runs on hard float wheezy which will run faster than OpenJDK which is slower as it doesn't have JIT compiler... cannot wait

    I'm kind of wondering how now to get Tomcat and the environment variables all to run ok at bootup without logging in. Any advice?

    ReplyDelete
    Replies
    1. My advice would be to learn UNIX

      Delete
    2. sudo nano /etc/rc.local

      Delete
  15. Notable points on your website. We are interested to add some more information to this post. Keep posting new content.
    Thanks
    Reliable dedicated hosting

    ReplyDelete