网站搭建图片,用户上传网站用什么做,销售水果网站建设,学做蛋糕有哪些网站一、目标 浏览器中访问http://{IP地址}:9002/edu/index.html#xff0c;浏览器交替打印清华大学8080、清华大学8081.
二、步骤
2.1、在tomcat8080、tomcat8081的webapps中分别创建edu文件夹
2.2、将index.html分别上传至edu文件夹 注意事项#xff1a;tomcat8080的edu文件…一、目标 浏览器中访问http://{IP地址}:9002/edu/index.html浏览器交替打印清华大学8080、清华大学8081.
二、步骤
2.1、在tomcat8080、tomcat8081的webapps中分别创建edu文件夹
2.2、将index.html分别上传至edu文件夹 注意事项tomcat8080的edu文件夹中的index.html的内容为清华大学8080、清华大学8081index.html模板如下
!DOCTYPE html
html langen
headmeta charsetUTF-8title首页/title
/head
bodyp stylecolor: red;font-size: 30px aligncenter清华大学/p
/body
/html
2.3、分别启动tomcat8080、tomcat8081
# 启动tomcat8080
/opt/tomcat/tomcat8080/apache-tomcat-8.5.63/bin
./startup.sh# 启动tomcat8081
/opt/tomcat/tomcat8081/apache-tomcat-8.5.63/bin
./startup.sh2.4、测试
http://192.168.173.222:8080/edu/index.htmlhttp://192.168.173.222:8081/edu/index.html 2.5、修改nginx配置
worker_processes 1;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 80;server_name localhost;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location /50x.html {root html;}}# Nginx配置实例之反向代理2配置信息server {listen 9001;server_name localhost;location ~ /basketball/ {proxy_pass http://127.0.0.1:8080;}location ~ /football/ {proxy_pass http://127.0.0.1:8081;}}# Nginx负载均衡配置upstream loadBalanceServer{server 127.0.0.1:8080;server 127.0.0.1:8081;}server {listen 9002;server_name 127.0.0.1;location / {proxy_pass http://loadBalanceServer;}}}注意事项修改完nginx.conf后需要重新加载nginx的配置信息
./nginx -s reload
2.6、测试
http://192.168.173.222:9002/edu/index.html 结果分析通过上述配置实现了负载均衡
三、坑总结
坑1配置完nginx的配置文件后启动nginx如果出现下面的显示效果说明upstream中配置的tomcat服务没有开启需要开启才行。 坑2、tomcat服务启动了nginx也启动了如果不能实现负载均衡功能很有可能是tomcat由于端口冲突问题导致的此时需要修改server.xml中的端口。
Serverport、Connector port、redirectPort。可以通过查看tomcat的日志查看具体的报错信息 四、负载均衡的其他配置
4.1、轮询默认
4.2、weight按照权重分配
weight 代表权重默认为 1,权重越高被分配的客户端越多。
指定轮询几率weight 和访问比率成正比用于后端服务器性能不均的情况。配置信息如下upstream server_pool {server 192.168.6.148 weight10;server 192.168.6.149 weight6;
}4.3、ip_hash
每个请求按访问 ip 的 hash 结果分配这样每个访客固定访问一个后端服务器可以解决 session 的问题。 例如
upstream server_pool {ip_hash; server 192.168.5.21:80; server 192.168.5.22:80;
}4.4、fair第三方
按后端服务器的响应时间来分配请求响应时间短的优先分配。upstream server_pool{ server 192.168.5.21:80; server 192.168.5.22:80; fair;
}