资讯专栏INFORMATION COLUMN

FastDFS集群版搭建

Awbeci / 3673人阅读

摘要:所有配置文件在下总用量月月月月月月至此安装完成。将运行命令行添加进文件依次在上全部安装上并确认运行正常。将防火墙规则保存到确定启动,确认启动是否成功。

什么是FastDFS

FastDFS是用c语言编写的一款开源的分布式文件系统。FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

说明

本文原地址:http://blog.lovefoods.top/201...

本文内容可下载word版本文档

局域网Svn地址:https://192.168.1.60/svn/resources/linux/FastDFS
阿里云code Svn地址:http://code.taobao.org/p/FastDFS-INFO/src/trunk/
Github 地址:https://github.com/guoshiqiufeng/fastDFS

软件版本说明

    软件名                    版本        说明
    FastDFS                 v5.05    FastDFS源代码
    fastdfs-nginx-module    v1.16    nginx模块源代码
    libfastcommon            v1.0.7    版本依赖
    nginx                    v1.8.0    nginx服务器源代码
    nginx-upstream-fair    master    Nginx upstream fair 插件源代码
    ngx_cache_purge            v2.3    nginx cache purge插件源代码
    pcre                    v8.34    nginx依赖的pcre库源代码
    zlib                    v1.2.8    nginx依赖的zlib库源代码
网络结构

本手册使用CentOS 6.5 x86_64版操作系统,按照以下网络结构进行部署:

安装tracker 安装

确认是否安装gcc,若未安装按照以下命令使用yum 进行安装

yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++

安装libfastcommonV1.0.7工具包

解压缩
./make.sh
./make.sh install
把/usr/lib64/libfastcommon.so文件向/usr/lib/下复制一份 
cp /usr/lib64/libfastcommon.so /usr/lib

在172.16.1.202上安装FastDFS tracker,使用FastDFS_v5.05.tar.gz源代码包。
可以直接从Linux系统下载源代码包并解压安装。

使用tar命令解压

tar zxf FastDFS_v5.05.tar.gz
cd FastDFS

运行make.sh,确认make成功。期间如果有错误,可能会是缺少依赖的软件包,需安装后再次make。

./make.sh

运行make.sh install,确认install成功。

./make.sh install

安装完成后,所有可执行文件在/usr/local/bin下,以fdfs开头:

[root@storage1 FastDFS]# ll /usr/local/bin/fdfs*
-rwxr-xr-x. 1 root root  522918 3月  25 14:57 /usr/local/bin/fdfs_appender_test
-rwxr-xr-x. 1 root root  522871 3月  25 14:57 /usr/local/bin/fdfs_appender_test1
-rwxr-xr-x. 1 root root  514023 3月  25 14:57 /usr/local/bin/fdfs_append_file
-rwxr-xr-x. 1 root root  513433 3月  25 14:57 /usr/local/bin/fdfs_crc32
-rwxr-xr-x. 1 root root  513967 3月  25 14:57 /usr/local/bin/fdfs_delete_file
-rwxr-xr-x. 1 root root  514377 3月  25 14:57 /usr/local/bin/fdfs_download_file
-rwxr-xr-x. 1 root root  514133 3月  25 14:57 /usr/local/bin/fdfs_file_info
-rwxr-xr-x. 1 root root  525064 3月  25 14:57 /usr/local/bin/fdfs_monitor
-rwxr-xr-x. 1 root root 1179682 3月  25 14:57 /usr/local/bin/fdfs_storaged
-rwxr-xr-x. 1 root root  529845 3月  25 14:57 /usr/local/bin/fdfs_test
-rwxr-xr-x. 1 root root  527774 3月  25 14:57 /usr/local/bin/fdfs_test1
-rwxr-xr-x. 1 root root  655809 3月  25 14:57 /usr/local/bin/fdfs_trackerd
-rwxr-xr-x. 1 root root  514213 3月  25 14:57 /usr/local/bin/fdfs_upload_appender
-rwxr-xr-x. 1 root root  514999 3月  25 14:57 /usr/local/bin/fdfs_upload_file

把FastDFS/conf目录下的所有的配置文件都复制到/etc/fdfs下。

cp * /etc/fdfs/

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

