Tuesday, October 19, 2010

mod_jk instalation on ubuntu 9.4

Assuming Tomcat and Apache are installed and running

1. Install the mod_jk
sudo su -
apt-get install libapache2-mod-jk

2. Enable md_jk loading
cd /etc/apache2/mods-enabled
ln -s jk.load ../mods-available/jk.load

3. Create the mod_jk conf file
cd /etc/apache2/mods-available
vi jk.conf
# Where to find workers.properties
# Update this path to match your conf directory location
JkWorkersFile /etc/libapache2-mod-jk/workers.properties

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile /var/log/apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# Shm log file
JkShmFile /var/log/apache2/jk-runtime-status

4.Enable mod_jk configurations
cd ../mods-enabled
ln -s jk.conf ../mods-available/jk.conf

5. Create a worker properties file
vi /etc/libapache2-mod-jk/workers.properties
workers.tomcat_home=/var/lib/tomcat6
workers.java_home=/usr/lib/jvm/java-6-sun
ps=/
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
worker.ajp13_worker.lbfactor=1

6.Configure url forwarding from Apache to Tomcat
cd /etc/apache2/sites-enabled
vi 000-default ##Which is a symbolic link to ../sites-available/default

...
JkMount /examples/ ajp13_worker
JkMount /examples/* ajp13_worker
JkMount /docs/ ajp13_worker
JkMount /docs/* ajp13_worker
...

##This will forward any request to /examples/ and /docs/ to Tomcat

7. Configure AJP in Tomcat Server.
vi /etc/tomcat6/server.xml
##Uncomment the following line


8. Restart Apache and Tomcat
/etc/init.d/tomcat6 restart
/etc/init.d/apache2 restart

9. Test it
Open a browser
http://localhost:8080/examples
Then remove the port
http://localhost:/examples

You must see the same content, so Apache is forwawrding the request to Tomcat to show /examples content

Friday, October 8, 2010

Postgres Stream replication set up

Master
-IP: 192.168.1.1
-TCP Port: 5432
-Data directory: /var/lib/pgsql/9.0/data
-WAL directory: /var/lib/pgsql/9.0/data/wals

Slave
-IP: 192.168.1.2
-TCP Port: 5432
-Data directory: /var/lib/pgsql/9.0/data
-WAL directory: /var/lib/pgsql/9.0/data/wals

Master configuration: ($ /var/lib/pgsql/9.0/data/postgresql.conf)
-listen_addresses = '*'
-port = 5432
-archive_mode = on
-archive_command = 'cp "%p" /var/lib/pgsql/9.0/data/wals/"%f" < /dev/null'
-max_wal_senders = 1
-wal_level = hot_standby
-hot_standby = on

Authentication Configuration: ($ /var/lib/pgsql/9.0/data/pg_hba.conf)
-host replication all 10.16.35.213/23 trust

Start Up the Master
/usr/pgsql-9.0/bin/postgres -D /var/lib/pgsql/9.0/data &

Make a Base Backup for stand by from the master (Snapshot)
$ psql -c "SELECT pg_start_backup('base_backup')"
$ cd 9.0/data
$ scp -rp x postgres@10.16.35.213:/var/lib/pgsql/9.0/data
$ psql -c "SELECT pg_stop_backup()"

Slave Configuration ($ /var/lib/pgsql/9.0/data/postgresql.conf)

-listen_addresses = '*'
-port = 5432
-archive_mode = on
-archive_command = 'cp "%p" /var/lib/pgsql/9.0/data/wals/"%f" < /dev/null'
-max_wal_senders = 1
-wal_level = hot_standby
-hot_standby = on

$ rm -fr /var/lib/pgsql/9.0/data/postmaster.pid
$ rm -fr /var/lib/pgsql/9.0/data/pg_xlog/000*
$ rm -fr /var/lib/pgsql/9.0/data/pg_xlog/archive_status/*
$ rm -fr /var/lib/pgsql/9.0/data/wals/*

Recovery configuration on the slave: (/var/lib/pgsql/9.0/data/recovery.conf)
standby_mode = 'on'
primary_conninfo = 'host=192.168.1.1 port=5432 user=postgres password=postgres'
restore_command = 'cp -i /var/lib/pgsql/9.0/data/wals/%f %p < /dev/null'

Start up the slave
/usr/pgsql-9.0/bin/postgres -D /var/lib/pgsql/9.0/data &

Check the process
$ ps -fea | grep postgres
root 12121 11960 0 19:43 pts/1 00:00:00 su - postgres
postgres 12122 12121 0 19:43 pts/1 00:00:00 -bash
postgres 12823 12122 0 20:23 pts/1 00:00:00 /usr/pgsql-9.0/bin/postgres -D /var/lib/pgsql/9.0/data
postgres 12824 12823 0 20:23 ? 00:00:00 postgres: logger process
postgres 12825 12823 0 20:23 ? 00:00:00 postgres: startup process recovering 00000001000000000000000C
postgres 12828 12823 0 20:23 ? 00:00:00 postgres: wal receiver process streaming 0/C024038
postgres 12829 12823 0 20:23 ? 00:00:00 postgres: writer process
postgres 12830 12823 0 20:23 ? 00:00:00 postgres: stats collector process
postgres 12901 12122 0 20:59 pts/1 00:00:00 ps -fea
postgres 12902 12122 0 20:59 pts/1 00:00:00 grep postgres

Test it

Insert some data in the master:

$ psql
postgres=# create table t (i int);
postgres=# insert into t values(1);
postgres=# insert into t values(2);
postgres=# select * from t;
i
---
1
2
(2 rows)

Check in the Slave
$ psql
postgres=# select * from t;
i
---
1
2
(2 rows)