FastDFS安装与配置

一、搭建步骤


1、把FastDFS文件都上传到Linux系统

-rw-r--r--. 1 mark mark    345400 Jul 29 21:04 FastDFS_v5.05.tar.gz
-rw-r--r--. 1 mark mark     17510 Jul 29 21:04 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r--. 1 mark mark     97125 Jul 29 21:04 libfastcommonV1.0.7.tar.gz

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz

2、安装FastDFS之前,先安装gcc、libevent工具包

gcc: yum install gcc-c++

libevent:yum -y install libevent


3、安装libfastcommon工具包

1)、解压缩

[root@com Software]# tar -zxf libfastcommonV1.0.7.tar.gz

2)、make.sh

[root@com Software]# cd libfastcommon-1.0.7
[root@com libfastcommon-1.0.7]# ll
total 24
-rw-rw-r--. 1 root root 2170 Sep 16  2014 HISTORY
-rw-rw-r--. 1 root root  582 Sep 16  2014 INSTALL
-rw-rw-r--. 1 root root 1341 Sep 16  2014 libfastcommon.spec
-rwxrwxr-x. 1 root root 2151 Sep 16  2014 make.sh
-rw-rw-r--. 1 root root  617 Sep 16  2014 README
drwxrwxr-x. 2 root root 4096 Sep 16  2014 src

[root@com libfastcommon-1.0.7]# ./make.sh

[root@com libfastcommon-1.0.7]# ./make.sh install

安装完会在/usr/lib64文件夹下复制 libfastcommon.so

[root@com libfastcommon-1.0.7]# cd /usr/lib64
[root@com usr]# ll libfastcommon*

-rwxr-xr-x.  1 root root   284032 Jul 29 21:43 libfastcommon.so

如果你是32位系统,需要把这个文件复制到/usr/lib


4、安装Tracker服务

1)、解压缩

[root@com Software]# tar -zxf FastDFS_v5.05.tar.gz

2)、make.sh

[root@com Software]# cd FastDFS
[root@com FastDFS]# ls -l
total 132
drwxr-xr-x. 3 8980 users  4096 Dec  1  2014 client
drwxr-xr-x. 2 8980 users  4096 Dec  1  2014 common
drwxr-xr-x. 2 8980 users  4096 Dec  1  2014 conf
-rw-r--r--. 1 8980 users 35067 Dec  1  2014 COPYING-3_0.txt
-rw-r--r--. 1 8980 users  2802 Dec  1  2014 fastdfs.spec
-rw-r--r--. 1 8980 users 31386 Dec  1  2014 HISTORY
drwxr-xr-x. 2 8980 users  4096 Dec  1  2014 init.d
-rw-r--r--. 1 8980 users  7755 Dec  1  2014 INSTALL
-rwxr-xr-x. 1 8980 users  5813 Dec  1  2014 make.sh
drwxr-xr-x. 2 8980 users  4096 Dec  1  2014 php_client
-rw-r--r--. 1 8980 users  2380 Dec  1  2014 README.md
-rwxr-xr-x. 1 8980 users  1768 Dec  1  2014 restart.sh
-rwxr-xr-x. 1 8980 users  1680 Dec  1  2014 stop.sh
drwxr-xr-x. 4 8980 users  4096 Dec  1  2014 storage
drwxr-xr-x. 2 8980 users  4096 Dec  1  2014 test
drwxr-xr-x. 2 8980 users  4096 Dec  1  2014 tracker

[root@com FastDFS]#./make.sh


3)、makesh install

[root@com FastDFS]# ./make.sh install

安装完后会在/usr/bin 下多一些文件,会后到fdfs_storaged和fdfs_trackerd

[root@com FastDFS]# cd /usr/bin
[root@com bin]# ll fdfs_*
-rwxr-xr-x. 1 root root 260988 Jul 29 21:51 fdfs_appender_test
-rwxr-xr-x. 1 root root 260685 Jul 29 21:51 fdfs_appender_test1
-rwxr-xr-x. 1 root root 251053 Jul 29 21:51 fdfs_append_file
-rwxr-xr-x. 1 root root 253513 Jul 29 21:51 fdfs_crc32
-rwxr-xr-x. 1 root root 251072 Jul 29 21:51 fdfs_delete_file
-rwxr-xr-x. 1 root root 251943 Jul 29 21:51 fdfs_download_file
-rwxr-xr-x. 1 root root 251621 Jul 29 21:51 fdfs_file_info
-rwxr-xr-x. 1 root root 264261 Jul 29 21:51 fdfs_monitor
-rwxr-xr-x. 1 root root 891631 Jul 29 21:51 fdfs_storaged
-rwxr-xr-x. 1 root root 267396 Jul 29 21:51 fdfs_test
-rwxr-xr-x. 1 root root 266565 Jul 29 21:51 fdfs_test1
-rwxr-xr-x. 1 root root 379654 Jul 29 21:51 fdfs_trackerd
-rwxr-xr-x. 1 root root 251959 Jul 29 21:51 fdfs_upload_appender
-rwxr-xr-x. 1 root root 253057 Jul 29 21:51 fdfs_upload_file

