Nginx + Tomcat 在 Windows7 上搭建负载均衡集群
一、安装Tomcat和Nginx
首先安装两个apache-tomcat-8.0.41,下载地址:http://tomcat.apache.org
并安装一个nginx-1.13.0,下载地址http://nginx.org/en/download.html
都是绿色版,直接解压就能用,不需要进行环境变量之类的配置的。
这里碰到个小问题:公司电脑环境变量配的是jdk6,所以我的Tomcat8启动的时候黑窗口一闪而过,JDK版本不匹配的原因,把jdk6换成jdk8之后,Tomcat8正常启动。
二、修改Tomcat的端口号

我的第一个Tomcat是默认的,只修改第二个Tomcat,确保两个Tomcat能同时启动,需要修改下面三处的端口号(O(∩_∩)O我只是在默认多口号加了1~):



三、修改Tomcat的默认页面,用于识别访问的是哪个Tomcat


另一个Tomcat这里添加的是=====Tomcat1
四、修改Nginx的配置

配置内容
#user nobody;
worker_processes 1;#工作进程的个数,一般与计算机的cpu核数一致 #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;#单个进程最大连接数(最大连接数=连接数*进程数)
} http {
include mime.types;#文件扩展名与文件类型映射表
default_type application/octet-stream;#默认文件类型 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,
#对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,
#以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65;#长连接超时时间,单位是秒 #gzip on;#启用Gizp压缩 #服务器的集群
upstream netitcast.com { #服务器集群名字
server 127.0.0.1:8080 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
server 127.0.0.1:8081 weight=2;
} #当前的Nginx的配置
server {
listen 80;#监听80端口,可以改成其他端口
server_name localhost;#当前服务的域名 #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
proxy_pass http://netitcast.com;
proxy_redirect default;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
其实也就修改了以下两个地方:

五、开始测试
通过startup.bat直接启动两个Tomcat。会出现两个黑窗口,里面有Tomcat的启动日志。

接着通过Nginx目录下的nginx.exe启动Nginx。

六、测试结果
如下图所示,浏览器中访问localhost,不断刷新,访问的Tomcat会在1和2中来回切换,切换的概率是由所配置的权重决定的。


集群就涉及到session共享的问题,参考http://www.linuxidc.com/Linux/2016-09/135550.htm
Nginx + Tomcat 在 Windows7 上搭建负载均衡集群的更多相关文章
- keepalived + nginx 搭建负载均衡集群
第一章 keepalived 1.1 keepalived 服务说明 Keepalived软件起初是专为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实现 ...
- Nginx+Tomcat搭建负载均衡集群
Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器, 使用 Nginx 可以使得程序在高并发的情况下依旧可以保持良好的性能.使用 Nginx+Tomcat ...
- Nginx搭建负载均衡集群
(1).实验环境 youxi1 192.168.5.101 负载均衡器 youxi2 192.168.5.102 主机1 youxi3 192.168.5.103 主机2 (2).Nginx负载均衡策 ...
- LVS搭建负载均衡集群(一)——NAT模式
(1).集群技术的分类 集群技术主要分为三大类:负载均衡(Load Balance)集群,简称LB集群:高可用(High Availability)集群,简称 HA 集群:高性能计算(High Per ...
- LVS搭建负载均衡集群(二)——DR模式
(1).DR模式和TUN模式介绍 Direct Routing(直接路由):director分配请求到不同的real server.real server处理请求后直接回应给用户,这样director ...
- 简单的 Nginx+Tomcat 配置负载均衡集群
简单 Nginx+Tomcat 配置负载均衡集群 前期准备 解压两个tomcat,修改端口号 server1:8081 server:8082 同时启动 nginx官网下载解压版nginx 创建一个简 ...
- LVS负载均衡集群
回顾-Nginx反向代理型负载 负载均衡(load balance)集群,提供了一种廉价.有效.透明的方法,来扩展网络设备和服务器的负载.带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用 ...
- Nginx+Tomcat+Memcached负载均衡集群服务搭建
操作系统:CentOS6.5 本文档主要讲解,如何在CentOS6.5下搭建Nginx+Tomcat+Memcached负载均衡集群服务器,Nginx负责负载均衡,Tomcat负责实际服务,Memc ...
- Linux平台上搭建apache+tomcat负载均衡集群
传统的Java Web项目是通过tomcat来运行和发布的.但在实际的企业应用环境中,采用单一的tomcat来维持项目的运行是不现实的.tomcat 处理能力低,效率低,承受并发小(1000左右).当 ...
随机推荐
- Match-----Correlation-----find_ncc_model_exposure
* This example program shows how to use HALCON's correlation-based* matching. In particular it demon ...
- IntelliJ IDEA2017 激活方法 最新的(亲测可用)
IntelliJ IDEA2017 激活方法(亲测可用): 搭建自己的授权服务器,对大佬来说也很简单,我作为菜鸟就不说了,网上有教程. 我主要说第二种,现在,直接写入注册码,是不能成功激活的(如果你成 ...
- CAFE: a computational tool for the study of gene family evolution
1.摘要 摘要:我们提出了CAFE(计算分析基因家族进化),这是一个统计分析基因家族进化规模的工具.它使用随机的出生和死亡过程来模拟一个系统发育过程中基因家族大小的进化.对于一个特定的系统发育树,并给 ...
- day42 字段的增删改查详细操作
复习 # 1.表的详细操作 create table nt like ot; # 只复制表的结构包括约束 create table nt select * from ot where 1=2; # 复 ...
- MyBatis :Insert (返回主键、批量插入)
一.前言 数据库操作怎能少了INSERT操作呢?下面记录MyBatis关于INSERT操作的笔记,以便日后查阅. 二.insert元素 属性详解 其属性如下: parameterType , ...
- 安装64位office时,弹出提示,要求卸载32位office
运行 regedit,进入到HKEY_CLASSES_ROOT\Installer\Products下,删除0000510开头的项或00002开头项.然后重启计算机. 参考: https://blo ...
- MariaDB ColumnStore初探(1):安装、使用及测试
相信大家在对接BI数据报表部门有很深刻的体验,高大上的复杂SQL关联JOIN十几张表在InnoDB里跑起来,会让你酸爽到死.它的出现正是解决这个问题,DBA能不能轻松愉快地玩耍,就要靠它了,“神州行我 ...
- Codeforces Round #554 (Div. 2)-C(gcd应用)
题目链接:https://codeforces.com/contest/1152/problem/C 题意:给定a,b(<1e9).求使得lcm(a+k,b+k)最小的k,若有多个k,求最小的k ...
- np.cumsum()函数和正则表达式的含义
- python + Jquery,抓取西东网上的Java教程资源网址
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-06-15 14:01:45 # @Author : Chenjun (320 ...