一、需要三台主机,一台安装apache,两台安装tomcat
二、tomcat1与tomcat2安装Tomcat tomcat-8.5.16(为了便于区分tomcat1使用默认页面,tomcat2使用测试页面)
安装tomcat之前需要安装java的jdk,版本为:jdk-8u191-linux-x64.tar.gz
1、第一台tomcat主机tomcat1(默认页面安装)
关闭防火墙
[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# iptables -F [root@localhost ~]# setenforce 0
查看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)
卸载用rpm方式安装的JDK
[root@localhost ~]# which java /usr/bin/java [root@localhost ~]# rm -rf /usr/bin/java [root@localhost ~]# java -version -bash: /usr/bin/java: 没有那个文件或目录
安装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
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版本
启动
[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
2、第二台tomcat主机tomcat2(测试页面安装)
安装tomcat的过程与安装第一台一样,过程省略
主要设置tomcat网页存放位置
[root@localhost ~]# mkdir -p /web/webapp/ //创建存放网页的目录 [root@localhost ~]# vim /web/webapp/index.jsp //添加要存放的网页 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>JSP test1 page</title> </head> <body> <% out.println("Welcome to test site,http://www.test1.com");%> </body> </html> [root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context docBase="/web/webapp" path="" reloadable="flash"></Context> 注释:docBase="/web/webapp" //web应用的文档基准目录 path=" " //设置默认"类" reloadable="flase" //设置监视"类"是否变化 [root@localhost ~]# /usr/local/tomcat8/bin/shutdown.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
[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.
网页测试
三、apache安装,Apache httpd-2.2.15,直接使用yum安装httpd
[root@localhost ~]# yum -y install httpd
修改配置文件
[root@localhost ~]# vim /etc/httpd/conf/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 ~]# systemctl restart httpd //重启服务
网页测试