Tomcat单机多实例配置

原文链接:http://blog.csdn.net/xyang81/article/details/51997053

当一个进程的线程超过500个的话,那么这个进程的运行效率会变得很低。因为一个进程产生过多的线程,CPU资源会浪费在线程间切换过程当中。但当服务器配置很高的情况下,如:32G内存,16核的CPU。这样一台高配的机器上只装一个Tomcat实例,会有点浪费。其实我们可以根据服务器的硬件配置,配置多个Tomcat实例,充分利用硬件的资源。你第一时间可能会想到,直接下载多份Tomcat安装包,直接解压,改下端口跑起来不就可以了? 这样也是可以的,但不好维护。假设你在一台机器上安装了5个Tomcat实例,日后要升级Tomcat时,你需要将新版本的tomcat复制并覆盖掉旧的5个tomcat安装程序和配置,所以还是挺麻烦的。下面介绍多个Tomcat实例共享同一个安装包的配置方法。

安装环境

操作系统:CentOS7 64位 Mini版 
JDK:1.8,安装目录:/opt/jdk1.8 
Tomcat:Tomcat8.0.35,安装目录:/opt/apache-tomcat-8.0.35 
配置3个Tomcat实例组件一个集群: 
/opt/tomcat_instance/tomcat1 
/opt/tomcat_instance/tomcat2 
/opt/tomcat_instance/tomcat3

安装步聚

1> 下载Tomcat安装包并解压,目录结构如下:

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">drwxr<span class="hljs-attribute" style="box-sizing: border-box;">-xr</span><span class="hljs-attribute" style="box-sizing: border-box;">-x</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> root root  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>月  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">26</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">01</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">41</span> bin
drwxr<span class="hljs-attribute" style="box-sizing: border-box;">-xr</span><span class="hljs-attribute" style="box-sizing: border-box;">-x</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> root root  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>月  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">28</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">14</span> conf
drwxr<span class="hljs-attribute" style="box-sizing: border-box;">-xr</span><span class="hljs-attribute" style="box-sizing: border-box;">-x</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> root root  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>月  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">25</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">22</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12</span> lib
drwxr<span class="hljs-attribute" style="box-sizing: border-box;">-xr</span><span class="hljs-attribute" style="box-sizing: border-box;">-x</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> root root  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>月  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">28</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">48</span> logs
drwxr<span class="hljs-attribute" style="box-sizing: border-box;">-xr</span><span class="hljs-attribute" style="box-sizing: border-box;">-x</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> root root  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>月  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">25</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">22</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12</span> temp
drwxr<span class="hljs-attribute" style="box-sizing: border-box;">-xr</span><span class="hljs-attribute" style="box-sizing: border-box;">-x</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">7</span> root root  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>月  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">25</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">22</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">14</span> webapps
drwxr<span class="hljs-attribute" style="box-sizing: border-box;">-xr</span><span class="hljs-attribute" style="box-sizing: border-box;">-x</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> root root  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4096</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>月  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">05</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">57</span> work</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

2> 在/opt/tomcat_instance下分别创建3个实例的目录:

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">shell</span>> mkdir -p /opt/tomcat_instance/tomcat1
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">shell</span>> mkdir -p /opt/tomcat_instance/tomcat2
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">shell</span>> mkdir -p /opt/tomcat_instance/tomcat3</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

3> 拷贝tomcat安装目录下的conf目录分别放入3个实例目录中

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">shell<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">></span> copy <span class="hljs-attribute" style="box-sizing: border-box;">-R</span> /opt/apache<span class="hljs-attribute" style="box-sizing: border-box;">-tomcat</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.35</span>/conf /opt/tomcat_instance/tomcat1<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">/</span>
shell<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">></span> copy <span class="hljs-attribute" style="box-sizing: border-box;">-R</span> /opt/apache<span class="hljs-attribute" style="box-sizing: border-box;">-tomcat</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.35</span>/conf /opt/tomcat_instance/tomcat2<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">/</span>
shell<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">></span> copy <span class="hljs-attribute" style="box-sizing: border-box;">-R</span> /opt/apache<span class="hljs-attribute" style="box-sizing: border-box;">-tomcat</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.35</span>/conf /opt/tomcat_instance/tomcat3<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">/</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

4> 在tomcat实例下创建实例启动和停止脚本

启动和停止脚本放到tomcat实例的bin目录下

a) 启动脚本

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">shell</span>> mkdir -p /opt/tomcat_instance/tomcat[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>]/bin
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">shell</span>> touch startup.sh
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">shell</span>> chown +x startup.sh</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

