揭秘企业级web负载均衡完美架构(2)

本文详细介绍Nginx负载均衡器的安装步骤及配置过程,包括用户与组的创建、依赖包安装等,并提供了一个纯80端口转发的具体配置案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


    第二部分:分别安装Nginx负载均衡器及相关配置脚本

    先安装Nginx负载均衡器,nginx负载的配置就用一般的模板来配置了

       
    1. #添加运行nginx的用户和组www  
    2. groupadd www   
    3. useradd -g www www   
    4. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz  
    5. tar zxvf pcre-7.8.tar.gz  
    6. cd pcre-7.8/  
    7. ./configure  
    8. make && make install  
    9. wget http://sysoev.ru/nginx/nginx-0.7.51.tar.gz  
    10. tar zxvf nginx-0.7.51.tar.gz  
    11. cd nginx-0.7.51/  
    12. ./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module  
    13. make && make install 

    配置nginx负载均衡器的配置文件vim /usr/local/nginx/conf/nginx.conf,此篇文章仅仅只是我的某项目的配置文档,纯80转发;如果对nginx配置有https要求的可参考张宴的相关文章。

       
    1. user www www;  
    2. worker_processes 8;  
    3.  
    4. pid /usr/local/nginx/logs/nginx.pid;  
    5. worker_rlimit_nofile 65535;  
    6.  
    7. events  
    8. {  
    9. use epoll;  
    10. worker_connections 65535;  
    11. }  
    12. http{  
    13. include       mime.types;  
    14. default_type application/octet-stream;  
    15. server_names_hash_bucket_size 128;  
    16. client_header_buffer_size 32k;  
    17. large_client_header_buffers 4 32k;  
    18. client_max_body_size 8m;  
    19. sendfile on;  
    20. tcp_nopush     on;  
    21. keepalive_timeout 60;  
    22. tcp_nodelay on;  
    23. fastcgi_connect_timeout 300;  
    24. fastcgi_send_timeout 300;  
    25. fastcgi_read_timeout 300;  
    26. fastcgi_buffer_size 64k;  
    27. fastcgi_buffers 4 64k;  
    28. fastcgi_busy_buffers_size 128k;  
    29. fastcgi_temp_file_write_size 128k;  
    30. gzip on;  
    31. gzip_min_length 1k;  
    32. gzip_buffers     4 16k;  
    33. gzip_http_version 1.0;  
    34. gzip_comp_level 2;  
    35. gzip_types       text/plain application/x-javascript text/css application/xml;  
    36. gzip_vary on;  
    37.  
    38. upstream backend  
    39. {  
    40. server 192.168.1.102:80;  
    41. server 192.168.1.103:80;  
    42. server 192.168.1.105:80;  
    43. }  
    44. server {  
    45. listen 80;  
    46. server_name www.yuhongchun027.com;  
    47. location / {  
    48. root /var/www ;  
    49. index index.jsp index.htm index.html;  
    50. proxy_redirect off;  
    51. proxy_set_header Host $host;  
    52. proxy_set_header X-Real-IP $remote_addr;  
    53. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    54. proxy_pass http://backend;  
    55. }  
    56.  
    57. location /nginx {  
    58. access_log on;  
    59. auth_basic "NginxStatus";  
    60. auth_basic_user_file /usr/local/nginx/htpasswd;  
    61. }  
    62.  
    63. log_format access '$remote_addr - $remote_user [$time_local] "$request" '  
    64. '$status $body_bytes_sent "$http_referer" '  
    65. '"$http_user_agent" $http_x_forwarded_for';  
    66. access_log /var/log/access.log access;  
    67.  
    68. }  

    小节:

    第一部分和第二部分讲的是如何通过安装Nginx来达到负载均衡后端web集群的过程,Nginx能实现自动切换后端有故障的web服务器;但Nginx负载均衡器出了问题怎么办呢,它们之间是如何实现无故障转移的呢?

    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值