[root@tracker FastDFS]# ll /etc/fdfs/
总用量 60
-rw-r--r--. 1 root root  1461 3月  13 15:15 client.conf
-rw-r--r--. 1 root root   858 3月  13 15:15 http.conf
-rw-r--r--. 1 root root 31172 3月  13 15:15 mime.types
-rw-r--r--. 1 root root  3837 3月  25 10:03 mod_fastdfs.conf
-rw-r--r--. 1 root root  7515 3月  24 10:36 storage.conf
-rw-r--r--. 1 root root  6989 3月  13 15:15 tracker.conf

至此tracker安装完成。

配置

编辑配置文件目录下的tracker.conf,设置相关信息并保存。

vim /etc/fdfs/tracker.conf

一般只需改动以下几个参数即可:

disabled=false            #启用配置文件
port=22122                #设置tracker的端口号
base_path=/fdfs/tracker   #设置tracker的数据文件和日志目录(需预先创建)
http.server_port=8080     #设置http端口号
运行

运行tracker之前,先要把防火墙中对应的端口打开(本例中为22122)。

[root@tracker FastDFS]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22122 -j ACCEPT
[root@tracker FastDFS]# /etc/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]

启动tracker,确认启动是否成功。(查看是否对应端口22122是否开始监听)

[root@tracker FastDFS]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[root@tracker FastDFS]# netstat -unltp | grep fdfs
tcp    0    0.0.0.0:22122       0.0.0.0:*           LISTEN      1766/fdfs_trackerd

也可查看tracker的日志是否启动成功或是否有错误。

cat /home/fastdfs/tracker/logs/trackerd.log

设置开机自动启动。

vim /etc/rc.d/rc.local

将运行命令行添加进文件:

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
安装storage 安装

在172.16.1.203上安装FastDFS storage,使用FastDFS_v5.05.tar.gz源代码包。
可以直接从Linux系统下载源代码包并解压安装。

使用tar命令解压

tar zxf FastDFS_v5.05.tar.gz
cd FastDFS

运行make.sh,确认make成功。期间如果有错误,可能会是缺少依赖的软件包,需安装后再次make。

./make.sh

运行make.sh install,确认install成功。

./make.sh install

安装完成后,所有可执行文件在/usr/local/bin下,以fdfs开头:

[root@storage1 FastDFS]# ll /usr/local/bin/fdfs*
-rwxr-xr-x. 1 root root  522918 3月  25 14:57 /usr/local/bin/fdfs_appender_test
-rwxr-xr-x. 1 root root  522871 3月  25 14:57 /usr/local/bin/fdfs_appender_test1
-rwxr-xr-x. 1 root root  514023 3月  25 14:57 /usr/local/bin/fdfs_append_file
-rwxr-xr-x. 1 root root  513433 3月  25 14:57 /usr/local/bin/fdfs_crc32
-rwxr-xr-x. 1 root root  513967 3月  25 14:57 /usr/local/bin/fdfs_delete_file
-rwxr-xr-x. 1 root root  514377 3月  25 14:57 /usr/local/bin/fdfs_download_file
-rwxr-xr-x. 1 root root  514133 3月  25 14:57 /usr/local/bin/fdfs_file_info
-rwxr-xr-x. 1 root root  525064 3月  25 14:57 /usr/local/bin/fdfs_monitor
-rwxr-xr-x. 1 root root 1179682 3月  25 14:57 /usr/local/bin/fdfs_storaged
-rwxr-xr-x. 1 root root  529845 3月  25 14:57 /usr/local/bin/fdfs_test
-rwxr-xr-x. 1 root root  527774 3月  25 14:57 /usr/local/bin/fdfs_test1
-rwxr-xr-x. 1 root root  655809 3月  25 14:57 /usr/local/bin/fdfs_trackerd
-rwxr-xr-x. 1 root root  514213 3月  25 14:57 /usr/local/bin/fdfs_upload_appender
-rwxr-xr-x. 1 root root  514999 3月  25 14:57 /usr/local/bin/fdfs_upload_file

把FastDFS/conf目录下的所有的配置文件都复制到/etc/fdfs下。

cp * /etc/fdfs/

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

