How to Install GlassFish on a CentOS 6 VPS
You can download the JDK here:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
I'm using the latest, which is JDK 8, update 24. The JDK is
specific to 32 and 64 bit versions.
My CentOS box is 64 bit, so I'll need: jdk-8u45-linux-x64.tar.gz.
Download the appropriate JDK and save it to a directory. I'm
saving it to /root.
Move (mv) or copy (cp) the file to the /opt directory:
Create the directory /usr/java.
1. [root@testserver
~]# mkdir /usr/java
2. [root@testserver
~]# cd mkdir /usr/java
3. [root@testserver
~]# tar -xvf /root/jdk-8u45-linux-x64.tar.gz
4 [root@testserver
jdk1.8.0_45]# pwd
/usr/java/jdk1.8.0_45
Set the JAVA_HOME path. This is where we installed the JDK
above.
To do this for your current session, you can issue the following:
1. [root@sv2
java]# JAVA_HOME=/usr/java/jdk1.8.0_45
2. [root@sv2
java]# export JAVA_HOME
3. [root@sv2
java]# PATH=$JAVA_HOME/bin:$PATH
4. [root@sv2
java]# export PATH
To set the JAVA_HOME for users, we add below to the user
~/.bashrc or ~/.bash_profile of the desired user(s). We can also add it
/etc/profile and then source it to give to all users.
view plaincopy to clipboardprint?
1. JAVA_HOME=/usr/java/jdk1.8.0_45
2. export
JAVA_HOME
3. PATH=$JAVA_HOME/bin:$PATH
4. export
PATH
Once you have added the above to ~/.bash_profile or
~/.bashrc, you should log out, then log back in and check that the JAVA_HOME is
set correctly.
1. [root@sv2
~]# echo $JAVA_HOME
2. /usr/java/jdk1.8.0_45
2. Install the GlassFish Server
Change to the directory where you want to install the
GlassFish application:
You can download both the GlassFish Server Open Source
Edition 4.01 and Oracle GlassFish Server 4.01 at http://glassfish.java.net/
1. [root@sv2
~]# cd /usr/share
2. [root@sv2
~]# unzip /root/glassfish-4.1.zip
The unzip will create the following directory:
/usr/share/glassfish4
At this point, we should be able to start and stop GlassFish
using:
/usr/share/glassfish4/glassfish/bin/asadmin start-domain
domain1
and
/usr/share/glassfish4/glassfish/bin/asadmin stop-domain
domain1
Start GlassFish:
[root@testserver glassfish4]#
/usr/share/glassfish4/glassfish/bin/asadmin start-domain domain1
Waiting for domain1 to start ................
Successfully started the domain : domain1
domain Location:
/usr/share/glassfish4/glassfish/domains/domain1
Log File:
/usr/share/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
[root@testserver glassfish4]#
Stop GlassFish:
[root@testserver glassfish4]#
/usr/share/glassfish4/glassfish/bin/asadmin stop-domain domain1
Waiting for the domain to stop.
Command stop-domain executed successfully.
3. You should now be able to access the GlassFish Admin Console
at:
http://yourdomain.com:4848 or http://192.168.1.51:4848
http://yourdomain.com:4848 or http://192.168.1.51:4848
Glassfish also comes with a web environment which gives you
a graphical interface to work with. However for security reasons it’s disabled
by default. To enable it, you must first set a password for the admin account
type:
/usr/share/glassfish4/bin/asadmin change-admin-password
You’ll be prompted for the admin user name (which is admin
by default), then the current password (which is blank by default so just press
enter) finally you’ll be asked to enter your password and confirm it.
[root@testserver glassfish4]#
/usr/share/glassfish4/bin/asadmin change-admin-password
Enter admin user name [default: admin]>
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>
Command change-admin-password executed successfully.
Now that’s a password is set you can enable the remote
admin, type the following and then enter the admin name and password:
[root@testserver
glassfish4]# /usr/share/glassfish4/bin/asadmin enable-secure-admin
Enter admin user name> admin
Enter admin password for user "admin">
You must restart all running servers for the change in
secure admin to take effect.
Command enable-secure-admin executed successfully.
Step 3: Create a start/stop/restart script:.
[root@testserver glassfish4]# cd /etc/init.d
[root@testserver init.d]# vi glassfish
#!/bin/bash
# description: Glassfish Start Stop Restart
# processname: glassfish
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/jdk1.8.0_45
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
GLASSFISH_HOME=/usr/share/glassfish4/glassfish
case $1 in
start)
sh $GLASSFISH_HOME/bin/asadmin start-domain domain1
;;
stop)
sh $GLASSFISH_HOME/bin/asadmin stop-domain domain1
;;
restart)
sh $GLASSFISH_HOME/bin/asadmin stop-domain domain1
sh $GLASSFISH_HOME/bin/asadmin start-domain domain1
;;
esac
exit 0
#Save the script and make it executable:
[root@testserver init.d]# chmod +x glassfish
To start/stop/restart Glassfish use the command:
[root@testserver init.d]# /etc/init.d/glassfish restart
Waiting for the domain to stop.
Command stop-domain executed successfully.
Waiting for domain1 to start........
Successfully started the domain: domain1
Domain Location:
/usr/share/glassfish4/glassfish/domains/domain1
Log File:
/usr/share/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
[root@testserver init.d]#
If you want to start up your GlassFish application on boot
execute the following commands:
# chkconfig --add glassfish
# chkconfig glassfish on
Comments