将以下脚本拷贝到startup.sh文件中,注意修改CATALINA_BASE指向的tomcat实例路径:

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-shebang" style="color: rgb(0, 102, 102); box-sizing: border-box;">#!/bin/bash</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> JRE_HOME=/opt/jdk1.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>/jre
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> CATALINA_HOME=/opt/tomcat8
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> CATALINA_BASE=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/opt/tomcat_instance/tomcat1"</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> CATALINA_TMPDIR=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_BASE</span>/temp"</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> CATALINA_PID=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_BASE</span>/bin/tomcat.pid"</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> JAVA_OPTS=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-server -Xms1024m -Xmx1024m -Djava.awt.headless=true -Dtomcat.name=tomcat1"</span>

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#创建logs目录</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> [ ! <span class="hljs-operator" style="box-sizing: border-box;">-d</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_BASE</span>/logs"</span> ]; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">then</span>
  mkdir <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_BASE</span>/logs
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">fi</span>

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#创建temp目录</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> [ ! <span class="hljs-operator" style="box-sizing: border-box;">-d</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_BASE</span>/temp"</span> ]; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">then</span>
  mkdir <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_BASE</span>/temp
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">fi</span>

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># 调用tomcat启动脚本</span>
bash <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_HOME</span>/bin/startup.sh <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$@</span>"</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li></ul>

b) 停止脚本

<code class="hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">shell> touch <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">shutdown</span>.sh
shell> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">chown</span> +<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">x</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">shutdown</span>.sh
shell> vim <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">shutdown</span>.sh</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

拷贝以下脚本到shutdown.sh文件中:

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-shebang" style="color: rgb(0, 102, 102); box-sizing: border-box;">#!/bin/bash</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> JRE_HOME=/opt/jdk1.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>/jre
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> CATALINA_HOME=/opt/tomcat8
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> CATALINA_BASE=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/opt/tomcat_instance/tomcat1"</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> CATALINA_TMPDIR=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_BASE</span>/temp"</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">export</span> CATALINA_PID=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_BASE</span>/bin/tomcat.pid"</span>

bash <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$CATALINA_HOME</span>/bin/shutdown.sh <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$@</span>"</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul>

5、修改每个tomcat实例中server.xml中的端口

<code class="hljs r has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><Server port=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"8005"</span> shutdown=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"SHUTDOWN"</span>>
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">...</span>
  <Service name=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Catalina"</span>>
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">...</span>

    <Connector port=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"8080"</span> protocol=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"HTTP/1.1"</span>
               connectionTimeout=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"20000"</span>
               redirectPort=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"8443"</span> />
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">...</span>

    <Connector port=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"8009"</span> protocol=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"AJP/1.3"</span> redirectPort=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"8443"</span> />
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">...</span>

    <Engine name=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Catalina"</span> defaultHost=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"localhost"</span>>
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">...</span>
      <Host name=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"localhost"</span>  appBase=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/opt/deploy/webapps"</span>
            unpackWARs=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"true"</span> autoDeploy=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"true"</span>>
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">...</span>
      </Host>
    </Engine>
  </Service>
</Server></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li></ul>

上面是裁剪过后的server.xml,分别修改以上三个端口(Server、HTTP、AJP),不要和其它实例的端口或系统已经占用的端口发生冲突。

6、创建实例部署应用的目录

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">shell</span>> mkdir -p /opt/deploy/webapps</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

所有实例的app默认都部署到/opt/deploy/webapps目录下,注意修改server.xml中Host节点的appBase属性的值。

7、启动服务

<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">shell> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/opt/tomcat</span>_instance/tomcat1/bin/startup.sh
shell> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/opt/tomcat</span>_instance/tomcat2/bin/startup.sh
shell> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/opt/tomcat</span>_instance/tomcat2/bin/startup.sh</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

服务器启动之后,会分别在相应的实例目录下生成logs、temp、work和webapps目录。另外也可以在实例目录下创建lib目录,用于存放app的jar。现在来看实例的安装目录,就和tomcat的安装包解压后的目录结构一样了,但所有实例共享同一套tomcat安装程序的bin和lib。后面如果需要升级tomcat或修改tomcat脚本的相关配置,只需要更新这一套程序就行,也方便了日后的维护。tomcat1实例的目录结构如下:

时间: 2024-09-29 10:19:12

Tomcat单机多实例配置的相关文章

学习tomcat之tomcat单机多实例部署

