Configuring Multiple Instances of Railo on Linux The purpose of this guide is to explain how to set up multiple instances of Railo on a single instance of Linux. The instances can then be used for redundancy, development environments, etc. This guide was written specifically for CentOS 6, but setting up multiple instances on other versions of Linux should be quite similar. Feel free to adapt the commands and methods described here as necessary in order to accomplish the same processes for your specific environment. We will be using the Railo 4.1.1.009 Linux 64-bit installers, as they are the most recent at the time this document was created. System Shortlist: CentOS 6 Linux 64-bit Apache 2.2 Railo 4.1.1.009 (railo-4.1.1.009-pl0-linux-x64-installer.run) Logged in as root Preplanning It will be necessary to do a small amount of pre-planning in order to organize our multiple instances of Railo using file names, directory names, and port numbers that we can easily identify as we use our system. In the following scenario, I will be naming my instances simply using numbers (railo instance 01, and so on). Using this naming convention makes it easy to identify which shared resource belongs to which instance. For example, the home folder of /opt/railo01/ is easily identified as the home folder for Railo instance 01. The control script is likewise easily identified as /etc/init.d/railo01_ctl. Using a numbering method is also useful in identifying ports: Tomcat HTTP default port: 8888 Tomcat AJP default port: 8009 Tomcat SHUTDOWN default port: 8005 We can rename these to match our numbering mechanism: Tomcat http custom port: 88nn Tomcat ajp custom port: 89nn Tomcat shutdown custom port: 85nn
In this way, we can easily identify which ports belong to which instance and what the port is connected to. You may also want to consider a naming mechanism for the home directories of each site that each instance will use. For example, sites that are run from the 01 instance, you may want to store in a directory that is named something similar to /var/www01/, however, this is less important as these files are not necessarily tied to a specific Railo instance. It would be purely for organizational purposes and would not be needed for anything functional like custom ports and railo home directories are. Installing the First Instance of Railo/Tomcat Installing the first instance of Railo is pretty strait-forward, with a few customizations: 1. Download the installer from http://railo.viviotech.net/ 2. Change the permissions on the newly downloaded file to be executable by running the command: root@local# chmod 700 railo-4.1.*.run
3. Launch the installer, and set the installation directory to /opt/railo01/ - this will help us properly identify our separate installations later on. root@local#./railo-4.1.1.009-pl0-linux-x86-installer.run 4. On the Tomcat Ports prompts, set the ports to the customized port numbers that we talked about earlier. Since this is our first install, I will use ports 8801, 8901, and 8501, to match our numbering convention: 5. You can customize the user Railo runs as also, but that is entirely up to you. In this example, since this is jut a dev machine, we'll keep things easy and run as root. 6. Do NOT select to start at boot time; we need to customize it first. 7. Do NOT install the Apache Connector at this time; we need to install it manually. Now that we have the first instance up and running, we should be able to run the netstat command to see our first Railo instance running happily on it's custom ports: root@local# netstat -ltpn
Customizing the Railo/Tomcat Daemon The next thing we need to customize is the Railo/Tomcat Daemon by customizing the railo_ctl file a little bit. Thankfully, the bulk of the customization is done by the installer, and we just need to tweak a couple small things in the file along with the file name: 1. Update the railo_ctl service description: 1. Open the railo_ctl file using the editor of your choice. I'll use vim here, but nano is also pretty popular due to it's easy control reference: root@local# cd /opt/railo01/ root@local# vim railo_ctl 2. At the top of the file, update the Provides file name to be railo01_ctl (or whichever instance you're working on) and update the description to be more specific. Updating these will ensure the service will be reported correctly if you're using a system that displays INIT INFO values.
2. Rename and Copy railo_ctl 1. Next we need to rename our railo_ctl file to match our Railo instance number. You can do that with the following command: root@local# mv railo_ctl railo01_ctl 2. After we've renamed the file, let's put a copy in the init.d directory so we can have that instance of Railo start at boot time: root@local# cp railo01_ctl /etc/init.d/ 3. Create the Railo Daemon 1. Last we need to add Railo to the list of deamons that start at boot time. We do this on CentOS using the chkconfig command: root@local# chkconfig railo01_ctl on 2. We can make sure the daemon was added by having chkconfig list out the runlevels that the daemon is set to start on using the --list parameter: # chkconfig railo01_ctl list root@local# chkconfig railo01_ctl --list Test that your new service starts correctly by giving your machine a quick restart. Repeat the above installation and deamon configuration steps for each instance you create on your server. Connecting an Apache VirtualHost to a Railo Instance Now that you have multiple Railo instances to work with, you need to connect your Apache VirtualHosts a specific Railo instance. I'm going to show you how to do that specifically in mod_proxy, since it's currently the default connector method of the Railo Installer,
however, every connection method I'm aware of has the ability to customize which port it connects to, and that's pretty much all we'll be doing here customizing the ports that each VirtualHost connects to. Install mod_cfml Mod_cfml is a helper module, which means it doesn't do any connecting on it's own. This is nice, in a way, because it gives us some flexibility in what actual Apache connector we use. Further, it also means that we only need to install mod_cfml ONCE. Since mod_cfml does not do any actual connecting on its own, the standard, global install of mod_cfml will work just fine when it comes to multiple instances of Railo. Each Railo instance you installed comes with a mod_cfml installation script. We can use any one of them in order to install it. For this example, I'll be using the mod_cfml install script that we installed with our first Railo01 instance. IMPORTANT: Try to use a Railo instance that you will not remove from your server, as mod_cfml will be point to files within that instance. If you ever remove that Railo instance from your system that mod_cfml is pointing to, your sites will not load and you will get errors from Apache until you re-point your mod_cfml config to files from an existing Railo install. The mod_cfml install script is located in the sys folder of any Railo install: root@local# cd /opt/railo01/sys/ The install script will need to know a few things, like where the Apache config file is, etc. Just run the script without any parameters to get usage information: We'll use the CentOS defaults in our command: root@local# /opt/railo01/sys/install_mod_cfml.sh -m install -l /opt/railo01 -f /etc/httpd/conf/httpd.conf -c /usr/sbin/apachectl
Well, the output could have been prettier, but it looks like it worked just fine. The install script is nice because it makes sure you have mod_perl installed as well. If you don't already have mod_perl installed, it will attempt to install it for you. Let's go check out our Apache config. Our mod_cfml code should be at the very bottom of it. Looks good. Notice how the mod_cfml.pm file it points to is in the Railo01 directory. This is important. If you ever remove the Railo01 instance, you will need to update this to either point to a Railo instance that exists, or put the mod_cfml.pm file in a more permanent location. Configure the Apache VirtualHosts Now that mod_cfml is installed, we need to configure our sites to connect to a specific Railo instance. As stated earlier, all we need to do to accomplish is customize our connector method to use the specific port of whichever instance we want it to use. In the following example, I've used the 8801 port to connect my railo01-testsite to my Railo 01 instance: <VirtualHost *:80> ServerName railo01-testsite
DocumentRoot /var/www/railo01-testsite/ DirectoryIndex index.cfm index.html ErrorLog logs/railo01-testsite-error_log CustomLog logs/railo01-testsite-access_log common <IfModule mod_proxy.c> <Proxy *> Allow from 127.0.0.1 </Proxy> ProxyPreserveHost On ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8801/$1$2 ProxyPassMatch ^/(.+\.cfchart)(/.*)?$ http://127.0.0.1:8801/$1$2 ProxyPassMatch ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8801/$1$2 ProxyPassReverse / http://127.0.0.1:8801/ </IfModule> </VirtualHost> Works like a charm! Customize your mod_proxy config and ports for each site/instance you want to connect to.
Note About Firewall Exceptions During install, CentOS will prompt you if you want to install a firewall. Most folks say yes because they want to be secure, and this is a good thing. However, this can block you from seeing your sites. To fix this, you may need to add an exception to your firewall rules. You can do this by modifying your /etc/sysconfig/iptables (on CentOS) file and adding an exception similar to the one in the attached screen shot:
Once you've added the exception, restart your firewall so your new exception takes effect: root@local# /etc/init.d/iptables restart Note on SELinux SELinux or, Security Enhanced Linux is suggested to be installed during the install process. While it is possible to run Railo with SELinux enabled and running, it is time-consuming to manage and generally not required for development environments. If you have difficulty getting your sites to work (IE: getting permission denied errors in your apache logs for mod_proxy, and Service Temporarily Unavailable from Apache), it is probably due to SELinux restricting access to your files. Managing your sites with SELinux enabled is outside the scope of this document, but you can disable SELinux and see if it is SELinux that is causing your problem by running the following command as root: root@local# echo 0 >/selinux/enforce If you want to permanently disable SELinux, you can modify the following file: /etc/selinux/config with SELINUX=disabled.