Tomcat学习之一Tomcat的安装

     Tomcat 是由java实现的java的web应用服务器,属于轻量级的,主要应用在中小型系统和并发访问不是很大的场合下(在高并发时,访问量比较大时做集群)。tomcat是开发调试程序的首选。

     ubuntu和centos系统 

    一,安装j配置Java环境.

         1. Linux下的安装Java环境,下载JDK。(现在的Java的版本有很多,具体哪一个版本,根据程序员的需求安装。)

         jdk1.7下载的地址(http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html)。   


zhaifengguo@zhaifg:~$ sudo cp 下载/jdk-7u45-linux-i586.tar.gz /usr/local/
[sudo] password for zhaifengguo: 
zhaifengguo@zhaifg:~$ 
zhaifengguo@zhaifg:/usr/local$ ls
bin  etc  games  include  jdk-7u45-linux-i586.tar.gz  lib  man  sbin  share  src
zhaifengguo@zhaifg:/usr/local$ sudo tar -zxf jdk-7u45-linux-i586.tar.gz 
zhaifengguo@zhaifg:/usr/local$ ls
bin  etc  games  include  jdk1.7.0_45  jdk-7u45-linux-i586.tar.gz  lib  man  sbin  share  src
zhaifengguo@zhaifg:/usr/local$ cd jdk1.7.0_45/

zhaifengguo@zhaifg:/usr/local/jdk1.7.0_45$ ls
bin  COPYRIGHT  db  include  jre  lib  LICENSE  man  README.html  release  src.zip  THIRDPARTYLICENSEREADME-JAVAFX.txt  THIRDPARTYLICENSEREADME.txt
zhaifengguo@zhaifg:/usr/local/jdk1.7.0_45$ pwd
/usr/local/jdk1.7.0_45

zhaifengguo@zhaifg:/usr/local/jdk1.7.0_45$ sudo vim /etc/profile

添加: 
  export JAVA_HOME=/usr/local/jdk1.7.0_45
  export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  export PATH=$JAVA_HOME/bin:$PATH
 zhaifengguo@zhaifg:/usr/local/jdk1.7.0_45$ source /etc/profile
zhaifengguo@zhaifg:/usr/local/jdk1.7.0_45$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)
zhaifengguo@zhaifg:/usr/local/jdk1.7.0_45$

   2,下载并安装Tomcat(http://tomcat.apache.org)

zhaifengguo@zhaifg:~$ sudo cp 下载/apache-tomcat-8.0.0-RC5.tar.gz /usr/local/
[sudo] password for zhaifengguo: 
zhaifengguo@zhaifg:~$ cd /usr/local/
zhaifengguo@zhaifg:/usr/local$ sudo tar -zxf apache-tomcat-8.0.0-RC5.tar.gz 
zhaifengguo@zhaifg:/usr/local$ ls
apache-tomcat-8.0.0-RC5  apache-tomcat-8.0.0-RC5.tar.gz  bin  etc  games  include  jdk1.7.0_45  jdk-7u45-linux-i586.tar.gz  lib  man  sbin  share  src


zhaifengguo@zhaifg:/usr/local$ sudo mv apache-tomcat-8.0.0-RC5 tomcat8
zhaifengguo@zhaifg:/usr/local$

3,启动tomcat.

  默认的情况下tomcat的启动是进入tomcat的bin目录,通过startup.sh,shutdown.sh 分别进行启动,关闭的.

也可以自己制作启动文件,添加到系统服务里.

zhaifengguo@zhaifg:/usr/local/tomcat8$ sudo bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/local/jdk1.7.0_45
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
zhaifengguo@zhaifg:/usr/local/tomcat8$

4,制作启动脚本,并添加系统服务里,添加开机启动.

vim tomcatd
 1 #!/bin/sh
  2 # chkconfig: 345 99 10
  3 # description: Auto-starts tomcat
  4 # /etc/init.d/tomcatd
  5 # Tomcat auto-start
  6 # Source function library.
  7 . /etc/init.d/functions
  8 # source networking configuration.
  9 . /etc/sysconfig/network
 10 RETVAL=0
 11 # CATALINA_HOME="/software/apache-tomcat-6.0.20"
 12 export JAVA_HOME=/usr/local/jdk1.7.0_45
 13 export CATALINA_HOME=/usr/local/tomcat8
 14 export CATALINA_BASE=/usr/local/tomcat8
 15 #TOMCATUSER=root
 16 start()
 17 {
 18         if [ -f $CATALINA_HOME/bin/startup.sh ];
 19           then
 20             echo $"Starting Tomcat"
 21 #            /bin/su $TOMCATUSER -c 
 22         $CATALINA_HOME/bin/startup.sh
 23             RETVAL=$?
 24             echo " OK"
 25             return $RETVAL
 26         fi
 27 }
 28 stop()
 29 {
 30         if [ -f $CATALINA_HOME/bin/shutdown.sh ];
 31           then
 32             echo $"Stopping Tomcat"
 33 #            /bin/su $TOMCATUSER -c $CATALINA_HOME/bin/shutdown.sh
 34         $CATALINA_HOME/bin/shutdown.sh
 35             RETVAL=$?
 36             sleep 1
 37         #ps fwwu|grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9 
 38         ps -ef|grep tomcat|grep -v grep|grep conf|awk '{print $2}'|xargs kill -9
 39         echo " OK"
 40             # [ $RETVAL -eq 0 ] && rm -f /var/lock/...
 41             return $RETVAL
 42         fi
 43 }
 44 
 45 case "$1" in
 46  start)
 47         start
 48         ;;
 49  stop)
 50         stop
 51         ;;
 52 
 53  restart)
 54          echo $"Restaring Tomcat"
 55          $0 stop
 56          sleep 1
 57          $0 start
 58          ;;
 59  *)
 60         echo $"Usage: $0 {start|stop|restart}"
 61         exit 1
 62         ;;
 63 esac
 64 exit $RETVAL

复制tomcatd到init.d的目录下,

cp tomcatd /etc/init.d/

改变tomcatd的执行权限

chmod  755 /etc/init.d/tomcatd

添加到系统服务里

chkconfig --add tomcatd

添加开机启动

chkconfig --level 35  tomcatd  on

查看系统启动

chkconfig --list | grep tomcatd

你可能感兴趣的:(tomcat)