FastDFS-27集群架构Tracker整合Nginx

本文介绍如何在Nginx中配置ngx_cache_purge模块以实现高效的缓存管理和负载均衡。包括ngx_cache_purge模块的安装、配置过程及Nginx负载均衡设置。

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

  • 配置列表清单
    主机名IP地址用途
    tracker_group1192.168.47.203tracker服务器group1
    tracker_group2192.168.47.204tracker服务器group2
ngx_cache_purge作用
安装Nginx
  • 创建用户www来启动执行nginx进程

    useradd www
    
  • 安装编译所需的依赖包

    yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
    
  • nginx编译添加ngx_cache_purge模块
    cd nginx-1.17.1

     ./configure     --user=www    --group=www     --prefix=/application/nginx-1.15.2     --with-http_ssl_module     --with-http_gzip_static_module  --with-http_stub_status_module  --add-module=/root/ngx_cache_purge-master
    

    编译参数可根据实际情况而配置,只需要在编译的时候添加ngx_cache_purge module模块即可

  • 安装

    make && make install
    
  • 软链接

    ln -s /application/nginx-1.15.2   /application/nginx 
    
  • 配置nginx负载均衡和缓存

    user  root;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    events {
    	worker_connections  1024;
    	use epoll;
    }
    
    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  65;
    
    	#gzip  on;
    	server_names_hash_bucket_size 128;
    	client_header_buffer_size 32k;
    	large_client_header_buffers 4 32k;
    	client_max_body_size 300m;
    
    	proxy_redirect off;
    	proxy_set_header Host $http_host;
    	proxy_set_header X-Real-IP $remote_addr;
    	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    	proxy_connect_timeout 90;
    	proxy_send_timeout 90;
    	proxy_read_timeout 90;
    	proxy_buffer_size 16k;
    	proxy_buffers 4 64k;
    	proxy_busy_buffers_size 128k;
    	proxy_temp_file_write_size 128k;
    	proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2
    	keys_zone=http-cache:200m max_size=1g inactive=30d;
    	proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp;
    
    	upstream fdfs_group1 {
        	server 192.168.47.205:8888 weight=1 max_fails=2 fail_timeout=30s;
         	server 192.168.47.206:8888 weight=1 max_fails=2 fail_timeout=30s;
    	}
     
    	upstream fdfs_group2 {
         	server 192.168.47.207:8888 weight=1 max_fails=2 fail_timeout=30s;
         	server 192.168.47.208:8888 weight=1 max_fails=2 fail_timeout=30s;
    	}
    
    	server {
        	listen       8000;
        	server_name  localhost;
    
        	#charset koi8-r;
    
        	#access_log  logs/host.access.log  main;
    
        	location /group1/M00 {
            	proxy_next_upstream http_502 http_504 error timeout invalid_header;
            	proxy_cache http-cache;
            	proxy_cache_valid  200 304 12h;
            	proxy_cache_key $uri$is_args$args;
            	proxy_pass http://fdfs_group1;
            	expires 30d;
        	}
         
        	location /group2/M00 {
            	proxy_next_upstream http_502 http_504 error timeout invalid_header;
            	proxy_cache http-cache;
            	proxy_cache_valid  200 304 12h;
            	proxy_cache_key $uri$is_args$args;
            	proxy_pass http://fdfs_group2;
            	expires 30d;
        	}
    	
        	location ~/purge(/.*) {
            	allow 127.0.0.1;
            	allow 192.168.47.0/24;
            	deny all;
            	proxy_cache_purge http-cache $1$is_args$args;
        	}    
    
        	#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;
        	}
    	}
    }
    
  • 创建缓存使用目录

    mkdir -p /fastdfs/cache/nginx/proxy_cache
    mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp
    
  • 防火墙开启8000端口

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值