RSS

Tag Archives: tomcat

How to install Tomcat 6 on Ubuntu 10.04/Debian


Apache Tomcat is a free and open source software implementation for JavaServlets, providing support for Java Server Pages (JSP). Many popular web-based applications use servlets. You may choose to run Tomcat with either Sun’s Java implementation or the OpenJDK implementation of Java.

Because Tomcat version 6 was included in Ubuntu 10.04, installing a working Tomcat server is reasonably straightforward. However, before we can start installing Tomcat itself, we must first install Java.

 

Install tomcat 6 in ubuntu 9.04

sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples

Start tomcat server

sudo /etc/init.d/tomcat6 start

Stop tomcat server

sudo /etc/init.d/tomcat6 stop

Restart tomcat server

sudo /etc/init.d/tomcat6 restart

Get tomcat server status

sudo /etc/init.d/tomcat6 status

After installation type http://localhost:8080 or http://serverip:8080/examples/servlets/ in your browser.Now you should see tomcat welcome page

* To enable admin web based features add the following lines to your /etc/tomcat6/tomcat-user.xml

<role rolename="manager"/>
<role rolename="admin"/>
<user name="admin" password="secret_password" roles="manager,admin"/>

* you should be able to see your manage page here http://your_ip_goes_here:8080/manager/html

* log in with the name and password you just set in /etc/tomcat6/tomcat-users.xml

* ls /var/lib/tomcat6 directory.

* you should see these directories conf, logs, webapps, work

* webapps is where your servlets will go ( or at least a xml file that points to them )

* as a test download this war file http://simple.souther.us/SimpleServlet.war

* then use the tomcat management page and select war file to deploy ( in the deploy section) to upload this file to your server

* optionally just wget http://simple.souther.us/SimpleServlet.war directly to the webapps folder

* tomcat should recognize the war file and expand it with everything you need

* browse to http://serverip:8080/SimpleServlet/

Change tomcat server to run on port 80

If you want to Change tomcat server to run on port 80 follow this procedure

You need to edit the /etc/tomcat6/server.xml file

nano /etc/tomcat6/server.xml

Now replace the part that says Connector port=”8080? with Connector port=”80?

Save and exit the file

Restart tomcat server with the following command

sudo /etc/init.d/tomcat6 restart
 
 

Nhãn: ,

Install Tomcat 6 on fedora or CentOS


Download and Install JAVA
Download j2sdk-1.4.2 from Sun Download center Sun Developer Network (SDN) Downloads Here I have used j2sdk-1_4_2_18-linux-i586-rpm.bin which will install j2sdk using RPMS and set the Path of JAVA_HOME automatically

#chmod +x j2sdk-1_4_2_09-linux-i586.bin
#./j2sdk-1_4_2_09-linux-i586.bin

Now Check if Java is installed on the server using command java -version

[root@vps907 ~]# java -version
java version “1.6.0_07”
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

Download Tomcat

#cd /usr/local/
#wget Blue Dog Fan Blogs
#tar -zxvf apache-tomcat-6.0.18.tar.gz

Create Symlink for the Tomcat Folder

#ln -s /usr/local/apache-tomcat-6.0.18 /usr/local/apache/tomcat

Install Tomcat

#cd apache-tomcat-6.0.18
#cd bin
#tar xvfz jsvc.tar.gz
#cd jsvc-src
#chmod +x configure
#./configure
#make
#cp jsvc ..
#cd ..

Start Tomcat

Use Following script to start Tomcat Service on the Server

#/usr/local/apache/tomcat/bin/startup.sh

Running Tomcat as non root user

Due to security reasons always run tomcat as non-root user i.e. tomcat. Following are the steps to run tomcat as non-root user

#chown tomcat.tomcat /usr/local/apache-tomcat-6.0.18 -R

Now Tomcat can be stopped and started under user tomcat using following commands:

#su -l tomcat -c /usr/local/apache/tomcat/bin/startup.sh
#su -l tomcat -c /usr/local/apache/tomcat/bin/shutdown.sh

Test Tomcat installation
open a browser and browse website http://xx.xx.xx.xx:8080 where xx.xx.xx.xx will be your Server IP and If you get following output than Tomcat has been installed properly on the Server.

Script to start, stop and restart Tomcat

The above installation step will not create tomcat service so that user can restart tomcat using command service tomcat restart. Create a new file in /etc/init.d as tomcat and copy following contenents into it.

#vi /etc/init.d/tomcat
#!/bin/bash
#
# Startup script for Tomcat
#
# chkconfig: 345 84 16
# description: Tomcat jakarta JSP server
#Necessary environment variables
export CATALINA_HOME=”/usr/local/tomcat”
if [ ! -f $CATALINA_HOME/bin/catalina.sh ]
then
echo “Tomcat not available…”
exit
fi

