Sei sulla pagina 1di 13

www.goodwill.co.

id

Installing ADempiere with PostgreSQL 8.2

Overview
This article provides series of guides to install ADempiere with PostgreSQL 8.2
on a Linux systems.

Part I: Pre-Installation Steps


In this article, we are going to store PostgreSQL and ADempiere application in
/u01/app , while the database files will be in /u02/pg_data. This guide adheres to
the Optimal Flexible Architecture (OFA) for the naming conventions used in
creating the directory structure.

Login as root. First, create a directory to store the applications.


$ mkdir /u01
$ mkdir /u01/app

Extract ADempiere distribution under /u01/app.


$ unzip -o ADempiere_313.zip -d /u01/app

Setup Environment Variables


On some systems, we must set the environment variables priorly. So let's do it
now then. You can also put them in file /etc/profile so they get run everytime you
log in.
$ cat >> /etc/profile <<EOF
export JAVA_HOME=/usr/java/jdk1.5.0_11
export ADEMPIERE_HOME=/u01/app/ADempiere
export
LD_LIBRARY_PATH=/u01/app/pgsql/lib:$JAVA_HOME/jre/lib/i386:$JAVA_HOME/
jre/lib/i386/client
EOF

Part II: Installing Java


Login in as root. Download Java 2 SDK from Sun Microsystems website. Assume
it is J2SDK version 1.5.0.11. Put it in /usr/java.

Install with:
$ ./jdk-1_5_0_11-linux-i586-rpm.bin

And link with:


$ ln -s /usr/java/jdk1.5.0_11/bin/java /usr/bin/java

If you run the following command and see the same result, you re doing good.
$ java -version
www.goodwill.co.id

java version "1.5.0_11"


Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

Part III: Installing PostgreSQL


The PostgreSQL 8.2.1 sources can be downloaded any place in internet. Use a
mirror if possible. After you have obtained the file, unpack it:
$ gunzip postgresql-8.2.1.tar.gz
$ tar xf postgresql-8.2.1.tar

This will create a directory postgresql-8.2.1 under the current directory with the
PostgreSQL sources. Change into that directory for the rest of the installation
procedure.

Next, we rebuild the source.


$ ./configure --prefix=/u01/app/pgsql
$ make

You will get a line:


All of PostgreSQL successfully made. Ready to install.

When everything is finished. You'll need to log in as root to do the rest:


$ su -
Go back to the postgresql directory and do:
$ make install

Now we create PostgreSQL user account


$ groupadd postgres
$ adduser postgres -d /u01/app/pgsql -g postgres -p <password>

Add .bash_profile file in postgres home directory for user postgres environment
variable
$ cat >> /u01/app/pgsql/.bash_profile <<EOF
# .bash_profile

# Get the aliases and functions


if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
www.goodwill.co.id

PGLIB=/u01/app/pgsql/lib
PGDATA=/u02/pgdata
export PGLIB PGDATA
EOF

PostgreSQL doesn't allow root to start up the server for security reasons, so next
you'll have to change the owner of the files:
$ chown -R postgres:postgres /u01/app/pgsql

Create a new database cluster.


$ mkdir /u02
$ mkdir /u02/pgdata
$ chown postgres /u02/pgdata
$ su - postgres
$ /u01/app/pgsql/bin/initdb -D /u02/pgdata
This will create a /u02/pgdata directory and initialize it ready for startup and
use.

For more information on installing PostgreSQL, please refer to:


http://www.postgresql.org/docs/8.2/interactive/installation.html

To PostgreSQL works in network is necessary to run postmaster with parameter


