Saturday, 16 March 2019

Install GlassFish 5.0 on CentOS 7

Install GlassFish 5.0 on CentOS 7

GlassFish is an open source application server for the Java EE platform. GlassFish project is initially started by Sun Microsystem and now sponsored by Oracle Corporation. GlassFish is free software and dual-licensed under two free software licenses CDDL (Common Development and Distribution License) and GPL (GNU General Public License).

Oracle GlassFish Server was the commercially supported. In Nov-2013, Oracle discontinued support of Oracle GlassFish Server while continuing open source updates. Thereafter, Oracle encouraged its customer to migrate to another alternate product Oracle Weblogic Server.

The only commercially supported fork of GlassFish available is Payara Server.

In this article, we are installing GlassFish 5.0 on CentOS 7. We are using the open source version of GlassFish with Oracle Java SE 8.

You should have a reference book like

to help you during your GlassFish study.

 

This Article Provides:

     

    System Specification:

    We are using a CentOS 7 virtual machine with following specification.

    • Hostname - glassfish-01.example.com
    • IP Address - 192.168.116.147/24
    • Operating System - CentOS 7.6
    • GlassFish Version - 5.0

     

    Installing Oracle Java SE 8 on CentOS 7:

    Connect with glassfish-01.example.com using ssh as root user.

    As a best practice, we always minimally install our CentOS 7 servers and then install required packages on demand.

    We required wget and unzip commands to download and extract software respectively. Therefore, we are installing both of these packages using yum command.

    [root@glassfish-01 ~]# yum install -y wget unzip Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.ges.net.pk * extras: mirrors.ges.net.pk * updates: mirrors.ges.net.pk Resolving Dependencies --> Running transaction check ---> Package unzip.x86_64 0:6.0-19.el7 will be installed ---> Package wget.x86_64 0:1.14-18.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: unzip x86_64 6.0-19.el7 base 170 k wget x86_64 1.14-18.el7 base 547 k Transaction Summary ================================================================================ Install 2 Packages Total download size: 717 k Installed size: 2.3 M Downloading packages: (1/2): wget-1.14-18.el7.x86_64.rpm | 547 kB 00:03 (2/2): unzip-6.0-19.el7.x86_64.rpm | 170 kB 00:03 -------------------------------------------------------------------------------- Total 200 kB/s | 717 kB 00:03 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : wget-1.14-18.el7.x86_64 1/2 Installing : unzip-6.0-19.el7.x86_64 2/2 Verifying : unzip-6.0-19.el7.x86_64 1/2 Verifying : wget-1.14-18.el7.x86_64 2/2 Installed: unzip.x86_64 0:6.0-19.el7 wget.x86_64 0:1.14-18.el7 Complete!

    GlassFish 5.0 requires Java JDK 8. Therefore, we are downloading Oracle Java SE 8 from Oracle website.

    Although, it is not necessary that, we must use Oracle Java SE 8, instead we can also use OpenJDK as well. Since we are using OpenJDK in our previous articles, therefore, we decided to try Oracle Java SE 8 this time.

    [root@glassfish-01 ~]# wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm" --2019-03-15 00:20:15-- https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm Resolving download.oracle.com (download.oracle.com)... 23.198.73.122 Connecting to download.oracle.com (download.oracle.com)|23.198.73.122|:443... connected. HTTP request sent, awaiting response... 302 Moved Temporarily Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm [following] --2019-03-15 00:20:16-- https://edelivery.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm Resolving edelivery.oracle.com (edelivery.oracle.com)... 184.86.116.38, 2600:1417:7a:2a3::366, 2600:1417:7a:288::366 Connecting to edelivery.oracle.com (edelivery.oracle.com)|184.86.116.38|:443... connected. HTTP request sent, awaiting response... 302 Moved Temporarily Location: http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1552591337_33165c6d74a8540150b0c2ddb6f3633b [following] --2019-03-15 00:20:18-- http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1552591337_33165c6d74a8540150b0c2ddb6f3633b Connecting to download.oracle.com (download.oracle.com)|23.198.73.122|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1552591337_33165c6d74a8540150b0c2ddb6f3633b [following] --2019-03-15 00:20:18-- https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1552591337_33165c6d74a8540150b0c2ddb6f3633b Connecting to download.oracle.com (download.oracle.com)|23.198.73.122|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 176209195 (168M) [application/x-redhat-package-manager] Saving to: âjdk-8u201-linux-x64.rpm.1â 100%[======================================>] 176,209,195 152KB/s in 16m 10s 2019-03-15 00:36:29 (177 KB/s) - âjdk-8u201-linux-x64.rpm.1â saved [176209195/176209195]

    Install Java JDK 8u201 using yum command.

    [root@glassfish-01 ~]# yum install jdk-8u201-linux-x64.rpm Loaded plugins: fastestmirror Examining jdk-8u201-linux-x64.rpm: 2000:jdk1.8-1.8.0_201-fcs.x86_64 Marking jdk-8u201-linux-x64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package jdk1.8.x86_64 2000:1.8.0_201-fcs will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: jdk1.8 x86_64 2000:1.8.0_201-fcs /jdk-8u201-linux-x64 288 M Transaction Summary ================================================================================ Install 1 Package Total size: 288 M Installed size: 288 M Is this ok [y/d/N]: N Exiting on user command Your transaction was saved, rerun it with: yum load-transaction /tmp/yum_save_tx.2019-03-15.00-37.Vcrei7.yumtx [root@glassfish-01 ~]# yum install -y jdk-8u201-linux-x64.rpm Loaded plugins: fastestmirror Examining jdk-8u201-linux-x64.rpm: 2000:jdk1.8-1.8.0_201-fcs.x86_64 Marking jdk-8u201-linux-x64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package jdk1.8.x86_64 2000:1.8.0_201-fcs will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: jdk1.8 x86_64 2000:1.8.0_201-fcs /jdk-8u201-linux-x64 288 M Transaction Summary ================================================================================ Install 1 Package Total size: 288 M Installed size: 288 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 2000:jdk1.8-1.8.0_201-fcs.x86_64 1/1 Unpacking JAR files... tools.jar... plugin.jar... javaws.jar... deploy.jar... rt.jar... jsse.jar... charsets.jar... localedata.jar... Verifying : 2000:jdk1.8-1.8.0_201-fcs.x86_64 1/1 Installed: jdk1.8.x86_64 2000:1.8.0_201-fcs Complete!

    Set JAVA_HOME environment variable.

    [root@glassfish-01 ~]# echo "export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64/" >> /etc/profile [root@glassfish-01 ~]# . /etc/profile [root@glassfish-01 ~]# env | grep JAVA_HOME JAVA_HOME=/usr/java/jdk1.8.0_201-amd64/

    Check Java version to verify installation.

    [root@glassfish-01 ~]# java -version java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

     

    Installing Glassfish 5.0 on CentOS 7:

    Create a user to own Glassfish software.

    [root@glassfish-01 ~]# useradd -s /sbin/nologin glassfish

    Download Glassfish 5.0 from Glassfish website.

    There are two editions of Glassfish are available, Web Profile and Full Platform.

    Full Platform is the full fledge Java EE server, with complete Java Platform support. Whereas, Web Profile is the subset of Glassfish Full Platform, provides only commonly used elements.

    Here, we will download Glassfish 5.0 Full Platform.

    [root@glassfish-01 ~]# wget http://download.oracle.com/glassfish/5.0/release/glassfish-5.0.zip --2019-03-15 20:29:03-- http://download.oracle.com/glassfish/5.0/release/glassfish-5.0.zip Resolving download.oracle.com (download.oracle.com)... 23.211.4.135 Connecting to download.oracle.com (download.oracle.com)|23.211.4.135|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://download.oracle.com/glassfish/5.0/release/glassfish-5.0.zip [following] --2019-03-15 20:29:04-- https://download.oracle.com/glassfish/5.0/release/glassfish-5.0.zip Connecting to download.oracle.com (download.oracle.com)|23.211.4.135|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 119735241 (114M) [application/zip] Saving to: âglassfish-5.0.zipâ 100%[======================================>] 119,735,241 298KB/s in 9m 3s 2019-03-15 20:38:09 (215 KB/s) - âglassfish-5.0.zipâ saved [119735241/119735241]

    Extract glassfish-5.0.zip file.

    [root@glassfish-01 ~]# unzip -d /opt/ glassfish-5.0.zip

    Change ownership of /opt/glassfish5 directory.

    [root@glassfish-01 ~]# chown -R glassfish:glassfish /opt/glassfish5/

    Create a systemd service to autostart Glassfish server.

    [root@glassfish-01 ~]# vi /usr/lib/systemd/system/glassfish.service

    and add following directives therein.

    [Unit] Description = GlassFish Server v5.0 After = syslog.target network.target [Service] User = glassfish ExecStart = /usr/bin/java -jar /opt/glassfish5/glassfish/lib/client/appserver-cli.jar start-domain ExecStop = /usr/bin/java -jar /opt/glassfish5/glassfish/lib/client/appserver-cli.jar stop-domain ExecReload = /usr/bin/java -jar /opt/glassfish5/glassfish/lib/client/appserver-cli.jar restart-domain Type = forking [Install] WantedBy = multi-user.target

    Start and enable glassfish.service.

    [root@glassfish-01 ~]# systemctl enable glassfish.service Created symlink from /etc/systemd/system/multi-user.target.wants/glassfish.service to /usr/lib/systemd/system/glassfish.service. [root@glassfish-01 ~]# systemctl start glassfish.service

    Glassfish uses following Service ports.

    4848 - Administration Console
    8080 - HTTP Service

    8181 - HTTPS Service

    Allow Glassfish Service ports in Linux Firewall.

    [root@glassfish-01 ~]# firewall-cmd --permanent --add-port={4848,8080,8181}/tcp success [root@glassfish-01 ~]# firewall-cmd --reload success

    Add Glassfish binaries to PATH environment variable.

    [root@glassfish-01 ~]# sed -i 's/^PATH=*/PATH=\/opt\/glassfish5\/bin:/g' ~/.bash_profile

    Set password for Glassfish 5.0 Admin user.

    [root@glassfish-01 ~]# asadmin --port 4848 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.

    By default, Glassfish Admin Console is running as a clear text HTTP service. Run following command to enable secure administration console.

    [root@glassfish-01 ~]# asadmin --host glassfish-01.example.com --port 4848 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.

    Restart glassfish.service.

    [root@glassfish-01 ~]# systemctl restart glassfish.service

    After restarting glassfish.service, we are not able to access the Glassfish Admin Console.

    Thanks to M.S. Dousti at StackOverflow, we come to know about this bug. It is caused by the use of an older version of Grizzly module. As a workaround, he suggested to upgrade the grizzly-npn-bootstrap.jar to a newer version.

    Therefore, we have downloaded and upgraded grizzly-npn-bootstrap.jar as per his advice.

    [root@glassfish-01 ~]# cd /opt/glassfish5/glassfish/modules/endorsed [root@glassfish-01 endorsed]# mv grizzly-npn-bootstrap.jar grizzly-npn-bootstrap.jar.1 [root@glassfish-01 endorsed]# wget https://search.maven.org/remotecontent?filepath=org/glassfish/grizzly/grizzly-npn-bootstrap/1.9/grizzly-npn-bootstrap-1.9.jar -O grizzly-npn-bootstrap.jar --2019-03-15 23:12:01-- https://search.maven.org/remotecontent?filepath=org/glassfish/grizzly/grizzly-npn-bootstrap/1.9/grizzly-npn-bootstrap-1.9.jar Resolving search.maven.org (search.maven.org)... 54.87.22.154, 54.236.172.66, 52.200.115.228 Connecting to search.maven.org (search.maven.org)|54.87.22.154|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 126502 (124K) [application/java-archive] Saving to: âgrizzly-npn-bootstrap.jarâ 100%[======================================>] 126,502 204KB/s in 0.6s 2019-03-15 23:12:03 (204 KB/s) - âgrizzly-npn-bootstrap.jarâ saved [126502/126502] [root@glassfish-01 endorsed]# chown glassfish:glassfish grizzly-npn-bootstrap.jar

    Restart glassfish.service.

    [root@glassfish-01 endorsed]# systemctl restart glassfish.service

    Browse URL https://glassfish-01.example.com:4848/ from a client's browser. You have to ignore certificate warning and add exception in your browser.

    glassfish-5-admin-console-01

    We have reached at the login page of Glassfish 5.0 Admin Console.

    glassfish-5-admin-console-login-01

    Login as Admin user with password, that we have set in previous steps.

    glassfish-5-admin-console-dashboard-01

    We have successfully login to Glassfish Admin Console.

    Now, Browse URLs http://glassfish-01.example.com/ and https://glassfish-01.example.com/ from a client's browser.

    Both URLs will bring you to the same page. The only difference is that, former will serve you a clear text HTTP version, however the later will serve a encrypted HTTPS version of the same webpage.

    glassfish-5-default-page-01

    We have successfully installed Glassfish 5.0 on CentOS 7 server.

    Install GlassFish 5.0 on CentOS 7


    YOU MIGHT ALSO LIKE:

    4 comments:

    1. Thank you for your post!

      I installed my new version of glassfish in a few minutes!

      But, there are two issues in your post:
      1. There is a recent Oracle Java License Update just after your post. I can't install Oracle JDK version.
      2. In the step for update grizzly-npn-bootstrap.jar is a typo in --O option. It's only with one hyphen. -O is the correct spell.

      Thank you again!

      ReplyDelete
      Replies
      1. Hi,
        It is good to here from you.

        1. You can use openjdk instead of Oracle JDK.
        2. Thanks for point out this typo. It has been corrected now.

        Delete
    2. After downloading Grizzly jar one should chown it. Just for consistency.

      ReplyDelete
      Replies
      1. Hi,
        Agreed with you.
        Although the configurations work fine, but it is better to change the file owner for consistency.

        Updating above article as per your advice.

        Delete