centos 7 安装FastDFS 5.09

原博客地址:http://blog.csdn.net/hohoo1990/article/details/51444793


安装FastDFS还需要安装libfastcommon作为前提条件,首先准备安装包FastDFS和libfastcommon。

libfastcommon下载地址: https://github.com/happyfish100/libfastcommon/releases

FastDFS的下载地址:https://github.com/happyfish100/fastdfs/releases

首先安装libfastcommon,得到libfastcommon-1.0.35.tar.gz后解压、编译、安装:

[plain]  view plain  copy
  1. # tar xvf libfastcommon-1.0.35.tar.gz   
  2. # cd libfastcommon-1.0.35  
  3. # ./make.sh  
  4. # ./make.sh install  
libfastcommon之前的版本安装好后的库文件,32位系统安装在/usr/lib中,64位系统安装在/usr/lib64下。由于FastDFS程序引用usr/lib目录,所以需要将/usr/lib64下的库文件拷贝至/usr/lib下。但是1.0.35这个版本我看了一下,在/usr/lib和/usr/lib64下都有libfastcommon.so文件存在,不用再手动复制了,如果没有,那就复制一下。

接着安装FastDFS,得到FastDFS_v5.09.tar.gz后解压:

[plain]  view plain  copy
  1. #tar xvf FastDFS_v5.09.tar.gz  

[html]  view plain  copy
  1. #./make.sh   
确认make没有错误后,执行安装,默认会安装到/usr/bin中,并在/etc/fdfs中添加三个配置文件。

[html]  view plain  copy
  1. # ./make.sh install  

安装成功后,可执行文件在/usr/bin/目录下,以fdfs_为前缀,配置文件在/etc/fdfs/目录下,当然,安装源文件的conf目录中也有几个其他的配置文件。

在/etc/fdfs查看生成的配置文件:

[html]  view plain  copy
  1. # cd /etc/fdfs  
  2. # ls  
  3. client.conf.sample  storage.conf.sample  tracker.conf.sample  storage_ids.conf.sample  
首先将三个文件的名字去掉sample,暂时只修改以下几点,先让fastdfs跑起来,其余参数调优的时候再考虑。

[html]  view plain  copy
  1. # mv client.conf.sample client.conf  
  2. # mv storage.conf.sample storage.conf  
  3. # mv tracker.conf.sample tracker.conf  
  4. # mv storage_ids.conf.sample storage_ids.conf  

tracker.conf 中修改以下几处,采用server id作为存储服务器标识,以便以后的迁移。

[html]  view plain  copy
  1. # the base path to store data and log files  
  2. base_path=/data/fdfs/base  
  3.   
  4. # if use storage ID instead of IP address  
  5. # default value is false  
  6. # since V4.00  
  7. use_storage_id = true  
  8.   
  9. # specify storage ids filename, can use relative or absolute path  
  10. # since V4.00  
  11. storage_ids_filename = storage_ids.conf  
  12.   
  13. # id type of the storage server in the filename, values are:  
  14. ## ip: the ip address of the storage server  
  15. ## id: the server id of the storage server  
  16. # this paramter is valid only when use_storage_id set to true  
  17. # default value is ip  
  18. # since V4.03  
  19. id_type_in_filename = id  
  20.    
在storage.conf中修改,groupname暂定为group1,tracker_server改为内网地址

[html]  view plain  copy
  1. # the base path to store data and log files  
  2. base_path=/data/fdfs/base  
  3.    
[html]  view plain  copy
  1. # store_path#, based 0, if store_path0 not exists, it's value is base_path  
  2. # the paths must be exist  
  3. store_path0=/data/fdfs/store_group1  
[html]  view plain  copy
  1. # tracker_server can ocur more than once, and tracker_server format is  
  2. #  "host:port", host can be hostname or ip address  
  3. tracker_server=192.168.183.128:22122  
在client.conf中修改

[html]  view plain  copy
  1. # the base path to store log files  
  2. base_path=/data/fdfs/base  
  3.   
  4. # tracker_server can ocur more than once, and tracker_server format is  
  5. #  "host:port", host can be hostname or ip address  
  6. tracker_server=192.168.183.128:22122  
  7.   
  8. # if use storage ID instead of IP address  
  9. # same as tracker.conf  
  10. # valid only when load_fdfs_parameters_from_tracker is false  
  11. # default value is false  
  12. # since V4.05  
  13. use_storage_id = true  
  14.   
  15. # specify storage ids filename, can use relative or absolute path  
  16. # same as tracker.conf  
  17. # valid only when load_fdfs_parameters_from_tracker is false  
  18. # since V4.05  
  19. storage_ids_filename = storage_ids.conf  
  20.   
  21. #HTTP settings  
  22. http.tracker_server_port=8080  
  23.   
  24. #use "#include" directive to include HTTP other settiongs  
  25. #include http.conf   
