Showing posts with label tomcat. Show all posts
Showing posts with label tomcat. Show all posts

Sunday, December 19, 2004

Running Tomcat as a Service on Linux

This is the script that im using to startup and shutdown tomcat automatically on Linux

1. Save tomcat start / stop script
Copy and paste the following script into your text editor:




#!/bin/bash
#
# Startup script for Tomcat
#
# chkconfig: 345 84 16
# description: Tomcat jakarta JSP server

TOMCAT_HOME=/usr/local/tomcat
startup=$TOMCAT_HOME/bin/startup.sh
shutdown=$TOMCAT_HOME/bin/shutdown.sh

#Necessary environment variables
export JAVA_HOME="/usr/local/java/java"
export CATALINA_HOME="/usr/local/tomcat"
#export LD_KERNEL_ASSUME="2.2.5"

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

#Check for tomcat script
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then
echo "Tomcat not available..."
exit
fi

start(){
echo -n $"Starting Tomcat service: "
#daemon -c
$startup
RETVAL=$?
echo
}

stop(){
action $"Stopping Tomcat service: "
$shutdown
RETVAL=$?
echo
}


status() {
ps ax --width=1000 grep "[o]rg.apache.catalina.startup.Bootstrap start" awk '{printf $1 " "}' wc awk '{print $2}' > /tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt if [ $line -gt 0 ]; then echo -n "tomcatd ( pid " ps ax --width=1000 grep "[o]rg.apache.catalina.startup.Bootstrap start" awk '{printf $1 " "}' echo -n ") is running..." echo else echo "Tomcat is stopped" fi } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 3 start ;; status) status ;; *) echo "Usage: tomcatd {start stop restart status}" exit 1 esac exit 0 Edit the lines that start with tomcat and export to match where you installed tomcat and your jdk. 2. Save to /etc/init.d and chmod
Save the edited file above to /etc/init.d directory as "tomcatd"

Then you have to allow execute access to the script, so run:
chmod a+x tomcat

3. Add to appropriate run level directories
The easy way to do this is to just simply run:
chkconfig --add tomcat

thats it.

this will also allow you to start and stop tomcat manually

service tomcatd start
service tomcatd stop

Sunday, December 12, 2004

installing tomcat on linux - restart

I wasnt happy with the way the install of apache/tomcat/database (postgresql) had gone so far so I decided to start again.

Basically im reinstalling Mandrake 10.0 on my p200 64mb PC.

The first problem that I had previously encountered is that a vncserver is not installed as default in Mandrake. The thing that makes this confusing is that the tightvnc client is!

By googling I discovered that

urpmi tightvnc-server

would perform an install of tightvnc server, and it did, excellent.

Typed vncserver and setup my passwords, and im in business connected to my linux box in the office from the the laptop

Saturday, December 11, 2004

Setting up java tomcat on linux X - Install Pgaccess

Install Pgaccess

cd /usr/local/src
gunzip pgaccess-0_99_0_20040219.tgz
tar -xf pgaccess-0_99_0_20040219.tar

cp -R pgaccess-0_99_0_20040219 /usr/local/pgaccess

cd pgaccess-0_99_0_20040219

make clean
make all
cat "/usr/local/pgaccess/lib" >> /etc/ld.so.conf
ldconfig

Setting up java tomcat on linux IX - Install Postgresql


Creating the “postgres” User
Create a UNIX user account to own and manage the PostgreSQL database files. Typically, this user is named postgres, but it can be named anything that you choose.

You will need to have root privileges to create the PostgreSQL superuser. You can use the command shown to add the postgres user.

su - -c "useradd postgres"

Install Postgresql

cd /usr/local/src
tar xvfz postgresql-7.3.4.tar.gz
cd postgresql-7.3.4

then logoff and login as the postgres user (this wont work if your java and ant environment variables and path additions are not setup properly)

./configure --with-tcl --with-java

gmake
su -c "gmake install"
su -c "chown -R postgres.postgres /usr/local/pgsql"

