首先装tomcat服务步骤如下:
1、关闭防火墙和安全机制
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
2、查看JDK是否安装
[root@localhost ~]# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
3、卸载用rpm方式安装的JDK
方法一、
[root@localhost ~]# rpm -qa | grep -i openjdk 检测是否为需要的版本
java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64
java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64
[root@localhost ~]# rpm -e java-1.8.0-openjdk --nodeps //有依赖关系,解除依赖关系后面加 --nodeps
[root@localhost ~]# rpm -e java-1.8.0-openjdk-headless
[root@localhost ~]# rpm -qa | grep -i openjdk
方法二、
[root@localhost ~]# which java
/usr/bin/java
[root@localhost ~]# rm -rf /usr/bin/java
[root@localhost ~]# java -version
-bash: /usr/bin/java: 没有那个文件或目录
4、安装JDK
[root@localhost ~]# tar -xf jdk-8u191-linux-x64.tar.gz //解压压缩包
[root@localhost ~]# mv jdk1.8.0_191/ /usr/local/java //将解压后的包移动到指定目录下
[root@localhost ~]# /usr/local/java/bin/java -version //此时只有通过绝对路径才可以查看java的版本号信息
[root@localhost ~]# vim /etc/profile //修改
export JAVA_HOME=/usr/local/java //设置java的根目录
export PATH=$PATH:$JAVA_HOME/bin //在PATH环境变量中添加java根目录下的bin子目录
[root@localhost ~]# echo $PATH //在未执行修改的脚本时查看PATH变量
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# source /etc/profile //重置一下脚本
[root@localhost ~]# echo $PATH //再查一遍
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin
5、Tomcat安装
[root@localhost ~]# tar -xf apache-tomcat-8.5.16.tar.gz
[root@localhost ~]# mv apache-tomcat-8.5.16 /usr/local/tomcat8
[root@localhost ~]# ls /usr/local/tomcat8/bin
bootstrap.jar setclasspath.sh
catalina.bat shutdown.bat
catalina.sh shutdown.sh
catalina-tasks.xml startup.bat
commons-daemon.jar startup.sh (启动文件)
commons-daemon-native.tar.gz tomcat-juli.jar
configtest.bat tomcat-native.tar.gz
configtest.sh tool-wrapper.bat
daemon.sh tool-wrapper.sh
digest.bat version.bat
digest.sh version.sh
setclasspath.bat
//.bat Windows版本
//.sh Linus版本
6、启动
复制代码
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.
[root@localhost ~]# netstat -anpt | grep :8080
tcp6 0 0 :::8080 :::* LISTEN 3226/java
注意事项:实际访问时要ip加:8080
第二台tomcat以上面步骤在做一遍
httpd服务
[root@localhost ~]# yum -y install httpd //安装httpd服务
[root@localhost ~]# cd /etc/httpd/
[root@localhost httpd]# ls
conf conf.d conf.modules.d logs modules run
[root@localhost httpd]# cd conf
[root@localhost conf]# ls
httpd.conf magic
[root@localhost conf]# vim httpd.conf //修改主配置文件添加以下内容
<Proxy balancer://tomcat/>
BalancerMember ajp://192.168.200.111:8009/ loadfactor=1
BalancerMember ajp://192.168.200.112:8009/ loadfactor=1
proxyset lbmethod=byrequests
</Proxy>
proxyrequests off
ProxyPass / balancer://tomcat/
proxypassreverse / balancer://tomcats/
ProxyPass /server-status !
ProxyPass /balancer-manager !
[root@localhost conf]# systemctl restart httpd //重新启动httpd服务
为了实验效果两台tomcat将展示页面做成不同的