国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 互联网 > FastDFS安装与nginx反向代理配置

FastDFS安装与nginx反向代理配置

来源:程序员人生   发布时间:2016-07-04 16:43:11 阅读次数:3102次

操作系统 Ubuntu Server

nginx相干软件

nginx⑴.10.1
http://nginx.org/en/download.html
nginx清除缓存模块 ngx_cache_purge⑵.3
http://labs.frickle.com/nginx_ngx_cache_purge/
pcre⑻.36
https://sourceforge.net/projects/pcre/files/pcre/8.36/
zlib库
http://zlib.net/zlib⑴.2.8.tar.gz

FastDFS相干软件

FastDFS_v5.08
https://sourceforge.net/projects/fastdfs/files/FastDFS%20Server%20Source%20Code/stats/timeline
或https://github.com/happyfish100/fastdfs
FastDFS Nginx Module 1.16
http://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/
或https://github.com/happyfish100/fastdfs-nginx-module
libfastcommon
https://github.com/happyfish100/libfastcommon
其中github上的代码是最新的,sourceforge上不1定是最新的,当前FastDFS版本为5.08。
网络拓扑图

tracker的安装与配置

以下操作是在 tracker 10.10.10.80上操作。
通过rz工具或FileZilla,把软件上传到Ubuntu的/usr/local/src目录下。

安装libfastcommon

root@tracker:/usr/local/src# unzip libfastcommon-master.zip root@tracker:/usr/local/src# cd libfastcommon-master root@tracker:/usr/local/src/libfastcommon-master# ls HISTORY INSTALL libfastcommon.spec make.sh php-fastcommon README src root@tracker:/usr/local/src/libfastcommon-master# ./make.sh root@tracker:/usr/local/src/libfastcommon-master# ./make.sh install

安装FastDFS (FastDFS_v5.08.tar.gz)

root@tracker:/usr/local/src# tar zxvf FastDFS_v5.08.tar.gz root@tracker:/usr/local/src# cd FastDFS root@tracker:/usr/local/src/FastDFS# ./make.sh root@tracker:/usr/local/src/FastDFS# ./make.sh install

到这里FastDFS在 tracker上安装完成,所有的可履行文件位于 /usr/bin 目录下,以fdfs开头的文件:

root@tracker:~$ ll /usr/bin/fdfs_* -rwxr-xr-x 1 root root 379725 Jun 16 19:25 /usr/bin/fdfs_appender_test* -rwxr-xr-x 1 root root 375174 Jun 16 19:25 /usr/bin/fdfs_appender_test1* -rwxr-xr-x 1 root root 356800 Jun 16 19:25 /usr/bin/fdfs_append_file* -rwxr-xr-x 1 root root 356994 Jun 16 19:25 /usr/bin/fdfs_crc32* -rwxr-xr-x 1 root root 356827 Jun 16 19:25 /usr/bin/fdfs_delete_file* -rwxr-xr-x 1 root root 357754 Jun 16 19:25 /usr/bin/fdfs_download_file* -rwxr-xr-x 1 root root 357928 Jun 16 19:25 /usr/bin/fdfs_file_info* -rwxr-xr-x 1 root root 377621 Jun 16 19:25 /usr/bin/fdfs_monitor* -rwxr-xr-x 1 root root 1313605 Jun 16 19:25 /usr/bin/fdfs_storaged* -rwxr-xr-x 1 root root 389327 Jun 16 19:25 /usr/bin/fdfs_test* -rwxr-xr-x 1 root root 387896 Jun 16 19:25 /usr/bin/fdfs_test1* -rwxr-xr-x 1 root root 539675 Jun 16 19:25 /usr/bin/fdfs_trackerd* -rwxr-xr-x 1 root root 357728 Jun 16 19:25 /usr/bin/fdfs_upload_appender* -rwxr-xr-x 1 root root 363268 Jun 16 19:25 /usr/bin/fdfs_upload_file*

所有的配置文件在 /etc/fdfs/ 目录下:

root@tracker:~$ ll /etc/fdfs/ total 28 drwxr-xr-x 2 root root 4096 Jun 16 19:33 ./ drwxr-xr-x 117 root root 4096 Jun 16 19:44 ../ -rwxr-xr-x 1 root root 1463 Jun 16 19:32 client.conf.sample -rwxr-xr-x 1 root root 7927 Jun 16 19:25 storage.conf.sample -rwxr-xr-x 1 root root 7202 Jun 16 19:33 tracker.conf.sample