配置文件都放到了/etc/fdfs,但初始时只有一些sample文件

[root@com bin]# cd /etc/fdfs
[root@com fdfs]# ll
total 20
-rw-r--r--. 1 root root 1461 Jul 29 21:51 client.conf.sample
-rw-r--r--. 1 root root 7829 Jul 29 21:51 storage.conf.sample
-rw-r--r--. 1 root root 7102 Jul 29 21:51 tracker.conf.sample

4)、拷贝所有安装目录/FastDFS/conf下的所有配置文件到/etc/fdfs

[root@com fdfs]# cd /home/mark/Software/FastDFS/conf

[root@com FastDFS]# cd conf
[root@com conf]# ll
total 84
-rw-r--r--. 1 8980 users 23981 Dec  1  2014 anti-steal.jpg
-rw-r--r--. 1 8980 users  1461 Dec  1  2014 client.conf
-rw-r--r--. 1 8980 users   858 Dec  1  2014 http.conf
-rw-r--r--. 1 8980 users 31172 Dec  1  2014 mime.types
-rw-r--r--. 1 8980 users  7829 Dec  1  2014 storage.conf
-rw-r--r--. 1 8980 users   105 Dec  1  2014 storage_ids.conf
-rw-r--r--. 1 8980 users  7102 Dec  1  2014 tracker.conf

[root@com conf]# cp * /etc/fdfs/

[root@com fdfs]# ll
total 104
-rw-r--r--. 1 root root 23981 Jul 29 22:00 anti-steal.jpg
-rw-r--r--. 1 root root  1461 Jul 29 22:00 client.conf
-rw-r--r--. 1 root root  1461 Jul 29 21:51 client.conf.sample
-rw-r--r--. 1 root root   858 Jul 29 22:00 http.conf
-rw-r--r--. 1 root root 31172 Jul 29 22:00 mime.types
-rw-r--r--. 1 root root  7829 Jul 29 22:00 storage.conf
-rw-r--r--. 1 root root  7829 Jul 29 21:51 storage.conf.sample
-rw-r--r--. 1 root root   105 Jul 29 22:00 storage_ids.conf
-rw-r--r--. 1 root root  7102 Jul 29 22:00 tracker.conf
-rw-r--r--. 1 root root  7102 Jul 29 21:51 tracker.conf.sample

5)、配置Tracker服务

[root@com fdfs]# cp tracker.conf tracker.conf.bak
[root@com fdfs]# vim tracker.conf

更改fastdfs日志路径

base_path=/home/yuqing/fastdfs   --->    /home/mark/fastdfs

创建日志路径

[root@com fdfs]# mkdir -p /home/mark/fastdfs/tracker



6)、启动tracker

[root@com fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

重启使用

[root@com fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
waiting for pid [5330] exit ...
starting ...

查看进程

[root@com fdfs]# ps aux|grep tracker
root      5340  0.0  0.2  78728  2788 ?        Sl   22:12   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
root      5351  0.0  0.0 103308   832 pts/0    S+   22:13   0:00 grep tracker
[root@com fdfs]#

5、安装Storage服务

1)、如果tracker和storage安装在不同的服务器,第四步的1~4要重新安装

2)、配置storage服务

[root@com fdfs]# cd /etc/fdfs
[root@com fdfs]# ll
total 112
-rw-r--r--. 1 root root 23981 Jul 29 22:00 anti-steal.jpg
-rw-r--r--. 1 root root  1461 Jul 29 22:00 client.conf
-rw-r--r--. 1 root root  1461 Jul 29 21:51 client.conf.sample
-rw-r--r--. 1 root root   858 Jul 29 22:00 http.conf
-rw-r--r--. 1 root root 31172 Jul 29 22:00 mime.types
-rw-r--r--. 1 root root  7829 Jul 29 22:00 storage.conf
-rw-r--r--. 1 root root  7829 Jul 29 21:51 storage.conf.sample
-rw-r--r--. 1 root root   105 Jul 29 22:00 storage_ids.conf
-rw-r--r--. 1 root root  7100 Jul 29 22:07 tracker.conf
-rw-r--r--. 1 root root  7102 Jul 29 22:06 tracker.conf.bak
-rw-r--r--. 1 root root  7102 Jul 29 21:51 tracker.conf.sample


[root@com fdfs]# vim storage.conf


# the base path to store data and log files
base_path=/home/yuqing/fastdfs    ---->    /home/mark/fastdfs/storage

store_path0=/home/yuqing/fastdfs    ---->    /home/mark/fastdfs/storage

tracker_server=192.168.209.121:22122   ---->    tracker_server=192.168.86.130:22122 ##自己的Ip


3)、  启动storage服务