[root@tracker FastDFS]# ll /etc/fdfs/
总用量 60
-rw-r--r--. 1 root root  1461 3月  13 15:15 client.conf
-rw-r--r--. 1 root root   858 3月  13 15:15 http.conf
-rw-r--r--. 1 root root 31172 3月  13 15:15 mime.types
-rw-r--r--. 1 root root  3837 3月  25 10:03 mod_fastdfs.conf
-rw-r--r--. 1 root root  7515 3月  24 10:36 storage.conf
-rw-r--r--. 1 root root  6989 3月  13 15:15 tracker.conf

至此storage安装完成。

配置

编辑配置文件目录下的storage.conf,设置相关信息并保存。

vim /etc/fdfs/storage.conf

一般只需改动以下几个参数即可:

disabled=false                    #启用配置文件
group_name=group1                 #组名,根据实际情况修改
port=23000                        #设置storage的端口号
base_path=/fdfs/storage           #设置storage的日志目录(需预先创建)
store_path_count=1                #存储路径个数,需要和store_path个数匹配
store_path0=/fdfs/storage         #存储路径
tracker_server=172.16.1.202:22122 #tracker服务器的IP地址和端口号
http.server_port=8080     #设置http端口号
运行

运行storage之前,先要把防火墙中对应的端口打开(本例中为23000)。

[root@storage1 FastDFS]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 23000 -j ACCEPT
[root@storage1 FastDFS]# /etc/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]

启动storage,会根据配置文件的设置自动创建多级存储目录,确认启动是否成功。(查看是否对应端口23000是否开始监听)

[root@storage1 FastDFS]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
data path: /fdfs/storage/data, mkdir sub dir...
mkdir data path: 00 ...
mkdir data path: 01 ...
mkdir data path: 02 ...
mkdir data path: 03 ...
...
data path: /fdfs/storage/data, mkdir sub dir done.
[root@storage1 FastDFS]# netstat -unltp | grep fdfs
tcp    0    0.0.0.0:23000       0.0.0.0:*           LISTEN      1766/fdfs_storaged

也可查看storage的日志是否启动成功或是否有错误。

cat /home/fastdfs/storage/logs/storaged.log

确认启动成功后,可以运行fdfs_monitor查看storage服务器是否已经登记到tracker服务器。

[root@storage1 FastDFS]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2014-03-26 01:51:20] DEBUG - base_path=/fdfs/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 172.16.1.202:22122

group count: 1

Group 1:
group name = group1
disk total space = 27789 MB
disk free space = 23920 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 8080
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0

    Storage 1:
        id = 172.16.1.203
        ip_addr = 172.16.1.203  ACTIVE
        http domain = 
        version = 5.01
        join time = 2014-03-26 01:48:19
        up time = 2014-03-26 01:48:19
        total storage = 27789 MB
        free storage = 23920 MB
        upload priority = 10
        store_path_count = 1
        subdir_count_per_path = 256
        storage_port = 23000
        storage_http_port = 8080
        current_write_path = 0
        source storage id= 
        if_trunk_server= 0
        total_upload_count = 0
        success_upload_count = 0
        total_append_count = 0
        success_append_count = 0
        total_modify_count = 0
        success_modify_count = 0
        total_truncate_count = 0
        success_truncate_count = 0
        total_set_meta_count = 0
        success_set_meta_count = 0
        total_delete_count = 0
        success_delete_count = 0
        total_download_count = 0
        success_download_count = 0
        total_get_meta_count = 0
        success_get_meta_count = 0
        total_create_link_count = 0
        success_create_link_count = 0
        total_delete_link_count = 0
        success_delete_link_count = 0
        total_upload_bytes = 0
        success_upload_bytes = 0
        total_append_bytes = 0
        success_append_bytes = 0
        total_modify_bytes = 0
        success_modify_bytes = 0
        stotal_download_bytes = 0
        success_download_bytes = 0
        total_sync_in_bytes = 0
        success_sync_in_bytes = 0
        total_sync_out_bytes = 0
        success_sync_out_bytes = 0
        total_file_open_count = 0
        success_file_open_count = 0
        total_file_read_count = 0
        success_file_read_count = 0
        total_file_write_count = 0
        success_file_write_count = 0
        last_heart_beat_time = 2014-03-26 01:51:03
        last_source_update = 1970-01-01 08:00:00
        last_sync_update = 1970-01-01 08:00:00
        last_synced_timestamp = 1970-01-01 08:00:00

