#Tomcat學習(3)#Tomcat多例項配置和反向代理叢集配置
Tomcat多例項配置多例項(多程式)
:同一個程式啟動多次,分為兩種情況:
第一種:一臺機器跑多個站點;
第二種:一個機器跑一個站點多個例項,配合負載均衡
1、複製程式檔案
[root@localhost ~]# cd /usr/local
[root@localhost local]# cp -r tomcat/ tomcat_2
[root@localhost local]# ls
bin games java lib64 sbin src tomcat_2
etc include lib libexec share tomcat
修改埠,以啟動多例項。多例項之間埠不能一致
[root@localhost local]# sed -i 's#8005#8011#;s#8080#8081#' tomcat/conf/server.xml
[root@localhost local]# sed -i 's#8005#8012#;s#8080#8082#' tomcat_2/conf/server.xml
[root@localhost local]# sed -i 's#8009#8019#' tomcat/conf/server.xml
[root@localhost local]# sed -i 's#8009#8029#' tomcat_2/conf/server.xml
[root@localhost local]# diff tomcat/conf/server.xml tomcat_2/conf/server.xml
#對比檔案不同之處
22c22
< <Server port="8011" shutdown="SHUTDOWN">
---
> <Server port="8012" shutdown="SHUTDOWN">
67c67
< Define a non-SSL/TLS HTTP/1.1 Connector on port 8081
---
> Define a non-SSL/TLS HTTP/1.1 Connector on port 8082
69c69
< <Connector port="8081" protocol="HTTP/1.1"
---
> <Connector port="8082" protocol="HTTP/1.1"
75c75
< port="8081" protocol="HTTP/1.1"
---
> port="8082" protocol="HTTP/1.1"
115,116c115,116
< <!-- Define an AJP 1.3 Connector on port 8019 -->
< <Connector port="8019" protocol="AJP/1.3" redirectPort="8443" />
---
> <!-- Define an AJP 1.3 Connector on port 8029 -->
> <Connector port="8029" protocol="AJP/1.3" redirectPort="8443" />
啟動tomcat多例項
修改兩臺tomcat主頁標頭檔案資訊,便於區分
[root@localhost local]# vim tomcat/webapps/ROOT/index.jsp
[root@localhost local]# vim tomcat_2/webapps/ROOT/index.jsp
啟動配置如下:
[root@localhosts local]# cd /usr/local/tomcat/bin/
[root@localhosts bin]# vim start.sh
#!/bin/bash
#tomcat
export CATALINA_BASE="/usr/local/tomcat"
case "$1" in
start)
$CATALINA_BASE/bin/startup.sh
;;
stop)
$CATALINA_BASE/bin/shutdown.sh
esac
[root@localhost bin]# chmod +x start.sh
#修改catalina.sh ---新增如下內容
[root@localhost bin]# vim catalina.sh
CATALINA_HOME=/usr/local/tomcat #新增的環境變數注意修改
----------------------------------------------------------
[root@localhost bin]# cd /usr/local/tomcat_2/bin/
[root@localhost bin]# vim start.sh
#!/bin/bash
#tomcat
export CATALINA_BASE="/usr/local/tomcat"
case "$1" in
start)
$CATALINA_BASE/bin/startup.sh
;;
stop)
$CATALINA_BASE/bin/shutdown.sh
esac
[root@localhost bin]# chmod +x start.sh
[root@localhost bin]# vim catalina.sh
CATALINA_HOME=/usr/local/tomcat_2
# 如果多例項部署使用JDK版本不同,修改catalina.sh再這裡定義java
JAVA_HOME=
JRE_HOME=
啟動:
[root@localhost ~]# /usr/local/tomcat/bin/start.sh start
[root@localhost ~]# /usr/local/tomcat_2/bin/start.sh start
檢查埠檢視是否啟動:
[root@localhost local]# 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
2、在瀏覽器訪問,進行測試
檢查多例項的啟動
http://192.168.204.131:8081
http://192.168.204.131: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]# vim default.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.204.131:8081 weight=1 max_fails=1 fail_timeout=2s;
server 192.168.204.131:8082 weight=1 max_fails=1 fail_timeout=2s;
}
啟動nginx
[root@nginx-proxy ~]# systemctl start nginx
3、使用命令進行訪問測試
使用curl 命令進行測試,tail進行關鍵字提取
[root@nginx-proxy ~]# curl -s 192.168.204.134 | tail -1
8082
[root@nginx-proxy ~]# curl -s 192.168.204.134 | tail -1
8081
4、在瀏覽器上進行訪問測試
#使用負載均衡器那臺的ip進行訪問
http://192.168.204.134
相關文章
- tomcat 配置nginx 反向代理TomcatNginx
- 構建一機多例項tomcat叢集Tomcat
- NGINX生產環境反向代理到後端tomcat配置Nginx後端Tomcat
- tomcat配置Tomcat
- Nginx學習筆記(反向代理&搭建叢集)Nginx筆記
- Linux配置jdk和tomcatLinuxJDKTomcat
- Nginx正向代理和反向代理配置Nginx
- centos7下配置nginx反向代理負載均衡叢集CentOSNginx負載
- MySQL多例項配置MySql
- Tomcat安全配置Tomcat
- 注意這幾點,輕輕鬆鬆配置 Nginx + Tomcat 的叢集和負載均衡NginxTomcat負載
- Nginx 配置:反向代理Nginx
- Nginx 配置反向代理Nginx
- Spring Boot 學習系列(11)—tomcat引數配置建Spring BootTomcat
- MySQL 多例項配置管理:MySql
- 配置Tomcat伺服器Tomcat伺服器
- Springboot整合外部Tomcat配置Spring BootTomcat
- spring boot 配置外接tomcatSpring BootTomcat
- linux下tomcat安全配置LinuxTomcat
- tomcat 配置根路徑Tomcat
- SpringBoot中配置外部TomcatSpring BootTomcat
- SpringBoot 之配置外部TomcatSpring BootTomcat
- Tomcat常用優化配置Tomcat優化
- 寶塔反向代理配置
- history 模式反向代理配置模式
- 什麼是Tomcat? 如何在IDEA中配置Tomcat?TomcatIdea
- Nginx之路--配置正向代理、反向代理Nginx
- Linux安裝和配置tomcat詳細教程LinuxTomcat
- 02 eclipse中配置Web專案(含eclipse基本配置和Tomcat的配置)EclipseWebTomcat
- Tomcat配置Gizp 客戶端使用okHttp3Tomcat客戶端HTTP
- 快速實現 Tomcat 叢集 Session 共享TomcatSession
- Tomcat修改記憶體配置Tomcat記憶體
- tomcat網頁壓縮配置Tomcat網頁
- JDK Tomcat MySQL環境配置JDKTomcatMySql
- windows下Tomcat安裝配置WindowsTomcat
- nginx多站路由配置tomcatNginx路由Tomcat
- JAVA TOMCAT域名解析配置JavaTomcat
- CentOS下tomcat安裝配置CentOSTomcat