• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

cynchanpin

  • 博客园
  • 联系
  • 订阅
  • 管理

View Post

[Linux]nginx tomcat做负载均衡

之前使用nginx做过web反向代理,没有做过负载均衡,今天有个同学须要做tomcat的负载均衡,我也研究下。

一共是2个机器,一个物理机(win7)上面部署2个tomcat,使用不同的port启动。

vm中的虚拟机放(centos)nginx,给tomcat做负载均衡.

  • inux ip: 192.168.37.129
  • win ip: 192.168.37.1

首先保证两个主机能够互ping,响应的port开放。

  • nginx上使用80
  • tomcat1 使用8081 tomcat2使用8080
  • nginx,tomcat的安装和启动不在说了,特别是windows下非常easy。遇到困难百度下就能够了。

  • windows安装启动个tomcat 还有 一个系统启动多个tomcat 为了区分每一个tomcat的不同。把首页的html加上些标志。

  • nginx版本号1.4 tomcat 版本号6.0
  • 2个tomcat实例能够正常启动,nginx实例也能正常使用,win上的浏览器中能够正常訪问3个网页
    • http://192.168.37.1:8081/
    • http://192.168.37.1:8080/
    • http://192.168.37.129/

然后開始配置nginx:

[root@localhost conf]# cat /etc/nginx/nginx.conf

#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
 
http {
include mime.types;
default_type application/octet-stream;
 
upstream localhost{
server 192.168.37.1:8080 weight=2;
server 192.168.37.1:8081 weight=1;
#ip_hash;
}
 
sendfile on;
keepalive_timeout 65;
 
server {
listen 80;
server_name localhost;
 
location / {
proxy_connect_timeout 3;
#proxy_redirect off;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost;
}
 
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

这怎么重新启动nginx都没生效,最后发现是由于启动的配置文件不正确。能够通过 nginx -c /etc/nginx/nginx.conf 来指定陪配置文件的路径。
当然这里是最简单的轮询,没有其它策略,实验来说基本成功。

本文出自 “orangleliu笔记本” 博客,转载请务必保留此出处http://blog.csdn.net/orangleliu/article/details/41251397

作者: orangleliu  


posted on 2017-08-01 16:05  cynchanpin  阅读(235)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3