安装FastDFS

安装libfastcommon

安装FastDFS之前要先安装它的依赖库libfastcommon,

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

  1. git clone https://github.com/happyfish100/libfastcommon.git
  2. cd libfastcommon; git checkout V1.0.48
  3. ./make.sh clean && ./make.sh && ./make.sh install

或使用压缩包:解压libfastcommon-master压缩包

  1. unzip libfastcommon-master.zip

或者

  1. tar -zxvf libfastcommon-master.tar.gz

进入libfastcommon目录

  1. cd libfastcommon

编译libfastcommon

  1. ./make.sh

安装libfastcommon

  1. ./make.sh install

安装FastDFS

安装FastDFS

下载地址:https://github.com/happyfish100/fastdfs.git

  1. FastDFS may be copied only under the terms of the GNU General
  2. Public License V3, which may be found in the FastDFS source kit.
  3. Please visit the FastDFS Home Page for more detail.
  4. Chinese language: http://www.fastken.com/
  5. # step 1. download libfastcommon source codes and install it,
  6. # github address: https://github.com/happyfish100/libfastcommon.git
  7. # gitee address: https://gitee.com/fastdfs100/libfastcommon.git
  8. # command lines as:
  9. git clone https://github.com/happyfish100/libfastcommon.git
  10. cd libfastcommon; git checkout V1.0.43
  11. ./make.sh clean && ./make.sh && ./make.sh install
  12. # step 2. download fastdfs source codes and install it,
  13. # github address: https://github.com/happyfish100/fastdfs.git
  14. # gitee address: https://gitee.com/fastdfs100/fastdfs.git
  15. # command lines as:
  16. git clone https://github.com/happyfish100/fastdfs.git
  17. cd fastdfs; git checkout V6.06
  18. ./make.sh clean && ./make.sh && ./make.sh install
  19. # step 3. setup the config files
  20. # the setup script does NOT overwrite existing config files,
  21. # please feel free to execute this script (take easy :)
  22. ./setup.sh /etc/fdfs
  23. # step 4. edit or modify the config files of tracker, storage and client
  24. such as:
  25. vi /etc/fdfs/tracker.conf
  26. vi /etc/fdfs/storage.conf
  27. vi /etc/fdfs/client.conf
  28. and so on ...
  29. # step 5. run the server programs
  30. # start the tracker server:
  31. /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
  32. # start the storage server:
  33. /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
  34. # (optional) in Linux, you can start fdfs_trackerd and fdfs_storaged as a service:
  35. /sbin/service fdfs_trackerd restart
  36. /sbin/service fdfs_storaged restart
  37. # step 6. (optional) run monitor program
  38. # such as:
  39. /usr/bin/fdfs_monitor /etc/fdfs/client.conf
  40. # step 7. (optional) run the test program
  41. # such as:
  42. /usr/bin/fdfs_test <client_conf_filename> <operation>
  43. /usr/bin/fdfs_test1 <client_conf_filename> <operation>
  44. # for example, upload a file for test:
  45. /usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h
  46. tracker server config file sample please see conf/tracker.conf
  47. storage server config file sample please see conf/storage.conf
  48. client config file sample please see conf/client.conf
  49. Item detail
  50. 1. server common items
  51. ---------------------------------------------------
  52. | item name | type | default | Must |
  53. ---------------------------------------------------
  54. | base_path | string | | Y |
  55. ---------------------------------------------------
  56. | disabled | boolean| false | N |
  57. ---------------------------------------------------
  58. | bind_addr | string | | N |
  59. ---------------------------------------------------
  60. | network_timeout | int | 30(s) | N |
  61. ---------------------------------------------------
  62. | max_connections | int | 256 | N |
  63. ---------------------------------------------------
  64. | log_level | string | info | N |
  65. ---------------------------------------------------
  66. | run_by_group | string | | N |
  67. ---------------------------------------------------
  68. | run_by_user | string | | N |
  69. ---------------------------------------------------
  70. | allow_hosts | string | * | N |
  71. ---------------------------------------------------
  72. | sync_log_buff_interval| int | 10(s) | N |
  73. ---------------------------------------------------
  74. | thread_stack_size | string | 1M | N |
  75. ---------------------------------------------------
  76. memo:
  77. * base_path is the base path of sub dirs:
  78. data and logs. base_path must exist and it's sub dirs will
  79. be automatically created if not exist.
  80. $base_path/data: store data files
  81. $base_path/logs: store log files
  82. * log_level is the standard log level as syslog, case insensitive
  83. # emerg: for emergency
  84. # alert
  85. # crit: for critical
  86. # error
  87. # warn: for warning
  88. # notice
  89. # info
  90. # debug
  91. * allow_hosts can ocur more than once, host can be hostname or ip address,
  92. "*" means match all ip addresses, can use range like this: 10.0.1.[1-15,20]
  93. or host[01-08,20-25].domain.com, for example:
  94. allow_hosts=10.0.1.[1-15,20]
  95. allow_hosts=host[01-08,20-25].domain.com
  96. 2. tracker server items
  97. ---------------------------------------------------
  98. | item name | type | default | Must |
  99. ---------------------------------------------------
  100. | port | int | 22000 | N |
  101. ---------------------------------------------------
  102. | store_lookup | int | 0 | N |
  103. ---------------------------------------------------
  104. | store_group | string | | N |
  105. ---------------------------------------------------
  106. | store_server | int | 0 | N |
  107. ---------------------------------------------------
  108. | store_path | int | 0 | N |
  109. ---------------------------------------------------
  110. | download_server | int | 0 | N |
  111. ---------------------------------------------------
  112. | reserved_storage_space| string | 1GB | N |
  113. ---------------------------------------------------
  114. memo:
  115. * the value of store_lookup is:
  116. 0: round robin (default)
  117. 1: specify group
  118. 2: load balance (supported since V1.1)
  119. * store_group is the name of group to store files.
  120. when store_lookup set to 1(specify group),
  121. store_group must be set to a specified group name.
  122. * reserved_storage_space is the reserved storage space for system
  123. or other applications. if the free(available) space of any stoarge
  124. server in a group <= reserved_storage_space, no file can be uploaded
  125. to this group (since V1.1)
  126. bytes unit can be one of follows:
  127. # G or g for gigabyte(GB)
  128. # M or m for megabyte(MB)
  129. # K or k for kilobyte(KB)
  130. # no unit for byte(B)
  131. 3. storage server items
  132. -------------------------------------------------
  133. | item name | type | default | Must |
  134. -------------------------------------------------
  135. | group_name | string | | Y |
  136. -------------------------------------------------
  137. | tracker_server | string | | Y |
  138. -------------------------------------------------
  139. | port | int | 23000 | N |
  140. -------------------------------------------------
  141. | heart_beat_interval | int | 30(s) | N |
  142. -------------------------------------------------
  143. | stat_report_interval| int | 300(s) | N |
  144. -------------------------------------------------
  145. | sync_wait_msec | int | 100(ms) | N |
  146. -------------------------------------------------
  147. | sync_interval | int | 0(ms) | N |
  148. -------------------------------------------------
  149. | sync_start_time | string | 00:00 | N |
  150. -------------------------------------------------
  151. | sync_end_time | string | 23:59 | N |
  152. -------------------------------------------------
  153. | store_path_count | int | 1 | N |
  154. -------------------------------------------------
  155. | store_path0 | string |base_path| N |
  156. -------------------------------------------------
  157. | store_path# | string | | N |
  158. -------------------------------------------------
  159. |subdir_count_per_path| int | 256 | N |
  160. -------------------------------------------------
  161. |check_file_duplicate | boolean| 0 | N |
  162. -------------------------------------------------
  163. | key_namespace | string | | N |
  164. -------------------------------------------------
  165. | keep_alive | boolean| 0 | N |
  166. -------------------------------------------------
  167. | sync_binlog_buff_interval| int | 60s | N |
  168. -------------------------------------------------
  169. memo:
  170. * tracker_server can ocur more than once, and tracker_server format is
  171. "host:port", host can be hostname or ip address.
  172. * store_path#, # for digital, based 0
  173. * check_file_duplicate: when set to true, must work with FastDHT server,
  174. more detail please see INSTALL of FastDHT. FastDHT download page:
  175. http://code.google.com/p/fastdht/downloads/list
  176. * key_namespace: FastDHT key namespace, can't be empty when
  177. check_file_duplicate is true. the key namespace should short as possible