启动tracker和storage

[html]  view plain  copy
  1. [root@iZ259rykn9vZ ~]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf  
  2. [root@iZ259rykn9vZ ~]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf   

[html]  view plain  copy
  1. [root@iZ259rykn9vZ fdfs]# ps -ef|grep fdfs  
  2. root      1741     1  0 16:51 ?        00:00:00 /usr/local/FastDFS/bin/fdfs_trackerd /etc/fdfs/tracker.conf  
  3. root      1787     1  0 17:16 ?        00:00:00 /usr/local/FastDFS/bin/fdfs_storaged /etc/fdfs/storage.conf  
  4. root      1797 27704  0 17:17 pts/0    00:00:00 grep fdfs  

EI,看来是启动成功了。

那下面来上传或者删除测试一下能不能用。

[html]  view plain  copy
  1. [root@iZ259rykn9vZ local]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/local/86.jpg  
  2. This is FastDFS client test program v5.05  
  3.   
  4. Copyright (C) 2008, Happy Fish / YuQing  
  5.   
  6. FastDFS may be copied only under the terms of the GNU General  
  7. Public License V3, which may be found in the FastDFS source kit.  
  8. Please visit the FastDFS Home Page http://www.csource.org/   
  9. for more detail.  
  10.   
  11. [2016-05-18 17:26:30] DEBUG - base_path=/root/fastdfsdata, connect_timeout=30network_timeout=60tracker_server_count=1anti_steal_token=0, anti_steal_secret_key length=0use_connection_pool=0g_connection_pool_max_idle_time=3600suse_storage_id=0, storage server id count: 0  
  12.   
  13. tracker_query_storage_store_list_without_group:   
  14.     server 1. group_name=, ip_addr=12x.5x.x2.x9, port=23000  
  15.   
  16. group_name=group1ip_addr=12x.5x.x2.x9, port=23000  
  17. storage_upload_by_filename  
  18. group_name=group1remote_filename=M00/00/00/eziEHVc8NUaABy2WAAC8HVEx1pI625.jpg  
  19. source ip address: 12x.5x.x2.x9  
  20. file timestamp=2016-05-18 17:26:30  
  21. file size=48157  
  22. file crc32=1362220690  
  23. example file url: http://12x.5x.x2.x9/group1/M00/00/00/eziEHVc8NUaABy2WAAC8HVEx1pI625.jpg  
  24. storage_upload_slave_by_filename  
  25. group_name=group1remote_filename=M00/00/00/eziEHVc8NUaABy2WAAC8HVEx1pI625_big.jpg  
  26. source ip address: 12x.5x.x2.x9  
  27. file timestamp=2016-05-18 17:26:30  
  28. file size=48157  
  29. file crc32=1362220690  
  30. example file url: http://12x.5x.x2.x9/group1/M00/00/00/eziEHVc8NUaABy2WAAC8HVEx1pI625_big.jpg  

这说明上传成功了。那再删除试试。删除文件需要完整的group_name和remote_filename。

[html]  view plain  copy
  1. [root@iZ259rykn9vZ local]# /usr/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/eziEHVc8NUaABy2WAAC8HVEx1pI625.jpg  
立即返回,执行结束。


如果要添加多个group,只需添加多个storage.conf即可,修改其中的groupid,port ,tracker_server。然后使用以下方式启动OK。

[html]  view plain  copy
  1. /usr/bin/fdfs_storaged /etc/fdfs/storage.conf.*  

然后再看一下进程:

[html]  view plain  copy
  1. root      7086     1  0 15:31 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf  
  2. root      7150     1  0 15:48 ?        00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.group1.conf  
  3. root      7170     1  0 15:56 ?        00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.group2.conf  
  4. root      7181     1  0 15:56 ?        00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.group3.conf  
  5. root      7192     1  0 15:56 ?        00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.group4.conf  

简略安装流程就完了。