配置

①进入到 /etc/fdfs 目录下,将tracker.conf.sample重命名为tracker.conf。

root@tracker:/etc/fdfs# mv tracker.conf.sample tracker.conf

②创建数据文件和日志文件目录

root@tracker:/etc/fdfs# mkdir -pv /data/fastdfs/tracker mkdir: 已创建目录 "/data" mkdir: 已创建目录 "/data/fastdfs" mkdir: 已创建目录 "/data/fastdfs/tracker"

③编辑 tracker.conf 文件,测试的时候只需要修改以下参数便可

disabled=false #启用配置文件 port=22122 #设置 tracker 的端口号 base_path=/data/fastdfs/tracker #设置 tracker 的数据文件和日志目录(需预先创建) http.server_port=8888 #设置 http 端口号 这个http.server_port=8888 指的是在tracker服务器上启动http服务进程,如:apache或nginx 启动时所监听的端口

运行

直接使用 fdfs_trackerd 来启动tracker进程,然后使用netstat 查看端口是不是起来。

root@tracker:/etc/fdfs# fdfs_trackerd /etc/fdfs/tracker.conf restart root@tracker:/etc/fdfs# netstat -antp | grep trackerd tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 14520/fdfs_trackerd root@tracker:/etc/fdfs#

也能够查看日志看服务是不是正常运行:

root@tracker:~# cat /data/fastdfs/tracker/logs/trackerd.log
[2016-06-28 11:55:55] INFO - FastDFS v5.08, base_path=/data/fastdfs/tracker, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=2048, accept_threads=1, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=10.00%, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, use_storage_id=0, id_type_in_filename=ip, storage_id_count=0, rotate_error_log=0, error_log_rotate_time=00:00, rotate_error_log_size=0, log_file_keep_days=0, store_slave_file_use_link=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s [2016-06-28 11:56:01] INFO - file: tracker_relationship.c, line: 383, selecting leader... [2016-06-28 11:56:02] INFO - file: tracker_relationship.c, line: 401, I am the new tracker leader 10.10.10.80:22122

⑤设置开机自动启动

root@tracker:/etc# vi rc.local /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

至此tracker上的安装与配置结束。

storage的安装与配置

两台机器(10.10.10.81, 10.10.10.82)配置完全1样,以81为例。

安装

利用上传 FastDFS_v5.08.tar.gz 和 libfastcommon-master.zip 至 storage服务器的/usr/local/src 目录下,解压安装 libfastcommon,这个和前面安装tracker1样。

安装libfastcommon root@storage1:/usr/local/src# unzip libfastcommon-master.zip root@storage1:/usr/local/src# cd libfastcommon-master root@storage1:/usr/local/src/libfastcommon-master# ls HISTORY INSTALL libfastcommon.spec make.sh php-fastcommon README src root@storage1:/usr/local/src/libfastcommon-master# ./make.sh root@storage1:/usr/local/src/libfastcommon-master# ./make.sh install
安装FastDFS FastDFS_v5.08.tar.gz root@storage1:/usr/local/src# tar zxvf FastDFS_v5.08.tar.gz root@storage1:/usr/local/src# cd FastDFS root@storage1:/usr/local/src/FastDFS# ./make.sh root@storage1:/usr/local/src/FastDFS# ./make.sh install

配置