或使用压缩包:解压FastDFS压缩包

  1. tar -xzf FastDFS_v5.08.tar.gz

或者

  1. unzip fastdfs-master.zip

进入FastDFS目录

  1. cd FastDFS

编译FastDFS

  1. ./make.sh

安装FastDFS

  1. ./make.sh install

修改配置文件

  1. cd /etc/fdfs/

会看到三个配置文件:

  1. client.conf.sample, tracker.conf.sample,storage.conf.sample

复制,然后配置:

  1. cp client.conf.sample client.conf
  2. cp tracker.conf.sample tracker.conf
  3. cp storage.conf.sample storage.conf

配置storage.conf

注意:同一个组内的不同的storage的配置要相同(方便同步文件)

配置storage属于哪个group:

  1. group_name=group1 (因为现在先只是配一个组,所以这里就为group1)

配置base_path:

  1. 原来 base_path=/home/yuqing/fastdfs 这里需要改为自己的文件路径,
  2. 如:base_path=/home/xxx/fastdfs (这里的文件目录如果没有,要自己新建,不然会报错)

配置store_path0:

  1. 这里 store_path0=/home/yuqing/fastdfs 也要改为自己的文件路径
  2. 如: store_path0=/home/xxx/fastdfs (建议与bast_path一样)

配置tracker_server:

  1. 还有:tracker_server要改为自己的trakcer_serverip
  2. 如:tracker_server=172.16.36.245:22122 (若有特殊要求可查看文档根据实际情况配置)

