tomcat及jdk源码包编译安装
1、简介
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上Tomcat 部分是Apache 服务器的扩展,但它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的。
jdk是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。
2、下载地址
tomcat-9.0官方下载地址:http://tomcat.apache.org/download-90.cgi
jdk-1.7官方下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
3、首先编译安装jdk
[root@DS-CentOS107 ~]# mkdir /usr/local/jdk
[root@DS-CentOS107 ~]# tar -zxvf jdk-7u79-linux-x64.gz -C /usr/local/jdk
[root@DS-CentOS107 ~]# vi /etc/profile #编辑profile文件,在最后添加下面的内容
export JAVA_HOME=/usr/local/jdk/jdk1.7.0_79 export JRE_HOME=/usr/local/jdk/jdk1.7.0_79/jre export PATH=$PATH:/usr/local/jdk/jdk1.7.0_79/bin export CLASSPATH=./:/usr/local/jdk/jdk1.7.0_79/jre/lib
[root@DS-CentOS107 ~]# source /etc/profile #使profile文件更改的内容立即生效
[root@DS-CentOS107 ~]# java -version #查看jdk是否已安装成功
openjdk version "1.8.0_65" OpenJDK Runtime Environment (build 1.8.0_65-b17) OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)
4、接下编译tomcat
[root@DS-CentOS107 ~]# mkdir /usr/local/tomcat
[root@DS-CentOS107 ~]# tar -zxvf apache-tomcat-9.0.0.M1.tar.gz -C /usr/local/tomcat
[root@DS-CentOS107 ~]# vi /usr/local/tomcat/apache-tomcat-9.0.0.M1/conf/server.xml
<Connector port="8080" protocol="HTTP/1.1" #端口设置,默认为8080,可以自定义修改,注意 防火墙需要开放相应端口 <Host name="localhost" appBase="webapps" #默认站点根目录,把webapps修改为/usr/local/nginx/
5、设置tomcat开机启动
[root@DS-CentOS107 ~]# vi /etc/rc.d/init.d/tomcat #新建一个tomcat文件
# # chkconfig: 345 90 10 # description: Tomcat is a Servlet+JSP Engine. # Enter the jdk installation directory jdk_File=/usr/local/jdk/jdk1.7.0_79 # Enter the tomcat installation directory tomcat_File=/usr/local/tomcat/apache-tomcat-9.0.0.M1 export JAVA_HOME=$jdk_File # Source function library. . /etc/rc.d/init.d/functions start(){ if [ -z $(/sbin/pidof java) ]; then echo "Starting tomcat" $tomcat_File/bin/startup.sh touch /var/lock/subsys/tomcat else echo "tomcat allready running" fi } stop(){ if [ ! -z $(/sbin/pidof java) ]; then echo "Shutting down tomcat" $tomcat_File/bin/shutdown.sh until [ -z $(/sbin/pidof java) ]; do :; done rm -f /var/lock/subsys/tomcat else echo "tomcat not running" fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) $tomcat_File/bin/catalina.sh version ;; *) echo "Usage: $0 {start|stop|restart|status}" esac exit 0
[root@DS-CentOS107 ~]# chmod 755 /etc/rc.d/init.d/tomcat #给tmocat文件添加执行权限
[root@DS-CentOS107 ~]# chkconfig -add tomcat #添加到服务项
[root@DS-CentOS107 ~]# chkconfig tomcat on #设置开机启动
[root@DS-CentOS107 ~]# service tomcat restart #重启tomcat
tomcat not running Starting tomcat Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.0.M1 Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.0.M1 Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.0.M1/temp Using JRE_HOME: /usr/local/jdk/jdk1.7.0_79 Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.0.M1/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.0.M1/bin/tomcat-juli.jar Tomcat started.
[root@DS-CentOS107 ~]# service tomcat stauts
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.0.M1 Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.0.M1 Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.0.M1/temp Using JRE_HOME: /usr/local/jdk/jdk1.7.0_79 Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.0.M1/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.0.M1/bin/tomcat-juli.jar Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/catalina/util/ServerInfo : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)