目录
Tomcat多实例配置
1.首先配置Tomcat单实例
2.tomcat多实例配置
1.1复制单实例tomcat
1.2修改端口,以启动多实例。多实例之间端口不能一致
1.3对比文件不同之处
3.启动tomcat
4.检查端口查看是否启动:
5.测试浏览器访问
二、tomcat反向代理集群
1、负载均衡器说明
2、配置负载均衡器
3.启动nginx
4.使用命令进行访问测试
5.、在浏览器上进行访问测试
Tomcat多实例配置
多实例(多进程):同一个程序启动多次,分为两种情况:
第一种:一台机器跑多个站点;
第二种:一个机器跑一个站点多个实例,配合负载均衡
1.首先配置Tomcat单实例
单实例配置参考博主博客
部署TOMCAT详解-CSDN博客
2.tomcat多实例配置
1.1复制单实例tomcat
[root@java-tomcat1 application]# cp -r tomcat/ tomcat2
[root@java-tomcat1 application]# cp -r tomcat/ tomcat3
1.2修改端口,以启动多实例。多实例之间端口不能一致
[root@java-tomcat1 application]# sed -i 's#8005#8011#;s#8080#8081#' tomcat2/conf/server.xml
[root@java-tomcat1 application]# sed -i 's#8005#8012#;s#8080#8082#' tomcat3/conf/server.xml
1.3对比文件不同之处
[root@java-tomcat1 application]# diff tomcat2/conf/server.xml tomcat3/conf/server.xml
3.启动tomcat
[root@java-tomcat2 application]# cd /data/application/tomcat2/bin/
[root@java-tomcat2 bin]# vim start.sh
#!/bin/bash
#tomcat2
export CATALINA_BASE="/data/application/tomcat2"
case "$1" in
start)
$CATALINA_BASE/bin/startup.sh
;;
stop)
$CATALINA_BASE/bin/shutdown.sh
esac
[root@java-tomcat2 bin]# chmod +x start
#修改catalina.sh ---添加如下内容
[root@java-tomcat2 bin]# vim catalina.sh
CATALINA_HOME=/data/application/tomcat2 #添加的环境变量注意修改
[root@java-tomcat bin]# cd /data/application/tomcat3/bin/
[root@java-tomcat3 bin]# vim start.sh
#!/bin/bash
#tomcat3
export CATALINA_BASE="/data/application/tomcat3"
case "$1" in
start)
$CATALINA_BASE/bin/startup.sh
;;
stop)
$CATALINA_BASE/bin/shutdown.sh
esac
[root@java-tomcat3 bin]# chmod +x start.sh
[root@java-tomcat3 bin]# vim catalina.sh
CATALINA_HOME=/data/application/tomcat3
启动:
[root@java-tomcat2 ~]# /data/application/tomcat2/bin/start.sh start
[root@java-tomcat2 ~]# /data/application/tomcat3/bin/start.sh start
4.检查端口查看是否启动:
[root@java-tomcat1 application]# netstat -lntp | grep java
tcp6 0 0 127.0.0.1:8011 :::* LISTEN 1729/java
tcp6 0 0 127.0.0.1:8012 :::* LISTEN 1783/java
tcp6 0 0 :::8081 :::* LISTEN 1729/java
tcp6 0 0 :::8082 :::* LISTEN 1783/java
tcp6 0 0 :::8019 :::* LISTEN 1729/java
tcp6 0 0 :::8029 :::* LISTEN 1783/java
5.测试浏览器访问
http://192.168.50.114:8081/
http://192.168.50.114:8082/
二、tomcat反向代理集群
1、负载均衡器说明
关闭防火墙和selinux
yum安装nginx
[root@nginx-proxy ~]# cd /etc/yum.repos.d/
[root@nginx-proxy yum.repos.d]# vim nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
[root@nginx-proxy yum.repos.d]# yum install yum-utils -y
[root@nginx-proxy yum.repos.d]# yum install nginx -y
2、配置负载均衡器
备份原配置文件并修改
[root@nginx-proxy ~]# cd /etc/nginx/conf.d/
[root@nginx-proxy conf.d]# cp default.conf default.conf.bak
[root@nginx-proxy conf.d]# mv default.conf tomcat.conf
[root@nginx-proxy conf.d]# vim tomcat.conf
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/proxy.access.log main;
location / {
proxy_pass http://testweb;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
创建upstream配置文件:
[root@nginx-proxy conf.d]# vim upstream.conf
upstream testweb {
server 192.168.50.114:8081 weight=1 max_fails=1 fail_timeout=2s;
server 192.168.50.114:8082 weight=1 max_fails=1 fail_timeout=2s;
}
3.启动nginx
[root@nginx-proxy ~]# systemctl start nginx
4.使用命令进行访问测试
使用curl 命令进行测试,tail进行关键字提取
[root@nginx-proxy ~]# curl -s 192.168.50.118 | tail -1
8082
[root@nginx-proxy ~]# curl -s 192.168.50.118 | tail -1
8081
5.、在浏览器上进行访问测试
http://192.168.50.118/
http://192.168.50.118/