nginx tomcat集群安装

一.nginx tomcat集群安装简介

       
Nginx ("engine x") 是一个高性能的 HTTP反向代理服务器,也是一个IMAP/POP3/SMTP 服务器。Nginx是由Igor Sysoev为 俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将 源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而 闻名。2011年6月1日,nginx 1.0.4发布。
Nginx是一款 轻量级Web 服务器/ 反向代理服务器及 电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少, 并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有: 百度新浪网易腾讯

二.集群环境准备

  准备材料:           
     CentOS 6.5 、apache-tomcat-7.0.67.tar.gz、nginx-1.9.14.tar.gz
 安装3台集群虚拟机ip地址分别是:
                 192.168.139.130   
   192.168.139.131
   192.168.139.132
 安装tomcat 访问地址分别是
           192.168.139.130:8130  
   192.168.139.131:8131
   192.168.139.132:8132
  安装nginx 访问地址:
           192.168.139.130:6130  
   192.168.139.131:6131
   192.168.139.132:6132

第三步.安装tomcat

    1.创建tomcat安装目录
          mkdir  /usr/local/tomcat
     2.把安装apache-tomcat-7.0.67.tar.gz复制到安装目录

         mv /home/wgy/apache-tomcat-7.0.67.tar.gz./local/tomcat/

     3.解压缩apache-tomcat-7.0.67.tar.gz

       tar -zxvf  apache-tomcat-7.0.67.tar.gz

     4.到apache-tomcat-7.0.67的bin目录下驱动tomcat

         ./startup.sh 

     5.停止tomcat服务,修改server.xml文件tomcat默认访问端口

       [root@master bin]    ./shutdown.sh

       [root@master conf]# vi server.xml 

         <Connector port="8130" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

     6.重启tomcat服务

        

   安装成功:

    7.在另外的两台机器执行相同的步骤,安装tomcat(也可以把安装成功的配置copy到其他两台机器上),这样三台服务器的tomcat安装结束


第四步.安装nginx

      nginx的安装见http://blog.csdn.net/wangguanyin98/article/details/51143595

第五步.配置nginx负载均衡

    192.168.139.131:8131为列配置nginx.conf文件 红色部分是需要配置的部分
#创建进程用户和用户组
user  root root;
#服务进程数量,一般等于CPU数量
worker_processes  1;


#全局错误日志定义,建议开启error级别日志.[ debug | info | notice | warn | error | crit ]
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


#pid        logs/nginx.pid;



#epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能.Linux建议使用epoll,FreeBSD建议使用#kqueue.
events {
    use epoll;
    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;
    #tcp_nopush     on;

     #http连接的持续时间
    #keepalive_timeout  0;
    keepalive_timeout  65;


    #gzip  on;
    

    #gzip压缩设置

    gzip  on;           #开启gzip

   gzip_min_length 1k;  #最小压缩文件大小

   gzip_buffers 4 16k;  #压缩缓冲区

    #http的协议版本(1.0/1.1),默认1.1,前端如果是squid2.5请使用1.0

   gzip_http_version 1.1;

    #gzip压缩比,1压缩比最小处理速度最快,9压缩比最大但处理速度最慢(传输快但比较消耗cpu)

   gzip_comp_level 2;   

    #和http头有关系,加个vary头,给代理服务器用的,有的浏览器支持压缩,有的不支持,所以避免浪费不支持的也压缩,所以根据客户端的HTTP头来判断,是否需要压缩

    gzip_vary on;

  #gzip压缩类型,不用添加text/html,否则会有警告信息

   gzip_types text/plain text/javascript text/css application/xmlapplication/x-javascript application/json;



 

    #设定负载均衡的服务器列表,可以设置多个upstream,但是upstream 名称192.168.139.131不同

    upstream 192.168.139.131{
      ip_hash;
      server 192.168.139.130:8130  weight=1;
      server 192.168.139.131:8131  weight=1;
      server 192.168.139.132:8132  weight=1;
    }



    server {
         #nginx监听的端口号
        listen       6131;
         #域名可以有多个,用空格隔开
        server_name  192.168.139.131;



        #charset koi8-r;
        charset utf-8

#设定本虚拟主机的访问日志。关闭日志可以减少IO,提高性能。

        #access_log  logs/host.access.log  main;


        location / {
              #定义服务器的默认网站根目录位置
             root   html;
                #定义首页索引文件的名称
             index  index.html index.htm;
               #请求转向负载均衡的服务器列表
             proxy_pass http://192.168.139.131;
             proxy_redirect default;
                #跟代理服务器连接的超时时间,必须留意这个time out时间不能超过75秒,当一台服务器当掉时,过10秒转发到另外一台服务器。
             proxy_connect_timeout 10;

        }


        #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;
    #    }
    #}


}
 
    

第六步.重启nginx服务

     ./nginx
     验证是集群成功:
       http://192.168.139.131:6131/如果能跳转到tomcat的成功页面表示集群安装成功
如图:
   


配置文件详细见:http://download.csdn.net/detail/wangguanyin98/9491234 欢迎下载

       

        



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值