配置tracker.conf

配置base_path:

  1. 原来 base_path=/home/yuqing/fastdfs 这里需要改为自己的文件路径,
  2. 如:base_path=/home/xxx/fastdfs (这里的文件目录如果没有,要自己新建,不然会报错)
  3. (若有特殊要求可查看文档根据实际情况配置)

配置client.conf

配置base_path:

  1. 原来 base_path=/home/yuqing/fastdfs 这里需要改为自己的文件路径,
  2. 如:base_path=/home/xxx/fastdfs (这里的文件目录如果没有,要自己新建,不然会报错)

启动服务程序

启动tracker server

  1. /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

启动storage server

  1. /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

启动测试程序

上传文件测试:

  1. /usr/bin/fdfs_test /etc/fdfs/client.conf upload tff.jpeg

上传成功会返回信息如:

  1. This is FastDFS client test program v5.08
  2. Copyright (C) 2008, Happy Fish / YuQing
  3. ……(此处省略很多字)
  4. example file url:
  5. http://172.16.36.245/group1/M00/00/00/rBAk9VhH11aAQznLAACgiYdLO3c42_big.jpeg

安装nginx

安装前请先升级gcc:

1、安装gcc套装:

  1. yum install cpp
  2. yum install binutils
  3. yum install glibc
  4. yum install glibc-kernheaders
  5. yum install glibc-common
  6. yum install glibc-devel
  7. yum install gcc
  8. yum install make

2、升级gcc

  1. yum -y install centos-release-scl
  2. yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
  3. scl enable devtoolset-9 bash

安装nginx依赖:gcc套件和升级后可不安装

SL功能需要openssl库,下载地址:http://www.openssl.org/

gzip模块需要zlib库,下载地址:http://www.zlib.net/

pcre库,下载地址:http://www.pcre.org/

gcc-c++ 编译器

Nginx的安装包:下载地址为:http://nginx.org/en/download.html

安装软件

安装SSL功能需要的openssl库插件

注意:安装过程是按照我在linux下设置的文件路径来安装的,命令如下:

  1. tar -zxvf soft/openssl-SNAP-20160104
  2. cd cd openssl-SNAP-20160104/
  3. ./config
  4. make
  5. make install

安装 pcre-8.39.zip

  1. 进入目录:
  1. cd pcre-8.39
  1. 执行命令:
  1. ./configure
  1. 执行命令:
  1. make
  1. 执行命令:
  1. sudo make install

安装 zlib-1.2.8.tar.xz

  1. 进入目录:
  1. cd zlib-1.2.8
  1. 执行命令:
  1. ./configure
  1. 执行命令:
  1. make
  1. 执行命令:
  1. sudo make install

安装 gcc-c++

  1. yum install -y gcc gcc-c++

安装Nginx

下载:

从官方网址上下载稳定版本nginx,网址为:https://nginx.org/en/download.html
用ftp或sftp工具将nginx-1.18.0.tar.gz拷贝到linux操作系统

安装:

