How to set up an Ubuntu, Glassfish, MySQL, Java stack
April 6, 2010 3:41 PM
Follow these instructions to get a nice clean install of the GUMJ stack. That could be the MyJUG stack though by that logic the LAMP stack might become the MyLAP stack... anyways... here's how I set up Ubuntu, MySql, Connector/J, Glassfish and Java on Ubuntu.
These instructions were carried out on a VMWare virtual machine with Ubuntu 9.10 Server minimal install. During installation I selected the virtualization and minimal packages. If you're not running in a virtual machine there's no need to include the virtualization package. I'm not going to go into further details on this here as it's a pretty straight forward follow the on screen prompts install and I'll post full installation guide for the Ubuntu 10.04 LTS release at the end of this month.
One thing to note about these instructions is that the Glassfish Application Server (formerly Sun Java System Application Server) will run as root. This is not best practice for a production environment and was done for simplicity in my environment. I will update these instructions after the Ubuntu 10.04 release with details on how to install and run Glassfish as a non-privileged system user. Update: Ubuntu, Glassfish, MySQL, Java stack on Ubuntu 10.04 Lucid Lynx Server
Environment:
- Ubuntu 9.10 Server, minimal install with SSH Server
Configuration:
- Server IP Address: 192.168.180.160
- Username: username1
Procedure:
All these instructions can be entered at the command prompt or over an SSH connection.
1. [optional] Connect to the SSH Server form remote client (enter password if requested)
ssh 192.168.180.160 -l username1
2. Update the repository index and upgrade all packages
sudo aptitude update
sudo aptitude upgrade
3. Install the required packages
sudo aptitude install sun-java6-jdk wget nano
4. Create a user download directory and download the latest Glassfish (I chose the multi-language version)
cd /home/username1
mkdir Downloads
cd Downloads
sudo wget http://download.java.net/javaee5/v2.1.1_branch/promoted/Linux/glassfish-installer-v2.1.1-b31g-linux-ml.jar
5. Copy the Glassfish install jar to where you'd like to install Glassfish.
sudo cp /home/username1/Downloads/glassfish-installer-v2.1.1-b31g-linux-ml.jar /opt
6. Run the installer then you can remove the install jar.
cd /opt
sudo java -Xmx256m -jar glassfish-installer-v2.1.1-b31g-linux-ml.jar
sudo rm glassfish-installer-v2.1.1-b31g-linux-ml.jar
7. Give executable permissions to the Glassfish ant scripts and run setup. This will create domain1 with http port 8080, https on 8181 and admin on 4848.
cd glassfish
sudo chmod -R +x lib/ant/bin
sudo lib/ant/bin/ant -f setup.xml
8. Create a startup and shutdown script for Glassfish.
sudo nano /etc/init.d/glassfish
9. Add the following to the file
#!/bin/bash
GLASSFISHHOME=/opt/glassfish
case "$1" in
start)
${GLASSFISHHOME}/bin/asadmin start-domain domain1
;;
stop)
${GLASSFISHHOME}/bin/asadmin stop-domain domain1
;;
restart)
${GLASSFISHHOME}/bin/asadmin stop-domain domain1
${GLASSFISHHOME}/bin/asadmin start-domain domain1
;;
*)
echo $"usage: $0 {start|stop|restart}"
exit 1
esac Save and exit nano (Ctrl+o,Ctrl+x)
10. Make the script executable and set it for automatic startup and shutdown.
sudo chmod +x /etc/init.d/glassfish
sudo update-rc.d glassfish defaults
At this stage you have a working Glassfish install. The remaining steps will install the MySql Server and allow Glassfish connect to the database server. Skip to step 15 now if you do not wish to use MySql Server.
11. Install MySql Server
sudo aptitude install mysql-server
12. Download MySql Connector/J
cd /home/username1/Downloads
sudo wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.12.tar.gz/from/http://sunsite.informatik.rwth-aachen.de/mysql/
13. Extract the contents
tar xvfz mysql-connector-java-5.1.12.tar.gz
14. Add the Connector/J jar to the domain1 lib directory and remove the extracted folder
cd mysql-connector-java-5.1.12
sudo cp mysql-connector-java-5.1.12-bin.jar /opt/glassfish/domains/domain1/lib
cd ..
rm -r mysql-connector-java-5.1.12
15. Reboot the server to ensure all went well.
sudo reboot
You can now log into the Glassfish Application Server at http://192.168.180.160:4848/
Username: admin
Password: adminadmin
It's a good idea to change the default password as soon as you log in. Application Server > Administrator Password