Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 information is distributed accross other pages.

However, it would be good to have a walktrough guide to easily install and configure these.

like image 457
vahapt Avatar asked Jan 15 '23 16:01

vahapt


1 Answers

Preparing for installation

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

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

Oracle Java JDK and JBoss AS installations are not automatic. So we should download them from their web sites. We'll use jdk-7u10-linux-i586.tar.gz (or later version) and jboss-as-7.1.1.Final.tar.gz

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

or try the commandline links below [2]. (The links might get 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 one might like to install OpenJDK which is available on apt-get repository and preferred by Ubuntu. However that is a preference and I'd like to use Oracle's JDK.

Optional: Adding extra locale support for Postgresql: In my experience I needed Turkish locale support on Postgresql but it was not installed on Ubuntu by default. Here are sample commands to add Turkish collation support to Ubuntu, hence to Postgresql. [3]

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

Configuring Postgresql

We've already installed postgresql via apt-get. Now it would be good to make some changes to the config. [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 selected to bind to all interfaces instead of localhost, then you'll need an extra configuration to allow remote connections. [5] Open up pg_hba.conf

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

Add the line:

host    all             all             0.0.0.0/0               md5

Restart Postgresql to apply new config.

sudo /etc/init.d/postgresql restart

Now we'll set the password for default postgres user [6]. First fire up postgresql commandline.

sudo -u postgres psql

execute the following command. [7]

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

Now you may connect to your server via PgAdmin3 or your favorite SQL Client or via command line...

Installing and Configuring Java and JBoss AS 7.1.1

I've selected /opt directory as our install directory. You are free to choose your own as long as you configure scripts accordingly. First extract JDK.

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

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

First create a user for JBoss (jboss-as), it is a good habit to run your servers impersonating a user instead of directly executing them as root. This will tighten security.

sudo useradd -s /bin/sh jboss-as

Extract jboss-as-7.1.1.Final.tar.gz to /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 you'll run JBoss in standalone mode. Open up 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 user by executing

sudo -su jboss-as

First test the server by executing

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

It should fire-up without problems. Use CTRL+C to shut down the server. You might connect to the server on your browser at port 8080.

http://<your server address>:8080

Now we'll create a management user for JBoss. It is required to use administration console running at 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'

Exit from impersonated jboss-as user.

exit

Now you may configure your server via its web interface at

http://<your server address>:9990

This address only accept your if you are at localhost Whenever you need to configure your server remotely, fire up the server with the following command.

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

Again for security reasons do not bind to 0.0.0.0 if you don't need it.

Install JBoss as System Service

We'll prepare a server management script for init daemon (aka. init.d) [10]

cd /etc/init.d/
sudo pico jboss

Copy and paste the content below. Do not forget to modify JAVA_HOME, JBOSS_HOME directories and --chuid jboss-as (impersonates as jboss-as user when running the server) parameter accordingly.

#!/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

Set the script as executable and update rc.d

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

Now JBoss will start with your server. You might use the commands below to start and stop the server

sudo service jboss start
sudo service jboss stop
like image 68
vahapt Avatar answered Jan 17 '23 06:01

vahapt