Tomcat多实例部署
安装jdk
[ root@localhost ~]
[ root@localhost ~]
[ root@localhost ~]
[ root@localhost opt]
apache-tomcat-8.5.16.tar.gz jdk-8u91-linux-x64.tar.gz rh
[ root@localhost opt]
[ root@localhost opt]
apache-tomcat-8.5.16.tar.gz jdk1.8.0_91 jdk-8u91-linux-x64.tar.gz rh
[ root@localhost opt]
jdk1.8.0_91/ jdk-8u91-linux-x64.tar.gz
[ root@localhost opt]
[ root@localhost opt]
bin etc games include jdk1.8.0_91 lib lib64 libexec sbin share src
[ root@localhost opt]
[ root@localhost profile.d]
256term.csh colorgrep.csh flatpak.sh less.sh vte.sh
256term.sh colorgrep.sh lang.csh PackageKit.sh which2.csh
abrt-console-notification.sh colorls.csh lang.sh vim.csh which2.sh
bash_completion.sh colorls.sh less.csh vim.sh
[ root@localhost profile.d]
export JAVA_HOME = /usr/local/jdk1.8.0_91
export JRE_HOME = $JAVA_HOME /jre
export CLASSPATH = .:$JAVA_HOME /lib:$JRE_HOME
export PATH = $JAVA_HOME /bin:$JRE_HOME /bin:$PATH [ root@localhost profile.d] 部署Tomcat
[ root@localhost profile.d]
[ root@localhost opt]
apache-tomcat-8.5.16.tar.gz jdk-8u91-linux-x64.tar.gz rh
[ root@localhost opt]
[ root@localhost opt]
apache-tomcat-8.5.16 apache-tomcat-8.5.16.tar.gz jdk-8u91-linux-x64.tar.gz rh
[ root@localhost opt]
[ root@localhost opt]
[ root@localhost opt]
bin games jdk1.8.0_91 lib64 sbin src tomcat2
etc include lib libexec share tomcat1
[ root@localhost opt]
[ root@localhost opt]
[ root@localhost tomcat2]
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[ root@localhost tomcat2]
[ root@localhost bin]
bootstrap.jar configtest.bat setclasspath.sh tomcat-native.tar.gz
catalina.bat configtest.sh shutdown.bat tool-wrapper.bat
catalina.sh daemon.sh shutdown.sh tool-wrapper.sh
catalina-tasks.xml digest.bat startup.bat version.bat
commons-daemon.jar digest.sh startup.sh version.sh
commons-daemon-native.tar.gz setclasspath.bat tomcat-juli.jar[ root@localhost bin]
export CATALINA_BASE = /usr/local/tomcat2
export CATALINA_HOME = /usr/local/tomcat2
export TOMCAT_HOME = /usr/local/tomcat2[ root@localhost bin]
export CATALINA_BASE = /usr/local/tomcat2
export CATALINA_HOME = /usr/local/tomcat2
export TOMCAT_HOME = /usr/local/tomcat2[ root@localhost bin]
[ root@localhost tomcat1]
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[ root@localhost tomcat1]
[ root@localhost bin]
bootstrap.jar configtest.bat setclasspath.sh tomcat-native.tar.gz
catalina.bat configtest.sh shutdown.bat tool-wrapper.bat
catalina.sh daemon.sh shutdown.sh tool-wrapper.sh
catalina-tasks.xml digest.bat startup.bat version.bat
commons-daemon.jar digest.sh startup.sh version.sh
commons-daemon-native.tar.gz setclasspath.bat tomcat-juli.jar
[ root@localhost bin]
export CATALINA_BASE = /usr/local/tomcat1
export CATALINA_HOME = /usr/local/tomcat1
export TOMCAT_HOME = /usr/local/tomcat1
[ root@localhost bin]
export CATALINA_BASE = /usr/local/tomcat1
export CATALINA_HOME = /usr/local/tomcat1
export TOMCAT_HOME = /usr/local/tomcat1[ root@localhost bin]
Using CATALINA_BASE: /usr/local/tomcat1
Using CATALINA_HOME: /usr/local/tomcat1
Using CATALINA_TMPDIR: /usr/local/tomcat1/temp
Using JRE_HOME: /usr/local/jdk1.8.0_91/jre
Using CLASSPATH: /usr/local/tomcat1/bin/bootstrap.jar:/usr/local/tomcat1/bin/tomcat-juli.jar
Tomcat started.
[ root@localhost bin]
Using CATALINA_BASE: /usr/local/tomcat2
Using CATALINA_HOME: /usr/local/tomcat2
Using CATALINA_TMPDIR: /usr/local/tomcat2/temp
Using JRE_HOME: /usr/local/jdk1.8.0_91/jre
Using CLASSPATH: /usr/local/tomcat2/bin/bootstrap.jar:/usr/local/tomcat2/bin/tomcat-juli.jar
Tomcat started.[ root@localhost bin]
tcp6 0 0 :::8080 :::* LISTEN 40828 /java
tcp6 0 0 :::8081 :::* LISTEN 40885 /java
tcp6 0 0 127.0 .0.1:8005 :::* LISTEN 40828 /java
tcp6 0 0 127.0 .0.1:8006 :::* LISTEN 40885 /java
tcp6 0 0 :::8009 :::* LISTEN 40828 /java
tcp6 0 0 :::8010 :::* LISTEN 40885 /java 网页输入http://192.168.65.102:8080http://192.168.65.102:8081都可以出现画面
NGINX+Tomcat负载均衡、动静分离
部署Tomcat页面
Tomcat1
[ root@localhost ~]
[ root@localhost webapps]
docs examples host-manager manager ROOT
[ root@localhost webapps]
[ root@localhost webapps]
[ root@localhost mm]
< %@ page language = "java" import = "java.util.*" pageEncoding = "UTF-8" %>
< html>
< head>
< title> JSP tomcat1 page< /title>
< /head>
< body>
< % out.println( "动态页面 1,Hello Tomcat1" ) ; %>
< /body>
< /html> Tomcat2
[ root@localhost mm]
[ root@localhost webapps]
[ root@localhost webapps]
[ root@localhost webapps]
< %@ page language = "java" import = "java.util.*" pageEncoding = "UTF-8" %>
< html>
< head>
< title> JSP tomcat2 page< /title>
< /head>
< body>
< % out.println( "动态页面 2,Hello Tomcat2" ) ; %>
< /body>
< /html> [ root@www webapps]
[ root@www webapps]
docs examples host-manager manager mm ROOT test1 test2
[ root@www webapps]
[ root@www mm]
< %@ page language = "java" import = "java.util.*" pageEncoding = "UTF-8" %>
< html>
< head>
< title> JSP tomcat3 page< /title>
< /head>
< body>
< % out.println( "动态页面 2,Hello Tomcat3" ) ; %>
< /body>
< /html>
配置NGINX服务
yum安装NGINX
[ root@localhost opt]
[ root@localhost yum.repos.d]
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo[ root@localhost yum.repos.d]
[ root@localhost yum.repos.d]
[ root@localhost yum.repos.d]
repo.bak
[ root@localhost yum.repos.d]
[ nginx]
name = nginx repo
baseurl = http://nginx.org/packages/centos/$releasever /$basearch /
gpgcheck = 1
enabled = 1
gpgkey = https://nginx.org/keys/nginx_signing.key
module_hotfixes = true[ root@localhost yum.repos.d] 验证中 : 1 :nginx-1.24.0-1.el7.ngx.x86_64 1 /1
已安装:nginx.x86_64 1 :1.24.0-1.el7.ngx
完毕!部署NGINX页面
[ root@localhost ~]
[ root@localhost html]
50x.html index.html
[ root@localhost html]
[ root@localhost html]
[ root@localhost html]
[ root@localhost mm]
test.html
实现动静分离
[ root@localhost html]
[ root@localhost nginx] 在 upstream tomcat { server 192.168 .65.101:8080 weight = 1 server 192.168 .65.102:8080 weight = 1 server 192.168 .65.102:8082 weight = 1 } [ root@localhost nginx]
[ root@localhost conf.d]
default.conf
[ root@localhost conf.d]
location ~* .*\ .jsp$ { proxy_pass http://tomcat; proxy_set_header HOST $host ; proxy_set_header X-Real-IP $remote_addr ; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; } [ root@localhost nginx]
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[ root@localhost conf.d]
负载均衡
将192.168.65.104主机的nginx.repo拷贝到192.168.65.103
[ root@localhost ~]
[ root@localhost yum.repos.d]
nginx.repo repo.bak
[ root@localhost yum.repos.d]
The authenticity of host '192.168.65.103 (192.168.65.103)' can't be established.
ECDSA key fingerprint is SHA256:63CrYDGmi+o9Wnfxyu+ceZXb8PaFjKl3Ob3EEWD50ag.
ECDSA key fingerprint is MD5:6e:96:3c:ab:13:8b:b9:d2:cd:34:80:46:3c:52:8e:bc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ' 192.168 .65.103' (ECDSA) to the list of known hosts.
root@192.168.65.103' s password:
nginx.repo 100 % 178 134 .9KB/s 00:00192.168 .65.103
[ root@localhost ~]
[ root@localhost yum.repos.d]
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo epel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo epel-testing.repo
[ root@localhost yum.repos.d]
[ root@localhost yum.repos.d]
[ root@localhost yum.repos.d]
repo.bak
[ root@localhost yum.repos.d]
nginx.repo repo.bak
[ root@localhost yum.repos.d] 验证中 : 1 :nginx-1.24.0-1.el7.ngx.x86_64 1 /1
已安装:nginx.x86_64 1 :1.24.0-1.el7.ngx
完毕!104
[ root@localhost yum.repos.d]
[ root@localhost nginx]
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
[ root@localhost nginx]
root@192.168.65.106's password:
default.conf 100% 1292 324.4KB/s 00:00
nginx.conf 100% 804 630.6KB/s 00:00
[root@localhost nginx]# cd /usr/share/nginx/html/
[root@localhost html]# ls
50x.html index.html mm
[root@localhost html]# vim mm/test.html
<h1>this is nginx static web1 page!</h1>
[root@localhost html]# scp -r mm/ 192.168.65.103:`pwd`
root@192.168.65.106' s password:
test.html 100 % 40 12 .1KB/s 00:00103
[ root@localhost yum.repos.d]
[ root@localhost html]
50x.html index.html mm
[ root@localhost html]
< h1 > this is nginx static web2 page! < /h1 >
[ root@localhost html]
[ root@localhost nginx]
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[ root@localhost nginx] 输入以下网址出现下图
http://192.168.65.103/mm/test.html
http://192.168.65.103/mm/test.jsp
192.168 .65.105
[ root@localhost ~]
[ root@localhost opt]
nginx-1.18.0 .tar.gz rh
[ root@localhost opt]
[ root@localhost opt]
[ root@localhost opt]
nginx-1.18.0 nginx-1.18.0 .tar.gz rh
[ root@localhost opt]
[ root@localhost nginx-1.18.0]
> --user = nginx \
> --group = nginx \
> --with-http_stub_status_module \
> --with-stream
[ root@localhost nginx-1.18.0]
[ root@localhost conf]
[ root@localhost nginx]
conf html logs sbin
[ root@localhost nginx]
[ root@localhost conf]
fastcgi.conf koi-utf nginx.conf uwsgi_params
fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
fastcgi_params mime.types scgi_params win-utf
fastcgi_params.default mime.types.default scgi_params.default
[ root@localhost conf]
在http上一行添加
stream { upstream nginx_server{ server 192.168 .65.103:80; server 192.168 .65.104:80; } server { listen 80 ; proxy_pass nginx_server; }
}
下边的80监听端口改为8333
[ root@localhost conf]
[ root@localhost nginx]
[ root@localhost sbin]
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[ root@localhost sbin]
[ root@localhost sbin]
tcp 0 0 0.0 .0.0:8333 0.0 .0.0:* LISTEN 5480 /nginx: master
tcp 0 0 0.0 .0.0:80 0.0 .0.0:* LISTEN 5480 /nginx: master
[ root@localhost sbin]
[ root@localhost nginx]
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
[ root@localhost nginx]
[ root@localhost conf]
fastcgi.conf koi-utf nginx.conf uwsgi_params
fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
fastcgi_params mime.types scgi_params win-utf
fastcgi_params.default mime.types.default scgi_params.default
[ root@localhost conf]
keepalive_timeout 0 ;
[ root@localhost conf]
105 未设置页面,但是可以访问其他的静态和动态页面