解压
  1. tar -zxvf nginx-1.18.0.tar.gz

编译 安装
  1. cd nginx-1.18.0

指定目录安装nginx
  1. ./configure --prefix=/data/nginx
  2. make && make install

启动
  1. cd /data/nginx/sbin
  2. ./nginx

服务化 以下步骤可跳过
  1. 服务化:新增文件 vim /usr/lib/systemd/system/nginx.service,文件编码如下:
  1. [Unit]
  2. Description=nginx
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/data/nginx/sbin/nginx
  7. ExecReload=/data/nginx/sbin/nginx -s reload
  8. ExecStop=/data/nginx/sbin/nginx -s quit
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target

将nginx加入到开机启动
  1. systemctl enable nginx.service

安装fastdfs-nginx-module

下载

下载地址:https://github.com/happyfish100/fastdfs-nginx-module/

fastdfs-nginx_module作用:在storage之间同步数据时候,还没同步完全时候就发生下载时,直接从源数据storage下载

将fastdfs-nginx-module压缩包解压,并记录下它的路径,因为安装的时候要用到

进入nginx的安装包的源目录,然后编译和安装fastdfs-nginx-module

命令如下:

注意:要先关闭所有的nginx进程,在进行下面这一步骤

  1. cd nginx
  2. ./configure --add-module=/home/ningqijun/fastdfs-nginx-module/src
  3. (/home/ningqijun/fastdfs-nginx-module/src根据自己的文件目录来配)
  4. make
  5. make install

配置nginx.conf

(默认nginx.conf是在目录/usr/local/nginx/conf/ 里面的)

命令:

  1. cd /usr/local/nginx/conf/
  2. vi nginx.conf

只有一个group默认配置

最简单的配置:当mod_fastdfs.conf 配置文件中只有一个group1, 且配置了 url_have_group_name = false 时,即访问地址不使用分组名称,那么只需在nginx的配置文件中增加以下配置即可:

在nginx.conf里面的server{里面添加location /M00……},添加下面的几行:

  1. location /M00 {
  2. root /home/ningqijun/fastdfs/data;
  3. ngx_fastdfs_module;
  4. }

多个group的配置

当配置多个组,且mod_fastdfs.conf 里面指定了url_have_group_name= true 时,配置方式:

  1. location ~ /group([0-9]) /M00 {
  2. root /home/ningqijun/fastdfs/data;
  3. ngx_fastdfs_module;
  4. }

比如:在group1上的 nginx 的nginx.conf 配置是

  1. location /group1 /M00 {
  2. root /home/ningqijun/fastdfs/data;
  3. ngx_fastdfs_module;
  4. }

比如:在group2上的 nginx 的nginx.conf 配置是

  1. location /group2 /M00 {
  2. root /home/ningqijun/fastdfs/data;
  3. ngx_fastdfs_module;
  4. }

创建/M00软连接

命令:

  1. ln -s /home/ningqijun/fastdfs/data /home/ningqijun/fastdfs/data/M00

修改mod_fastdfs.conf

将/home/…/fastdfs-nginx-module-master/src(位置看自己将解压到哪里)

里面的mod_fastdfs.conf复制到/etc/fdfs/里面

  1. 1. 更改tracker_serverIP如:tracker_server=172.16.36.245:22122
  2. 2. 更改store_path0这个要与storaged的配置一致,如:store_path0=/home/ningqijun/fastdfs

重新启动Nginx

将FastDFS配置目录下的2个文件复制到/etc/fdfs目录下:

  1. cp /usr/local/fastdfs/conf/http.conf /etc/fdfs/
  2. cp /usr/local/fastdfs/conf/mime.types /etc/fdfs/

命令:

  1. /usr/local/nginx/sbin/nginx -s stop
  2. /usr/local/nginx/sbin/nginx

注意:要实现HTTP下载必须要求Nginx和fastdfs-nginx-module起来

测试:

  1. /usr/bin/fdfs_test /etc/fdfs/client.conf upload test.png

假设返回链接如下:

  1. http://192.168.1.100/group1/M00/00/00/aIBdvl5Th7iAM1PwAACLyBo1AoQ37510.png

浏览器输入下面的URL(即去掉 group1):

  1. http://192.168.1.100/M00/00/00/aIBdvl5Th7iAM1PwAACLyBo1AoQ37510.png

能查看刚上传的 png 文件即 OK.