当前位置: > Linux发行版 > Debian >

debian安装nginx及其相关包

时间:2015-10-07 00:41来源:linux.it.net.cn 作者:IT

源头:apache+tomcat集群的负载均衡算法有问题,现象是apache把过多压力分配给本地tomcat,另一台服务器的tomcat极为清闲(连接数差一个数量级),于是改用nginx作前端负载均衡

  1. 下载nginx ,我下的是nginx-1.4.1
  2. 进入解压目录编译 ./configure :报缺少pcre库
  3. 回头安转pcre,我下的是pcre-8.33,还是linux源码安装三部曲
  4. 再进nginx编译,这回报缺少zlib库
  5. 常识apt-get安装失败,查了下说是名称换了:zlib1g-dev,再试,再失败,总之缺少其他关联包,怒了,用源码安装方式,官网下载地址,源码安装三部曲依旧
  6. 总算nginx编译通过,进入/usr/local/nginx/目录,启动命令就是nginx (注意默认80端口,不要被其他服务器抢了)
  7. 游览器输入localhost,出现welcome页,安装成功
  8. 修改配置后,用nginx -s reload命令参赛使配置生效,而停止服务器的命令是nginx -s stop

========以下是集群配置========

  1. 修改nginx.conf,增加多个后端tomcat
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    ......
     
    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;
     
        #keepalive_timeout  0;
        keepalive_timeout  65;
     
        #gzip  on;
     
            # ccq 6/5 add: tomcat_proxy
        upstream localhost {
            server localhost:9080;
            server localhost:8080;
                    ip_hash;
        }
        # ccq 6/5 add: tomcat_proxy end
     
        server {
            listen       80;
            server_name  localhost;
    ......
            location / {
                root   html;
                  # ccq 6/5 upd: tomcat_proxy
                  index  index.html index.jsp;
              proxy_pass   http://localhost;
              proxy_redirect    off;
              proxy_set_header   Host $host;
              proxy_set_header   X-Real-IP $remote_addr;
              proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
              client_max_body_size   10m;
              client_body_buffer_size   128k;
              proxy_connect_timeout   90;
              proxy_send_timeout   90;
              proxy_read_timeout   90;
              proxy_buffer_size   4k;
              proxy_buffers   4 32k;
              proxy_busy_buffers_size   64k;
              proxy_temp_file_write_size  64k; 
                  # ccq 6/5 upd: tomcat_proxy end
            }
    ……



     
  2. tomcat修改server.xml,防止端口冲突,这里是第二个tomcat的配置,第一个tomcat用默认的,注意加下jvmRoute

     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ……
    <Server port="9005" shutdown="SHUTDOWN">
    ……
        <Connector port="9080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
    ……
        <Connector port="9009" protocol="AJP/1.3" redirectPort="9443"  jvmRoute="tomcat1"/>
    ……
        <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
    ……


     
  3. 参考资料:
    http://www.blogjava.net/niumd/archive/2011/05/10/349958.html
    http://yifangyou.blog.51cto.com/900206/617217
(责任编辑:IT)
------分隔线----------------------------