INSTALLING & CONFIGURING TOMCAT IN CENTOS 5.4
Download And Install JDK or J2SDK on the server
You can download JDK or j2sdk fromhttp://java.sun.com/
I have downloaded jdk-6u18-linux-i586.bin .
Create a directory ‘java’ directory in /usr
Mkdir /usr/java
Mv jdk-6u18-linux-i586.bin /usr/java
Chmod a+x jdk-6u18-linux-i586.bin
./ jdk-6u18-linux-i586.bin
Press enter for confirmation
It should end with “Done”
export JAVA_HOME=/usr/java/jdk1.6.0_22
export PATH=$JAVA_HOME/bin:$PATH
which java
]#/usr/java/jdk1.6.0_18/bin/java –version ‘or’ java –version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)
Create a file java.sh in /etc/profile.d directory and add the following
[#Java Environment script
export JAVA_HOME="/usr/java/jdk1.6.0_22"
export JAVA_PATH="$JAVA_HOME"
export PATH="$JAVA_HOME/bin:$PATH"
chmod a+x java.sh
When done, hit
source /etc/profile.d/java.sh
Now any user root or other wise should be able to use the command;
which java
which java
java -version
[root@localhost ~]#env
Install tomcat on the server:-
Create a group and user account for Tomcat to run
[root@server1 /]#groupadd tomcat
[root@server1 /]#useradd -g tomcat -s /usr/sbin/nologin -m -d /home/tomcat tomcat
Download apache tomcat
[root@server1 /]#tar -zxvf apache-tomcat-6.0.29.tar.gz
[root@server1 /]#mv apache-tomcat-6.0.29 /usr/local/
Here in this case CATALINA_HOME=/usr/local/apache-tomcat-6.0.24
Create symlink for the tomcat directory:-
[root@server1 /]#cd /usr/local
[root@server1 /]#ln -s apache-tomcat-6.0.29 apache-tomcat
[root@server1 /]#chown -h tomcat.tomcat /usr/local/apache-tomcat
[root@server1 /]#chown -R tomcat.tomcat apache-tomcat-6.0.29
Check the tomcat version installed.
Execute the following command:-[root@server1 local]# /usr/local/apache-tomcat-6.0.29/bin/version.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-6.0.29
Using CATALINA_HOME: /usr/local/apache-tomcat-6.0.29
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.29/temp
Using JRE_HOME: /usr/java/jdk1.6.0_22
Using CLASSPATH: /usr/local/apache-tomcat-6.0.29/bin/bootstrap.jar
Server version: Apache Tomcat/6.0.29
Server built: July 19 2010 1458
Server number: 6.0.0.29
OS Name: Linux
OS Version: 2.6.18-164.el5
Architecture: i386
JVM Version: 1.6.0_22-b04
JVM Vendor: Sun Microsystems Inc.
Start the tomcat
[root@server1 local]# /usr/local/apache-tomcat/bin/startup.sh
Stop the tomcat
[root@server1 local]# /usr/local/apache-tomcat/bin/shutdown.sh
Setting Tomcat up as a Service (Optional):
If you want Tomcat to start automatically on boot then you need to set it up as a service. To do this you need to copy the code below and save it as a file called
tomcat
in the folder /etc/init.d
:CODE:
1. # This is the init script for starting up the
2. # Jakarta Tomcat server
3. #
4. # chkconfig: 345 91 10
5. # description: Starts and stops the Tomcat daemon.
6. #
7.
8. # Source function library.
9. . /etc/rc.d/init.d/functions
10.
11. # Get config.
12. . /etc/sysconfig/network
13.
14. # Check that networking is up.
15. [ "${NETWORKING}" = "no" ] && exit 0
16.
17. tomcat=/usr/local/tomcat
18. startup=$tomcat/bin/startup.sh
19. shutdown=$tomcat/bin/shutdown.sh
20. export JAVA_HOME=/usr/java/jdk1.5.0_6
21.
22. start(){
23. echo -n $"Starting Tomcat service: "
24. #daemon -c
25. $startup
26. RETVAL=$?
27. echo
28. }
29.
30. stop(){
31. action $"Stopping Tomcat service: " $shutdown
32. RETVAL=$?
33. echo
34. }
35.
36. restart(){
37. stop
38. start
39. }
40.
41.
42. # See how we were called.
43. case "$1" in
44. start)
45. start
46. ;;
47. stop)
48. stop
49. ;;
50. status)
51. # This doesn't work
52. status tomcat
53. ;;
54. restart)
55. restart
56. ;;
57. *)
58. echo $"Usage: $0 {start|stop|status|restart}"
59. exit 1
60. esac
61.
62. exit 0
JAVA_HOME
if your JDK is in a different location to mine. You then need to make the file executable with the command:sudo chmod +x /etc/init.d/tomcat
And finally you need to set it to start at boot with the command:sudo chkconfig --add tomcat
You now have a working Tomcat install that will start itself at boot time. You can also interact with it using the service
command to start, stop, restart and see the status of the service at any time. E.g.sudo service tomcat start
sudo service tomcat satus
sudo service tomcat stop
No comments:
Post a Comment