Install GlassFish 4.1 on a Centos 7

In this tutorial, we will explain how to install GlassFish Server Open Source Edition 4.1 on a Centos 7.1 VPS. GlassFish is an open-source application server project and it’s Oracle’s concrete implementation of Java EE. This guide should work on other Linux systems as well but was tested and written for a Centos 7.

Login to your System via SSH

ssh root@host

Update the system and install necessary packages

[root]$ yum -y update
[root]$ yum install unzip wget

Create a new system user

Create a new user for the Glassfish server:

[root]$ adduser \
   --comment 'Glassfish User' \
   --home-dir /home/glassfish \

Install Oracle JDK 8

GlassFish 4.1 requires JDK 8 u20 or above. Use the command below to download the Oracle JDK 8 from the command line using wget:

[root]$ wget --no-cookies \
    --no-check-certificate \
    --header "Cookie: oraclelicense=accept-securebackup-cookie" \
    "" \
    -O jdk-8u45-linux-x64.rpm

Once the rpm package is downloaded, install it with:

[root]$ yum install jdk-8u45-linux-x64.rpm

To check if JAVA has been properly installed on your CentOS box run java -version, and the output should be similar to the following:

[root]$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Download and extract the GlassFish 4.1 archive

Switch to the glassfish user:

[root]$ su - glassfish

As the glassfish user, download and extract the latest GlassFish 4.1 archive

[glassfish]$ wget
[glassfish]$ unzip
[glassfish]$ rm -f

Switch back to the root user:

[glassfish]$ exit

Create systemd service

To create a new systemd service for GlassFish, open your editor of choice and create a new file:

[root]$ nano /etc/systemd/system/glassfish.service

and add the following code lines:

Description = GlassFish Server v4.1
After =

ExecStart = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar start-domain
ExecStop = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar stop-domain
ExecReload = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar restart-domain
Type = forking

WantedBy =

Start the glassfish server and set it to start automatically on boot:

systemctl enable glassfish.service
systemctl start glassfish.service

To verify the unit started, run journalctl -f -u glassfish.service and you should see something like below:

[root]$ journalctl -f -u glassfish.service
Apr 26 17:36:13 vps systemd[1]: Starting GlassFish Server v4.1...
Apr 26 17:36:19 vps java[2767]: Waiting for domain1 to start .....
Apr 26 17:36:19 vps java[2767]: Successfully started the domain : domain1
Apr 26 17:36:19 vps java[2767]: domain  Location: /home/glassfish/glassfish4/glassfish/domains/domain1
Apr 26 17:36:19 vps java[2767]: Log File: /home/glassfish/glassfish4/glassfish/domains/domain1/logs/server.log
Apr 26 17:36:19 vps java[2767]: Admin Port: 4848
Apr 26 17:36:19 vps java[2767]: Command start-domain executed successfully.
Apr 26 17:36:19 vps systemd[1]: Started GlassFish Server v4.1.


The default GlassFish port numbers are:

  • Administration: 4848
  • HTTP listener: 8080
  • HTTPS listener: 8181

For example to open port 8080 in the firewall, run:

firewall-cmd --zone=pubic --add-port=8080/tcp --permanent  
firewall-cmd --reload  

For slower systems

# vi /etc/systemd/system.conf

That’s it. You have successfully installed your GlassFish . For more information about GlassFish , please refer to the Glassfish website.

Installing PostgreSQL 9.4 in CentOS 7/6.5/6.4


PostgreSQL is a powerful, open-source object-relational database system. It runs under all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS, Solaris, Tru64), and Windows OS.

PostgreSQL 9.4 has been released last week with major enhancements, fixes, and features. Read what is new in PostgreSQL 9.4 here.

In this handy tutorial, let us see how to install PostgreSQL 9.4 on CentOS 7/6.5/6.4 server.

Install PostgreSQL

