更新 Web容器-tomcat.md
This commit is contained in:
parent
ea692952e8
commit
3e22b88375
576
Web容器-tomcat.md
576
Web容器-tomcat.md
@ -1,288 +1,288 @@
|
||||
<h2><center>Tomcat</center></h2>
|
||||
|
||||
------
|
||||
|
||||
## 一:Tomcat 简介
|
||||
|
||||
### 1. 简介
|
||||
|
||||

|
||||
|
||||
Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目
|
||||
|
||||
Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器
|
||||
|
||||
Tomcat是WEB容器/WEB中间件
|
||||
|
||||
Tomcat官网:https://tomcat.apache.org/
|
||||
|
||||
### 2. 端口
|
||||
|
||||
- Tomcat自身服务的端口:8005
|
||||
- Tomcat和其他应用通信的端口:8009
|
||||
- Tomcat给客户端浏览器访问页面使用的端口:8080
|
||||
|
||||
### 3. 运行环境
|
||||
|
||||
JDK是 Java 语言的软件开发工具包
|
||||
|
||||
JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具
|
||||
|
||||
Tomcat运行需要JDK
|
||||
|
||||
## 二:Tomcat 安装
|
||||
|
||||
### 1. 下载
|
||||
|
||||
访问官方网站:[Apache Tomcat® - Welcome!](https://tomcat.apache.org/)
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# wget https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.59/bin/apache-tomcat-7.0.59.tar.gz
|
||||
```
|
||||
|
||||
### 2. 安装
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# tar xf apache-tomcat-7.0.59.tar.gz -C /usr/local/
|
||||
[root@tomcat ~]# tar xf jdk-8u211-linux-x64.tar.gz -C /usr/local/
|
||||
[root@tomcat ~]# ln -s /usr/local/jdk1.8.0_211 /usr/local/java
|
||||
[root@tomcat ~]# ln -s /usr/local/apache-tomcat-7.0.59 /usr/local/tomcat
|
||||
```
|
||||
|
||||
### 3. 环境变量
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# vim /etc/profile
|
||||
JAVA_HOME=/usr/local/java
|
||||
PATH=$JAVA_HOME/bin:$PATH
|
||||
export JAVA_HOME PATH
|
||||
[root@tomcat ~]# source /etc/profile
|
||||
```
|
||||
|
||||
### 4. 检查
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# java -version
|
||||
java version "1.8.0_211"
|
||||
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
|
||||
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
|
||||
```
|
||||
|
||||
### 5. 启动 Tomcat
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# /usr/local/tomcat/bin/startup.sh
|
||||
```
|
||||
|
||||
### 6. 管理方式
|
||||
|
||||
```shell
|
||||
启动tomcat的方法:
|
||||
1.直接执行/usr/local/tomcat/bin/startup.sh
|
||||
2.直接执行/usr/local/tomcat/bin/catalina.sh start
|
||||
关闭tomcat的方法:
|
||||
1.直接执行/usr/local/tomcat/bin/shutdown.sh
|
||||
2.直接执行/usr/local/tomcat/bin/catalina.sh stop
|
||||
```
|
||||
|
||||
### 7. 检测
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# netstat -tnlp | grep java
|
||||
tcp6 0 0 :::8080 :::* LISTEN 2838/java
|
||||
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2838/java
|
||||
tcp6 0 0 :::8009 :::* LISTEN 2838/java
|
||||
```
|
||||
|
||||
### 8. 测试
|
||||
|
||||
IP+端口访问
|
||||
|
||||
### 9. Tomcat 目录
|
||||
|
||||
Tomcat主目录介绍
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# cd /usr/local/tomcat/
|
||||
[root@tomcat tomcat]# tree -L 1
|
||||
.
|
||||
├── bin # 存放tomcat的管理脚本(二进制文件)
|
||||
├── conf # tomcat的配置文件(server.xml)
|
||||
├── lib # web应用调用的jar包存放路径
|
||||
├── LICENSE
|
||||
├── logs # tomcat日志存放目录
|
||||
├── NOTICE
|
||||
├── RELEASE-NOTES
|
||||
├── RUNNING.txt
|
||||
├── temp # 存放临时文件
|
||||
├── webapps # 默认网站发布目录
|
||||
└── work # 存放编译生产的.java与.class文件
|
||||
|
||||
7 directories, 4 files
|
||||
```
|
||||
|
||||
Webapps目录介绍
|
||||
|
||||
```bash
|
||||
[root@tomcat tomcat]# cd webapps/
|
||||
[root@tomcat webapps]# tree -L 1
|
||||
.
|
||||
├── docs # tomcat的帮助文档
|
||||
├── examples # web应用实例
|
||||
├── host-manager # 主机管理
|
||||
├── manager # 管理
|
||||
└── ROOT # 默认站点根目录
|
||||
|
||||
5 directories, 0 files
|
||||
```
|
||||
|
||||
Tomcat配置文件目录介绍
|
||||
|
||||
```bash
|
||||
[root@tomcat webapps]# cd ../conf/
|
||||
[root@tomcat conf]# tree -L 1
|
||||
.
|
||||
├── Catalina
|
||||
├── catalina.policy
|
||||
├── catalina.properties
|
||||
├── context.xml
|
||||
├── logging.properties
|
||||
├── server.xml # tomcat 主配置文件
|
||||
├── tomcat-users.xml # tomcat 管理用户配置文件
|
||||
└── web.xml
|
||||
|
||||
1 directory, 7 files
|
||||
```
|
||||
|
||||
## 三:Tomcat 扩展
|
||||
|
||||
### 1. Tomcat 配置文件
|
||||
|
||||
- server.xml: Tomcat的主配置文件,包含Service, Connector, Engine, Realm, Valve, Hosts主组件的相关配置信息;
|
||||
- web.xml:遵循Servlet规范标准的配置文件,用于配置servlet,并为所有的Web应用程序提供包括MIME映射等默认配置信息;
|
||||
- tomcat-user.xml:Realm认证时用到的相关角色、用户和密码等信息;
|
||||
- catalina.policy:Java相关的安全策略配置文件,在系统资源级别上提供访问控制的能力;
|
||||
- catalina.properties:Tomcat内部package的定义及访问相关的控制,也包括对通过类装载器装载的内容的控制;
|
||||
- logging.properties: Tomcat6通过自己内部实现的JAVA日志记录器来记录操作相关的日志;
|
||||
- context.xml:所有host的默认配置信息;
|
||||
|
||||
### 2. Tomcat 管理
|
||||
|
||||
```bash
|
||||
1.编辑一个文件tomcat
|
||||
[root@tomcat ~]# vim tomcat
|
||||
#!/bin/bash
|
||||
bash /usr/local/tomcat/bin/catalina.sh $1
|
||||
|
||||
2.给tomcat文件加执行权限
|
||||
|
||||
[root@tomcat ~]# chmod a+x tomcat
|
||||
|
||||
3.把tomcat放到/usr/bin目录下
|
||||
|
||||
[root@tomcat ~]# mv tomcat /usr/bin
|
||||
|
||||
4.使用
|
||||
|
||||
[root@tomcat ~]# tomcat stop 停止
|
||||
[root@tomcat ~]# tomcat start 启动
|
||||
```
|
||||
|
||||
## 四:Tomcat 日志管理
|
||||
|
||||
### 1. 日志
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# cd /usr/local/tomcat/conf/
|
||||
[root@tomcat conf]# vim server.xml
|
||||
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
|
||||
prefix="localhost_access_log." suffix=".txt"
|
||||
pattern="%h %l %u %t "%r" %s %b" />
|
||||
```
|
||||
|
||||
日志格式参数文件:https://tomcat.apache.org/tomcat-8.5-doc/config/valve.html#Access_Logging
|
||||
|
||||
### 2. JVM 参数优化
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# cd /usr/local/tomcat/bin/
|
||||
[root@tomcat bin]# vim catalina.sh
|
||||
JAVA_OPTS="$JAVA_OPTS -Xms4096m -Xmx4096m -XX:PermSize=1024m -XX:MaxPermSize=2048m"
|
||||
```
|
||||
|
||||
设置初始堆、非堆内存大小以及年轻代
|
||||
|
||||
```shell
|
||||
-Xms50m -Xmx200m -XX:PermSize=30m -XX:MaxPermSize=60m
|
||||
-Xloggc:eclipse_gc.log (设置垃圾回收日志打印的文件,文件名称可以自定义)
|
||||
-XX:+PrintGCTimeStamps (打印垃圾回收时间信息时的时间格式)
|
||||
-XX:+PrintGCDetails (打印垃圾回收详情)
|
||||
-XX:PermSize:设置永久代(perm gen)初始值。默认值为物理内存的1/64。
|
||||
-XX:MaxPermSize:设置持久代最大值。物理内存的1/4。
|
||||
-Xms:初始堆大小,默认为物理内存的1/64(<1GB)
|
||||
-Xmx:最大堆大小
|
||||
-Xmn:新生代的内存空间大小
|
||||
```
|
||||
|
||||
### 3. gc 日志
|
||||
|
||||
阅读GC日志,我们可以了解Java虚拟机内存分配与回收策略(开发使用)
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# cd /usr/local/tomcat/bin/
|
||||
[root@tomcat bin]# vim catalina.sh
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails \
|
||||
-XX:+PrintGCDateStamps \
|
||||
-Xloggc:/var/log/tomcat/gc.log \
|
||||
-XX:+UseGCLogFileRotation \
|
||||
-XX:NumberOfGCLogFiles=10 \
|
||||
-XX:GCLogFileSize=100M"
|
||||
```
|
||||
|
||||
参数说明:
|
||||
|
||||
- -XX:+PrintGCDetails:打印详细的GC信息。
|
||||
- -XX:+PrintGCDateStamps:添加日期时间戳。
|
||||
- -Xloggc:/var/log/tomcat/gc.log:指定GC日志文件路径。
|
||||
- -XX:+UseGCLogFileRotation:启用日志轮转。
|
||||
- -XX:NumberOfGCLogFiles=10:保留最多10个日志文件。
|
||||
- -XX:GCLogFileSize=100M":每个日志文件最大100MB。
|
||||
|
||||
## 五:Tomcat 负载均衡
|
||||
|
||||
### Nginx 配置
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# vim /usr/local/nginx/conf/nginx.conf
|
||||
这个地方是 地址池,这里包含了后端服务器的地址和端口,这里的名字随便启。
|
||||
http {
|
||||
upstream tomcat_pool {
|
||||
#ip_hash; 最大失败次数 失败超时时间
|
||||
server 192.168.122.105:8081 weight=1 max_fails=2 fail_timeout=2;
|
||||
server 192.168.122.105:8082 weight=1 max_fails=2 fail_timeout=2;
|
||||
server 192.168.122.105:8083 weight=1 max_fails=2 fail_timeout=2;
|
||||
server 192.168.122.105:8084 weight=1 max_fails=2 fail_timeout=2;
|
||||
}
|
||||
负载均衡的算法: RR round robin session ip_hash 是常用的负载均衡的算法
|
||||
server {
|
||||
location / {
|
||||
proxy_pass http://tomcat_pool;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<h2><center>Tomcat</center></h2>
|
||||
|
||||
------
|
||||
|
||||
## 一:Tomcat 简介
|
||||
|
||||
### 1. 简介
|
||||
|
||||

|
||||
|
||||
Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目
|
||||
|
||||
Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器
|
||||
|
||||
Tomcat是WEB容器/WEB中间件
|
||||
|
||||
Tomcat官网:https://tomcat.apache.org/
|
||||
|
||||
### 2. 端口
|
||||
|
||||
- Tomcat自身服务的端口:8005
|
||||
- Tomcat和其他应用通信的端口:8009
|
||||
- Tomcat给客户端浏览器访问页面使用的端口:8080
|
||||
|
||||
### 3. 运行环境
|
||||
|
||||
JDK是 Java 语言的软件开发工具包
|
||||
|
||||
JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具
|
||||
|
||||
Tomcat运行需要JDK
|
||||
|
||||
## 二:Tomcat 安装
|
||||
|
||||
### 1. 下载
|
||||
|
||||
访问官方网站:[Apache Tomcat® - Welcome!](https://tomcat.apache.org/)
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# wget https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.59/bin/apache-tomcat-7.0.59.tar.gz
|
||||
```
|
||||
|
||||
### 2. 安装
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# tar xf apache-tomcat-7.0.59.tar.gz -C /usr/local/
|
||||
[root@tomcat ~]# tar xf jdk-8u211-linux-x64.tar.gz -C /usr/local/
|
||||
[root@tomcat ~]# ln -s /usr/local/jdk1.8.0_211 /usr/local/java
|
||||
[root@tomcat ~]# ln -s /usr/local/apache-tomcat-7.0.59 /usr/local/tomcat
|
||||
```
|
||||
|
||||
### 3. 环境变量
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# vim /etc/profile
|
||||
JAVA_HOME=/usr/local/java
|
||||
PATH=$JAVA_HOME/bin:$PATH
|
||||
export JAVA_HOME PATH
|
||||
[root@tomcat ~]# source /etc/profile
|
||||
```
|
||||
|
||||
### 4. 检查
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# java -version
|
||||
java version "1.8.0_211"
|
||||
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
|
||||
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
|
||||
```
|
||||
|
||||
### 5. 启动 Tomcat
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# /usr/local/tomcat/bin/startup.sh
|
||||
```
|
||||
|
||||
### 6. 管理方式
|
||||
|
||||
```shell
|
||||
启动tomcat的方法:
|
||||
1.直接执行/usr/local/tomcat/bin/startup.sh
|
||||
2.直接执行/usr/local/tomcat/bin/catalina.sh start
|
||||
关闭tomcat的方法:
|
||||
1.直接执行/usr/local/tomcat/bin/shutdown.sh
|
||||
2.直接执行/usr/local/tomcat/bin/catalina.sh stop
|
||||
```
|
||||
|
||||
### 7. 检测
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# netstat -tnlp | grep java
|
||||
tcp6 0 0 :::8080 :::* LISTEN 2838/java
|
||||
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2838/java
|
||||
tcp6 0 0 :::8009 :::* LISTEN 2838/java
|
||||
```
|
||||
|
||||
### 8. 测试
|
||||
|
||||
IP+端口访问
|
||||
|
||||
### 9. Tomcat 目录
|
||||
|
||||
Tomcat主目录介绍
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# cd /usr/local/tomcat/
|
||||
[root@tomcat tomcat]# tree -L 1
|
||||
.
|
||||
├── bin # 存放tomcat的管理脚本(二进制文件)
|
||||
├── conf # tomcat的配置文件(server.xml)
|
||||
├── lib # web应用调用的jar包存放路径
|
||||
├── LICENSE
|
||||
├── logs # tomcat日志存放目录
|
||||
├── NOTICE
|
||||
├── RELEASE-NOTES
|
||||
├── RUNNING.txt
|
||||
├── temp # 存放临时文件
|
||||
├── webapps # 默认网站发布目录
|
||||
└── work # 存放编译生产的.java与.class文件
|
||||
|
||||
7 directories, 4 files
|
||||
```
|
||||
|
||||
Webapps目录介绍
|
||||
|
||||
```bash
|
||||
[root@tomcat tomcat]# cd webapps/
|
||||
[root@tomcat webapps]# tree -L 1
|
||||
.
|
||||
├── docs # tomcat的帮助文档
|
||||
├── examples # web应用实例
|
||||
├── host-manager # 主机管理
|
||||
├── manager # 管理
|
||||
└── ROOT # 默认站点根目录
|
||||
|
||||
5 directories, 0 files
|
||||
```
|
||||
|
||||
Tomcat配置文件目录介绍
|
||||
|
||||
```bash
|
||||
[root@tomcat webapps]# cd ../conf/
|
||||
[root@tomcat conf]# tree -L 1
|
||||
.
|
||||
├── Catalina
|
||||
├── catalina.policy
|
||||
├── catalina.properties
|
||||
├── context.xml
|
||||
├── logging.properties
|
||||
├── server.xml # tomcat 主配置文件
|
||||
├── tomcat-users.xml # tomcat 管理用户配置文件
|
||||
└── web.xml
|
||||
|
||||
1 directory, 7 files
|
||||
```
|
||||
|
||||
## 三:Tomcat 扩展
|
||||
|
||||
### 1. Tomcat 配置文件
|
||||
|
||||
- server.xml: Tomcat的主配置文件,包含Service, Connector, Engine, Realm, Valve, Hosts主组件的相关配置信息;
|
||||
- web.xml:遵循Servlet规范标准的配置文件,用于配置servlet,并为所有的Web应用程序提供包括MIME映射等默认配置信息;
|
||||
- tomcat-user.xml:Realm认证时用到的相关角色、用户和密码等信息;
|
||||
- catalina.policy:Java相关的安全策略配置文件,在系统资源级别上提供访问控制的能力;
|
||||
- catalina.properties:Tomcat内部package的定义及访问相关的控制,也包括对通过类装载器装载的内容的控制;
|
||||
- logging.properties: Tomcat6通过自己内部实现的JAVA日志记录器来记录操作相关的日志;
|
||||
- context.xml:所有host的默认配置信息;
|
||||
|
||||
### 2. Tomcat 管理
|
||||
|
||||
```bash
|
||||
1.编辑一个文件tomcat
|
||||
[root@tomcat ~]# vim tomcat
|
||||
#!/bin/bash
|
||||
bash /usr/local/tomcat/bin/catalina.sh $1
|
||||
|
||||
2.给tomcat文件加执行权限
|
||||
|
||||
[root@tomcat ~]# chmod a+x tomcat
|
||||
|
||||
3.把tomcat放到/usr/bin目录下
|
||||
|
||||
[root@tomcat ~]# mv tomcat /usr/bin
|
||||
|
||||
4.使用
|
||||
|
||||
[root@tomcat ~]# tomcat stop 停止
|
||||
[root@tomcat ~]# tomcat start 启动
|
||||
```
|
||||
|
||||
## 四:Tomcat 日志管理
|
||||
|
||||
### 1. 日志
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# cd /usr/local/tomcat/conf/
|
||||
[root@tomcat conf]# vim server.xml
|
||||
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
|
||||
prefix="localhost_access_log." suffix=".txt"
|
||||
pattern="%h %l %u %t "%r" %s %b" />
|
||||
```
|
||||
|
||||
日志格式参数文件:https://tomcat.apache.org/tomcat-8.5-doc/config/valve.html#Access_Logging
|
||||
|
||||
### 2. JVM 参数优化
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# cd /usr/local/tomcat/bin/
|
||||
[root@tomcat bin]# vim catalina.sh
|
||||
JAVA_OPTS="$JAVA_OPTS -Xms4096m -Xmx4096m -XX:PermSize=1024m -XX:MaxPermSize=2048m"
|
||||
```
|
||||
|
||||
设置初始堆、非堆内存大小以及年轻代
|
||||
|
||||
```shell
|
||||
-Xms50m -Xmx200m -XX:PermSize=30m -XX:MaxPermSize=60m
|
||||
-Xloggc:eclipse_gc.log (设置垃圾回收日志打印的文件,文件名称可以自定义)
|
||||
-XX:+PrintGCTimeStamps (打印垃圾回收时间信息时的时间格式)
|
||||
-XX:+PrintGCDetails (打印垃圾回收详情)
|
||||
-XX:PermSize:设置永久代(perm gen)初始值。默认值为物理内存的1/64。
|
||||
-XX:MaxPermSize:设置持久代最大值。物理内存的1/4。
|
||||
-Xms:初始堆大小,默认为物理内存的1/64(<1GB)
|
||||
-Xmx:最大堆大小
|
||||
-Xmn:新生代的内存空间大小
|
||||
```
|
||||
|
||||
### 3. gc 日志
|
||||
|
||||
阅读GC日志,我们可以了解Java虚拟机内存分配与回收策略(开发使用)
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# cd /usr/local/tomcat/bin/
|
||||
[root@tomcat bin]# vim catalina.sh
|
||||
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails \
|
||||
-XX:+PrintGCDateStamps \
|
||||
-Xloggc:/var/log/tomcat/gc.log \
|
||||
-XX:+UseGCLogFileRotation \
|
||||
-XX:NumberOfGCLogFiles=10 \
|
||||
-XX:GCLogFileSize=100M"
|
||||
```
|
||||
|
||||
参数说明:
|
||||
|
||||
- -XX:+PrintGCDetails:打印详细的GC信息。
|
||||
- -XX:+PrintGCDateStamps:添加日期时间戳。
|
||||
- -Xloggc:/var/log/tomcat/gc.log:指定GC日志文件路径。
|
||||
- -XX:+UseGCLogFileRotation:启用日志轮转。
|
||||
- -XX:NumberOfGCLogFiles=10:保留最多10个日志文件。
|
||||
- -XX:GCLogFileSize=100M":每个日志文件最大100MB。
|
||||
|
||||
## 五:Tomcat 负载均衡
|
||||
|
||||
### Nginx 配置
|
||||
|
||||
```bash
|
||||
[root@tomcat ~]# vim /usr/local/nginx/conf/nginx.conf
|
||||
这个地方是 地址池,这里包含了后端服务器的地址和端口,这里的名字随便启。
|
||||
http {
|
||||
upstream tomcat_pool {
|
||||
#ip_hash; 最大失败次数 失败超时时间
|
||||
server 192.168.122.105:8081 weight=1 max_fails=2 fail_timeout=2;
|
||||
server 192.168.122.105:8082 weight=1 max_fails=2 fail_timeout=2;
|
||||
server 192.168.122.105:8083 weight=1 max_fails=2 fail_timeout=2;
|
||||
server 192.168.122.105:8084 weight=1 max_fails=2 fail_timeout=2;
|
||||
}
|
||||
负载均衡的算法: RR round robin session ip_hash 是常用的负载均衡的算法
|
||||
server {
|
||||
location / {
|
||||
proxy_pass http://tomcat_pool;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user