tomcat多实例及负载均衡

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tomcat多实例及负载均衡相关的知识,希望对你有一定的参考价值。

[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

以上是关于tomcat多实例及负载均衡的主要内容,如果未能解决你的问题,请参考以下文章

Tomcat多实例和负载均衡

Tomcat多实例和负载均衡

必须要掌握的开源Web应用服务器—Tomcat多实例和负载均衡

tomcat 多实例部署以及负载均衡配置

tomcat的多实例部署和负载均衡

Nginx 配置实例-配置负载均衡