debian安裝nginx及其相關包

 源頭:apache+tomcat集羣的負載均衡算法有問題,現象是apache把過多壓力分配給本地tomcat,另外一臺服務器的tomcat極爲悠閒(鏈接數差一個數量級),因而改用nginx做前端負載均衡 html

  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
    ......
    
    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
    ……
    <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
相關文章
相關標籤/搜索