FastDFS 分布式文件服务器安装 分享

代工匠码 2012-11-01

经过几天的折腾,终于搞定了。

现在和大家分享一下:

一、安装libevent

fastDFS需要安装libevent比较新的版本,将本机的比较低的版本卸载了。

rpm -qa libevent
libevent-1.4.13-1.el6.x86_64
rpm -e --nodeps libevent

安装一个最新稳定版

wget https://github.com/downloads/libevent/libevent/libevent-2.0.18-stable.tar.gz
tar zxvf libevent-2.0.18-stable.tar.gz
cd libevent-2.0.18-stable
./configure
make && make install

为libevent创建软链接到/lib库下,64位系统对应/lib64

ln -s /usr/local/lib/libevent* /lib/
ln -s /usr/local/lib/libevent* /lib64/

二、安装FastDFS

wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz
tar zxvf FastDFS_v3.06.tar.gz
cd FastDFS
./make.sh
./make.sh install

三、配置FastDFS

1、配置并启动trackerserver

①配置tracker.conf

mkdir /data/fastdfs
vim /etc/fdfs/tracker.conf
base_path=/data/fastdfs
http.server_port=8080 -> http.server_port=8020
##include http.conf -> #include http.conf

②启动tracker

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

③开机启动

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

2、配置并启动storageserver

①配置storage.conf

mkdir /data/fastdfs
mkdir /data/images
vim /etc/fdfs/storage.conf
base_path=/data/fastdfs
store_path0=/data/images
tracker_server=127.0.0.1:22122

②启动tracker

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

③开机启动

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

3、为storage节点安装fastdfs-nginx-module模块

①安装模块

安装Nginx详见:

需重新编译Nginx

wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.10.tar.gz
tar zxvf fastdfs-nginx-module_v1.10.tar.gz
wget http://nginx.org/download/nginx-1.2.0.tar.gz
tar zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure --prefix=/usr/local/nginx --add-module=../fastdfs-nginx-module/src
make && make install
cd ..

②配置

编辑nginx.conf

vim /usr/local/nginx/conf/nginx.conf
#user  nobody;
user root; --如果下载遇到权限问题就改为root
server {
    listen       8010; 
    server_name  localhost;
 
    location /M00 {
        alias /data/images/data;
        ngx_fastdfs_module;
    }
    ......
}

给storage的存储目录做一个软连接

ln -s /data/images/data/ /data/images/data/M00

拷贝mod_fastdfs.conf到/etc/fdfs/

cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
base_path=/data/fastdfs
tracker_server=127.0.0.1:22122
store_path0=/data/images

启动nginx

/usr/local/nginx/sbin/nginx

四、使用FastDFS

1、上传文件

FastDFS安装包中,自带了客户端程序,通过程序可以进行文件上传。在使用这个客户端程序之前,首先需要配置client.conf,然后再进行文件上传及下载。

在tracker上修改客户端配置文件client.conf

vim /etc/fdfs/client.conf
base_path=/data/fastdfs
tracker_server=127.0.0.1:22122
1
2
vim a.html
This Is FastDFS  HELLO SONGYI.

上传文件

[root@uhzc006469 sy]# /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload a.html
This is FastDFS client test program v3.06

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.

[2012-11-01 23:30:03] INFO - base_path=/home/sy/data/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0

tracker_query_storage_store_list_without_group: 
        server 1. group_name=group1, ip_addr=223.4.155.155, port=23000

group_name=group1, ip_addr=223.4.155.155, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/3wSbm1CSlXv7SNZHAAAAGmciNqs65.html
source ip address: 223.4.155.155
file timestamp=2012-11-01 23:30:03
file size=26
file crc32=1730295467
file url: http://223.4.155.155:8010/group1/M00/00/00/3wSbm1CSlXv7SNZHAAAAGmciNqs65.html
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/3wSbm1CSlXv7SNZHAAAAGmciNqs65_big.html
source ip address: 223.4.155.155
file timestamp=2012-11-01 23:30:03
file size=26
file crc32=1730295467
file url: http://223.4.155.155:8010/group1/M00/00/00/3wSbm1CSlXv7SNZHAAAAGmciNqs65_big.html

上传成功大功告成!

试试用地址栏:

http://223.4.155.155:8010/M00/00/00/3wSbm1CSlXv7SNZHAAAAGmciNqs65_big.html

相关推荐

huhuhuemail / 0评论 2019-02-16