start() {
echo -n -e ‘\E[0;0m'”33[1;32mStarting Tomcat: 33[0m \n”
su -l tomcat -c $CATALINA_HOME/bin/startup.sh
echo
touch /var/lock/subsys/tomcatd
sleep 3
}

stop() {
echo -n -e ‘\E[0;0m'”33[1;31mShutting down Tomcat: 33[m \n”
su -l tomcat -c $CATALINA_HOME/bin/shutdown.sh
rm -f /var/lock/subsys/tomcatd
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

Save and exit from the file. Now assign executable permission to this file

#chown 755 /etc/init.d/tomcat

Add and Enable tomcat for all the Run-levels

#chkconfig –add tomcat
#chkconfig tomcat on

Now you can restart tomcat service using following commands (you can check the screenshot too)

#service tomcat restart <<< To restart tomcat
#service tomcat stop <<< To stop Tomcat
#service tomcat start <<< To start Tomcat
#service tomcat Status <<< to check the status of Tomcat

 
 

Nhãn:

Install JDK + Tomcat on Linux (CentOs 5) –so hot


Bài viết dưới đây hướng dẫn các bạn cài JDK + Tomcat trên Cent Os 5.7

 

I.Cài đặt jdk + Tomcat
· Tạo thư mục và cài đặt jdk 

# mkdir /usr/java

# cd /usr/java

#wget http://rahulsoni.in/jdk-6u7-linux-i586-rpm.bin

# sh /root/jdk-6u7-linux-i586-rpm.bin

· Giải nén Tomcat /usr/share 
vào trang này
http://archive.apache.org/dist/tomca…6/v6.0.13/bin/
và dow file apache-tomcat-6.0.13.tar.gz  về,đặt trong thư mục /usr/share 
# cd /usr/share

# tar -xzf apache-tomcat-6.0.13.tar.gz

· Tạo môi trường cho JAVA_HOME , thông qua chỉnh sửa file catalina.sh

# cd /usr/share/apache-tomcat-6.0.13/bin

# vi catalina.sh

>>Thêm dòng dưới vào dòng đầu trên cùng của file  catalina.sh <<
JAVA_HOME=/usr/java/jdk1.6.0_07

· Chạy thử tomcat và kiểm tra xem thử có lỗi không 

# cd /usr/share/apache-tomcat-6.0.13/bin

# ./startup.sh

· >>Xem lại log quá trình cài đặt<< 

# less /usr/share/apache-tomcat-6.0.13/logs/catalina.out

· Tạo đoạn script để khởi động Tomcat 

# cd /usr/share/apache-tomcat-6.0.13/bin

# tar -xzf jsvc.tar.gz

· >> Chúng ta sẽ biên dịch , và sử dụng gcc, install the gcc compiler << 

# yum install gcc -y

# cd /usr/share/apache-tomcat-6.0.13/bin/jsvc-src

· !!! Xem file INSTALL.txt !!! – file đính kèm trong thư mục jsvc-src 

# chmod +x configure

# ./configure –with-java=/usr/java/jdk1.6.0_07

# make

# alternatives –install /etc/alternatives/java java /usr/java/jdk1.6.0_07/bin/java 90

# useradd -d /usr/share/apache-tomcat-6.0.13/ tomcat

· >> Chỉnh sửa file khởi động tomcat và copy đến /etc/init.d << 

# cd /usr/share/apache-tomcat-6.0.13/bin/jsvc-src/native/

# vi Tomcat5.sh

!!! Tìm kiếm và thay đổi !!! mấy dòng này cho giống đoạn dưới đây
JAVA_HOME=/usr/java/jdk1.6.0_07
CATALINA_HOME=/usr/share/apache-tomcat-6.0.13
DAEMON_HOME=/usr/share/apache-tomcat-6.0.13/bin
TOMCAT_USER=tomcat

Và sửa path: chỗ Start và Stop (jsvc-src/jsvc)

# chmod +x Tomcat5.sh

· >> Kiểm tra xem có chạy được không sau khi thay đổi << 

# ./Tomcat5.sh start

# pgrep -u tomcat -l

 

II.Automate start up

1. Tạo 1 đoạn scrip trong  /etc/init.d để nó tự động chạy khi mở máy tính

# cd /etc/init.d
# vi tomcat

2. Place following in the file

#!/bin/bash
# chkconfig: 234 20 80
# description: Tomcat Server basic start/shutdown script
# processname: tomcat
JAVA_HOME=/usr/java/jdk1.6.0_07
export JAVA_HOME
TOMCAT_HOME=/usr/local/apache-tomcat-6.0.13/bin
START_TOMCAT=/usr/local/apache-tomcat-6.0.13/bin/startup.sh
STOP_TOMCAT=/usr/local/apache-tomcat-6.0.13/bin/shutdown.sh
start() {
echo -n “Starting tomcat: ”
cd $TOMCAT_HOME
${START_TOMCAT}
echo “done.”
}
stop() {
echo -n “Shutting down tomcat: ”
cd $TOMCAT_HOME
${STOP_TOMCAT}
echo “done.”
}
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo “Usage: $0 {start|stop|restart}”
esac
exit 0

2. Change permissions

# chmod 755 tomcat

3. Add script to system services

# chkconfig –add tomcat

4. Verify modifications (this script uses levels 2-4)

# chkconfig –level 234 tomcat on
# chkconfig –list tomcat

you should see that service using levels 2, 3 and 4:
tomcat 0:off 1:off 2:on 3:on 4:on 5:off 6:off
5. Test script start up/shutdown 

# service tomcat start
# service tomcat stop

So, at this point, tomcat service will start automatically upon reboot. G’luck (:

và nếu thành công,khi gõ ip:8080 thì nó sẽ chạy tomcat (Tomcat chạy trên cổng 8080)

như hình sau:

 
 

Nhãn: ,