标签:源码 方式 127.0.0.1 dir 生产 单实例 内存 add 说明
Tomcat 的基本组成
tomcat的单实例部署见https://www.cnblogs.com/liliyang/p/9742284.html
安装好之后,看下目录结构:
[root@docker121 tomcat]# ll total 96 drwxr-xr-x 2 root root 4096 Aug 28 00:08 bin drwxr-xr-x 3 root root 198 Oct 5 12:30 conf drwxr-xr-x 2 root root 4096 Aug 27 22:32 lib -rw-r--r-- 1 root root 57011 Dec 1 2017 LICENSE drwxr-xr-x 2 root root 4096 Oct 5 00:11 logs -rw-r--r-- 1 root root 1444 Dec 1 2017 NOTICE -rw-r--r-- 1 root root 6792 Dec 1 2017 RELEASE-NOTES -rw-r--r-- 1 root root 16242 Dec 1 2017 RUNNING.txt drwxr-xr-x 3 root root 49 Oct 5 00:19 temp drwxr-xr-x 10 root root 162 Oct 4 22:11 webapps drwxr-xr-x 3 root root 22 Aug 27 22:35 work
再介绍一下各个目录及文件:
上面是Tomcat安装后的组成部分,进入bin目录执行startup.sh或catalina.sh start 就可以了,接着就可以在浏览器输入http://localhost:8080/访问了。
那么问题来了:当你有了三个、五个以及十个应用服务需要同时部署到同一台服务器上时,你的 Tomcat 服务正确启动方式是什么?是把上面文件全部复制出 N 多个目录么?还是有其他处理方式呢?
Tomcat 常见的几种部署场景
通常,我们在同一台服务器上对Tomcat部署需求可以分为以下几种:单实例单应用,单实例多应用,多实例单应用,多实例多应用。
实例的概念可以理解为上面说的一个Tomcat目录。
本文要说的就是这种多实例多应用方式,但多个 Tomcat 就是简单的复制出一个新的 Tomcat 目录后改一下端口么?当然不是,其实真这么做也可以,当当同一台服务器部署了多个不同基于 Tomcat 的 Web 服务时,会遇到下面几个极其现实的问题。
当然,好像上面的都不是很重要,注意,划重点,多实例部署最大作用就是最大化利用服务器资源。
官方文档:
不建议复制一个又一份的全部 Tomcat 目录进行多实例的部署,说安照下图可以实现更优雅的 Tomcat 单机多实例部署:
CATALINA_HOME指Tomcat安装路径,CATALINA_BASE指实例所在位置。
CATALINA_HOME路径下只需要包含bin和lib目录,
CATALINA_BASE只存放conf、webapps、logs等这些文件
这样部署的好处在于升级方便,配置及安装文件间互不影响,在不影响Tomcat实例的前提下,替换掉CATALINA_HOME中的安装文件。
主机地址:10.0.0.125
环境:CentOS 7.x
1、安装JDK,见https://www.cnblogs.com/liliyang/p/9742284.html
2、部署tomcat,按照单实例部署
mkdir -p /application/tomcat-8.5.31
cd /application/
下载或上传tomcat源码包
tar xvf apache-tomcat-8.5.31.tar.gz
mv apache-tomcat-8.5.31/* /application/tomcat-8.5.31/
ln -s tomcat-8.5.31/ tomcat
echo ‘export CATALINA_HOME="/application/tomcat"‘ >> /etc/profile
echo ‘export PATH="${CATALINA_HOME}/bin:${PATH}"‘ >> /etc/profile
source /etc/profile
cd tomcat
mkdir tomcat-01
mv conf/ LICENSE logs/ NOTICE RELEASE-NOTES RUNNING.txt temp/ webapps/ work/ tomcat-01
cp -a tomcat-01/ tomcat-02
[root@sample tomcat]# ll total 8 drwxr-x--- 2 root root 4096 Oct 5 03:55 bin drwxr-x--- 2 root root 4096 Oct 5 03:55 lib drwxr-xr-x 7 root root 138 Oct 5 03:59 tomcat-01 drwxr-xr-x 7 root root 138 Oct 5 03:59 tomcat-02 [root@sample tomcat]# ll tomcat-01 total 84 drwx------ 2 root root 238 Apr 27 16:26 conf -rw-r----- 1 root root 57092 Apr 27 16:26 LICENSE drwxr-x--- 2 root root 6 Apr 27 16:24 logs -rw-r----- 1 root root 1723 Apr 27 16:26 NOTICE -rw-r----- 1 root root 7138 Apr 27 16:26 RELEASE-NOTES -rw-r----- 1 root root 16246 Apr 27 16:26 RUNNING.txt drwxr-x--- 2 root root 30 Oct 5 03:55 temp drwxr-x--- 7 root root 81 Apr 27 16:24 webapps drwxr-x--- 2 root root 6 Apr 27 16:24 work [root@sample tomcat]# ll tomcat-02 total 84 drwx------ 2 root root 238 Apr 27 16:26 conf -rw-r----- 1 root root 57092 Apr 27 16:26 LICENSE drwxr-x--- 2 root root 6 Apr 27 16:24 logs -rw-r----- 1 root root 1723 Apr 27 16:26 NOTICE -rw-r----- 1 root root 7138 Apr 27 16:26 RELEASE-NOTES -rw-r----- 1 root root 16246 Apr 27 16:26 RUNNING.txt drwxr-x--- 2 root root 30 Oct 5 03:55 temp drwxr-x--- 7 root root 81 Apr 27 16:24 webapps drwxr-x--- 2 root root 6 Apr 27 16:24 work
3、新建 Tomcat 启动、停止脚本
注意:多实例启停脚本中必须设定CATALINA_BASE变量
mkdir -p /application/tomcat/tomcat-shell/
cd /application/tomcat/tomcat-shell/
cat >> start-tomcat01.sh <<end
#!/bin/bash
export CATALINA_BASE="/application/tomcat/tomcat-01"
export CATALINA_HOME="/application/tomcat"
/application/tomcat/bin/catalina.sh start
end
cat >> stop-tomcat01.sh <<end
#!/bin/bash
export CATALINA_BASE="/application/tomcat/tomcat-01"
export CATALINA_HOME="/application/tomcat"
/application/tomcat/bin/catalina.sh stop
end
cat >> start-tomcat02.sh <<end
#!/bin/bash
export CATALINA_BASE="/application/tomcat/tomcat-02"
export CATALINA_HOME="/application/tomcat"
/application/tomcat/bin/catalina.sh start
end
cat >> stop-tomcat02.sh <<end
#!/bin/bash
export CATALINA_BASE="/application/tomcat/tomcat-02"
export CATALINA_HOME="/application/tomcat"
/application/tomcat/bin/catalina.sh stop
end
[root@sample tomcat-shell]# ll total 16 -rw-r--r-- 1 root root 128 Oct 5 04:15 start-tomcat01.sh -rw-r--r-- 1 root root 128 Oct 5 04:15 start-tomcat02.sh -rw-r--r-- 1 root root 127 Oct 5 04:17 stop-tomcat01.sh -rw-r--r-- 1 root root 127 Oct 5 04:17 stop-tomcat02.sh
修改实例2服务的启动端口
cd ../tomcat-02/conf/
修改server.xml文件,将其中的服务端口(默认8005)、2个连接器端口(默认8080和8009)及转发端口(默认8443)全部修改,避免和tomcat01实例冲突
cd ../webapps/ROOT/
cat >>index.html<<end
<html>
<title>Tomcat-02</title>
<body>
This is from tomcat-02.
</body>
</html>
end
cat >>/application/tomcat/tomcat-01/webapps/ROOT/index.html<<end
<html>
<title>Tomcat-01</title>
<body>
This is from tomcat-01.
</body>
</html>
end
chmod +x /application/tomcat/tomcat-shell/*
启动测试:
[root@sample tomcat-shell]# /application/tomcat/tomcat-shell/start-tomcat01.sh Using CATALINA_BASE: /application/tomcat/tomcat-01 Using CATALINA_HOME: /application/tomcat Using CATALINA_TMPDIR: /application/tomcat/tomcat-01/temp Using JRE_HOME: /application/jdk/jre Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar Tomcat started. [root@sample tomcat-shell]# /application/tomcat/tomcat-shell/start-tomcat02.sh Using CATALINA_BASE: /application/tomcat/tomcat-02 Using CATALINA_HOME: /application/tomcat Using CATALINA_TMPDIR: /application/tomcat/tomcat-02/temp Using JRE_HOME: /application/jdk/jre Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar Tomcat started. [root@sample tomcat-shell]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN 24892/python3 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 19441/sshd tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 24892/python3 tcp6 0 0 :::8080 :::* LISTEN 96531/java tcp6 0 0 :::8081 :::* LISTEN 96583/java tcp6 0 0 :::22 :::* LISTEN 19441/sshd tcp6 0 0 127.0.0.1:8005 :::* LISTEN 96531/java tcp6 0 0 127.0.0.1:8006 :::* LISTEN 96583/java tcp6 0 0 :::8009 :::* LISTEN 96531/java tcp6 0 0 :::8010 :::* LISTEN 96583/java
停止:
[root@sample tomcat-shell]# /application/tomcat/tomcat-shell/stop-tomcat01.sh Using CATALINA_BASE: /application/tomcat/tomcat-01 Using CATALINA_HOME: /application/tomcat Using CATALINA_TMPDIR: /application/tomcat/tomcat-01/temp Using JRE_HOME: /application/jdk/jre Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar [root@sample tomcat-shell]# /application/tomcat/tomcat-shell/stop-tomcat02.sh Using CATALINA_BASE: /application/tomcat/tomcat-02 Using CATALINA_HOME: /application/tomcat Using CATALINA_TMPDIR: /application/tomcat/tomcat-02/temp Using JRE_HOME: /application/jdk/jre Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar [root@sample tomcat-shell]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN 24892/python3 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 19441/sshd tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 24892/python3 tcp6 0 0 :::22 :::* LISTEN 19441/sshd
标签:源码 方式 127.0.0.1 dir 生产 单实例 内存 add 说明
原文地址:https://www.cnblogs.com/liliyang/p/9745282.html