[root@com fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf

重启可以加上 restart

[root@com fdfs]# ps aux|grep storage
root      3220  0.0  6.5  80848 66732 ?        Sl   17:35   0:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root      3268  0.0  0.0 103308   828 pts/0    S+   17:43   0:00 grep storage
[root@com fdfs]#



6、测试服务

1) 要修改一个配置文件

[root@com fdfs]# vim client.conf

base_path=/home/yuqing/fastdfs    ---->    /home/mark/fastdfs/client

tracker_server=192.168.209.121:22122   ---->    tracker_server=192.168.86.130:22122 ##自己的Ip

2) 测试

[root@com fdfs]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg



7、搭建Nginx提供HTTP服务

1)、可以使用官方的nginx插件。要使用nginx插件需要重新编
[root@com Software]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
[root@com Software]# cd fastdfs-nginx-module
[root@com fastdfs-nginx-module]# ll
total 12
-rw-rw-r--. 1 mark mark 2342 May  4  2014 HISTORY
-rw-rw-r--. 1 mark mark 1733 May  4  2014 INSTALL
drwxrwxr-x. 2 mark mark 4096 May  4  2014 src
[root@com fastdfs-nginx-module]# cd src
[root@com src]# ll
total 76
-rw-rw-r--. 1 mark mark 33207 Aug 29  2013 common.c
-rw-rw-r--. 1 mark mark  3479 Jan  2  2012 common.h
-rw-rw-r--. 1 mark mark   447 Nov  4  2010 config
-rw-rw-r--. 1 mark mark  3679 Mar 29  2013 mod_fastdfs.conf
-rw-rw-r--. 1 mark mark 28542 May  4  2014 ngx_http_fastdfs_module.c
[root@com src]# vim config
把所有/usr/local/include改成/usr/include,因为我们的fastdfs路径都是/usr/include


2)、nginx重新config,添加插件


[root@com Software]# tar -zxvf nginx-1.8.1.tar.gz
[root@com Software]# cd nginx-1.8.1

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/home/mark/Software/fastdfs-nginx-module/src ##你的fastdfs 插件的路径

3)、make

4)、make install

5)、把/home/mark/Software/fastdfs-nginx-module/src/mod_fastdfs.conf拷贝到/etc/fdfs

[root@com src]# cp mod_fastdfs.conf /etc/fdfs


编辑[root@com fdfs]# vim mod_fastdfs.conf
base_path=/tmp ##日志存放路径

tracker_server=tracker:22122##tracker 服务器地址---->tracker_server=192.168.86.130:22122

url_have_group_name = false ----> true

store_path0=/home/yuqing/fastdfs  ---->/home/mark/fastdfs/storage

6)、Nginx的配置

[root@com fdfs]# cd /usr/local/nginx
[root@com nginx]# ll
total 12
drwxr-xr-x. 2 root root 4096 Jul 23 22:34 conf
drwxr-xr-x. 2 root root 4096 Jul 23 22:34 html
drwxr-xr-x. 2 root root 4096 Aug  5 23:22 sbin

[root@com nginx]# cd conf

在nginx的配置文件中添加一个server


    server {
        listen       80;
        server_name  mark.com;

        location /group1/M00/ {
            ngx_fastdfs_module;
        }
    }
##需要设置user, 否则会在nginx/logs/error.log出现Permission denied
user root

保存;重新加载配置文件[root@com conf]# service nginx reload

7)、将libdfsclient.so 拷贝至/usr/lib下

[root@com lib64]# cp /usr/lib64/libfdfsclient.so /usr/lib


8)、启动nginx

[root@com lib64]# service nginx restart
ngx_http_fastdfs_set pid=8135
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
Stopping nginx:                                            [  OK  ]
Starting nginx: ngx_http_fastdfs_set pid=8143
                                                           [  OK  ]

fastdfs插件独立占一个进程

9)、测试

[root@com fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf  ##启动tracker
[root@com fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf ##启动storage

[root@com fdfs]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg
This is FastDFS client test program v5.05

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.

[2016-08-05 23:56:09] DEBUG - base_path=/home/mark/fastdfs/client, 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

tracker_query_storage_store_list_without_group:
 server 1. group_name=, ip_addr=192.168.86.130, port=23000

group_name=group1, ip_addr=192.168.86.130, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKhWgleligmAIp5vAABdrZgsqUU420.jpg
source ip address: 192.168.86.130
file timestamp=2016-08-05 23:56:09
file size=23981
file crc32=2553063749
example file url: http://192.168.86.130/group1/M00/00/00/wKhWgleligmAIp5vAABdrZgsqUU420.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKhWgleligmAIp5vAABdrZgsqUU420_big.jpg
source ip address: 192.168.86.130
file timestamp=2016-08-05 23:56:09
file size=23981
file crc32=2553063749
example file url: http://192.168.86.130/group1/M00/00/00/wKhWgleligmAIp5vAABdrZgsqUU420_big.jpg


在浏览器输入:http://mark.com/group1/M00/00/00/wKhWgleligmAIp5vAABdrZgsqUU420_big.jpg








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值