手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

使用Nginx+Tomcat7在RHEL6.3下实现负载均衡

[日期:2013-02-02] 来源:Linux社区  作者:guo_rui22 [字体:大 中 小]

2、配置Nginx服务器做为负载平衡(使用root用户操作)

2.1、修改配置文件 /etc/nginx/nginx.conf

user  nginx;
worker_processes  8;            # 工作的子进程数量,默认为1(通常设置为等于CPU数量或者2倍于CPU)
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

# add by guorui
worker_rlimit_nofile    8192;  # 在nginx级别上提高打开的文件句柄限制,必须大于 worker_connections 的值

events {
  # add by guorui
  use epoll;                  # 使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue

  worker_connections  2048;  # 每个进程允许的最多连接数,必须小于 worker_rlimit_nofile 的值
                              # 服务器的最大访问客户数 max clients = worker_processes * worker_connections
}


http {
  include      /etc/nginx/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  /var/log/nginx/access.log  main;

  sendfile        on;
  #tcp_nopush    on;

  keepalive_timeout  65;

  #gzip  on;

  # add by guorui                                # 添加 upstream 模块,参考PS1
  upstream mtserver {                            # mtserver 是服务器集群名称,后面会用到
      server localhost:8081 fail_timeout=5;      # 添加多个负载服务器的地址、端口及其他负载参数
      server localhost:8080;
  }

  include /etc/nginx/conf.d/*.conf;
}

2.2、修改配置文件 /etc/nginx/conf.d/default.conf

location / {
  proxy_pass http://mtserver;# 添加这一行,引用上面定义的 服务器集群 mtserver
  #root  /usr/share/nginx/html;# 注释掉
  #index  index.html index.htm;# 注释掉
}

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款