本文件是采用的模板是CentOS 6,同样适用于CentOS 系列其他发行版本。

1. 测试环境

2. Install Java SE Development Kit 7 (JDK7)

  1. [root@ultraera ~]# curl -LO -H "Cookie: oraclelicense=accept-securebackup-cookie" \
  2. "http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.rpm"
  3. [root@ultraera ~]# rpm -Uvh jdk-7u75-linux-x64.rpm
  4. Preparing... ########################################### [100%]
  5. 1:jdk ########################################### [100%]
  6. Unpacking JAR files...
  7. rt.jar...
  8. jsse.jar...
  9. charsets.jar...
  10. tools.jar...
  11. localedata.jar...
  12. jfxrt.jar...

3. Build Java Environment.

  1. [root@ultraera ~]# vi /etc/profile
  2. # add follows to the end
  3. export JAVA_HOME=/usr/java/default
  4. export PATH=$PATH:$JAVA_HOME/bin
  5. export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
  6. [root@ultraera ~]# source /etc/profile
  7. [root@ultraera ~]# java -version
  8. java version "1.7.0_75"
  9. Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
  10. Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

4. Download Tomcat7

Make sure the latest one and download it from the site below.
=》 http://ftp.riken.jp/net/apache/tomcat/tomcat-7/

  1. [root@ultraera ~]# wget http://ftp.riken.jp/net/apache/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70.tar.gz
  2. [root@ultraera ~]# tar zxvf apache-tomcat-7.0.70.tar.gz
  3. [root@ultraera ~]# mv apache-tomcat-7.0.70 /usr/tomcat7
  4. [root@ultraera ~]# useradd -M -d /usr/tomcat7 tomcat7
  5. [root@ultraera ~]# chown -R tomcat7. /usr/tomcat7

5. create a script , use service manage tomcat7

  1. [root@ultraera ~]# cat /etc/rc.d/init.d/tomcat7
  2. #!/bin/bash
  3. # Tomcat7: Start/Stop Tomcat 7
  4. #
  5. # chkconfig: - 90 10
  6. # description: Tomcat is a Java application Server.
  7. . /etc/init.d/functions
  8. . /etc/sysconfig/network
  9. CATALINA_HOME=/usr/tomcat7
  10. TOMCAT_USER=tomcat7
  11. LOCKFILE=/var/lock/subsys/tomcat7
  12. RETVAL=0
  13. start(){
  14. echo "Starting Tomcat7: "
  15. su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"
  16. RETVAL=$?
  17. echo
  18. [ $RETVAL -eq 0 ] && touch $LOCKFILE
  19. return $RETVAL
  20. }
  21. stop(){
  22. echo "Shutting down Tomcat7: "
  23. $CATALINA_HOME/bin/shutdown.sh
  24. RETVAL=$?
  25. echo
  26. [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
  27. return $RETVAL
  28. }
  29. case "$1" in
  30. start)
  31. start
  32. ;;
  33. stop)
  34. stop
  35. ;;
  36. restart)
  37. stop
  38. start
  39. ;;
  40. *)
  41. echo $"Usage: $0 {start|stop|restart}"
  42. exit 1
  43. ;;
  44. esac
  45. exit $?

6. Add tomcat7 to system service

  1. [root@ultraera ~]# chmod 755 /etc/rc.d/init.d/tomcat7
  2. [root@ultraera ~]# /etc/rc.d/init.d/tomcat7 start
  3. Starting Tomcat7:
  4. Using CATALINA_BASE: /usr/tomcat7
  5. Using CATALINA_HOME: /usr/tomcat7
  6. Using CATALINA_TMPDIR: /usr/tomcat7/temp
  7. Using JRE_HOME: /usr/java/default
  8. Using CLASSPATH: /usr/tomcat7/bin/bootstrap.jar:/usr/tomcat7/bin/tomcat-juli.jar
  9. Tomcat started.
  10. [root@ultraera ~]# netstat -ntlp | grep java
  11. tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 6326/java
  12. tcp 0 0 :::8009 :::* LISTEN 6326/java
  13. tcp 0 0 :::8080 :::* LISTEN 6326/java
  14. [root@ultraera ~]# ps axu | grep java
  15. tomcat7 6326 8.3 85.6 5229768 2910176 ? Sl Aug22 3216:38 /usr/bin/java -Djava.util.logging.config.file=/usr/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Djava.endorsed.dirs=/usr/tomcat7/endorsed -classpath /usr/tomcat7/bin/bootstrap.jar:/usr/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/usr/tomcat7 -Dcatalina.home=/usr/tomcat7 -Djava.io.tmpdir=/usr/tomcat7/temp org.apache.catalina.startup.Bootstrap start
  16. [root@ultraera ~]# chkconfig --add tomcat7
  17. [root@ultraera ~]# chkconfig tomcat7 on

7. 打开浏览器测试Tomcat Server搭建完成,默认页面如下

HowTo Install a Tomcat Server 7 - 图1

8. 使用curl 测试

  1. [root@ultraera ~]# curl -I http://localhost:8080
  2. HTTP/1.1 200 OK
  3. Server: Apache-Coyote/1.1
  4. Content-Type: text/html;charset=ISO-8859-1
  5. Transfer-Encoding: chunked
  6. Date: Sun, 18 Sep 2016 11:14:06 GMT

9. Tomcat 文件树

  1. [root@ultraera /usr/tomcat7]# tree
  2. .
  3. ├── bin
  4. ├── bootstrap.jar
  5. ├── catalina.bat
  6. ├── catalina.sh
  7. ├── catalina-tasks.xml
  8. ├── commons-daemon.jar
  9. ├── commons-daemon-native.tar.gz
  10. ├── configtest.bat
  11. ├── configtest.sh
  12. ├── daemon.sh
  13. ├── digest.bat
  14. ├── digest.sh
  15. ├── setclasspath.bat
  16. ├── setclasspath.sh
  17. ├── shutdown.bat
  18. ├── shutdown.sh
  19. ├── startup.bat
  20. ├── startup.sh
  21. ├── tomcat-juli.jar
  22. ├── tomcat-native.tar.gz
  23. ├── tool-wrapper.bat
  24. ├── tool-wrapper.sh
  25. ├── version.bat
  26. └── version.sh
  27. ├── conf
  28. ├── catalina.policy
  29. ├── catalina.properties
  30. ├── context.xml
  31. ├── logging.properties
  32. ├── server.xml
  33. ├── tomcat-users.xml
  34. └── web.xml
  35. ├── lib
  36. ├── LICENSE
  37. ├── logs
  38. ├── catalina.2016-09-18.log
  39. ├── catalina.out
  40. ├── host-manager.2016-09-18.log
  41. ├── localhost.2016-09-18.log
  42. └── manager.2016-09-18.log
  43. ├── NOTICE
  44. ├── RELEASE-NOTES
  45. ├── RUNNING.txt
  46. ├── temp
  47. ├── webapps
  48. └── ROOT
  49. └── work