官方站点:http://tomcat.apache.org/
CentOS7 OpenJDK 系统自带的tomcat tomcata 192.168.52.120
CentOS7 OracleJDK 官方二进制编译 tomcatb 192.168.52.121
一、OpenJDK+系统自带的tomcat
a.安装JDK
Tomcat本身由java代码实现,所以其需要依赖JVM环境和相应的编译器与库文件。固我们需要提供jdk环境。此处我们使用系统仓库自带的jdk进行安装演示。
[root@tomcata ~]# yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel
b.配置JAVA_HOME环境
[root@tomcata ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr
[root@tomcata ~]# . /etc/profile.d/java.sh
[root@tomcata ~]# echo $JAVA_HOME
/usr
c.安装tomcat
tomcat的安装也有两种方式,一种是系统自带的,一种是rpm包方式安装。磁珠演示系统自带的yum安装.
[root@tomcata ~]# yum install tomcat tomcat-lib tomcat-webapps tomcat-admin-webapps
d.启动服务
[root@tomcata ~]# systemctl start tomcat.service
二、Oracle JDK+tomcat
1.安装Oracle JDK
这里我们安装两个版本的jdk,是为了在后面演示切换jdk版本,一般而言,我们只需要安装一个就可以了。视频安装的是jdk-7u79故我们将当前版本切换为7u79版本。
[root@tomcatb ~]# rpm -ivh jdk-8u25-linux-x64.rpm
[root@tomcatb ~]# rpm -ivh jdk-7u79-linux-x64.rpm
2.切换版本
切换版本无非就是修改latest的符号链接即可实现。
[root@tomcatb ~]# java -version #当前版本
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)[root@tomcatb ~]# ll /usr/java/
total 8
lrwxrwxrwx 1 root root 16 Apr 2 21:15 default -> /usr/java/latest
drwxr-xr-x 8 root root 4096 Apr 2 21:17 jdk1.7.0_79
drwxr-xr-x 9 root root 4096 Apr 2 21:15 jdk1.8.0_25
lrwxrwxrwx 1 root root 21 Apr 2 21:15 latest -> /usr/java/jdk1.8.0_25
[root@tomcatb ~]# rm -rf /usr/java/latest #删除原来的link
[root@tomcatb ~]# ln -sv /usr/java/jdk1.7.0_79 /usr/java/latest 建立一个新的link
‘/usr/java/latest’ -> ‘/usr/java/jdk1.7.0_79’
[root@tomcatb ~]# java -version # 已经修改过来了
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
3.定义环境变量
[root@tomcatb ~]# vim /etc/profile.d/java.sh
JAVA_HOME=/usr/java/latest
PATH=$JAVAJ_HOME/bin:$PATH
export JAVA_HOME PATH
[root@tomcatb ~]# echo $JAVA_HOME
/usr/java/latest
4.安装官方编译的二进制编译包
使用官方编译的二进制包,并使用系统自带的多一步骤配置环境变量。
[root@tomcatb ~]#
[root@tomcatb ~]# wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.76/bin/apache-tomcat-7.0.57.tar.gz
[root@tomcatb ~]# tar -xf apache-tomcat-7.0.57.tar.gz -C /usr/local/
[root@tomcatb ~]# cd /usr/local/
[root@tomcatb local]# ln -sv /usr/local/apache-tomcat-7.0.57/ tomcat
5.配置tomcat二进制编译包的环境变量
[root@tomcatb local]# vim /etc/profile.d/tomcat.sh
CATALINA_BASE=/usr/local/tomcat
PATH=$CATALINA_BASE/bin:$PATH
export CATAlINA_BASE PATH
[root@tomcatb local]# . /etc/profile.d/tomcat.sh
[root@tomcatb local]# echo $CATALINA_BASE
/usr/local/tomcat
6.catalina命令详解
[root@tomcatb local]# catalina.sh --help
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
Usage: catalina.sh ( commands ... )
commands:
debug Start Catalina in a debugger
debug -security Debug Catalina with a security manager
jpda start Start Catalina under JPDA debugger
run Start Catalina in the current window
run -security Start in the current window with security manager
start Start Catalina in a separate window
start -security Start in a separate window with security manager
stop Stop Catalina, waiting up to 5 seconds for the process to end
stop n Stop Catalina, waiting up to n seconds for the process to end
stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running
stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running
configtest Run a basic syntax check on server.xml - check exit code for result
version What version of tomcat are you running?
Note: Waiting for the process to end and use of the -force option require that $CATALINA_PID is defined
网友评论