vi /etc/fdfs/mod_fastdfs.conf base_path=/data/fastdfs tracker_server=192.168.5.71:22122 store_path0=/data/fastdfs url_have_group_name = true group_name=group1/group2 # 所有组名 group_count = 2 # 组的总数 # 把所有组和目录都添加上 [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/data/fastdfs [group2] group_name=group2 storage_server_port=23000 store_path_count=1 store_path0=/data/fastdfs
#在所有storage机器上,创建所有组的store_path目录
mkdir -p /data/fastdfs
#修改所有storage server的nginx配置文件
server { listen 80; server_name localhost; location ~/group([0-9])/M00/{ ngx_fastdfs_module; } }
#重启storage server的nginx
/etc/init.d/nginx restart
#修改tracker server的反向代理
user www www; worker_processes 8; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 65535; #工作模式及连接数上限 events { worker_connections 65535; } 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 off; tcp_nopush on; keepalive_timeout 300; #nginx跟后端服务器连接超时时间(代理连接超时) proxy_connect_timeout 300s; #连接成功后,后端服务器响应时间(代理接收超时) proxy_read_timeout 300s; proxy_send_timeout 300s; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 proxy_buffer_size 64k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置 proxy_buffers 4 32k; #高负荷下缓冲大小(proxy_buffers*2) proxy_busy_buffers_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘 proxy_temp_file_write_size 64k; #不允许代理端主动关闭连接 proxy_ignore_client_abort on; proxy_cache_path /data/cache1 levels=1:2 keys_zone=fastdfs_cache:200m inactive=1d max_size=20g; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 128k; fastcgi_buffers 4 128k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-Javascript text/css application/xml; gzip_vary on; #nginx cache命中率统计日志 log_format cachelog '$remote_addr - $remote_user [$time_local] "$request" ' '$status "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$upstream_cache_status" $body_bytes_sent'; #设置 group1 的服务器 upstream fdfs_group1 { server 192.168.5.72 weight=1 max_fails=2 fail_timeout=30s; server 192.168.5.73 weight=1 max_fails=2 fail_timeout=30s; } #设置 group2 的服务器 upstream fdfs_group2 { server 192.168.5.74 weight=1 max_fails=2 fail_timeout=30s; server 192.168.5.75 weight=1 max_fails=2 fail_timeout=30s; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #设置 group 的负载均衡参数 location /group1/M00 { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache fastdfs_cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; proxy_pass ; expires 30d; } location /group2/M00 { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache fastdfs_cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; proxy_pass ; expires 30d; } #设置清除缓存的访问权限 location ~/purge(/.*) { allow 127.0.0.1; allow 192.168.5.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; } } }
#fastdfs状态监控
[root@storage71 /]# fdfs_monitor /etc/fdfs/client.conf server_count=1, server_index=0 tracker server is 192.168.5.71:22122 group count: 2 Group 1: group name = group1 Storage 1: id = 192.168.5.72 ip_addr = 192.168.5.72 (storage72.blufly.com) ACTIV Storage 2: id = 192.168.5.73 ip_addr = 192.168.5.73 (storage73.blufly.com) WAIT_SYNC Group 2: group name = group2 Storage 1: id = 192.168.5.74 ip_addr = 192.168.5.74 (storage74.blufly.com) ACTIVE Storage 2: id = 192.168.5.75 ip_addr = 192.168.5.75 (storage75.blufly.com) WAIT_SYNC
#上传图片测试
#fastdfs的storage server的状态查询