How to install Postgresql v9.1 and JBoss AS v7.1.1 on Ubuntu 12.04 LTS

There are really good sources that describe how to install Postgresql and JBoss on Ubuntu 12.04 LTS, but the information spreads to other pages.

However, it would be nice to have a walkthrough to easily install and configure them.

+4
source share
1 answer

Preparation for installation

sudo apt-get install postgresql postgresql-contrib postgresql-common pgadmin3 openssh-server openssh-client 

This command will install the latest packages Postgresql, PgAdmin3, Postgresql-contrib and SSH. An SSH server is not required, but it’s good to manage the server remotely. So I added it to the installation list. [ 1 ]

Installations of Oracle JDK and JBoss AS are not automatic. Therefore, we must download them from our websites. We will use jdk-7u10-linux-i586.tar.gz (or later) and jboss-as-7.1.1.Final.tar.gz

See http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html for the JDK and http://www.jboss.org/jbossas/downloads/ for the JBoss.

or try the links on the command line below [ 2 ]. (Links may become invalid in the future, sorry for that ...)

 wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-i586.tar.gz" wget "http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.tar.gz" 

Note that you can install OpenJDK, available in the apt-get repository, and preferred by Ubuntu. However, this is preference, and I would like to use Oracle JDK.

Optional: Adding additional language support for Postgresql: In my experience, I need Turkish language support on Postgresql, but by default it was not installed on Ubuntu. The following are examples of commands to add support for Turkish mapping in Ubuntu, hence for Postgresql. [ 3 ]

 sudo locale-gen tr_TR sudo locale-gen tr_TR.UTF-8 

Postgresql setup

We have already installed postgresql via apt-get. Now it would be nice to make some configuration changes. [ 4 ]

By default, Postgresql does not allow TCP connections. Edit postgresql.conf (my favorite editor is pico)

 sudo pico /etc/postgresql/9.1/main/postgresql.conf 

add

 listen_addresses = '*' #Listens on all interfaces!! 

or uncomment

 listen_addresses = 'localhost' #More secure way to configure the server. Prefer this one if you won't connect to the server remotely 

line.

If you chose to bind to all interfaces instead of the local host, you will need additional configuration to allow remote connections. [ 5 ] Open pg_hba.conf

 sudo pico /etc/postgresql/9.1/main/pg_hba.conf 

Add a line:

 host all all 0.0.0.0/0 md5 

Restart Postgresql to apply the new configuration.

 sudo /etc/init.d/postgresql restart 

Now we will set the password for the default postgres user [ 6 ]. First run the postgresql command.

 sudo -u postgres psql 

run the following command. [ 7 ]

 postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD '<your new password>'; 

Now you can connect to your server through PgAdmin3 or your favorite SQL client or through the command line ...

Installing and Configuring Java and JBoss AS 7.1.1

I selected the / opt directory as our installation directory. You can choose your own yourself while you customize your scripts accordingly. Remove the JDK first.

 sudo tar -zxvf <Full Path to jdk-7u10-linux-i586.tar.gz> -C /opt 

This will extract the JDK to the ** / opt / jdk1.7.0_10 * directory. Now we will retrieve and configure JBoss AS. [ 8 ] [ 9 ]

First create a user for JBoss ( jboss-as ), it is a good habit to start your servers, impersonating the user, and not directly execute them as root. This will enhance security.

 sudo useradd -s /bin/sh jboss-as 

Extract jboss-as-7.1.1.Final.tar.gz in /opt/jboss-as-7.1.1.Final

 sudo tar -zxvf <Full Path to jboss-as-7.1.1.Final.tar.gz> -C /opt 

I assume that you run JBoss offline. Open standalone.conf, add the lines below.

 JAVA_HOME="/opt/jdk1.7.0_10" #show your JAVA_HOME directory to JBoss JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address=0.0.0.0" #Bind to 0.0.0.0 so that remote clients can connect to your server. 

Impersonate jboss-as by doing

 sudo -su jboss-as 

First check the server by doing

 cd /opt/jboss-as-7.1.1.Final ./standalone.sh 

It should start without problems. Use CTRL + C to shut down the server. You can connect to the server in your browser on port 8080.

 http://<your server address>:8080 

Now we will create a managing user for JBoss. It is required to use the administration console running on port 9990.

 export JAVA_HOME=/opt/jdk1.7.0_10/ ./add-user.sh Management User -> Select (a) Realm (Management Realm) -> Accept the default and press enter Username : -> Enter <your admin user name> Password : -> Enter <your password> Is this correct yes/no? -> Type 'yes' and press Enter Added user '<your admin user name>' to file '/opt/jboss-as-7.1.1.Final/standalone/configuration/mgmt-users.properties' Added user '<your admin user name>' to file '/opt/jboss-as-7.1.1.Final/domain/configuration/mgmt-users.properties' 

Logout of impersonated user jboss-as .

 exit 

Now you can configure your server through the web interface

 http://<your server address>:9990 

This address is only yours if you are in localhost . When you need to remotely configure the server, start the server with the following command.

 sudo -u jboss-as ./standalone.sh -Djboss.bind.address.management=0.0.0.0 

For security reasons again, do not bind to 0.0.0.0 unless you need it.

Install JBoss as a system service

We will prepare script server management for init daemon (aka. Init.d) [ 10 ]

 cd /etc/init.d/ sudo pico jboss 

Copy and paste the content below. Do not forget to change the directories JAVA_HOME, JBOSS_HOME and - chuid jboss-as (impersonate as the jboss-as user parameter when starting the server).

 #!/bin/sh ### BEGIN INIT INFO # Provides: jboss # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/Stop JBoss AS v7.1.1 Final ### END INIT INFO # #source some script files in order to set and export environmental variables #as well as add the appropriate executables to $PATH export JAVA_HOME=/opt/jdk1.7.0_10 export PATH=$JAVA_HOME/bin:$PATH export JBOSS_HOME=/opt/jboss-as-7.1.1.Final export PATH=$JBOSS_HOME/bin:$PATH case "$1" in start) echo "Starting JBoss AS 7.1.1 Final" start-stop-daemon --start --quiet --background --chuid jboss-as --exec ${JBOSS_HOME}/bin/standalone.sh ;; stop) echo "Stopping JBoss AS 7.1.1 Final" start-stop-daemon --start --quiet --background --chuid jboss-as --exec ${JBOSS_HOME}/bin/jboss-cli.sh -- --connect command=:shutdown ;; *) echo "Usage: /etc/init.d/jboss {start|stop}" exit 1 ;; esac exit 0 

Define the script as an executable and update rc.d

 sudo chmod +x jboss sudo update-rc.d jboss defaults 

Now JBoss will start working from your server. You can use the commands below to start and stop the server.

 sudo service jboss start sudo service jboss stop 
+9
source

All Articles