看到“172.16.1.203 ACTIVE”即可确认storage运行正常。
设置开机自动启动。

vim /etc/rc.d/rc.local

将运行命令行添加进文件:

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

依次在172.16.1.204~208上全部安装上storage并确认运行正常。注意配置文件中group名参数需要根据实际情况调整,本例中group是这样分配的:
group1:172.16.1.203,172.16.1.204
group2:172.16.1.205,172.16.1.206
group3:172.16.1.207,172.16.1.208
另外每个group中所有storage的端口号必须一致。

在storage上安装nginx

在storage上安装的nginx主要为了提供http的访问服务,同时解决group中storage服务器的同步延迟问题。

安装

首先在172.16.1.203上安装nginx,使用nginx-1.8.0.tar.gz源代码包以及FastDFS的nginx插件fastdfs-nginx-module_v1.16.tar.gz。

解压

tar zxf nginx-1.8.0.tar.gz
tar zxf fastdfs-nginx-module_v1.16.tar.gz

运行./configure进行安装前的设置,主要设置安装路径、FastDFS插件模块目录、pcre库目录、zlib库目录。
如果提示错误,可能缺少依赖的软件包,需先安装依赖包

yum install pcre-devel
yum install make zlib zlib-devel gcc-c++ libtool

配置fastdfs-nginx-module下的config 修改为下面的路径

再次运行./configure

[root@storage1 nginx-1.8.0]# ./configure --add-module=/root/fastDFS/fastdfs-nginx-module/src

运行make进行编译、安装,确保编译、安装成功。

make
make install

将FastDFS的nginx插件模块的配置文件copy到FastDFS配置文件目录。

cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

安装完成后,nginx所有文件在/usr/local/nginx下:

[root@storage nginx-1.8.0]# ll /usr/local/nginx/
总用量 16
drwxr-xr-x. 2 root root 4096 3月  26 03:11 conf
drwxr-xr-x. 2 root root 4096 3月  26 03:11 html
drwxr-xr-x. 2 root root 4096 3月  26 03:11 logs
drwxr-xr-x. 2 root root 4096 3月  26 03:11 sbin

至此nginx以及FastDFS的nginx插件模块安装完成。

配置

编辑/usr/local/nginx/conf配置文件目录下的nginx.conf,设置添加storage信息并保存。

vim /usr/local/nginx/conf/nginx.conf

将server段中的listen端口号改为8080:

listen       8080;

在server段中添加:

location ~/group1/M00 {
    root /fdfs/storage/data;
    ngx_fastdfs_module;
}

进入/root/fastDFS/fastdfs-nginx-module/src拷贝mod_fastdfs.conf 到/etc/fdfs下

cp mod_fastdfs.conf /etc/fdfs

编辑/etc/fdfs配置文件目录下的mod_fastdfs.conf,设置storage信息并保存。

vim /etc/fdfs/mod_fastdfs.conf

一般只需改动以下几个参数即可:

base_path=/home/fastdfs/storage           #保存日志目录
tracker_server=172.16.1.202: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=/home/fastdfs/storage        #存储路径
http.need_find_content_type=true  #从文件扩展名查找文件类型(nginx时为true)
group_count = 3                   #设置组的个数

在末尾增加3个组的具体信息:

