Tomcat7安装基于jdk 1.7环境

Posted Linux无限探索

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tomcat7安装基于jdk 1.7环境相关的知识,希望对你有一定的参考价值。

这篇文章着重讲解tomcat7的安装,首先需要下载tomcat包和相应的jdk,如果你的系统是32位,那么下载x86的jdk,如果是64位的系统,那么下载X64的JDK。
tomcat7安装
1、查看系统版本
 # uname –a //是64位系统,那么我们选择64位的JDK
Linux 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 2011 x86_64 x86_64 x86_64 GNU/Linux
2、下载tomcat7和jdk1.7

Tarbag专门放源码包,software专门放解压后的软件包

# mkdir /usr/local/src/tarbag
# mkdir /usr/local/src/software
# cd /usr/local/src/tarbag
# wget http://mirror.bjtu.edu.cn/apache/tomcat/tomcat-7/v7.0.22/bin/apache-tomcat-7.0.22.tar.gz
# wgethttp://download.oracle.com/auth/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz
3、安装jdk(配置java环境)
# tar -xzvf jdk-7u1-linux-x64.tar.gz
# mv jdk1.7.0_01/ /usr/local/java

配置java环境

# vi /etc/profile
加上以下信息
export JAVA_HOME=/usr/local/java
CLASSPATH=/usr/local/java/lib/dt.jar:/usr/local/java/lib/tools.jar
PATH=/usr/local/java/bin:$PATH
export PATH JAVA_HOME CLASSPATH

查看是否成功

# source /etc/profile
# java  -version //看到1.7的字样说明安装成功了
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)
4、安装tomcat 7
# tar –xzvf  apache-tomcat-7.0.22.tar.gz
# mv apache-tomcat-7.0.22 /usr/local/tomcat7
5、启动关闭tomcat7

启动

# /usr/local/tomcat7/bin/startup.sh

关闭

# /usr/local/tomcat7/bin/shutdown.sh
6、开启tomcat测试

打开http://192.168.1.210:8080

具体下载地址如下:

Tomcat 7:
http://mirror.bjtu.edu.cn/apache/tomcat/tomcat-7/v7.0.22/bin/apache-tomcat-7.0.22.tar.gz
JDK 1.7(x86):
http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.rpm
JDK 1.7(X64):
http://download.oracle.com/auth/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz?e=1320470032&h=786351a82836b064c25af90e614d23fb

 

原文来自:http://www.ttlsa.com/web/install-tomcat7-on-linux/

本文地址:https://www.linuxprobe.com/tomcat7-install.html编辑:刘峰,审核员:苏西云

本文原创地址:https://www.linuxprobe.com/tomcat7-install.html

tomcat,jdk编译安装,并基于Apache负载均衡,session绑定

下载tomcat:
wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v8.5.34/bin/apache-tomcat-8.5.34.tar.gz

下载JDK:
wget http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.rpm?AuthParam=1536721970_38dbf1e81e1c24c45ef2e0ee119b29a4

安装jdk:
rpm -ivh jdk-8u181-linux-x64.rpm?AuthParam=1536721970_38dbf1e81e1c24c45ef2e0ee119b29a4
安装目录:
ls /usr/java
配置环境变量:
#vi /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH
重读配置:
#. /etc/profile.d/java.sh
查看版本:

java -version

java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
查看环境变量:
]# echo $JAVA_HOME
/usr/java/latest

解压tomca至usr/local:
tar xf apache-tomcat-8.5.34.tar.gz -C /usr/local/
ln -sv apache-tomcat-8.5.34 tomcat

添加环境变量:
vi /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH
重读:. /etc/profile.d/tomcat.sh
测试:

catalina.sh version

Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.34
Server built: Sep 4 2018 22:28:22 UTC
Server number: 8.5.34.0
OS Name: Linux
OS Version: 3.10.0-514.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_181-b13
JVM Vendor: Oracle Corporation
测试配置语法:
catalina.sh configtest
启动yomcat:

catalina.sh start

Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
查看端口:
ss -tnl

