Browsing posts in: Linux

Installing Tomcat 7 with Apache and mod_jk

Installing Java, Tomcat 7, Apache 2 and mod_jk in Ubuntu 12.04

Why would you need to install Apache and mod_jk to run a Java web application on your server? Well, you don’t have to, but there are a lot of reasons why you would want to. Removing :8080 from all the requests, rewriting URLs and handling static assets, performance (loadbalancing/clustering/CDN/etc.) and a whole host of other reasons. This guide assumes you have a brand new server up and running with nothing really installed yet.

The following is an extremely vanilla setup that I would consider my normal baseline configuration, the bare minimum to get Tomcat and Apache talking successfully. This will mainly aid in allowing all your web requests to be funneled through port 80 (instead of the normal Tomcat 8080) and allowing static assets to be served that exist outside of your application’s WAR file- think uploaded user images and such.

Install Java

First things first, without Java installed on your server, none of this works.

Go to the Oracle Java Download page and choose the proper JDK for your environment. Remember: A JRE is not enough for running Tomcat or other Java application/container servers.

Follow the instructions for unpacking and installing the JDK to your file system. This example assumes you installed the JDK to /usr/local

Install Tomcat

Download the latest Tomcat version, for this post we’ll be using Tomcat 7.

Unpack Tomcat and move the contents to where you want them. For this post, we’ll be using /usr/share/tomcat7

Install Apache and mod_jk

For Ubuntu, we’ll simply use the apt package manager to install these:

Configure the default site to use the default AJP worker. For this example, we will be configuring all requests to go to Tomcat

Edit /etc/apache2/sites-available/default:

Server Specific Configurations

These steps are not entirely necessary and can vary from OS to OS depending on how servers in your environment are normally set up.

Update alternatives to point to your Java install:

Edit /etc/environment and add the following:

Create a tomcat user for running the server and assign ownership of $TOMCAT_HOME (this is necessary for the Tomcat init script in the next step):

Install this tomcat7 init.d startup script that I created for better startup/shutdown of your server to /etc/init.d/tomcat7.


Simulating Slow Connections in OS X or Linux

Simulating Slow and Laggy Connections

 

Do you want to simulate how it feels to load your site from a mobile connection (If it’s AT&T just turn off your network for an accurate simulation- I kid, don’t sue. But seriously AT&T, figure it out.) or from a laggy network? In OS X or Linux, you’ve got everything you need already installed: ipfw (IP firewall and traffic shaper control).

Create a Pipe

Configure a pipe with the appropriate bandwidth (I’ve also added a 200 ms response delay in this example).

Attach the Pipe

In this example we’re going to use port 80, but you can also use port 443 or any other port that you may be testing communication on. Additionally, you can attach the pipe to multiple ports.

That’s it!

Wait a second, you say! Now your network connection is completely throttled and everything is running terribly! You need to delete both ipfw entries and the pipe that were previously created.

Here’s how you undo what you’ve just done:


Encrypting a tar or gz (gzip) File with OpenSSL

When you have sensitive data that you need to transmit but want to make it easy to encrypt and decrypt it, use some standard tools to get the job done!

I recently had an issue where a client was using OS X laptops running an Admin panel written in PHP on MAMP in an environment that may or may not have an internet connection. The problem was that they needed to be able to dump their database data into an encrypted file so that they could send the data off when they get a connection (via email, upload, who knows). My initial response was to use gpg to encrypt the file and hand out the keys to the people who would eventually be reading the data.

Turns out, this was going to be a nightmare and I needed something ‘easier’. How about encrypting a tar file with OpenSSL? Bingo! This solution uses utilities that are already on the machine and no installations need to be performed. The reason this was such a big deal is because the laptops running this software will be all over the world with various levels of technical acumen and it will be a nightmare to make sure every single laptop has been updated correctly.

Encrypting Your File

tar and gzip the file, then encrypt it using des3 and a secret key.

That simple!

Decrypting Your File

Essentially, just call all the commands in the reverse order.

Download the Utility Scripts

Download them!


Measuring Download Speed from Linux Command Line

I recently needed to test the network speed of the ISP from my Ubuntu 10.04 LTS server. I was trying to think of a better way to test it than going out to a Linux Distro's web site and downloading an ISO from them. I stumbled across this post on StackOverflow that had a URL to a speedtest.net test file and my speedtest scripts were born. I created two scripts; one utilizing wget and one utilizing curl. A lot of machines don’t come with curl by default, but it has a lot more output than wget does while downloading.

 

What Do They Do?

The scripts utilize wget or curl to download the speedtest.net 500M test file and you can view the speed results in real time. This is an entirely unscientific method of testing your speed, but much better than say, going to Ubuntu and downloading their latest ISO via wget. Finally, the output is set to go to /dev/null, which means it simply throws away everything it downloads (no cleanup).

 

The Code

Download both scripts here

speedtest-wget.sh

speedtest-curl.sh


Quickly Clean Up .svn Directories Recursively

Did you forget to export your subversion project before copying it? Inheriting a subversion mess? Here’s how you clean it up real quick on Mac and Linux:
Change to the root of your target project/directory


Install / Upgrade PHP 5.3 on CentOS 5 / RHEL 5

As I was setting up a staging VM (CentOS 5), I quickly realized I could only get PHP 5.1 from the standard repositories. Thanks to this blog post, I was able to quickly get up and running with PHP 5.3.

From the command line on your server, run the following:

This, of course, assumes that your LAMP stack is already installed. If not, you would want to replace ‘update’ with ‘install’.

Make sure that you run the last update command (if you’re running an update) as noted above. Not including one of the three packages will result in a bunch of file conflict errors.