Posted: May 8th, 2009 | Author: James | Filed under: Web Development, Work, linux | Tags: amazon, amazon ec2, apache, aws, ec2, hosting, lighttpd, ubuntu | No Comments »
I mentioned previously that I’d been looking at Amazon EC2 as a solution to host a site that underwent heavy bursts of traffic for only a couple of hours a week. The expected traffic bursts were 10-15k visitors in a 2 hour period and unfortunately a small EC2 instance just wasn’t enough. The next trial was with a large EC2 instance, with Apache tweaked to allow more simultaneous connections. Results went better than first time but I ended up having to bounce Apache a couple of times during the time frame to get it back up and running.
So fast forward to this week and it was time to try again. This time I went with an Extra Large instance running a stock 64-bit Ubuntu 8.04 and Lighttpd instead of Apache. And this time there were no problems. For the full 2 hours the site remained up and responsive, and because I could time the instance to come up just before the additional cost was negligible.
To give you an idea of the kind of traffic it had to deal with, the site took in just over 25,000 unique visitors in a 2 hour time frame. Glad to get the problem solved and now I know what to do next time I need some heavy traffic handled.
Posted: January 22nd, 2009 | Author: James | Filed under: Web Development | Tags: apache, cfml, coldfusion, linux, mod_jk, railo, tomcat, ubuntu | 20 Comments »
Well that headline is a bit of a mouthful, but i figured if this was something I was attempting to do then there was a good chance that others were attempting the same thing – and what I really could have done with is a guide. So here’s that guide.
First of all I started with a default install of Ubuntu Server 8.04, the latest LTS release. There’s no reason why this shouldn’t work on 8.10 though.
Setting Up Tomcat 6
First things first, install Java.
sudo apt-get install sun-java6-jdk
That should all without a hitch and the next step is to get Tomcat installed. The version available through is apt is version 5.5 and I wanted to use the latest release so after logging in to the server download the latest (6.0.18 at this time) by executing
wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
tar xvzf apache-tomcat-6.0.18.tar.gz
Next we need to move Tomcat somewhere permanent.
sudo mv apache-tomcat-6.0.18 /usr/local/tomcat
The next thing to do is set Tomcat to automatically start when the server starts (plus the script makes it easier to start and stop Tomcat). Start up your editor of choice.
sudo nano /etc/init.d/tomcat
And paste in the following script (which I got originally from HowToGeek.com)
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
export JAVA_HOME=/usr/lib/jvm/java-6-sun
case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0
The script also need to be made executable and hooked up to the startup folders.
sudo chmod 755 /etc/init.d/tomcat
sudo nano /etc/init.d/tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
Tomcat should now be up and running!
Railo
To install Railo we first need to get the Railo custom version and copy all of the files into the Tomcat lib directory.
wget http://www.railo-technologies.com/railo/remote/download/3.0.1.000/custom/all/railo-3.0.1.000-jars.tar.gz
tar zxvf railo-3.0.1.000-jars.tar.gz
sudo mv railo-3.0.1.000-jars/* /usr/local/tomcat/lib
The next step is to get Railo and Tomcat working together. I’ve assumed that you’re only using Tomcat for CFML processing so these instructions only cover installing Railo on a server wide basis rather than being site specific.
Open up the web config file
sudo nano /usr/local/tomcat/conf/web.xml
and append the following inside the <web-app> element.
<servlet>
<servlet-name>CFMLServlet</servlet-name>
<servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
<init-param>
<param-name>configuration</param-name>
<param-value>{web-root-directory}/WEB-INF/railo/</param-value>
<description>Configuraton directory</description>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfc</url-pattern>
</servlet-mapping>
Inside the <welcome-file-list> element insert the following
<welcome-file>index.cfm</welcome-file>
<welcome-file>index.cfml</welcome-file>
This tells Tomcat what files to process and what to do with them.
Apache
Next we need Apache. Originally I had installed this by selecting the LAMP stack while installing Ubuntu but if you missed that step then go for
sudo apt-get install apache2
Connecting Apache and Tomcat
There are various ways to connect Apache and Tomcat, but we’ll be using mod_jk which you can install on Ubuntu by typing in
sudo apt-get install libapache2-mod-jk
To specify the connection between Apache and Tomcat we set up a file called workers.properties and list the different connectors. Create the file in the Apache directory
sudo nano /etc/apache2/workers.properties
and paste in the following
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1
We then tell apache where this file is by adding the following to your /etc/apache2/httpd.conf
# Mod_jk settings
JkWorkersFile workers.properties
DirectoryIndex index.html index.htm index.cfm index.cfml
Setting Up A Site
To use Railo on a website we need to configure it in both Apache and Tomcat. In Tomcat’s server.xml (/usr/local/tomcat/conf/server.xml if you’re following my instructions) add the following (you can add many of these if you need to set it up for each application)
<Host name="your.url.com" appBase="/var/www/vhosts/yoursite">
<Context path="" docBase=""/>
</Host>
Finally we add the following to your site’s apache vhost config (most likely in /etc/apache2/sites-available)
JkMount /*.cfm default
This tells mod_jk to use the default connector (as specified in the workers.properties file) whenever it encounters a file ending in .cfm. By setting it up this way we can still use apache to server static files like images, css and js (or even run another language like php side by side with ColdFusion)
Last thing to do is to drop some Coldfusion into your website and check that everything is working.