想要获得更多的文章,可以关注我的微信ilanniweb 为了有效的利用服务器的资源,我们现在需要在一台服务器上部署多个tomcat,这也就是我们经常所说的tomcat单机多实例部署. PS:本次实验的测试OS为centos6.5 64bit. 一.配置JAVA_HOME路径 要配置JAVA_HOME路径,我们就要首先安装jdk.jdk的安装在此我们使用的是yum方式,没有使用源码方式安装. 1.1 yum安装jdk jdk我们现在是使用的yum方式进行安装的,首先我们先来查看能够安装的jdk版本

RabbitMQ单机多实例配置

由于某些因素的限制,有时候你不得不在一台机器上去搭建一个rabbitmq集群,当然这种集群只适合自己玩玩,验证下结论,这个有点类似zookeeper的单机版.真实生成环境还是要配成多机集群的.有关怎么配置多机集群的可以参考其他的资料,这里主要论述如何在单机中配置多个rabbitmq实例. 主要参考官方文档:https://www.rabbitmq.com/clustering.html 前提 配置的前提是你的rabbitmq可以运行起来,比如"ps aux|grep rabbitmq"

MySQL单机多实例方案部署

MySQL单机多实例方案,是指在一台物理服务器上运行多个MySQL数据库实例. MySQL单机多实例的优点: 1.节省成本,减少服务器.IP.机柜的数量,总体运营成本低于单机单实例方案. 2.提升利用率,利用NUMA特性,对MySQL实例进行CPU绑定. 3.提升用户体验,大幅度提高IO响应时间,有助于提升用户的体验. MySQL多实例部署的具体实施 1.MySQL多实例目录的规划(数据目录配置文件目录) 实例1 数据路径: /home/mysql/data 配置文件路径: /usr/local

PostgreSQL 主机性能测试方法 - 单机单实例

背景 业界有一些通用的数据库性能测试模型,可以用来测试硬件在不同测试模型下的性能表现. 参考http://www.tpc.org/https://github.com/oltpbenchmark/oltpbenchhttp://oltpbenchmark.com/ 本文主要以PostgreSQL为例,向大家介绍一下,如何使用PostgreSQL来测试硬件的性能. PostgreSQL 的功能非常的强大,所以可以适用于几乎所有的测试模型,同时用户还可以根据自己的应用场景设计测试模型. 前面已经介绍

tomcat环境变量详细配置步骤_Tomcat

本文实例为大家分享了tomcat环境变量的配置教程,供大家参考,具体内容如下 1.===> 进入bin目录下,双击startup.bat看是否报错.一般肯定会报.  2.===> 右键我的电脑===>高级===>环境变量   新建一个 变量名为 JAVA_HOME 然后变量值是 你的JDK的bin目录的上一层. 再新建一个 变量名为CATALINA_HOME 变量值是你的Tomcat的bin的目录的上一层.  3.===> 进入Tomcat bin目录下  双击shutdow

Corosync+Pacemaker+DRBD+NFS高可用实例配置

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://koumm.blog.51cto.com/703525/1738795 环境说明:     操作系统: CentOS 6.6 x64,本文采用rpm方式安装corosync+pacemaker+drbd+nfs.  本文与上文配置进行了一个对比,实现相同的功能,具体哪个好,还是根据需求以及对哪个方案理解比较透,Heartbeat+DRBD+NFS高可用实例配置http://kou

如何进行J2SDK和TOMCAT的安装及配置

经常看到jsp的初学者问tomcat下如何配置jsp.servlet的问题,于是总结了一下如何tomcat下配置jsp.servlet,希望对那些初学者有所帮助. 第一步:下载j2sdk和tomcat:到sun官方站点下载最新的jdk为1.5,tomcat为5.5,建议jdk1.4以上,tomcat4.0以上. 第二步:安装和配置你的j2sdk和tomcat:执行j2sdk和tomcat的安装程序,然后设置按照路径进行安装即可. 1.安装j2sdk以后,需要配置一下环境变量,在我的电脑->属性-

Tomcat 5.5.x 配置集锦 (续)

接 : Tomcat 5.5.x 配置集锦(x表示4,5,.6,7) 12.如果你的webapp需要只能够进行https方式访问,那么在webapp的web.xml里加上: <security-constraint>  <web-resource-collection>   <web-resource-name>must https</web-resource-name>   <url-pattern>/lizongbo/*</url-pa

jsp+tomcat+mssql系统的配置

js jsp+tomcat+mssql系统的配置程序说明:使用数据库为sqlserver,开发语言java.1 创建数据库:1.1 启动sqlserver,1.2 运行企业管理器.1.3 创建childrenbooks数据库,1.4 物理数据库名1.5 称:childrenbooks_Data.MDF,1.6 数据库日志:childrenbooks_Log.LDF:保存在实践目录下.1.7 创建表:user_table (idx为主键)idx int 4 非空 主键user_id char 16