轻量级分布式文件系统FastDFS安装和调试-分布式文件系统

轻量级分布式文件系统FastDFS安装和调试-分布式文件系统

fastdfs 安装

wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz

wget http://nginx.org/download/nginx-1.4.5.tar.gz

wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz

1. 安装libevent(5.X非必须步骤)

wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

tar -zvxf libevent-2.0.21-stable.tar.gz

cd libevent-2.0.21-stable

./configure --prefix=/usr (必须安装到这里)

make && make install

ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

ps : 我没有安装在那里貌似也可以

./configure --prefix=/usr/local/libevent-2.0.21-stable

make && make install

ln -s /usr/local/libevent-2.0.21-stable/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

2. 安装FastDFS

tar zxvf FastDFS_v5.01.tar.gz

cd FastDFS

vi make.sh (修改"#WITH_LINUX_SERVICE=1"为WITH_LINUX_SERVICE=1)

./make.sh

./make.sh install

3. Storage上安装nginx的附加模块

wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz

tar -zxvf fastdfs-nginx-module_v1.15.tar.gz

安装 ngx_cache_purge-2.1 和 ngx_slowfs_cache-1.9 模块

unzip ngx_slowfs_cache-master.zip

unzip ngx_cache_purge-master.zip

编译nginx

./configure --prefix=/usr/local/nginx-1.4.2 --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_mp4_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_dav_module --with-http_flv_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --add-module=../ngx_cache_purge-master --add-module=../ngx_slowfs_cache-master --add-module=/root/soft/fastdfs-nginx-module/src

make && make install

问题 : service nginx restart 成功 但项目失败 完成下方配置 就可以了

下方的一些参数配置需要编辑/etc/fdfs 一些配置文件

mkdir -p /data/fastdfs/tracker

mkdir -p /data/fastdfs/storage

/*

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

vi /etc/fdfs/mod_fastdfs.conf

修改内容为下方信息

base_path=/data/fastdfs

tracker_server=192.168.1.168:22122

store_path0=/data/images

*/

4. 配置tracker

vi /etc/fdfs/tracker.conf

base_path=/data/fastdfs/tracker

启动:service fdfs_trackerd restart

这里 tracker.conf 配置结束了

5. 配置storage

vi /etc/fdfs/storage.conf

group_name=group1 ==> 此台storage server所属的服务器组名。

base_path=/data/fastdfs/storage ==> 放置data和log的目录。此路径必须保证存在。

store_path0=/data/fastdfs/storage ==> 放置文件的目录,此路径必须保证存在.

tracker_server=192.168.112.131:22122 ==> 可以添加多个tracker_server,如下行

tracker_server=192.168.112.131:22122

http.disabled=true ==> 关闭内置的web server,如果有就设置,否则就不用设置。

http.server_port=80 ==> web server的端口改成8080(与nginx 端口一致)

这里 storage.conf 配置结束了

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

vi /etc/fdfs/mod_fastdfs.conf

base_path=/data/fastdfs/storage ==>放置log的目录,与storage中的配置保持一致。

tracker_server=192.168.112.131:22122

#tracker_server=192.168.112.131:22122

group_name=group1 ==> 此台storage server所属的服务器组名。

url_have_group_name = false ==> 在URL中包含group名称。一定要设置true 如果设置成true 可以在nginx 中 location 中设置

store_path0=/data/fastdfs/storage ==> 放置文件的目录,与storage中保持一致

response_mode=proxy ==> 对文件同步延迟的处理方式,通过redirect跳转和proxy代理两种方式解决

group_count=0 ==> group的个数,在本示例中有两个group,所以设为2,如果只有一个group则设置为0,而不是为1

启动:service fdfs_storaged restart

开放端口

# fdfs

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT

这里fastdfs 配置结束了

接下来配置nginx php关联 fastdfs

6. nginx配置

server节点添加:

vi /usr/local/nginx/conf/nginx.conf

location ~ /M00

{

# slowfs_cache fastcache;

# slowfs_cache_key $uri;

# slowfs_cache_valid 1d;

# add_header X-Cache '$slowfs_cache_status from $host';

# expires max;

if ($request_filename ~ [a-zA-Z0-9]+-([0-9]+)-([0-9]+).(gif|GIF|jpg|JPG|jpeg|JPEG|bmp|BMP|png|PNG)) {

rewrite ^(.*)-[0-9]+-[0-9]+.(gif|GIF|jpg|JPG|jpeg|JPEG|bmp|BMP|png|PNG)$ $1.$2 break;

}

ngx_fastdfs_module;

}

7. php配置

cd /root/soft/FastDFS/php_client

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

ls /usr/local/php-5.4.17/lib/php/extensions/no-debug-non-zts-20100525/

*添加fastdfs 扩展 或者直接执行 cat fastdfs_client.ini >> /usr/local/php/etc/php.ini 这个会自定将扩展模块加入到php.ini

[fastdfs]

extension=fastdfs_client.so

fastdfs_client.base_path = /data/fastdfs/tracker

fastdfs_client.connect_timeout = 2

fastdfs_client.network_timeout = 60

fastdfs_client.log_level = info

fastdfs_client.log_filename =

fastdfs_client.http.anti_steal_secret_key =

fastdfs_client.tracker_group_count = 1

fastdfs_client.tracker_group0 = /etc/fdfs/client.conf

fastdfs_client.use_connection_pool = false

fastdfs_client.connection_pool_max_idle_time = 3600

vi /etc/fdfs/client.conf

base_path=/data/fastdfs/tracker

tracker_server=192.168.112.131:22122

service php-fpm restart

重启php进程

运行测试吧:php fastdfs_test.php

8. 测试方法

1) 查看集群情况

/usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf

2)/usr/local/bin/fdfs_test conf/client.conf upload ~/11.webp

1) 上传一个文件:

<pre>$tracker = fastdfs_tracker_get_connection();

var_dump($tracker);

if (!fastdfs_active_test($tracker))

{

error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());

exit(1);

}

$storage = fastdfs_tracker_query_storage_store();

if (!$storage)

{

error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());

exit(1);

}

$file_info = fastdfs_storage_upload_by_filename("/zxy.webp", null, array(), null, $tracker, $storage);

</pre>

2) 下载一个文件

<pre>$group_name="group0";

$filename="M00/00/00/wKgBpFNN-T6AQZKtAAH4P9ysWgA950.webp";

fastdfs_storage_download_file_to_file($group_name,$filename, "test.webp");

</pre>

3) 删除一个文件

<pre>$group_name="group0";

$filename="M00/00/00/wKgAUE5zkhH8yBZwAAGH3hvfjJA398.webp";

echo fastdfs_storage_delete_file($group_name, $filename);&gt;

</pre>

推荐阅读