[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/fastdfs/storage

 [group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/home/fastdfs/storage

[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/home/fastdfs/storage

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

[root@storage1 nginx-1.8.0]# ln -s /home/fastdfs/storage/data /home/fastdfs/storage/data/M00
[root@storage1 nginx-1.8.0]# ll /fdfs/storage/data/M00
lrwxrwxrwx. 1 root root 19 3月  26 03:44 /fdfs/storage/data/M00 -> /fdfs/storage/data/

至此,nginx以及FastDFS插件模块设置完成。

运行

运行nginx之前,先要把防火墙中对应的端口打开(本例中为8080)。行nginx之前,先要把防火墙中对应的端口打开(本例中为8080)。

[root@storage1 nginx-1.8.0]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
[root@storage1 nginx-1.8.0]# /etc/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]

启动nginx,确认启动是否成功。(查看是否对应端口8080是否开始监听)

[root@storage1 nginx-1.8.0]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=40638
[root@storage1 nginx-1.8.0]# netstat -unltp | grep nginx
tcp    0    0.0.0.0:8080            0.0.0.0:*              LISTEN      40639/nginx

也可查看nginx的日志是否启动成功或是否有错误。

cat /usr/local/nginx/logs/error.log

在error.log中没有错误,既启动成功。可以打开浏览器,直接访问http://172.16.1.203:8080,查看是否弹出nginx欢迎页面。

设置开机自动启动。

[root@storage1 nginx-1.8.0]# vim /etc/rc.d/rc.local
将运行命令行添加进文件:/usr/local/nginx/sbin/nginx

之后依次在172.16.1.204~208上全部安装上nginx并确认运行正常。

在tracker上安装nginx

在tracker上安装的nginx主要为了提供http访问的反向代理、负载均衡以及缓存服务。

安装

首先将代码包和插件解压
运行./configure进行安装前的设置,主要设置安装路径、nginx cache purge插件模块目录、pcre库目录、zlib库目录。
如果提示错误,可能缺少依赖的软件包,需先安装依赖包,再次运行./configure

./configure --add-module=/root/fastDFS/ngx_cache_purge-2.3 --add-module=/root/fastDFS/nginx-upstream-fair-master

运行make进行编译、安装,确保编译、安装成功。

make
make install

至此nginx以及nginx cache purge插件模块安装完成。

配置

编辑/usr/local/nginx/conf配置文件目录下的nginx.conf,设置负载均衡以及缓存。

vim /usr/local/nginx/conf/nginx.conf

worker_processes  4;                  #根据CPU核心数而定
events {
    worker_connections  65535;        #最大链接数
    use epoll;                        #新版本的Linux可使用epoll加快处理性能
}
http {
    #设置缓存参数
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 300m;
    sendfile        on;
    tcp_nopush      on;
    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 {
    fair;
        server 192.168.126.139:8080 weight=1 max_fails=2 fail_timeout=30s;
        server 192.168.126.140:8080 weight=1 max_fails=2 fail_timeout=30s;
    }
    #设置group2的服务器
    upstream fdfs_group2 {
        server 192.168.126.141:8080 weight=1 max_fails=2 fail_timeout=30s;
        server 192.168.126.142:8080 weight=1 max_fails=2 fail_timeout=30s;
    }
    #设置group3的服务器
    upstream fdfs_group3 {
        server 172.16.1.207:8080 weight=1 max_fails=2 fail_timeout=30s;
        server 172.16.1.208:8080 weight=1 max_fails=2 fail_timeout=30s;
    }

   server {
        #设置服务器端口
        listen       8080;
        #设置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;
        }
        #设置group2的负载均衡参数
        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;
        }
        #设置group3的负载均衡参数
        location /group3/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_group3;
            expires 30d;
        }
        #设置清除缓存的访问权限
        location ~ /purge(/.*) {
            allow 127.0.0.1;
            allow 172.16.1.0/24;
            deny all;
            proxy_cache_purge http-cache  $1$is_args$args;
        }   

至此,nginx以及nginx cache purge插件模块设置完成。

运行

运行nginx之前,先要把防火墙中对应的端口打开(本例中为8080)。

[root@tracker nginx-1.8.0]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
[root@tracker nginx-1.8.0]# /etc/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]

启动nginx,确认启动是否成功。(查看是否对应端口8080是否开始监听)

[root@tracker nginx-1.8.0]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=40638
[root@tracker nginx-1.8.0]# netstat -unltp | grep nginx
tcp    0    0.0.0.0:8080            0.0.0.0:*              LISTEN      40639/nginx

尝试上传一个文件到FastDFS,然后访问试试。先配置client.conf文件。

vim /etc/fdfs/client.conf

修改以下参数:

base_path=/fdfs/tracker                    #日志存放路径
tracker_server=172.16.1.202:22122          #tracker服务器IP地址和端口号
http.tracker_server_port=8080              #tracker服务器的http端口号

使用/usr/local/bin/fdfs_upload_file上传一个文件,程序会自动返回文件的URL。

[root@tracker nginx-1.8.0]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /mnt/monk.jpg
group3/M00/00/00/rBABz1MzKG6Ad_hBAACKLsUDM60560.jpg

然后使用浏览器访问,可以看到文件被正确读取出来了。

查看nginx的access.log日志,可以看到访问返回200成功。

[root@tracker nginx-1.8.0]# tail -n 10 -f /usr/local/nginx/logs/access.log
172.16.1.201 - - [26/Mar/2014:13:15:00 +0800] "GET /group3/M00/00/00/rBABz1MzKG6Ad_hBAACKLsUDM60560.jpg HTTP/1.1" 200 35374 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

查看nginx的cache目录,可以看到已经生成了缓存文件。

[root@tracker nginx-1.8.0]# ll /var/cache/nginx/proxy_cache/ -R
/var/cache/nginx/proxy_cache/:
总用量 8
drwx------. 3 nobody nobody 4096 3月  26 12:57 6
drwxr-xr-x. 2 nobody root   4096 3月  26 13:14 tmp

/var/cache/nginx/proxy_cache/6:
总用量 4
drwx------. 2 nobody nobody 4096 3月  26 13:08 11

/var/cache/nginx/proxy_cache/6/11:
总用量 36
-rw-------. 1 nobody nobody 35686 3月  26 13:08 b1f6fb1f7266f796765b6d6965021116

如果要手动清除缓存,可以在文件URL之前加上purge:
设置开机自动启动。

vim /etc/rc.d/rc.local

将运行命令行添加进文件:/usr/local/nginx/sbin/nginx

至此,tracker服务器上的http反向代理+负载均衡+缓存已经安装完成。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/9811.html

相关文章

  • FastDFS Docker化部署 以及 Java SpringMVC实践

    摘要:启动后会连接到告知自己的信息,形成映射关联,并采用心跳机制保持状态。存储节点负责文件的存储,可以集群部署。一个卷组内之间相互通信,文件进行同步,保证卷内完全一致,所以一个卷的容量以最小的服务器为准。 简介 FastDFS是一个轻量级分布式文件系统。可以对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,而且可以集群部署,有高可用保障。相应的竞品有Ceph、T...

    li21 评论0 收藏0
  • FastDFS Docker化部署 以及 Java SpringMVC实践

    摘要:启动后会连接到告知自己的信息,形成映射关联,并采用心跳机制保持状态。存储节点负责文件的存储,可以集群部署。一个卷组内之间相互通信,文件进行同步,保证卷内完全一致,所以一个卷的容量以最小的服务器为准。 简介 FastDFS是一个轻量级分布式文件系统。可以对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,而且可以集群部署,有高可用保障。相应的竞品有Ceph、T...

    lemanli 评论0 收藏0
  • FastDFS+Nginx搭建分布式图片存储

    摘要:可以将称为追踪服务器或调度服务器。实际保存文件分为多个组,每个组之间保存的文件是不同的。虚拟磁盘路径配置的虚拟路径,与磁盘选项对应。数据两级目录服务器在每个虚拟磁盘路径下创建的两级目录,用于存储数据文件。1.什么是FastDFS FastDFS是用 c 语言编写的一款开源的分布式文件系统。FastDFS 为互联网量身定制, 充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等...

    CoderDock 评论0 收藏0
  • 图片服务器------FastDFS

    摘要:可以将称为追踪服务器或调度服务器。虚拟磁盘路径配置的虚拟路径,与磁盘选项对应。数据两级目录服务器在每个虚拟磁盘路径下创建的两级目录,用于存储数据文件。链接密码把图片服务器添加到中。要使用图片服务器,需要保证网络配置不变。 什么是FastDFS? FastDFS是用c语言编写的一款开源的分布式文件系统。FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高...

    array_huang 评论0 收藏0
  • 图片服务器------FastDFS

    摘要:可以将称为追踪服务器或调度服务器。虚拟磁盘路径配置的虚拟路径,与磁盘选项对应。数据两级目录服务器在每个虚拟磁盘路径下创建的两级目录,用于存储数据文件。链接密码把图片服务器添加到中。要使用图片服务器,需要保证网络配置不变。 什么是FastDFS? FastDFS是用c语言编写的一款开源的分布式文件系统。FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高...

    solocoder 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<