[root@localhost ~]# tar fx apache-tomcat-8.5.40.tar.gz
[root@localhost ~]# tar fx jdk-8u191-linux-x64.tar.gz
[root@localhost ~]# mv jdk1.8.0_191/ /usr/local/java
[root@localhost ~]# vim /etc/profile
JAVA_HOME=/usr/local/java
PATH=$PATH:$JAVA_HOME/bin
[root@localhost ~]# source /etc/profile
[root@localhost ~]# mv apache-tomcat-8.5.40 /usr/local/
[root@localhost ~]# mkdir -p /usr/local/tomcat_instance/tomcat1
[root@localhost ~]# mkdir -p /usr/local/tomcat_instance/tomcat2
[root@localhost ~]# cp -R /usr/local/apache-tomcat-8.5.40/conf/ /usr/local/tomcat_instance/tomcat1
[root@localhost ~]# cp -R /usr/local/apache-tomcat-8.5.40/conf/ /usr/local/tomcat_instance/tomcat2
[root@localhost ~]# mkdir /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin
[root@localhost ~]# touch /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/startup.sh
[root@localhost ~]# touch /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/shutdown.sh
[root@localhost ~]# chmod +x /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/startup.sh
[root@localhost ~]# chmod +x /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/shutdown.sh
[root@localhost ~]# vi /usr/local/tomcat_instance/tomcat1/bin/startup.sh
#/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
export CATALINA_BASE="/usr/local/tomcat_instance/tomcat1"
export CATALINA_TMPDIR="$CATALINA_BASE/temp"
export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Djava.awt.headless=true -Dtomcat.name=tomcat1"
if [ ! -d "$CATALINA_BASE/logs" ]; then
mkdir $CATALINA_BASE/logs
fi
if [ ! -d "$CATALINA_BASE/temp" ]; then
mkdir $CATALINA_BASE/temp
fi
bash $CATALINA_HOME/bin/startup.sh "$@"
[root@localhost ~]# vi /usr/local/tomcat_instance/tomcat2/bin/startup.sh
#/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
export CATALINA_BASE="/usr/local/tomcat_instance/tomcat2"
export CATALINA_TMPDIR="$CATALINA_BASE/temp"
export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Djava.awt.headless=true -Dtomcat.name=tomcat2"
if [ ! -d "$CATALINA_BASE/logs" ]; then
mkdir $CATALINA_BASE/logs
fi
if [ ! -d "$CATALINA_BASE/temp" ]; then
mkdir $CATALINA_BASE/temp
fi
bash $CATALINA_HOME/bin/startup.sh "$@"
[root@localhost ~]# vi /usr/local/tomcat_instance/tomcat1/bin/shutdown.sh
#/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
export CATALINA_BASE="/usr/local/tomcat_instance/tomcat1"
export CATALINA_TMPDIR="$CATALINA_BASE/temp"
export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
bash $CATALINA_HOME/bin/shutdown.sh "$@"
[root@localhost ~]# vi /usr/local/tomcat_instance/tomcat2/bin/shutdown.sh
#/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
export CATALINA_BASE="/usr/local/tomcat_instance/tomcat2"
export CATALINA_TMPDIR="$CATALINA_BASE/temp"
export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
bash $CATALINA_HOME/bin/shutdown.sh "$@"
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat2/conf/server.xml
22 <Server port="8006" shutdown="SHUTDOWN">
69 <Connector port="8090" protocol="HTTP/1.1"
116 <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
[root@localhost ~]# mkdir -p /usr/local/tomcat_instance/{tomcat1,tomcat2}/webapps/ROOT
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat1/webapps/ROOT/index.jsp
<html>
<title>Tomcat-1</title>
<body>
Hello This is Tomcat-1
</body>
</html>
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat2/webapps/ROOT/index.jsp
<html>
<title>Tomcat-2</title>
<body>
Hello This is Tomcat-2
</body>
</html>
[root@localhost ~]# /usr/local/tomcat_instance/tomcat1/bin/startup.sh
[root@localhost ~]# /usr/local/tomcat_instance/tomcat2/bin/startup.sh
192.168.200.111 安装nginx
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
http {
upstream tomcat_pool {
server 192.168.200.112:8080 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.200.112:8090 weight=1 max_fails=1 fail_timeout=10s;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcat_pool;
proxy_set_header Host $http_host;
}
}
[root@nginx ~]# killall -1 nginx
访问192.168.200.111进行测试