Due to the consistency requirements of the company's products, we switched from Jetty to glassfish3.1.2. this time we installed glassfish Web profile on ubuntu12.04 server (64bit.
The content of this paper mainly comes from http://www.nabisoft.com/tutorials/glassfish/installing-glassfish-311-on-ubuntu
The preceding section is very comprehensive. I deleted the section iptables that is not required because we use nginx for forwarding. It also solves some other problems.
For example, glassfish3.1.2 has changed the security rules. Some additional steps are required.
1. Install JDK and set environment variables.
I installed jdk1.6.
root@ciappserver1:~# java -versionjava version "1.6.0_32"Java(TM) SE Runtime Environment (build 1.6.0_32-b05)Java HotSpot(TM) 64-Bit Server VM (build 20.7-b02, mixed mode)
2. Create a dedicated account
Create a glassfish SYSTEM account first
# adduser --home /home/glassfish --system --shell /bin/bash glassfishAdding system user `glassfish' (UID 108) ...Adding new user `glassfish' (UID 108) with group `nogroup' ...Creating home directory `/home/glassfish' ...
Create a user group glassfishadmin
# groupadd glassfishadm
Add glassfish to the glassfishadm group, and set the directory of the glassfishadmin group to/home/glassfish.
# usermod -a -G glassfishadm glassfish
chgrp -R glassfishadm /home/glassfish
3. Install unzip
apt-get install unzip
4. Download glassfish
Switch to the glassfish user and download and decompress
su glassfishcd /home/glassfishmkdir downloadscd downloadswget http://download.java.net/glassfish/3.1.2/release/glassfish-3.1.2-web.zipunzip glassfish-3.1.2-web.zip
Copy the extracted file to the/hom/glassfish directory, and then exit the user.
mv /home/glassfish/downloads/glassfish3/* /home/glassfish/mv /home/glassfish/downloads/glassfish3/.org.opensolaris,pkg /home/glassfish/.org.opensolaris,pkg
exit
To use the Java command under the glassfish user, add two soft links:
ln -s /usr/jdk1.6/bin/java /etc/alternatives/javaln -s /etc/alternatives/java /usr/bin/java
5. modify directory permissions
Make sure that the program runs under the glassfish user
root@ciappserver1:~# chown -R glassfish /home/glassfishroot@ciappserver1:~# chmod -R ug+rwx /home/glassfish/bin/root@ciappserver1:~# chmod -R ug+rwx /home/glassfish/glassfish/bin/root@ciappserver1:~# chmod -R o-rwx /home/glassfish/bin/root@ciappserver1:~# chmod -R o-rwx /home/glassfish/glassfish/bin/
6. Modify the port
Modify/home/glassfish/domains/domain1/config/domain. XML as follows:
<network-listeners> <network-listener port="8081" protocol="http-listener-1" transport="tcp" name="http-listener-1" thread-pool="http-thread-pool"></network-listener> <network-listener port="8181" protocol="http-listener-2" transport="tcp" name="http-listener-2" thread-pool="http-thread-pool"></network-listener> <network-listener port="4848" protocol="admin-listener" transport="tcp" name="admin-listener" thread-pool="admin-thread-pool"></network-listener> </network-listeners>
In this way, HTTP uses 8081, https uses 8181, and admingui uses port 4848.
7. Start the service
$ su glassfish$ /home/glassfish/glassfish/bin/asadmin start-domain domain1There is a process already using the admin port 4848 -- it probably is another instance of a GlassFish server.
This is a common error in glassfish startup. Go to the/etc/hosts directory and check it.
It turns out that this is an error. The hostname command returns ciappserver1
127.0.1.1UBUNTU1204TEMPLATE
Modify:
127.0.0.1 ciappserver1
Now the startup is successful.
glassfish@ciappserver1:/root$ /home/glassfish/bin/asadmin start-domain domain1Waiting for domain1 to start .......Successfully started the domain : domain1domain Location: /home/glassfish/glassfish/domains/domain1Log File: /home/glassfish/glassfish/domains/domain1/logs/server.logAdmin Port: 4848Command start-domain executed successfully.
Open the webpage http: // 10.112.18.178: 4848/. The user name is admin and the password is adminadmin. Why?
Because 3.1.2 enhances security. Game rules have changed. The default admin password is no longer adminadmin, but empty.
Note: For localhost, you can directly go to the Administrator page without a password.
8. Enable Secure-Admin after startup
Change Admin default password
./asadmin change-admin-passwordEnter admin user name [default: admin]> (Press enter to use the default user name)Enter admin password> (Press enter to use the default password)Enter new admin password> Enter new admin password again> Command change-admin-password executed successfully.
Note that you can press enter directly for the first two questions. Set a new password, for example, 123456, twice.
./asadmin --host 10.112.18.178 --port 4848 enable-secure-admin
-- Host specifies the IP address of glassfish and answers two questions: user name and password, respectively admin/123456.
Restart glassfish.
Open myserver: 4848 again, and then prompt HTTPS. Log on and finally see.
9. View glassfish users
The following command is used to view the current glassfish users:
./asadmin list-file-users --authrealmname admin-realm
Only one admin.
10. Create System Services
First create the/etc/init. d/glassfish script
export AS_JAVA=/usr/lib/jvm/java-6-sun GLASSFISHPATH=/home/glassfish/bin case "$1" instart)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:
Add the executable permission:
Chmod + X./glassfish
Create a self-starting script
update-rc.d glassfish defaults
Now you can use
Servcie glassfis (START | stop | restart) to test
Restart the instance and check whether the instance has been started.
You also need to modify the default master password when using the product environment. You can refer to the last section of the article referenced earlier:
6. Security Configuration before first startup