进入到 /etc/fdfs 目录下,复制/usr/local/src/FastDFS/conf/* 下面的所有文件到当前目录下(/etc/fdfs):

root@storage1:/etc/fdfs$ ll total 96 drwxr-xr-x 2 root root 4096 Jun 17 16:07 ./ drwxr-xr-x 97 root root 4096 Jun 17 15:28 ../ -rwxr-xr-x 1 root root 23981 Jun 16 20:06 anti-steal.jpg -rwxr-xr-x 1 root root 1461 Jun 16 20:06 client.conf -rwxr-xr-x 1 root root 858 Jun 16 20:06 http.conf -rwxr-xr-x 1 root root 31172 Jun 16 20:06 mime.types -rwxr-xr-x 1 root root 7910 Jun 17 09:40 storage.conf -rwxr-xr-x 1 root root 105 Jun 16 20:06 storage_ids.conf -rwxr-xr-x 1 root root 7202 May 20 10:45 tracker.conf

编辑配置文件 storage.conf 测试的时候,只需修改以下内容便可

root@storage1:/etc/fdfs$ vi storage.conf disabled=false #启用配置文件 group_name=group1 #组名,根据实际情况修改 port=23000 #设置 storage 的端口号 base_path=/data/fastdfs/storage #设置 storage 的日志目录(需预先创建) store_path_count=1 #存储路径个数,需要和 store_path 个数匹配 store_path0=/data/fastdfs/storage #存储路径 tracker_server=10.10.10.81:22122 #tracker 服务器的 IP 地址和端口号 http.server_port=8888 #设置storage上启动的http服务的端口号,如安装的nginx的端口号

[备注]:store_path_count如果有多个,那末需要设置多个存储路径,如:

store_path_count=2
store_path0=/data/fastdfs/storage
store_path1=/data/fastdfs/storage1

运行

履行以下命令:

root@storage1:/etc/fdfs# fdfs_storaged /etc/fdfs/storage.conf restart

查看进程是不是运行:

root@dstorage1:/etc/fdfs# netstat -antp | grep storage tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 23426/fdfs_storaged

视察日志 /data/fastdfs/storage/logs/storaged.log 看运行情况

mkdir data path: FB ... mkdir data path: FC ... mkdir data path: FD ... mkdir data path: FE ... mkdir data path: FF ... data path: /data/fastdfs/storage/data, mkdir sub dir done. [2016-06-16 19:51:04] INFO - file: storage_param_getter.c, line: 191, use_storage_id=0, id_type_in_filename=ip, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=10.00%, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, store_slave_file_use_link=0 [2016-06-16 19:51:04] INFO - file: storage_func.c, line: 254, tracker_client_ip: 10.10.10.81, my_server_id_str: 10.10.10.81, g_server_id_in_filename: -771094006 [2016-06-16 19:51:04] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 10.10.10.80:22122, as a tracker client, my ip is 10.10.10.81 [2016-06-16 19:51:34] INFO - file: tracker_client_thread.c, line: 1235, tracker server 10.10.10.80:22122, set tracker leader: 10.10.10.80:22122

这里看到,创建了2级目录,成功连接到tracker。
可使用 fdfs_monitor 来查看1下storage的状态,看是不是已成功注册到了tracker:

root@storage1:/# fdfs_monitor /etc/fdfs/storage.conf 或: fdfs_monitor /etc/fdfs/client.conf(不过这个文件需要配置1下才行)
[2016-06-28 14:32:41] DEBUG - base_path=/data/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 server_count=1, server_index=0 tracker server is 10.10.10.80:22122 group count: 1 Group 1: group name = group1 disk total space = 7384 MB disk free space = 4306 MB trunk free space = 0 MB storage server count = 1 active server count = 1 storage server port = 23000 storage HTTP port = 10000 store path count = 1 subdir count per path = 256 current write server index = 0 current trunk file id = 0 Storage 1: id = 10.10.10.81 ip_addr = 10.10.10.81 ACTIVE http domain = version = 5.08 join time = 2016-06-16 20:49:05 up time = 2016-06-17 15:41:37 total storage = 19211 MB 。。。。。

看到这里显示“ACTIVE”,说明当前的storage节点已注册到了Tracker上。

设置开机启动

同Tracker中的配置,把以下命令加到/etc/rc.local中:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

到这里storage的安装配置也完成了。当第2台节点也加进来后,可以通过日志看到以下信息:

[2016-06⑴7 15:41:46] INFO - file: storage_sync.c, line: 2698, successfully connect to storage server 10.10.10.82:23000

【注】由于同1组的节点会进行数据同步,所以1个组内的所有storage节点会进行通讯,那末这个地方就能够看出来,他们上线后会建立连接。
另外,从端口信息上也能够看出来:

root@storage1:/# netstat -antp | grep storage tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 23426/fdfs_storaged tcp 0 0 10.10.10.81:23000 10.10.10.82:33842 ESTABLISHED 23426/fdfs_storaged tcp 0 0 10.10.10.81:50824 10.10.10.82:23000 ESTABLISHED 23426/fdfs_storaged tcp 0 0 10.10.10.81:58116 10.10.10.80:22122 ESTABLISHED 23426/fdfs_storaged

storage1会与storage2建立连接,同时会与tracker建立连接。

在storage上安装配置nginx

以下操作在storage1上完成。

安装nginx

上传 fastdfs-nginx-module_v1.16.tar.gz nginx⑴.10.0.tar.gz pcre⑻.36.tar.gz zlib⑴.2.8.tar.gz 到storage服务器上的/usr/local/src 目录下

root@storage1:/usr/local/src/nginx-1.10.0# ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src root@storage1:/usr/local/src/nginx-1.10.0# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module-master/src --with-pcre=/usr/local/src/pcre⑻.36 --with-zlib=/usr/local/src/zlib⑴.2.8

编译安装:

make && make install

配置nginx

修改nginx配置文件
① 修改nginx的监听端口
将 server 段中的 listen 端口号改成 8888:
② 在 server 段中添加fastdfs的配置:
这里的group[1⑶] 可以匹配 group1,group2,group3,固然group也能够是其他的名字,这里正则表达式只是用来过滤要求路径。
location ~ /group[1⑶]/M00 {
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}
/data/fastdfs/storage/data 这个是指向真正存储文件的地方,该目录下有这些个2级目录

root@dtv-210:/data/fastdfs/storage/data# ll total 1048 drwxr-xr-x 259 root root 4096 Jun 27 15:42 ./ drwxr-xr-x 4 root root 4096 Jun 16 19:50 ../ drwxr-xr-x 258 root root 4096 Jun 16 19:50 00/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 01/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 02/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 03/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 04/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 05/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 06/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 07/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 08/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 09/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 0A/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 0B/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 0C/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 0D/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 0E/ drwxr-xr-x 258 root root 4096 Jun 16 19:50 0F/ 。。。

③将 FastDFS 的 nginx 插件模块的配置文件拷贝到 FastDFS 配置文件目录:

root@storage1:/usr/local/src/fastdfs-nginx-module-master/src# cp mod_fastdfs.conf /etc/fdfs/

修改 fastdfs的nginx模块的配置文件 mod_fastdfs.conf

base_path=/data/fastdfs/storage #保存日志目录 tracker_server=10.10.10.80:22122 #tracker 服务器的 IP 地址和端口号 storage_server_port=23000 #storage服务器的端口号 group_name=group1 #当前服务器的group名 url_have_group_name = true #文件url中是不是有group 名 store_path_count=1 #存储路径个数,需要和store_path 个数匹配 store_path0=/data/fastdfs/storage #存储路径 group_count = 1 #设置组的个数 #然后在末尾添加分组信息,目前只有1个分组,就只写1个 [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/data/fastdfs/storage

④建立 M00 至存储目录的符号连接

root@storage1# ln -s /data/fastdfs/storage/data /data/fastdfs/storage/data/M00 root@storage1# ll /data/fastdfs/storage/data/M00 lrwxrwxrwx 1 root root 26 Jun 16 19:53 /data/fastdfs/storage/data/M00 -> /data/fastdfs/storage/data/

到这里,nginx和FastDFS 插件模块就配置完成了。
⑤启动nginx
履行/usr/local/nginx/sbin/nginx
把上述语句加入/etc/rc.local便可开机自启动。
可以通过netstat -unltp | grep nginx查看nginx是不是起来,如果有毛病,可以查看日志:

root@storage1:/usr/local/nginx/logs# cat error.log

也能够访问http://10.10.10.80:8888查看nginx是不是工作,看到以下界面说明nginx启动OK。
nginx
其他storage节点依照上述步骤安装与配置便可。

安装nginx反向代理及缓存服务器

在机器10.10.10.79上安装。

安装nginx

将所需的软件包上传至服务器/usr/local/src下

root@server:/usr/local/src# tar zxvf nginx⑴.10.0.tar.gz root@server:/usr/local/src# tar zxvf ngx_cache_purge⑵.3.tar.gz root@server:/usr/local/src# tar zxvf pcre⑻.36.tar.gz root@server:/usr/local/src# tar zxvf zlib⑴.2.8.tar.gz root@server:/usr/local/src# cd nginx⑴.10.0 root@server:/usr/local/src/nginx-1.10.0#./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/ngx_cache_purge⑵.3 --with-pcre=/usr/local/src/pcre⑻.36/ --with-zlib=/usr/local/src/zlib⑴.2.8 root@server:/usr/local/src/nginx-1.10.0#make && make install

nginx 和 nginx cache purge 插件模块安装终了。

配置nginx

①创建nginx的缓存目录

root@server# mkdir -pv /var/cache/nginx/proxy_cache/tmp

②增加系统打开文件数的限制,手写到rc.local

root@server# ulimit -SHn 102400 root@server# echo "ulimit -SHn 102400" >> /etc/rc.local

③编辑 vim /usr/local/nginx/conf/nginx.conf 文件修改以下内容:

user nobody; worker_processes 4; error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 65535; use epoll; } http { include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; keepalive_timeout 65; 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 /var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d; proxy_temp_path /var/cache/nginx/proxy_cache/tmp; #设置 group1 的服务器 upstream fdfs_group1 { server 10.10.10.80:8888 weight=1 max_fails=2 fail_timeout=30s; server 10.10.10.81:8888 weight=1 max_fails=2 fail_timeout=30s; } log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; server { listen 80; server_name localhost; access_log logs/host.access.log main; #设置 group1 的反向代理参数 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 ~ /purge(/.*) { allow 127.0.0.1; allow 10.10.10.0/24; deny all; proxy_cache_purge http-cache $1$is_args$args; } } }

接下来,可使用 /usr/local/nginx/sbin/nginx -t 来测试配置文件语法的正确性。

root@server:/usr/local/nginx# ./sbin/nginx -t ngx_http_fastdfs_set pid=5895 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful root@server:/usr/local/nginx#

④启动nginx并加入到开机启动

/usr/local/nginx/sbin/nginx

把/usr/local/nginx/sbin/nginx加入/etc/rc.local便可。
一样可以查看端口看是不是正常启动:

netstat -unltp | grep nginx

测试上传文件

以下操作在tracker服务器(10.10.10.80)上进行
①创建client 使用的日志目录

root@server# mkdir -pv /data/fastdfs/client

②修改客户真个配置文件/etc/fdfs/client.conf

base_path=/data/fastdfs/client #日志寄存路径 tracker_server=10.10.10.80:22122 #tracker 服务器 IP 地址和端口号 http.tracker_server_port=8888

③上传1个图片

root@server# fdfs_upload_file /etc/fdfs/client.conf 1.jpg group1/M00/00/00/CgoKeFRQqaaASddNAxEgRsu1UiU345.jpg root@server#

得到了以下的地址:
group1/M00/00/00/CgoKeFRQqaaASddNAxEgRsu1UiU345.jpg
还可以通过fdfs_file_info 来查看上传文件的信息

root@server# fdfs_file_info /etc/fdfs/client.conf

通过阅读器访问:
④使用阅读器访问1下该地址:
http://10.10.10.79/group1/M00/00/00/CgoKeFRQqaaASddNAxEgRsu1UiU345.jpg
便可成功访问到图片。
⑤查看nginx的缓存目录,可以查看缓存的内容。

root@server# ll -R /var/cache/nginx/proxy_cache/

⑥清除缓存
如果清除该图片的缓存,可以在文件 URL 之前加上 purge 便可,以下图
http://10.10.10.79/purge/group1/M00/00/00/CgoKeFRQqaaASddNAxEgRsu1UiU345.jpg
清除以后,当storage中文件被删除后,将没法再要求到文件。
⑦配置阅读器端查看是不是命中缓存
使用Chrome阅读器的开发工具,查看响应的头部信息来查看是不是命中缓存,要启用此功能,修改nginx的主配置文件以下:
在location /group1/M00 段增加这2个行

add_header X-Via $server_addr; add_header X-Cache-Status $upstream_cache_status;

终究效果

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; add_header X-Via $server_addr; add_header X-Cache-Status $upstream_cache_status; }

重启nginx,清除缓存再次访问便可查看响应头命中信息。

附录

需要再多写1点, FastDFS这样部署就已可以正常运行了,但是有1个问题,就是FastDFS本身不支持对上传的文件去重。也就是说,同1个文件,我们反复上传,那末会在Storage中保存多份,这明显是不公道的。解决办法,需要的请参考我另外一篇文章:
《FastDHT配合FastDFS进行文件上传去重》
http://blog.csdn.net/ForeverSunshine/article/details/51226061

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生