FASTDFS在OPENSUSE环境搭建

源码:http://code.google.com/p/fastdfs/

论坛:http://bbs.chinaunix.net/forum-240-1.html

配置说明:http://bbs.chinaunix.net/thread-1941456-1-1.html

 

安装篇

  1. 1.    服务器说明

角色

IP

操作系统

依赖软件

tracker

162.119.111.183

SUSE11.SP1

Fastdfs

libevent

nginx

storage

162.119.111.183

162.119.111.184

SUSE11.SP1

Fastdfs

libevent

nginx

fastdfs-nginx-module

  1. 2.    软件版本

软件名

版本

下载路径

libevent

  1. 0.21-stable

https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

Fastdfs

V4.0.6

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

fastdfs-nginx-module

v1.15

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

nginx

  1. 4.4

http://nginx.org/download/nginx-1.4.4.tar.gz

  1. 3.    安装libevent

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

>> cd libevent-2.0.21-stable

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

>> make

>>make install

 

64为系统执行

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

 

  1. 4.    安装FastDFS

>> tar zvxf FastDFS_v4.06.tar.gz

>> cd FastDFs

>> ./make.sh

>> ./make.sh install

安装成功后,FastDFS 安装在/usr/local/bin中。配置文件在/etc/fdfs

至此,FastDFS安装完毕

  1. 5.    Storage上安装nginx

FastDFS通过HTTP服务器来提供HTTP服务。为了支持高并发的访问,以及提供负载均衡等高性能的服务,本示例使用nginx作为HTTP服务器,FastDFS为我们提供了Nginx上使用的FastDFS模块(fastdfs-nginx-module)。此步操作只需要在storage上执行。tracker上不用执行。

>>  tar -zxvf fastdfs-nginx-module_v1.11.tar.gz   

(解压后的路径为/home/fastdfs/fastdfs-nginx-module/)

>> tar -zxvf nginx-1.4.4.tar.gz

>> cd nginx-1.4.4

>>./configure --add-module=/usr/fastdfs-nginx-module/src

>> make

>> make install 

 

 

配置启动篇

 

 

  1. 1.    tracker启动

mkdir /home/fastdfs/storage

 

vi /etc/fdfs/tracker.conf

base_path=/home/fastdfs/tracker    ====>放置datalog的目录。这个路径必须存在

##include http.conf 修改为#include http.conf    ====> 这里一定要注意!是 #include,不是include!!! 如果没有此配置项,则不需要处理

 

启动:

/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

关闭:

/usr/local/bin/stop.sh /usr/local/bin/fdfs_tracker

 

  1. 2.    storage启动

mkdir /home/fastdfs/storage

 

vi /etc/fdfs/storage.conf

 

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

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

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

tracker_server=162.119.111.183:22122  

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

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

 

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

vi  /etc/fdfs/mod_fastdfs.conf

 

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

tracker_server=162.119.111.183:22122   

 

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

url_have_group_name = true    ==> URL中包含group名称。一定要设置true

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

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

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

 

启动storage

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

关闭 storage

/usr/local/bin/stop.sh /usr/local/bin/fdfs_storage

  1. 3.    nginx启动(只需在storage启动)

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

 

server

  {

 

    location ~ /group([0-9])/M00

{

         alias /home/fastdfs/storage/data;

        ngx_fastdfs_module;

    }

    listen 8080;

    server_name  162.119.111183;

  }

启动ngnix

/usr/local/nginx/sbin/nginx

-----------------------------------------华丽的分割线-------------------------------------

到此fastdfs已经搭建完毕。

 

测试篇

  1. 1.    查看集群情况

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

 

  1. 2.    Upload测试

vi /etc/fdfs/client.conf

base_path=/home/fastdfs/storage

tracker_server=162.119.111.183:22122   

http.tracker_server_port=8080 //这个一定要跟tracker.conf里面配置的一样

##include http.conf 修改为#include http.conf    ====> 这里一定要注意!是 #include,不是include!!! 如果没有此配置项,则不需要处理

/usr/local/bin/fdfs_test /etc/fdfs/client.conf  upload  hello.txt

  1. 3.    下载测试

 

FastDFS 4.06Tracker Server不再内置http服务

访问文件有四种方式

1, 直接storage ip方式, 可供临时访问
2, dns
轮转
3,
负载均衡设备
4,
加一层代理.

 

采用第三种方式,引入nginx,做反向代理进行负载均衡

 

安装nginx不用引入 --add-module=/home/fastdfs/fastdfs-nginx-module/src

>> tar -zxvf nginx-1.4.4.tar.gz

>> cd nginx-1.4.4

>>./configure

>> make

>> make install 

 

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

upstream 162.119.111.183 {

        server 162.119.111.183:8080 weight=10;

        server 162.119.111.184:8080 weight=10;

        }

    server {

        listen       80;

        server_name  162.119.111.183;

 location / {

                proxy_pass    http://162.119.111.183/;

                proxy_redirect default ;

        }

}

 

Notice

*tracker 按正常部署。tracker 可部署在内网区,不对外。
*
每个storage都安装nginxfastdfs扩展模块,防止访问到此storage时文件不在此处,扩展模块能自动到其他服务器拿文件。storage可部署在内网区,不对外。
*
增加一个或多个负载均衡服务器(haproxy,nginx),每个group都做下storage配置,可负载,可解决单个storage服务器挂掉的问题。

 

 

参考:

http://www.cnblogs.com/chenfei0801/p/3455257.html

http://www.cnblogs.com/chenfei0801/p/3446697.html

http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=4101154


你可能感兴趣的:(fastDFS)