-i, remember to review client authentification
(http://www.postgresql.org/docs/8.2/interactive/client-authentication.html)

Example contents of file /u02/pgdata/pg_hba.conf


host all all 192.168.0.0 255.255.255.0 trust

If all goes well, now we can start the server:


$ pg_ctl start -D /u02/pgdata -l logfile -o "-i"

Create PostgreSQL startup/shutdown service


To create PostgreSQL startup/shutdown service, first create the file
/etc/rc.d/init.d/postgresql with the following contents:

#!/bin/sh
# postgresql This is the init script for starting up the PostgreSQL
# server
#
# chkconfig: - 64 36
# description: Starts and stops the PostgreSQL backend daemon that handles \
# all database requests.
# processname: postmaster
# pidfile: /var/run/postmaster.pid
www.goodwill.co.id

# Version 6.5.3-2 Lamar Owen


# Added code to determine if PGDATA exists, whether it is current version
# or not, and initdb if no PGDATA (initdb will not overwrite a database).

# Version 7.0 Lamar Owen


# Added logging code
# Changed PGDATA.

# Version 7.0.2 Trond Eivind Glomsrd <teg@redhat.com>


# use functions, add conditional restart

# Version 7.0.3 Lamar Owen <lamar@postgresql.org>


# Check for the existence of functions before blindly using them
# in particular -- check for success () and failure () before using.
# More Cross-distribution support -- PGVERSION variable, and docdir checks.

# Version 7.1 Release Candidate Lamar Owen <lamar@postgresql.org>


# initdb parameters have changed.

# Version 7.1.2 Trond Eivind Glomsrd <teg@redhat.com>


# Specify shell for su
# Handle stop better - kill unwanted output, make it wait until the database is
ready
# Handle locales slightly differently - always using "C" isn't a valid option
# Kill output from database initialization
# Mark messages for translation

# Version 7.1.2-2.PGDG Lamar Owen <lamar.owen@wgcr.org>


# sync up.
# Karl's fixes for some quoting issues.

# Version 7.2b2 Lamar Owen <lamar.owen@wgcr.org>


# version change.

# Version 7.2 final. Lamar Owen <lamar.owen@wgcr.org>


# reload from Peter E.
# Eliminate the pidof postmaster test in stop -- we're using pg_ctl so we don't
need pidof.
# Tested the $? return for the stop script -- it does in fact propagate.
# TODO: multiple postmasters.

# Version 7.3 Lamar Owen <lamar.owen@ramifordistat.net>


# Multiple postmasters, courtesy Karl DeBisschop
www.goodwill.co.id

# Version 7.4 Lamar Owen.

# Version 7.4.3 Tom Lane <tgl@sss.pgh.pa.us>


# Support condstop for uninstall
# Minor other changes suggested by Fernando Nasser.

# Version 7.4.5 Tom Lane <tgl@sss.pgh.pa.us>


# Rewrite to start postmaster directly, rather than via pg_ctl; this avoids
# fooling the postmaster's stale-lockfile check by having too many
# postgres-owned processes laying about.

# Version 8.1 Devrim Gunduz <devrim@PostgreSQL.org>


# Increased sleep time from 1 sec to 2 sec.

# Version 8.2 Devrim Gunduz <devrim@CommandPrompt.com>


# Set initdb as a seperate option.

# PGVERSION is the full package version, e.g., 8.2.0


# Note: the specfile ordinarily updates this during install
PGVERSION=8.2.1
# PGMAJORVERSION is major version, e.g., 8.0 (this should match
PG_VERSION)
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`

# Source function library.


INITD=/etc/rc.d/init.d
. $INITD/functions

# Get function listing for cross-distribution logic.


TYPESET=`typeset -f|grep "declare"`

# Get config.
. /etc/sysconfig/network

# Find the name of the script


NAME=`basename $0`
if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
then
NAME=${NAME:3}
fi

# For SELinux we need to use 'runuser' not 'su'


if [ -x /sbin/runuser ]
then
SU=runuser
www.goodwill.co.id

else
SU=su
fi

# Set defaults for configuration variables


PGENGINE=/u01/app/pgsql/bin
PGPORT=5432
PGDATA=/u02/pgdata

if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base/template1" ]


then
echo "Using old-style directory structure"
else
PGDATA=/u02/pgdata
fi
PGLOG=/u01/app/pgsql/pgstartup.log

# Override defaults from /etc/sysconfig/pgsql if file is present


[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}

export PGDATA
export PGPORT

# Check that networking is up.


# Pretty much need it for postmaster.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f "$PGENGINE/postmaster" ] || exit 1

script_result=0

start(){
PSQL_START=$"Starting ${NAME} service: "

# Make sure startup-time log file is valid


if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
then
touch "$PGLOG" || exit 1
chown postgres:postgres "$PGLOG"
chmod go-rwx "$PGLOG"
[ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t
postgresql_log_t "$PGLOG" 2>/dev/null
fi
www.goodwill.co.id

# Check for the PGDATA structure


if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
then
# Check version of existing PGDATA

if [ x`cat "$PGDATA/PG_VERSION"` != x"$PGMAJORVERSION" ]


then
SYSDOCDIR="(Your System's documentation directory)"
if [ -d "/usr/doc/postgresql-$PGVERSION" ]
then
SYSDOCDIR=/usr/doc
fi
if [ -d "/usr/share/doc/postgresql-$PGVERSION" ]
then
SYSDOCDIR=/usr/share/doc
fi
if [ -d "/usr/doc/packages/postgresql-$PGVERSION" ]
then
SYSDOCDIR=/usr/doc/packages
fi
if [ -d "/usr/share/doc/packages/postgresql-$PGVERSION" ]
then
SYSDOCDIR=/usr/share/doc/packages
fi
echo
echo $"An old version of the database format was found."
echo $"You need to upgrade the data format before using
PostgreSQL."
echo $"See $SYSDOCDIR/postgresql-
$PGVERSION/README.rpm-dist for more information."
exit 1
fi

# No existing PGDATA! Warn the user to initdb it.

else
echo
echo "$PGDATA is missing. Use \"service postgresql initdb\" to
initialize the cluster first."
echo_failure
echo
exit 1
fi

echo -n "$PSQL_START"
www.goodwill.co.id

$SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA'


${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null
sleep 2
pid=`pidof -s "$PGENGINE/postmaster"`
if [ $pid ] && [ -f "$PGDATA/postmaster.pid" ]
then
success "$PSQL_START"
touch /var/lock/subsys/${NAME}
head -n 1 "$PGDATA/postmaster.pid" >
"/var/run/postmaster.${PGPORT}.pid"
echo
else
failure "$PSQL_START"
echo
script_result=1
fi
}

stop(){
echo -n $"Stopping ${NAME} service: "
$SU -l postgres -c "$PGENGINE/pg_ctl stop -D '$PGDATA' -s -m fast" >
/dev/null 2>&1 < /dev/null
ret=$?
if [ $ret -eq 0 ]
then
echo_success
else
echo_failure
script_result=1
fi
echo
rm -f "/var/run/postmaster.${PGPORT}.pid"
rm -f "/var/lock/subsys/${NAME}"
}

restart(){
stop
start
}

initdb(){
if [ -f "$PGDATA/PG_VERSION" ]
then
echo "Data directory is not empty!"
echo_failure
www.goodwill.co.id

else
echo -n $"Initializing database: "
if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ]
then
mkdir -p "$PGDATA" || exit 1
chown postgres:postgres "$PGDATA"
chmod go-rwx "$PGDATA"
fi
# Clean up SELinux tagging for PGDATA
[ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA"
# Initialize the database
$SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --
auth='ident sameuser'" >> "$PGLOG" 2>&1 < /dev/null
# Create directory for postmaster log
mkdir "$PGDATA/pg_log"
chown postgres:postgres "$PGDATA/pg_log"
chmod go-rwx "$PGDATA/pg_log"

[ -f "$PGDATA/PG_VERSION" ] && echo_success


[ ! -f "$PGDATA/PG_VERSION" ] && echo_failure
echo
fi
}
condrestart(){
[ -e /var/lock/subsys/${NAME} ] && restart
}

condstop(){
[ -e /var/lock/subsys/${NAME} ] && stop
}

reload(){
$SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null
2>&1 < /dev/null
}

# This script is slightly unusual in that the name of the daemon (postmaster)
# is not the same as the name of the subsystem (postgresql)

# See how we were called.


case "$1" in
start)
start
;;
stop)
www.goodwill.co.id

stop
;;
status)
status postmaster
script_result=$?
;;
restart)
restart
;;
initdb)
initdb
;;
condrestart)
condrestart
;;
condstop)
condstop
;;
reload|force-reload)
reload
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|condstop|reload|
force-reload|initdb}"
exit 1
esac

exit $script_result

Set the appropriate owner and mode:


$ chown postgres:postgres /etc/rc.d/init.d/postgresql
$ chmod 0755 /etc/rc.d/init.d/postgresql

Register your postgresql service to the system:


$ ln -s /etc/init.d/postgresql /etc/rc.d/rc2.d/S97postgresql
$ ln -s /etc/init.d/postgresql /etc/rc.d/rc3.d/S97postgresql
$ ln -s /etc/init.d/postgresql /etc/rc.d/rc4.d/S97postgresql
$ ln -s /etc/init.d/postgresql /etc/rc.d/rc0.d/K03postgresql
$ ln -s /etc/init.d/postgresql /etc/rc.d/rc6.d/K03postgresql

If it has been done, then we can start the postgresql service by the following
command :
$ /etc/rc.d/init.d/postgresql start
or we can set postgresql service to start every time the computer boot .
www.goodwill.co.id

Install Procedure Languages


Login as postgres user :
$ su - postgres

Create User ADempiere :


prompt command :
[prompt]$ createuser -sdrlIPE ADempiere
OR
SQL command :
CREATE ROLE ADempiere WITH PASSWORD 'ADempiere'
SUPERUSER NOINHERIT CREATEDB CREATEROLE
VALID UNTIL 'infinity';
UPDATE pg_authid SET rolcatupdate=true WHERE rolname='ADempiere';

Create Database ADempiere:


prompt command :
[prompt]$ createdb --encoding='UTF8' --owner='ADempiere' ADempiere
SQL command :
CREATE DATABASE ADempiere
WITH ENCODING='UTF8'
OWNER=ADempiere;

Install PLJava
Login as root and create directory:
$ mkdir /u01/app/pgsql/pljava
$ mkdir /u01/app/pgsql/jdbc

Get the lastest PostgreSQL jdbc driver and put into /u01/app/pgsql/jdbc. Set
appropriate owner :
$ chown -R postgres:postgres /u01/app/pgsql/jdbc

Download the lastest PLJava. Extract the file into /u01/app/pgsql/pljava


$ unzip -o pljava.zip -d /u01/app/pgsql/pljava
Set appropriate owner :
$ chown -R postgres:postgres /u01/app/pgsql/pljava

Log in as postgres user :


$ su - postgres

Add parameters to your file /u02/pgdata/postgresql.conf :


# define "pljava" as a custom variable class. This is a comma separated
# list of names.
custom_variable_classes = 'pljava'
www.goodwill.co.id

# define the class path that the JVM will use when loading the
# initial library. Only meaningful for non GJC installations
pljava.classpath = '/u01/app/pgsql/pljava/pljava.jar'

# Set the size of the prepared statement MRU cache


#pljava.statement_cache_size = 10

# If true, lingering savepoints will be released on function exit. If false,


# the will be rolled back
pljava.release_lingering_savepoints = true

# Define startup options for the Java VM.


pljava.vmoptions = '-Xmx64M -Dbackchannel.port=48'

# Setting debug to true will cause the postgres process to go


# into a sleep(1) loop on its first call to java. This is
# only useful if you want to debug the PLJava internal C code.
pljava.debug = false

Also still in /u02/pgdata/postgresql.conf, you might want to set the


dynamic_library_path. Scroll up a little bit, you will find the entry
dynamic_library_path = $libdir . Uncomment the line and change that to point to
where you install PLJava.
Edit to following command :
dynamic_library_path = '/u01/app/pgsql/pljava'

And then scroll up even more until you find the Connection settings. Uncomment
these lines and make the necessary changes. This is when you need to connect to
PostgreSQL from other computers on the network.
listen_address = '192.168.0.10'
port = '5432'

Install PLJava into Database


$ java -classpath /u01/app/pgsql/jdbc/postgresql-8.2-
504.jdbc3.jar:/u01/app/pgsql/pljava/deploy.jar
org.postgresql.pljava.deploy.Deployer -install -database ADempiere -user
ADempiere -password ADempiere

Stop and restart PostgreSQL server

Connect to Database as ADempiere user


$ psql -U ADempiere
Welcome to psql 8.2.1, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
www.goodwill.co.id

\? for help with psql commands


\g or terminate with semicolon to execute query
\q to quit

Create Shema
SQL command :
ADempiere=# CREATE SCHEMA ADempiere AUTHORIZATION ADempiere;

Run SQL command :


SQL command :
ADempiere=#SET search_path TO ADempiere,sqlj;
ADempiere=#SELECT sqlj.install_jar('file:///u01/app/ADempiere/lib/sqlj.jar',
'sqlj', true);
ADempiere=#SELECT sqlj.set_classpath('ADempiere', 'sqlj');

Disconnect Database
ADempiere=# \q

Import /u01/app/ADempiere/data/admpiere_pg.dmp to Database :


$ psql -U ADempiere -d ADempiere -f
/u01/app/ADempiere/data/ADempiere_pg.dmp 2> dump_errors.log

Part IV: Installing ADempiere

Now login as root. Assuming the previous installation steps were successfully
done by you (e.g. PostgreSQL is running), execute the ADempiere setup script.
$ cd /u01/app/ADempiere
$ ./RUN_setup.sh

If all is ok, we can test the Compiere server.


$ cd /u01/app/ADempiere/utils
$ ./RUN_Server2.sh

And now the client:


$ ./RUN_ADempiere.sh

If it runs ok as expected, congratulations! You have succeeded installing


ADempiere with PostgreSQL.

Goodwill Consulting is an active contributor in Open Source Enterprise Solution


area. Since the creation of ADempiere, Goodwill Consulting has been an early
advocate and supporter of ADempiere, providing many contributions for the
advancement of ADempiere project.

Potrebbero piacerti anche