(Continued from Part I) I started out with the Ubuntu 8.0.4 AMI, created an instance off it. Then I did three more things using Elasticfox (see manual for instructions):
- Got an Elastic IP and associated with my instance. An Elastic IP is a static IP for your EC2 account that can be associated and deassociated with any instance in your account, at any time.
- Configured the security group of the instance to only accept connections at port 80 from any machine, and port 22 (for SSH) from my own machine
- I created an EBS and attached it to my instance. Be sure to create the EBS in the same availability zone as the instance, otherwise it cannot be attached.
These two steps allowed the instance to be accessible from the internet but securely. The third step created a storage for application data to reside. While the last step wasn’t absolutely necessary, because the applications would run fine with data on the same instance, it would be nice to have data in a separate storage area that was easily backed up and able to connect to multiple instances.
The next steps were to install MySQL, JDK, JBoss, and Apache. I did in that order because the first three worked OOB while Apache required some configuration to work with JBoss.
MySQL
I logged on to my instance using Putty, and followed step 4 and 5 of this blog verbatim without problems.
JDK
Follow step 2 of this blog – no problems. I used a newer update of JDK 6.
JBoss
JBoss download page is here. I downloaded the exact version (*.zip) I was using before, using wget. Copied it to /usr/local and unzip. Of course the server would say unzip wasn’t installed. So install unzip using
sudo apt-get install unzip
I created a soft link /usr/local/jboss to the installed jboss directory. Since it was a good practice to run JBoss not as root, I created a new user jboss, and changed the ownership of the JBoss installation:
sudo groupadd jboss sudo useradd -g jboss jboss chown -R jboss:jboss [JBOSS INSTALLATION DIRECTORY]
Now add Java to jboss user’s PATH by adding these lines to /home/jboss/.profile file (when installing JDK I already created the soft link /usr/local/java pointing to the JDK home directory):
#add java home in path export JAVA_HOME=/usr/local/java PATH=$JAVA_HOME/bin:$PATH
To ensure JBoss to start on reboot, I installed found this simple script off the net and put it in file /etc/init.d/jboss
#! /bin/sh start(){ echo "Starting jboss.." su -l jboss -c '/usr/local/jboss/bin/run.sh > /dev/null 2> /dev/null &' } stop(){ echo "Stopping jboss.." su -l jboss -c '/usr/local/jboss/bin/shutdown.sh -S &' } restart(){ stop # give stuff some time to stop before we restart sleep 60 # protect against any services that can't stop before we restart (warning this k ills all Java instances running as 'jboss' user) su -l jboss -c 'killall java' # if the 'su -l ...' command fails try: # sudo -u jboss killall java start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo "Usage: jboss {start|stop|restart}" exit 1 esac exit 0
and installed the startup script:
update-rc.d jboss defaultsNow it was time to startup JBoss:
/etc/init.d/jboss startVoila! The JBoss was up and running. I could verify that by
wget http://localhost:8080/It downloaded the default JBoss index.html page into the current directory. Of course I could also verify it using a browser if I opened up port 8080 in the security group.
Apache
Installing Apache was easy
sudo apt-get install apacheI was previously using Apache 2.0.x and mod_jk to connect to JBoss. The new Apache installation was 2.2.x and came with mod_proxy_ajp, so it took me fair amount of time to find all the details on the web. But once it wasn’t that bad, it wasn’t that bad at all.
I could first verify Apache was working by pointing my browser to the IP address of my instance. “It Works!” That is reassuing.
To integrate with JBoss I enabled mod_proxy_ajp
sudo a2enmod proxy_ajp
Then I created a new configuration file for my instance:
sudo vi /etc/apache2/sites-available/mysite
In this file I added these lines:
ProxyPass / ajp://localhost:8009/ ProxyPassReverse / ajp://localhost:8009/After restarting Apache I found a 403 error in my browser. It turned out the configuration for mod_proxy_ajp, /etc/apache2/mods-enabled/proxy.conf, the default is Deny From All
<Proxy *> AddDefaultCharset off Order deny,allow Deny from all </Proxy>It needed to be changed to allow connections to passed through. I simply changed it to “Allow from all” because I was using EC2’s security group to control the overall accessibility from the outside world.
After this change and restarting Apache, the browswer showed JBoss’s default web page. It worked!
One Last Problem
Now I got the basic configuration to work, I still faced one more problem. The Apache+JBoss configuration only worked if I restarted Apache after every JBoss restart. If I restarted JBoss without an Apache restart, I got “Service Temporarily Unavailable” error. That was not how it used to work on my hosted server.
Filed under: Technology | Tagged: ajp、Amazon EC2、Apache、JBoss、mod_proxy、MySQL、Ubuntu | Into the Cloud – Migrating My Apache+JBoss+MySQL Applications to Amazon’s EC2, Part II已关闭评论