添加第一个java程序:
1、创建目录结构
#mkdir myapp/{lib,classes,WEB-INF,META-INF} -pv
mkdir: 已创建目录 "myapp/lib"
mkdir: 已创建目录 "myapp/classes"
mkdir: 已创建目录 "myapp/WEB-INF"
mkdir: 已创建目录 "myapp/META-INF"
2、编写程序

vi myapp/index.jsp

<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>JSP Test Page</title>
</head>
<body>
<% out.println("hello world"); %>
</body>
</html>

配置管理界面:
添加管理员账号和密码:
#vi /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat1" roles="manager-gui"/>

配置远程访问manager:
tomat_home/conf/Catalina/localhost/下 添加manager.xml
<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>
配置host manager:

vi tomcat-users.xml

<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat1" roles="manager-gui,admin-gui"/>

#vim webapps/host-manager/META-INF/context.xml

    <Context antiResourceLocking="false" privileged="true" >
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
             allow="^.*$" />  #修改这里
        </Context>

创建目录文件:
mkdir -pv /data/{webapps,logs}
拷贝测试文件:
cp -r /usr/local/tomcat/webapps/myapp/* /data/webapps/
编辑tomcat配置文件:
#vi server.xml
</Host>
<Host name="web.shengjing360.com" appBase="/data/webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/data/webapps" reloadable="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/data/logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
配置hosts文件,然后测试虚拟机:http://web.shengjing360.com:8080/

tomcat基于httpd负载均衡示例:
vi /etc/httpd/conf.d/vhosts.conf

基于http:
proxy balancer://lbcluster1>
balancermember http://192.168.102.44:8080 loadfactor=10 route=TomcatA
balancermember http://192.168.102.46:8080 loadfactor=10 route=TomcatB
</proxy>

<VirtualHost :80>
ServerName web.shengjing360.com
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
<Proxy
>
Require all granted
</Proxy>
ProxyPass /status !
ProxyPass / balancer://lbcluster1/
ProxyPa***everse / balancer://lbcluster1/
<Location />
Require all granted
</Location>
<Location /balancer-manager> #balancer-manager管理页面
SetHandler balancer-manager
Proxypass !
Require all granted
</Location>
</VirtualHost>

会话绑定:
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<proxy balancer://lbcluster1>
balancermember http://192.168.102.44:8080 loadfactor=10 route=TomcatA
balancermember http://192.168.102.46:8080 loadfactor=10 route=TomcatB
ProxySet stickysession=ROUTEID
</proxy>

<VirtualHost :80>
ServerName web.shengjing360.com
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
<Proxy
>
Require all granted
</Proxy>
ProxyPass /status !
ProxyPass / balancer://lbcluster1/
ProxyPa***everse / balancer://lbcluster1/
<Location />
Require all granted
</Location>
<Location /balancer-manager>
SetHandler balancer-manager
Proxypass !
Require all granted
</Location>
</VirtualHost>

基于ajp:
[[email protected] conf.d]# vi vhosts.ajp.conf

#Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<proxy balancer://lbcluster1>
balancermember ajp://192.168.102.44:8009 loadfactor=10 route=TomcatA
balancermember ajp://192.168.102.46:8009 loadfactor=10 route=TomcatB
ProxySet stickysession=ROUTEID
</proxy>

<VirtualHost :80>
ServerName web.shengjing360.com
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
<Proxy
>
Require all granted
</Proxy>
ProxyPass /status !
ProxyPass / balancer://lbcluster1/
ProxyPa***everse / balancer://lbcluster1/
<Location />
Require all granted
</Location>
<Location /balancer-manager>
SetHandler balancer-manager
Proxypass !
Require all granted
</Location>
</VirtualHost>

以上是关于Tomcat7安装基于jdk 1.7环境的主要内容,如果未能解决你的问题,请参考以下文章

从 Tomcat 6 JDK 1.6 迁移到 Tomcat 7 JDK 1.7 会话问题

eclipse安装完,安装tomcat和jdk必须统一版本么?jdk1.7的必须安装tomcat7

Tomcat7调试运行环境搭建与源代码分析入门

linux下源码安装jdk1.8和tomcat8.5

安装JDK1.8之后又安装1.7出现的环境变量问题

win7安装两个jdk,1.7和1.8,下载安装配置环境变量,方便切换