下面安装一下nginx模块

安装fastdfs-nginx-module的依赖包:

yum install -y libevent-devel pcre-devel zlib-devel

下载fastdfs-nginx-module、nginx(http://nginx.org/en/download.html)源代码:

        fastdfs-nginx-module:https://github.com/happyfish100/fastdfs-nginx-module

        nginx:http://nginx.org/en/download.html

tar -xzvf nginx-1.12.0.tar.gz

cd nginx-1.12.0

./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src

make

编译没有成功,错误如下:

[plain]  view plain  copy
  1.     /usr/local/fastdfs-nginx-module-master/src/ngx_http_fastdfs_module.c  
  2. In file included from /usr/local/fastdfs-nginx-module-master/src/ngx_http_fastdfs_module.c:6:0:  
  3. /usr/local/fastdfs-nginx-module-master/src/common.c: 在函数‘fdfs_http_request_handler’中:  
  4. /usr/local/fastdfs-nginx-module-master/src/common.c:1245:61: 错误:‘FDFSHTTPParams’没有名为‘support_multi_range’的成员  
  5.                  (pContext->range_count > 1 && !g_http_params.support_multi_range))  
  6.                                                              ^  
  7. make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] 错误 1  
  8. make[1]: 离开目录“/usr/local/nginx-1.12.0”  
  9. make: *** [build] 错误 2  

网上查了下资料,是因为fastdfs-nginx-module版本问题,我搭建的版本是Version 5.09 2016-12-29。作者还有一个5.10的发行版本,你如果没有下载最近的,整合nginx的时候可能会遇到这个问题。

遇到这个错误的原因是,在fastdfs-nginx-module的HISTORY中你可以看到:



整合的时候,fastdfs-nginx-module中的support_multi_range在Version 5.10以下的版本中找不到。

Version 5.11对应的fastdfs-nginx-module的Version 1.20 

Version 5.10对应的fastdfs-nginx-module的Version 1.19

所以我这边fastdfs-nginx-module选择1.20以前的版本:

重新解压,config,编译等了一会,幸好,编译成功了,make install,Nginx安装成功了。

然后将fastdfs-nginx-module下的配置文件复制一份到/etc/fdfs/目录:

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

修改Nginx配置文件

[plain]  view plain  copy
  1.     server {  
  2.         listen       80;  
  3.         server_name  localhost;  
  4.   
  5.         location ~ /group[0-9]/M00 {  
  6.             ngx_fastdfs_module;  
  7.         }  
  8. }  
修改配置文件/etc/fdfs/mod_fastdfs.conf:
[plain]  view plain  copy
  1. # the base path to store log files  
  2. base_path=/data/fdfs/base  
  3.   
  4. # if use storage ID instead of IP address  
  5. # same as tracker.conf  
  6. # valid only when load_fdfs_parameters_from_tracker is false  
  7. # default value is false  
  8. # since V1.13  
  9. use_storage_id = true  
  10.   
  11. # store_path#, based 0, if store_path0 not exists, it's value is base_path  
  12. # the paths must be exist  
  13. # must same as storage.conf  
  14. store_path0=/data/fdfs/store_group1  
  15. #store_path1=/home/yuqing/fastdfs1  
  16.   
  17. # if the url / uri including the group name  
  18. # set to false when uri like /M00/00/00/xxx  
  19. # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx  
  20. # default value is false  
  21. url_have_group_name = true  

然后启动Nginx:

/usr/local/nginx/sbin/nginx

然后手动上传一图片:

[plain]  view plain  copy
  1. # /usr/bin/fdfs_upload_file /etc/fdfs/client.conf ./QQ截图20170623110805.png   
  2. group1/M00/00/00/oYYBAFlKDieAeWa2AACnkZKtWGY917.png  

在另外一主机浏览器测试,地址栏输入

http://192.168.183.128/group1/M00/00/00/oYYBAFlKDieAeWa2AACnkZKtWGY917.png

结果,其实是没反应的,啥都没有,直到超时结束。

猜测是因为防火墙的问题,查看进程:

[plain]  view plain  copy
  1. # ps -ef|grep firewalld  
  2. root        637      1  0 6月19 ?       00:00:04 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid  
  3. root      24040   6428  0 14:57 pts/0    00:00:00 grep --color=auto firewalld  

先关了吧,

# service firewalld stop

然后再试一下,就真的可以了。


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值