目录
192.168.88.50 #pc1
192.168.88.51 #pc2
systemctl stop firewalld
setenforce 0 #前期准备工作
tar -xf jdk-8u361-linux-x64.tar.gz
mv jdk1.8.0_361/ /usr/local
cd /usr/local
vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/jdk1.8.0_361
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
source /etc/profile.d/java.sh
java -version
tar -xf apache-tomcat-9.0.16.tar.gz
cp -a apache-tomcat-9.0.16 /usr/local/tomcat
cd /usr/local/tomcat/bin
vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=tomcat server
Wants=network-online.target
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target #将tomcat添加至系统服务
systemctl start tomcat
systemctl status tomcat
ss -natp|grep java #启动tomcat
cd /usr/local
mv tomcat tomcat1
mkdir tomcat tomcat2
mv tomcat1 tomcat2 tomcat
cd /opt
mv apache-tomcat-9.0.16 /usr/local/tomcat/tomcat2 #部署
cd /usr/local/tomcat/tomcat2/apache-tomcat-9.0.16
mv * ..
vim /usr/local/tomcat/tomcat1/bin/startup.sh
##21行添加##
export CATALINA_HOME=/usr/local/tomcat/tomcat1
export CATALINA_BASE=/usr/local/tomcat/tomcat1
export TOMCAT_HOME=/usr/local/tomcat/tomcat1
vim /usr/local/tomcat/tomcat1/bin/shutdown.sh
##21行添加##
export CATALINA_HOME=/usr/local/tomcat/tomcat1
export CATALINA_BASE=/usr/local/tomcat/tomcat1
export TOMCAT_HOME=/usr/local/tomcat/tomcat1
vim /usr/local/tomcat/tomcat2/bin/startup.sh
##21行添加##
export CATALINA_HOME=/usr/local/tomcat/tomcat2
export CATALINA_BASE=/usr/local/tomcat/tomcat2
export TOMCAT_HOME=/usr/local/tomcat/tomcat2
vim /usr/local/tomcat/tomcat2/bin/shutdown.sh
##21行添加##
export CATALINA_HOME=/usr/local/tomcat/tomcat2
export CATALINA_BASE=/usr/local/tomcat/tomcat2
export TOMCAT_HOME=/usr/local/tomcat/tomcat2
vim /usr/local/tomcat/tomcat2/conf/server.xml
#22行,修改Server prot,默认为8005 -> 修改为8006
<Server port="8006" shutdown="SHUTDOWN">
#69行,修改Connector port,HTTP/1.1 默认为8080 -> 修改为8081
<Connector port="8081" protocol="HTTP/1.1"
#116行,修改Connector port AJP/1.3,默认为8009 -> 修改为8010
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
systemctl stop tomcat #如果刚刚用sysemctl启动了tomcat一定要先关闭在重启,不然会报错
/usr/local/tomcat/tomcat1/bin/startup.sh
/usr/local/tomcat/tomcat2/bin/startup.sh
##192.168.88.50##
cd /usr/local/tomcat/tomcat1/webapps
mkdir test
vim test/123.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF- 8"%>
<html>
<head>
<title>JSP test page</title>
</head>
<body>
<% out.println("动态页面 1,http://www.test1.com");%>
</body>
</html>
cd /usr/local/tomcat/tomcat2/webapps
mkdir test
vim test/123.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF- 8"%>
<html>
<head>
<title>JSP test page</title>
</head>
<body>
<% out.println("动态页面 2,http://www.test2.com");%>
</body>
</html>
##192.168.88.51##
cd /usr/local/tomcat/webapps
mkdir test
vim test/123.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF- 8"%>
<html>
<head>
<title>JSP test page</title>
</head>
<body>
<% out.println("动态页面 3,http://www.test3.com");%>
</body>
</html>
192.168.88.22 #nginx1
192.168.88.31 #nginx2
systemctl stop firewalld
setenforce 0 #前期准备工作
vim /usr/local/nginx/conf/nginx.conf
upstream tomcat_server{
server 192.168.88.50:8080 weight=1;
server 192.168.88.50:8081 weight=1;
server 192.168.88.51:8080 weight=1;
}
location ~ .*\.jsp$ {
proxy_pass http://tomcat_server;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_ for;
}
location /static {
root html;
index index.html index.htm;
}
cd /usr/local/nginx/html
mkdir static
vim static/test.html
<html>
<body>
<h1>this is static web01</h1>
</body>
</html>
systemctl restart nginx
192.168.88.13 #安装有nginx
nginx -V
--with-stream #有此模块
vim /usr/local/nginx/conf/nginx.conf
stream {
upstream nginx_server {
server 192.168.88.22:80;
server 192.168.88.31:80;
}
server {
listen 9527;
proxy_pass nginx_server;
}
}
systemctl restart nginx