Monday, July 1, 2013

Pemasangan Server Glassfish Versi Opensource

So dalam kes aku ni , aku mengalakkan korang install fresh Ubuntu , cuma ada ssh server je , gui atau komponen server lain korang tauk buang (letak tepi) bak kata org utara. Hehehehe ...

So lepas korang install fresh Ubuntu 12.04 LTS kena wat

sudo apt-get update
sudo apt-get upgrade

 Lepas tu install plak JDK , skang ni JAVA 7

sudo apt-get install openjdk-7-jdk
javac -version

 Untuk security kita create user glassfish dan group glassfishadmin

#tambah user baru -> glassfish

sudo adduser --home /home/glassfish --system --shell /bin/bash glassfish

#tambah group baru -> glassfish administration

sudo groupadd glassfishadm

#tambah user skang kepada Glassfish adminstrators

sudo usermod -a -G glassfishadm $myAdminUser <- anda="" p="" username="">
#kalau nak padam group pada masa akan datang (ignore warnings):

#delgroup glassfishadm

Download dan install glassfish

#if you dont't have "unzip" installed run this here first
sudo apt-get install unzip
#now switch user to the glassfish user we created (see step 1)
sudo su glassfish
#change to home dir of glassfish
cd /home/glassfish/
#create new directory if not already available
mkdir downloads
#go to the directory we created
cd /home/glassfish/downloads/


#download Glassfish and unzip *latest g nengok kat https://glassfish.java.net/download.html

wget http://download.java.net/glassfish/4.0/release/glassfish-4.0.zip
unzip glassfish-4.0.zip
#move the relevant content to home directory
mv /home/glassfish/downloads/glassfish4/* /home/glassfish/

#if something has not been moved, then move it manually, i.e.:
mv /home/glassfish/downloads/glassfish4/.org.opensolaris,pkg /home/glassfish/.org.opensolaris,pkg
#exit from glassfish user
exit
#change group of glassfish home directory to glassfishadm
sudo chgrp -R glassfishadm /home/glassfish
#just to make sure: change owner of glassfish home directory to glassfish
sudo chown -R glassfish /home/glassfish
#make sure the relevant files are executable/modifyable/readable for owner and group
sudo chmod -R ug+rwx /home/glassfish/bin/
sudo chmod -R ug+rwx /home/glassfish/glassfish/bin/
#others are not allowed to execute/modify/read them
sudo chmod -R o-rwx /home/glassfish/bin/
sudo chmod -R o-rwx /home/glassfish/glassfish/bin/

Skang dah boleh try korangnya SERVER


#now switch user to the glassfish user
sudo su glassfish
#start glassfish
/home/glassfish/bin/asadmin start-domain domain1
#check the output...
#stop glassfish
/home/glassfish/bin/asadmin stop-domain domain1
#check the output...
#exit from glassfish user
exit

 Create init script untuk automatik run glassfish bila reboot

#create and edit file
sudo vi /etc/init.d/glassfish
#(paste the lines below into the file and save it...):
#! /bin/sh
#to prevent some possible problems
export AS_JAVA=/usr/lib/jvm/java-6-sun
GLASSFISHPATH=/home/glassfish/bin
case "$1" in
start)
echo "starting glassfish from $GLASSFISHPATH"
sudo -u glassfish $GLASSFISHPATH/asadmin start-domain domain1
;;
restart)
$0 stop
$0 start
;;
stop)
echo "stopping glassfish from $GLASSFISHPATH"
sudo -u glassfish $GLASSFISHPATH/asadmin stop-domain domain1
;;
*)
echo $"usage: $0 {start|stop|restart}"
exit 3
;;
esac
:

Configure autostart

#make the init script file executable
sudo chmod a+x /etc/init.d/glassfish
#configure Glassfish for autostart on ubuntu boot
sudo update-rc.d glassfish defaults
#if apache2 is installed:
#stopping apache2
sudo /etc/init.d/apache2 stop
#removing apache2 from autostart
update-rc.d -f apache2 remove

 Create init script untuk automatik run glassfish bila reboot dan start,stop,restart Glassfish macam selalu dalam Ubuntu

#start
/etc/init.d/glassfish start
#stop
/etc/init.d/glassfish stop
#restart
/etc/init.d/glassfish restart

Last config sebelum akses ke web browser

# the commands here change the file at
# /home/glassfish/glassfish/domains/domain1/config/domain.xml
#first we have to start Glassfish
/home/glassfish/bin/asadmin start-domain domain1
# enable https for remote access to admin console
# requests to http://xxx:4848 are redirected to https://xxx:4848

/home/glassfish/bin/asadmin set server-config.network-config.protocols.protocol.admin-listener.security-enabled=true

/home/glassfish/bin/asadmin enable-secure-admin

Run GLASSfish korang

#starting glassfish

sudo /etc/init.d/glassfish start

Browse GLASSFISH Administration Console

http://localhost:4848

atau

http://ipserver.korang.install:4848