Setting Environment Variables
The use of the PostgreSQL environment variables is not required. However, they are helpful when performing tasks within PostgreSQL, including starting and shutting down the postmaster processes.
The environment variables that should be set are for the man pages and the bin directory. You can do so by adding the following statements into the /etc/profile file.

PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PATH MANPATH

Initializing and Starting PostgreSQL
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

Running postmaster in the background
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /tmp/pgsql.log start

Configuring the PostgreSQL SysV Script
The SysV script will allow the graceful control of the PostgreSQL database through the use of the SysV runlevel system. The SysV script can be used for starting, stopping, and status-checking of PostgreSQL. It is known to work with most Red Hat based versions of Linux, including Mandrake; however, it should work with other SysV systems (e.g., UnixWare, Solaris, etc.) with little modification. The script is named linux. To use it, you will first need to copy the linux script to your init.d directory. You may require root access to do this.
First, change to the directory where you unpacked the PostgreSQL source. eg /usr/local/src/postgresql-7.1.3/. Then, issue a cp command to copy the script from contrib/start-scripts into the init.d

Copying the linux script
cd /usr/local/src/postgresql-7.4.6
su -c "cp contrib/start-scripts/linux /etc/rc.d/init.d/postgresql"

Making the linux script executable
su -c "chmod a+x /etc/rc.d/init.d/postgresql"

