当前位置:   article > 正文

FastDFS从入门到精通(二)之集群搭建篇_the method for selecting group to upload files 没生效

the method for selecting group to upload files 没生效

本文主要介绍从零开始搭建一个FastDFS集群,希望对你有所帮助。

一、FastDFS环境安装

1、安装libevent依赖库

FastDFS依赖libevent库,需要安装:

yum -y install libevent

2、安装libfastcommon

libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库。

  1. git clone https://github.com/happyfish100/libfastcommon.git --depth 1
  2. cd libfastcommon/
  3. ./make.sh && ./make.sh install #编译安装

3、安装fastdfs(storage和tracker一样)

  1. cd /Data/apps
  2. git clone https://github.com/happyfish100/fastdfs.git --depth 1
  3. cd fastdfs/
  4. ./make.sh && ./make.sh install #编译安装

4、拷贝配置文件

  1. cp /Data/apps/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用
  2. cp /Data/apps/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用
  3. #配置文件准备(Notice: 根据本机的角色,按需复制粘贴配置文件!)
  4. cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
  5. cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
  6. cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用

5、获取 fastdfs-nginx-module

此 module 用于避免上传完成后,且 group storage 同步文件完成前,客户端从正在同步的主机处下载文件导致的出错
  1. cd /Data/apps
  2. git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
  3. cp /Data/apps/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

6、安装nginx

  • tracker 和 storage 均需要安装 nginx
  • 对于 tracker, nginx 可以均衡负载到不同的 storage
  • 对于 storage, nginx 可以提供反向代理,从而访问数据存储位置的文件
  • 由于需要使用启用非默认 module , 故需要通过源码编译安装,不能使用 yum . 使用源码安装 nginx 的注意事项见《nginx - make install》
  1. wget http://nginx.org/download/nginx-1.15.7.tar.gz #下载 nginx mainline 版本的压缩包
  2. tar -zxvf nginx-1.15.4.tar.gz #解压
  3. cd nginx-1.15.7/
  4. #记得添加fastdfs-nginx-module模块
  5. # nginx configure arguments 内容丰富、配置自由,详见《nginx - make install》
  6. ./configure \
  7. --prefix=/usr/local/nginx \
  8. --user=nginx \
  9. --group=nginx \
  10. --conf-path=/etc/nginx/nginx.conf \
  11. --add-module=/usr/local/src/fastdfs-nginx-module/src/
  12. make && make install #编译安装

 

二、FastDFS配置和启动

  • 需要配置 nginx, tracker, storage 和 client
  • tracker 和 storage 需要搭配 nginx 使用,故在本教程中, nginx 的配置都是关于 tracker 和 storage 的,与 client 无关。
  • tracker, storage 和 client 都有自身的配置项,需要单独配置。

1、tracker配置

vim /etc/fdfs/tracker.conf
  1. port = 1001
  2. base_path = /Data/apps/fastdfs/tracker
  3. connect_timeout = 5
  4. max_connections = 1024
  5. # the method for selecting group to upload files
  6. # 0: round robin
  7. # 1: specify group
  8. # 2: load balance, select the max free space group to upload file
  9. store_lookup = 2
  10. # which storage server to upload file
  11. # 0: round robin (default)
  12. # 1: the first server order by ip address
  13. # 2: the first server order by priority (the minimal)
  14. # Note: if use_trunk_file set to true, must set store_server to 1 or 2
  15. store_server = 0
  16. # which path (means disk or mount point) of the storage server to upload file
  17. # 0: round robin
  18. # 2: load balance, select the max free space path to upload file
  19. store_path = 0
  20. # which storage server to download file
  21. # 0: round robin (default)
  22. # 1: the source storage server which the current file uploaded to
  23. download_server = 0

启动tracker

/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf start|stop|restart

2、storage配置

vim /etc/fdfs/storage.conf
  1. port=1002
  2. #当前主机是什么组,就写什么组
  3. group_name=g1
  4. base_path=/Data/apps/fastdfs/storage
  5. heart_beat_interval = 30
  6. stat_report_interval = 60
  7. store_path0 = /Data/apps/fastdfs/storage_data
  8. subdir_count_per_path = 256
  9. tracker_server = 172.31.125.65:1001
  10. upload_priority = 10
  11. use_access_log = true

启动storage

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start|stop|restart

成功画面

至此,tracker和storage都成功启动了

 

3、client配置

vim /etc/fdfs/client.conf
  1. base_path=/Data/apps/fastdfs/client
  2. tracker_server = 172.31.125.65:1001

mod_FastDFS配置(不是必须)

