Tomcat搭建
1.环境准备
规划节点:
节点IP |
主机名 |
节点 |
192.168.100.11 |
tomcat |
Tomcat |
使用VMWare Workstation软件安装CentOS 7.2操作系统,镜像使用提供的CentOS-7-x86_64-DVD-1511.iso(其他版本也可以)
关闭防火墙并设置开机不自启,配置SElinux规则
[aaa@qq.com ~]# systemctl stop firewalld.service
[aaa@qq.com ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[aaa@qq.com ~]# setenforce 0
2.修改主机名
使用hostnamectl命令修改主机名:
[aaa@qq.com ~]# hostnamectl set-hostname tomcat
[aaa@qq.com ~]# su
[aaa@qq.com ~]#
3.安装JDK
JDK的下载:
将提供的安装包JDK安装包和Tomcat安装包。通过CRT上传JDK到/usr/local/src/目录下
JDK安装:
部署Tomcat环境需要JDK软件环境,我们进入到/usr/local/src/目录下,解压刚刚上传的jdk将解压后的文件移动到/usr/local/目录下改名为jdk1.8,然后使用ls命令查看下/usr/local/目录下是否有jdk1.8目录
[aaa@qq.com ~]# cd /usr/local/src/
[aaa@qq.com src]# tar zxf jdk-8u211-linux-x64.tar.gz
[aaa@qq.com src]# mkdir /usr/local/jdk1.8
[aaa@qq.com src]# mv jdk1.8.0_211/* /usr/local/jdk1.8
[aaa@qq.com src]# ls /usr/local/
bin etc games include jdk1.8 lib lib64 libexec sbin share src
4.修改环境变量
设置环境变量,编辑/etc/profile文件,并使其立即生效
[aaa@qq.com src]# vi /etc/profile
//将一下内容添加到文件底部
JAVA_HOME=/usr/local/jdk1.8/
JAVA_BIN=/usr/local/jdk1.8/bin
JRE_HOME=/usr/local/jdk1.8/jre
PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin
CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar
[aaa@qq.com src]# source /etc/profile
5.检查JDK安装情况
配置完成环境变量后,使用java -version命令检查是否安装成功,如果显示结果带有java version "1.8.0_211"字样和我们解压的jdk-8u211-linux-x64.tar.gz包的版本相对应,则证明安装成功
[aaa@qq.com src]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
这里有可能出现的不是上面的这种,而是如下:
[aaa@qq.com src]# java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
如果发现不是自己安装的JDK,这是因为系统自带OpenJDK或者以前安装过OpenJDK。使用witch命令,查看现在Java的所在目录
[aaa@qq.com src]# which java
/usr/bin/java
如果结果为/usr/bin/java则说明这是系统自带的OpenJDK。这时,我们为了实验的一致性,把原来的Java目录重命名为java_bak,并使用source命令再次使环境变量生效,然后使用java -verison命令查看是否有java version "1.8.0_211"字样
[aaa@qq.com src]# mv /usr/bin/java /usr/bin/java_bak
[aaa@qq.com src]# source /etc/profile
[aaa@qq.com src]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
6.安装Tomcat
解压Tomcat软件包,将解压后的文件移动到/usr/local/tomcat目录下,并命名为tomcat
[aaa@qq.com ~]# cd /usr/local/src/
[aaa@qq.com src]# tar zxf apache-tomcat-9.0.21.tar.gz
[aaa@qq.com src]# mkdir /usr/local/tomcat
[aaa@qq.com src]# mv apache-tomcat-9.0.21/* /usr/local/tomcat
7.启动Tomcat
因解压的包是二进制包,不用我们去编译,使用/usr/local/tomcat/bin/startup.sh这个命令启动Tomcat
[aaa@qq.com src]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.8
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
8.测试
用netstat命令来监听java相关服务端口,查看是否有以下端口存在(8009、8080、8005),如果存在则证明Tomcat服务启动成功
[aaa@qq.com src]# netstat -lnpt | grep java
tcp6 0 0 :::8009 :::* LISTEN 49228/java
tcp6 0 0 :::8080 :::* LISTEN 49228/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 49228/java
然后打开浏览器,在地址栏中输入http://IP:8080/(这里的IP为你虚拟机的IP地址),可以看到Tomcat的默认页面