There are no additional requirements to use the SysV script with Red Hat, if you do not intend on using it to start PostgreSQL automatically (i.e., if you wish to use the script manually). However, if you do wish for the script to startup PostgreSQL automatically when the machine boots up (or changes runlevels), you will need to have the chkconfig program installed. If chkconfig is installed, you will also need to add the following two lines, including the hash (#) symbol, at the beginning of the /etc/rc.d/init.d/postgresql file:

# chkconfig: 345 85 15
# description: PostgreSQL RDBMS

Starting PostgreSQL with the SysV script:

service postgresql start
Starting PostgreSQL: ok

service postgresql stop
Stopping PostgreSQL: ok

The next step will be to create a new database. This will be a simple test database. We do not recommend using the default template1 database for testing purposes. As you have not created any users with database-creation rights, you will want to make sure that you are logged in as the postgres user when adding a new database.

To create a new database named testdb, enter the command shown:
createdb testdb

psql testdb

You can now start entering SQL commands (e.g., such as SELECT) at the psql prompt
To verify that the database is working correctly, you can issue the command shown in which should give you a listing of the languages installed in the database

SELECT * FROM pg_language;

lanname lanispl lanpltrusted lanplcallfoid lancompiler
----------+---------+--------------+---------------+-------------
internal f f 0 n/a
C f f 0 /bin/cc
sql f f 0 postgres

Wednesday, December 08, 2004

Setting up java tomcat on linux VIII - Configure Tomcat for mod_jk Connector

Configure Tomcat for mod_jk Connector

Directly below this line in '/usr/local/tomcat/conf/server.xml'

<Server port='8005' shutdown='SHUTDOWN' debug='1'\>

Add these lines:
<Listener className='org.apache.ajp.tomcat4.config.ApacheConfig'
modJk='/usr/local/apache2/modules/mod_jk.so'
workersConfig='/usr/local/tomcat/conf/jk/workers.properties'/>

Directly below this line in '/usr/local/tomcat/conf/server.xml'

<Host name='localhost' debug='0' appBase='webapps'>

Add this line

<Listener className='org.apache.ajp.tomcat4.config.ApacheConfig'
append='true' forwardAll='false'
modJk='/usr/local/apache2/modules/mod_jk.so' />

Comment out JK2 connector, and uncomment AJP1.3 connector (jk).(Does not appear to be required for tomcat5)
Change instances of localhost to whatever your domain name is

Create file '/usr/local/tomcat/conf/jk/workers.properties' with these contents:

# Setting Tomcat & Java Home
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/java/java
ps=/
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

Setting up java tomcat on linux VII - HowTo make your own Self-Signed SSL Certificate

cd /usr/local/ssl/bin

### Create server key

openssl genrsa -out mysite.key 1024

Generating RSA private key, 1024 bit long modulus
........................................++++++
....++++++
e is 65537 (0x10001)

### Create certificate request

openssl req -new -key mysite.key -out mysite.csr

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:GB
State or Province Name (full name) [Some-State]:Norfolk
Locality Name (eg, city) []:Norwich
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Manic Miner Ltd
Organizational Unit Name (eg, section) []:Web Development
Common Name (eg, YOUR name) []:dooley.com
Email Address []:webmaster@dooley.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:freedom1
An optional company name []:Manic Miner Ltd

### self sign key (increment the serial number "N" for each new cert)

openssl x509 -req -days 365 -set_serial 001 -in mysite.csr -signkey mysite.key -out mysite.crt

Signature ok
subject=/C=GB/ST=Norfolk/L=Norwich/O=Manic Miner Ltd/OU=Web Development/CN=mysite/emailAddress=webmaster@mysite
Getting Private key

cp myhost.mydomain.* /usr/local/apache2/conf

#edit http.conf (or ssl.conf) file

SSLCeritifcateFile /usr/local/apache2/conf/myhost.mydomain.cert
SSLCertificateKeyFile /usr/local/apache2/conf/myhost.mydomain.key

Tuesday, December 07, 2004

Basic Vim

Vim (Vi improved) is a very popular, full featured text editor for Linux/Unix systems. It is practically guaranteed to be installed on most systems. If you are using a Linux/Unix shell account, you will appreciate Vim's ability to open, edit, create, and save files. Unfortunately, Vim is not very intuitive. Most will remember the helpless feeling they had on their first encounter.

There are an astounding number of commands for Vim. Even advanced users only use a subset of the available commands. This tutorial will endeavor to teach you enough to be productive and point you in the right direction should you desire to learn more.

Vim operates from within a shell. All commands are made from the keyboard. There is no mouse support, no fancy GUI, and no hints appear on the screen.

To start Vim, simply type vi at the command line.
This will open Vim with a new document and give you some basic version information and a hint or two. As soon as you begin inserting text, the information will disappear.
A variation on this is to type vi filename which will open Vim with that file loaded.
This is where most people will get stuck. Right at the beginning with no idea of how to insert text, save a file, or even exit the program! It seems to be some sort of a cruel joke. Windows users may even resort to rebooting the system or crashing the shell. (Linux systems can run for years without rebooting, this is never a good option.)

Here are the most important commands that you need to know. Commands for saving, writing and exiting are available when you are not in insert mode and are in the form ":command". That is a colon followed by the command. To toggle from command mode to insert mode, press i to enter insert mode. Press the "Esc key" to get back to command mode..

To change to INSERT mode press i or "insert".
To change out of INSERT mode press "Esc".
To exit the program type: :q.
To exit without saving type: :q!.
To write your file type: :w.
To write a new file and name it, type: :w filename.
OK, that will get you started. You can now do the most important things that you would want to do with a text editor. You can now open, create, edit, and save files as well as start and exit the program. Whew...

Moving around within a document:

You will quickly notice that the arrow keys, and the "home" and "end" keys do just about what you would expect them to do. Some of the behavior, however, is not really what you are looking for. Notice that when you arrow up or down the cursor jumps to the carriage returns rather than the screen lines.

There are an over abundance of ways to move around a document. Most will require that you are not in insert mode. Get use to moving in and out of insert mode! Note that you can add a number before most commands to modify the command.

*Screen lines are different than lines terminated by a carriage return!
To move to the left type: h, Ctrl-H, "back space", or the left arrow key.
To move to the right type: l, "space key", or the right arrow key.
To move to the end of a line type: $ or "End".
To move to the beginning of a line type: 0 or ^.
To move to the first character in a screen line type: g0, or 0.
To move to the last character in a screen line type: g$, or $.
To move to the middle of a screen line type: gm.
To move to a character number (position) in a line type: num |. (pipe symbol)
To move to the n-th occurrence of a character from the right type: num t char.
To move to the n-th occurrence of a character from the left type: num T char.
To move to the right a number of words type: num W.
To move to the left a number of words type: num B.
To move forward a number of sentences type: num ).
To move backward a number of sentences type: num (.
To move forward a number of paragraphs type: num }.
To move backward a number of paragraphs type: num {.
There are many more... This is a good start though.


To move down a line type: j.
To move up a line type: k.
To move down a screen line type: gj, or g[down_arrow].
To move up a screen line type: gk, or g[up_arrow].
To goto a specified line type: num G.
To goto a percentage of the document type: num %.
There are many more...


To scroll the screen down type: Ctrl-E.
To scroll the screen up type: Ctrl-Y.

This is enough to get you started with Vim. This is, however, not even the tip of the iceberg. Vim includes a complete scripting language and is highly configurable. You can work with multiple files, make command line commands, incorporate other programs, and much more.

Search for text in vi or vim

Very useful for a guy with little vim knowledge

Description
vi and vim have powerful searching capabilities because they bring to bear the richness of regular expressions.


Directions
To search for the next occurence of the text 'maybe' from the current cursor position, type:


/maybe<ENTER>


Search backward from the current position by using ? instead of / in the command.

Once you have searched for something, you can find the next occurrence by pressing n or the previous occurrence with N.

Searching in vi/vim is enhanced with regular expressions. For example, to find the next occurence of the text 'Total' that occurs at the beginning of a line, use:


/^Total

Saturday, December 04, 2004

Setting up java tomcat on linux VI - Configure APACHE SSL

Configure Apache/SSL

mkdir /usr/local/htdocs/secure
mkdir /usr/local/htdocs/secure/myhost.mydomain
#Now make changes in ssl.conf
#Look for similar lines and make sure it looks like this:

# General setup for the virtual host
DocumentRoot '/usr/local/htdocs/secure/myhost'
ServerName myhost.mydomain:443
ServerAdmin me@myhost.mydomain
ErrorLog logs/error_log
TransferLog logs/access_log

#Redirect / https://myhost.mydomain/mywebapp

# Static files
Alias /mywebapp "/usr/local/tomcat/webapps/mywebapp"



Options Indexes FollowSymLinks
DirectoryIndex index.jsp


# Deny direct access to WEB-INF and META-INF

AllowOverride None
deny from all



AllowOverride None
deny from all


JkMount /mywebapp/*.do ajp13
JkMount /mywebapp/*.jsp ajp13

JkMount /mywebapp ajp13
JkMount /mywebapp/* ajp13

Thursday, December 02, 2004

Setting up java tomcat on linux V - Configure APACHE non-ssl

Configure APACHE/NON-SSL

  • md /www
  • md /www/hosts
  • md /www/hosts/nonsecure
  • md /www/hosts/nonsecure/www.mydomain.com
  • md /www/hosts/nonsecure/www.mydomain.com/docs
  • md /www/hosts/cgi-bin
  • md /www/hosts/cgi-bin/www.mydomain.com
  • md /www/hosts/cgi-bin/www.mydomain.com/cgi-bin

#Make sure you have VirtualHost like this

NameVirtualHost 192.168.2.101


<VirtualHost *:80>
ServerName www.mydomain.com
ServerAdmin webmaster@www.mydomain.com
DocumentRoot /www/hosts/nonsecure/www.mydomain.com/docs
ErrorLog logs/www.mydomain.com_public-err_log
CustomLog logs/www.mydomain.com_public-access_log common
ScriptAlias /cgi-bin/ /www/hosts/cgi-bin/www.mydomain.com/cgi-bin


# Static files
Alias /mywebapp "/usr/local/tomcat/webapps/mywebapp" <


Directory "/usr/local/tomcat/webapps/mywebapp">
Options Indexes FollowSymLinks
DirectoryIndex index.jsp
</Directory>


#Deny direct access to WEB-INF and META-INF
<Location "/mywebapp/WEB-INF/*">
Allowoverride None
deny from all
</Location>


<Location "/mywebpp/META-iNF/*">
AllowOverride None
deny from all
</Location>

JkMount /mywebapp_nonsecure/*.do ajp13
JkMount /mywebapp_nonsecure/*.jsp ajp13
JkMount /mywebapp_nonsecure ajp13
JkMount /mywebapp_nonsecure/* ajp13
</VirtualHost>

JkWorkersFile "/usr/local/tomcat/conf/jk/workers.properties"
JkLogFile "/usr/local/tomcat/logs/mod_jk.log"

Wednesday, December 01, 2004

Setting up java tomcat on linux IV - Install APACHE

Install APACHE

  • cd /usr/local/src
  • tar xfz httpd-2.0.52.tar.gz
  • cd httpd-2.0.52
  • ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/local/ssl --enable-proxy
  • make
  • make install (supposed to places in /usr/local/apache2, but make install placed it into /usr/locacl/apache2, see if this causes any problems later)


Build/Install MOD_JK Connector

  • cd /usr/local/src
  • unzip jakarta-tomcat-connectors-jk-1.2-src-current.zip
  • cd jakarta-tomcat-connectors-jk-1.2.6-src/jk/native
  • ./buildconf.sh
  • ./configure --with-apxs=/usr/locacl/apache2/bin/apxs
  • make
  • cp apache-2.0/mod_jk.so /usr/local/apache2/modules


Configure Apache for mod_jk

Put these lines in /usr/locacl/apache2/conf/http.conf just before NameVirtualHost

<IfModule !mod_jk.c>

LoadModule jk_module modules/mod_jk.so

</IfModule>

Tuesday, November 30, 2004

Setting up java tomcat on linux III - Install JAVA

Install JAVA


  • mkdir /usr/local/java
  • cd /usr/local/src
  • sh j2sdk-1_4_2-linux-i586.bin
  • mv j2sdk1.4.2_06 /usr/local/java
  • cd /usr/local/java
  • ln -s j2sdk1.4.02-06 java

Now the java directory will be in /usr/local/java/java. I do it like this so I can keep all my different JDKs/JREs in one directory and then just change the symbolic link to point to the current one.

Install Tomcat

  • cd /usr/local/src
  • tar xfz jakarta-tomcat-5.5.4.tar.gz
  • mv jakarta-tomcat-5.5.4 /usr/local/
  • ln -s jakarta-tomcat-4.1.29 tomcat

Install ANT

  • cd /usr/local/src
  • unzip apache-ant-1.6.2-bin.zip
  • mv apache-ant-1.6.2 /usr/local
  • cd /usr/local
  • ln -s jakarta-ant-1.6.0 ant
  • ln -s /usr/local/ant/bin/ant /usr/local/bin/ant

Install OPENSSL

  • cd /usr/local/src
  • tar xfz openssl-0.9.7e.tar.gz
  • cd openssl-0.9.7e
  • ./config
  • make
  • make test
  • make install

Setting up java tomcat on linux II

Configure Environment Variables

Edited and add the lines below to '/etc/profile'
Make sure you logout and login for this to take effect.
JAVA_HOME=/usr/local/java/java
CATALINA_HOME=/usr/local/tomcat
PATH=$JAVA_HOME/bin:$PATH:$HOME/bin:/sbin:/usr/sbin
CLASSPATH=$CATALINA_HOME/bin/bootstrap.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/common/lib/servlet.jar:/usr/local/pgsql/share/java/postgresql.jar:../lib/struts.jar:.
Now add the PATH JAVA_HOME CATALINA_HOME & CLASSPATH if any aren't in the export line
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME CATALINA_HOME CLASSPATH

Type env to check your environment variables

Setting up java tomcat on linux I

Downloaded the files
Got all appropriate files from web and place them in /usr/local/src/.
httpd-2.0.48.tar.Z (source) Download Apache Httpd
openssl-0.9.7d.tar.gz (source) Download Openssl
j2sdk-1_4_2_03-linux-i586.bin (binary) Download Java
jakarta-tomcat-4.1.29.tar.gz (binary) Download Tomcat
jakarta-ant-1.6.0-bin.zip (binary) Download Ant
jakarta-tomcat-connectors-1.2.5 (source) Download mod_jk
struts 1.1 (binary) Download Struts
postgresql-7.4.1.tar.gz (source) Download postrgresql
pgaccess-0.98.8.20030520.tar.gz (source) Download pgaccess This is a gui client to access db.