FastDFS笔记(一): 安装

2019-07-31  本文已影响0人  warmsirius

写在前面

这几天项目中用到了fastdfs,安装是个痛苦的过程,各种BUG,写篇文章纪念一下。

参考博客

1、安装 libfastcommon

tar -xzf libfastcommonV1.0.7.tar.gz
./make.sh && sudo ./make.sh install
sudo cp /usr/lib64/* /usr/lib/

2、编译FastDFS

tar zxf FastDFS_v5.05.tar.gz
./make.sh
sudo ./make.sh install
sudo cp conf/* /etc/fdfs/

3、安装tracker

base_path=/home/yuqing/fastdfs >>> base_path=/home/warmsirius/data/fastdfs

http.server_port=8080 >>> http.server_port=80
$ fdfs_trackerd /etc/fdfs/tracker.conf start
$ netstat -unltp | grep tracker
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      7281/fdfs_trackerd

4、安装storage

base_path=/home/yuqing/fastdfs >>> base_path=/home/warmsirius/data/fastdfs/storage
store_path0=/home/yuqing/fastdfs >>> store_path0=/home/warmsirius/data/fastdfs/storage
tracker_server=192.168.209.121:22122 >>> tracker_server=192.168.2.231:22122
http.server_port=80 >>> http.server_port=8888
$ fdfs_storaged /etc/fdfs/storage.conf start
$ netstat -unltp | grep storage
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      7348/fdfs_storaged
$ fdfs_monitor /etc/fdfs/storage.conf
...
current trunk file id = 0

    Storage 1:
        id = 192.168.2.231
        ip_addr = 192.168.2.231  ACTIVE
...

如上提示,出现ACTIVE,表示二者均正常启动,至此就可以进行上传文件测试了。

5、mod_fastdfs.conf和client.conf配置

mod_fastdfs.conf

tar -xvf fastdfs-nginx-module_v1.16.tar.gz;
cp path_to_fdfsdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf

base_path=/home/warmsirius/data/fastdfs
tracker_server=192.168.2.231:22122
url_have_group_name = true
store_path0=/home/warmsirius/data/fastdfs/storage

client.conf

$ sudo vi /etc/fdfs/client.conf
...
base_path=/home/warmsirius/data/fastdfs
tracker_server=192.168.2.231:22122
...

6、安装Nginx

cp -r /home/warmsirius/fastdfs-nginx-module/ /usr/local/src
$ sudo ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/

如果出现如下错误,

error: the HTTP rewrite module requires the PCRE library
请安装libpcre3和ssh的库

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

之后再执行configure配置,完成后进行安装:

sudo make

如果出现如下错误:

root/fastdfs-nginx-module/src//common.c:21:25: fatal error: fdfs_define.h: No such file or directory
 #include "fdfs_define.h"

则需要再添加如下配置:

sudo cp /usr/lib64/libfdfsclient.so /usr/lib/
sudo vi /usr/local/src/fastdfs-nginx-module/src/config


...
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
...

之后就可以执行编译和安装了:

sudo make && sudo make install

完成之后,可以查看fastdfs-nginx-module是否配置成功(下面提示表示配置成功):

/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.1
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
configure arguments: --add-module=/usr/local/src/fastdfs-nginx-module/src

7、整合fastdfs-nginx-module 和 Nginx

base_path=/home/warmsirius/data/fastdfs
tracker_server=192.168.2.231:22122
url_have_group_name = true
store_path0=/home/warmsirius/data/fastdfs/storage

然后配置Nginx,添加如下内容:

    server {
        listen       8888;# 注意这个端口要和storage.conf中的http.server_port一致
        server_name  localhost;

        ...

         # 配置fastdfs的访问路径
        location ~/group[0-9]/ {
            ngx_fastdfs_module;
        }
        ...
    }
$ sudo /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=23238
sudo /usr/local/nginx/sbin/nginx  -s stop

上传测试

然后,创建一个test.txt文件,随便输入一些内容,再进行上传:

$ echo HelloWorld > ~/test.txt
$ fdfs_test /etc/fdfs/client.conf upload ~/test.txt
...
[2017-09-23 20:12:00] DEBUG - base_path=/home/kelvin/data/fastdfs, 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.2.231, port=23000

group_name=group1, ip_addr=192.168.2.231, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgC51nHIoCACtpSAAAAC5KLpvs082.txt
source ip address: 192.168.2.231
file timestamp=2017-09-23 20:12:00
file size=11
file crc32=2458625787
example file url: http://192.168.2.231/group1/M00/00/00/wKgC51nHIoCACtpSAAAAC5KLpvs082.txt
...

最后,在浏览器里输入http://192.168.2.231/group1/M00/00/00/wKgC51nHIoCACtpSAAAAC5KLpvs082.txt,即可访问到test.txt的文件内容:

安装注意事项

上一篇 下一篇

猜你喜欢

热点阅读