Go to the PostgreSQL repository download page, and add the PostgreSQL 9.4 repository depending upon your server architecture.

For CentOS 6.x 32bit:
rpm -Uvh
For CentOS 6.x 64bit:
rpm -Uvh
For CentOS 7 64bit:
rpm -Uvh

Update the repository list using command:

yum update

Now, Install postgresql with the following command:

yum install postgresql94-server postgresql94-contrib

Initialize postgresql database using following command:

On CentOS 6.x systems:
service postgresql-9.4 initdb
On CentOS 7 systems:
/usr/pgsql-9.4/bin/postgresql94-setup initdb

Then, start postgresql service and make it to start automatically on every reboot.

On CentOS 6.x systems:
service postgresql-9.4 start
chkconfig postgresql-9.4 on
On CentOS 7 systems:
systemctl enable postgresql-9.4
systemctl start postgresql-9.4

Adjust Iptables/Firewall

Next, adjust iptables to access postgresql from remote systems.

On CentOS 6.x systems:
vi /etc/sysconfig/iptables

Add the following line:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Save and exit the file. Restart iptables service.

service iptables restart
On CentOS 7 systems:
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload

Adjust SELinux

Run the following command to make PostgreSQL work if SELinux enabled on your system.

setsebool -P httpd_can_network_connect_db 1

You may not login to PostegreSQL if you didn’t run the above command.

Access PostgreSQL command prompt

The default database name and database user are “postgres”. Switch to postgres user to perform postgresql related operations:

su - postgres

To login to postgresql, enter the command:


Sample Output:

psql (9.4.0)
Type "help" for help.

To exit from posgresql prompt, type \q following by quit to return back to the Terminal.

Set “postgres” user password

Login to postgresql prompt,

su - postgres

.. and set postgres password with following command:

postgres=# \password postgres 
Enter new password: 
Enter it again: 
postgres=# \q

To install PostgreSQL Adminpack, enter the command in postgresql prompt:

postgres=# CREATE EXTENSION adminpack;

Create New User and Database

For example, let us create a new user called “senthil” with password “centos”, and database called “mydb”.

Switch to postgres user:

su - postgres

Create user senthil.

$ createuser senthil

Create database:

$ createdb mydb

Now, login to the psql prompt, and set password and Grant access to the database mydb for senthil:

$ psql
psql (9.4.0)
Type "help" for help.
postgres=# alter user senthil with encrypted password 'centos';
postgres=# grant all privileges on database mydb to senthil;

Delete Users and Databases

To delete the database, switch to postgres user:

su - postgres

Enter command:

$ dropdb <database-name>

To delete a user, enter the following command:

$ dropuser <user-name>

Configure PostgreSQL-MD5 Authentication

MD5 authentication requires the client to supply an MD5-encrypted password for authentication. To do that, edit /var/lib/pgsql/9.4/data/pg_hba.conf file:

vi /var/lib/pgsql/9.4/data/pg_hba.conf

Add or Modify the lines as shown below

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all               md5
host    all             all             md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

OR simply add 

host    all             all                    md5

Restart postgresql service to apply the changes:

On CentOS 6.x systems:
service postgresql-9.4 restart
On CentOS 7 systems:
systemctl restart postgresql-9.4

Configure PostgreSQL-Configure TCP/IP

By default, TCP/IP connection is disabled, so that the users from another computers can’t access postgresql. To allow to connect users from another computers, Edit file /var/lib/pgsql/9.4/data/postgresql.conf:

vi /var/lib/pgsql/9.4/data/postgresql.conf

Find the lines:

#listen_addresses = 'localhost'
#port = 5432

Uncomment both lines, and set the IP address of your postgresql server or set ‘*’ to listen from all clients as shown below:

listen_addresses = '*'
port = 5432

Restart postgresql service to save changes:

On CentOS 6.x systems:
/etc/init.d/postgresql-9.4 restart
On CentOS 7 systems:
systemctl restart postgresql-9.4