vim /etc/fdfs/mod_fastdfs.conf
  1. base_path=/Data/apps/fastdfs/module
  2. tracker_server= 172.31.125.65:1001
  3. url_have_group_name=true #url中包含group名称
  4. store_path0=/Data/apps/fastdfs/storage_data #指定文件存储路径

三、FastDFS上传和下载

1、检测集群fdfs_monitor

/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
  1. [2020-02-22 17:42:17] DEBUG - base_path=/Data/apps/fastdfs/storage, connect_timeout=5, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=1, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
  2. server_count=1, server_index=0
  3. tracker server is 172.31.125.65:1001
  4. group count: 1
  5. Group 1:
  6. group name = g1
  7. disk total space = 40,183 MB
  8. disk free space = 30,677 MB
  9. trunk free space = 0 MB
  10. storage server count = 1
  11. active server count = 1
  12. storage server port = 1002
  13. storage HTTP port = 8888
  14. store path count = 1
  15. subdir count per path = 256
  16. current write server index = 0
  17. current trunk file id = 0
  18. Storage 1:
  19. id = 172.31.125.65
  20. ip_addr = 172.31.125.65 ACTIVE
  21. http domain =
  22. version = 6.06
  23. join time = 2020-02-22 17:22:45
  24. up time = 2020-02-22 17:24:44
  25. total storage = 40,183 MB
  26. free storage = 30,677 MB
  27. upload priority = 10
  28. store_path_count = 1
  29. subdir_count_per_path = 256
  30. storage_port = 1002
  31. storage_http_port = 8888
  32. current_write_path = 0
  33. source storage id =
  34. if_trunk_server = 0
  35. connection.alloc_count = 256
  36. connection.current_count = 0
  37. connection.max_count = 0
  38. total_upload_count = 0
  39. success_upload_count = 0
  40. total_append_count = 0
  41. success_append_count = 0
  42. total_modify_count = 0
  43. success_modify_count = 0
  44. total_truncate_count = 0
  45. success_truncate_count = 0
  46. total_set_meta_count = 0
  47. success_set_meta_count = 0
  48. total_delete_count = 0
  49. success_delete_count = 0
  50. total_download_count = 0
  51. success_download_count = 0
  52. total_get_meta_count = 0
  53. success_get_meta_count = 0
  54. total_create_link_count = 0
  55. success_create_link_count = 0
  56. total_delete_link_count = 0
  57. success_delete_link_count = 0
  58. total_upload_bytes = 0
  59. success_upload_bytes = 0
  60. total_append_bytes = 0
  61. success_append_bytes = 0
  62. total_modify_bytes = 0
  63. success_modify_bytes = 0
  64. stotal_download_bytes = 0
  65. success_download_bytes = 0
  66. total_sync_in_bytes = 0
  67. success_sync_in_bytes = 0
  68. total_sync_out_bytes = 0
  69. success_sync_out_bytes = 0
  70. total_file_open_count = 0
  71. success_file_open_count = 0
  72. total_file_read_count = 0
  73. success_file_read_count = 0
  74. total_file_write_count = 0
  75. success_file_write_count = 0
  76. last_heart_beat_time = 2020-02-22 17:41:49
  77. last_source_update = 1970-01-01 08:00:00
  78. last_sync_update = 1970-01-01 08:00:00
  79. last_synced_timestamp = 1970-01-01 08:00:00
  80. [root@iZm5eetbb1qeqn5t6ynbyiZ ~]#

2、上传测试fdfs_upload_file

  1. [root@iZm5eetbb1qeqn5t6ynbyiZ swh]# fdfs_upload_file /etc/fdfs/client.conf conf.php
  2. g1/M00/00/00/rB99QV5Q-IiAJeOIAAAAH75Mdr0476.php
  3. [root@iZm5eetbb1qeqn5t6ynbyiZ swh]#

3、下载测试fdfs_download_file

  1. [root@iZm5eetbb1qeqn5t6ynbyiZ home]# fdfs_download_file /etc/fdfs/client.conf g1/M00/00/00/rB99QV5Q-IiAJeOIAAAAH75Mdr0476.php
  2. [root@iZm5eetbb1qeqn5t6ynbyiZ home]# ls
  3. rB99QV5Q-IiAJeOIAAAAH75Mdr0476.php

4、php上传和下载

上传或者下载,PHP通过安装fastdfs_client扩展完成。

tracker_get_connection();是通过读取本地的/etc/fdfs/client.conf配置文件的配置,连接storage进行上传和下载

参考文档:Fast DFS安装教程

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/923263
推荐阅读
相关标签
  

闽ICP备14008679号