|
| 1 | +# FastDFS 安装和配置 |
| 2 | + |
| 3 | + |
| 4 | +-  |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## 它是什么 |
| 10 | + |
| 11 | +- FastDFS 介绍:<http://www.oschina.net/p/fastdfs> |
| 12 | +- 官网下载 1:<https://github.com/happyfish100/fastdfs/releases> |
| 13 | +- 官网下载 2:<https://sourceforge.net/projects/fastdfs/files/> |
| 14 | + |
| 15 | +## 为什么会出现 |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +## 哪些人喜欢它 |
| 20 | + |
| 21 | + |
| 22 | +## 哪些人不喜欢它 |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +## 为什么学习它 |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +## 同类工具 |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +### 安装部署(Linux 环境) |
| 36 | + |
| 37 | +- 环境准备: |
| 38 | + - 已经安装好 Nginx |
| 39 | +- 软件准备: |
| 40 | + - **FastDFS_v5.05.tar.gz** |
| 41 | + - **fastdfs-nginx-module_v1.16.tar.gz** |
| 42 | + - **libfastcommon-1.0.7.tar.gz** |
| 43 | +- 安装依赖包:`yum install -y libevent` |
| 44 | +- 安装 **libfastcommon-1.0.7.tar.gz** |
| 45 | + - 解压:`tar zxvf libfastcommon-1.0.7.tar.gz` |
| 46 | + - 进入解压后目录:`cd libfastcommon-1.0.7/` |
| 47 | + - 编译:`./make.sh` |
| 48 | + - 安装:`./make.sh install` |
| 49 | + - 复制一个配置文件:`cp /usr/lib64/libfastcommon.so /usr/lib/` |
| 50 | + - 复制一个配置文件:`cp /usr/lib64/libfdfsclient.so /usr/lib/` |
| 51 | +- 安装 tracker (跟踪器)服务 **FastDFS_v5.08.tar.gz** |
| 52 | + - 解压:`tar zxvf FastDFS_v5.05.tar.gz` |
| 53 | + - 进入解压后目录:`cd FastDFS/` |
| 54 | + - 编译:`./make.sh` |
| 55 | + - 安装:`./make.sh install` |
| 56 | + - 安装结果: |
| 57 | + ``` ini |
| 58 | + /usr/bin 存放有编译出来的文件 |
| 59 | + /etc/fdfs 存放有配置文件 |
| 60 | + ``` |
| 61 | +- 配置 tracker 服务 |
| 62 | + - 复制一份配置文件:`cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf` |
| 63 | + - 编辑:`vim /etc/fdfs/tracker.conf`,编辑内容看下面中文注释 |
| 64 | + ``` ini |
| 65 | + disabled=false |
| 66 | + bind_addr= |
| 67 | + port=22122 |
| 68 | + connect_timeout=30 |
| 69 | + network_timeout=60 |
| 70 | + # 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录,创建目录:mkdir -p /opt/fastdfs/tracker/data-and-log |
| 71 | + base_path=/opt/fastdfs/tracker/data-and-log |
| 72 | + max_connections=256 |
| 73 | + accept_threads=1 |
| 74 | + work_threads=4 |
| 75 | + store_lookup=2 |
| 76 | + store_group=group2 |
| 77 | + store_server=0 |
| 78 | + store_path=0 |
| 79 | + download_server=0 |
| 80 | + reserved_storage_space = 10% |
| 81 | + log_level=info |
| 82 | + run_by_group= |
| 83 | + run_by_user= |
| 84 | + allow_hosts=* |
| 85 | + sync_log_buff_interval = 10 |
| 86 | + check_active_interval = 120 |
| 87 | + thread_stack_size = 64KB |
| 88 | + storage_ip_changed_auto_adjust = true |
| 89 | + storage_sync_file_max_delay = 86400 |
| 90 | + storage_sync_file_max_time = 300 |
| 91 | + use_trunk_file = false |
| 92 | + slot_min_size = 256 |
| 93 | + slot_max_size = 16MB |
| 94 | + trunk_file_size = 64MB |
| 95 | + trunk_create_file_advance = false |
| 96 | + trunk_create_file_time_base = 02:00 |
| 97 | + trunk_create_file_interval = 86400 |
| 98 | + trunk_create_file_space_threshold = 20G |
| 99 | + trunk_init_check_occupying = false |
| 100 | + trunk_init_reload_from_binlog = false |
| 101 | + trunk_compress_binlog_min_interval = 0 |
| 102 | + use_storage_id = false |
| 103 | + storage_ids_filename = storage_ids.conf |
| 104 | + id_type_in_filename = ip |
| 105 | + store_slave_file_use_link = false |
| 106 | + rotate_error_log = false |
| 107 | + error_log_rotate_time=00:00 |
| 108 | + rotate_error_log_size = 0 |
| 109 | + log_file_keep_days = 0 |
| 110 | + use_connection_pool = false |
| 111 | + connection_pool_max_idle_time = 3600 |
| 112 | + http.server_port=8080 |
| 113 | + http.check_alive_interval=30 |
| 114 | + http.check_alive_type=tcp |
| 115 | + http.check_alive_uri=/status.html |
| 116 | + ``` |
| 117 | + - 启动 tracker 服务:`/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf` |
| 118 | + - 重启 tracker 服务:`/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart` |
| 119 | + - 查看是否有 tracker 进程:`ps aux | grep tracker` |
| 120 | + |
| 121 | + |
| 122 | +- storage (存储节点)服务部署 |
| 123 | + - 一般 storage 服务我们会单独装一台机子,但是这里为了方便我们安装在同一台。 |
| 124 | + - 如果 storage 单独安装的话,那上面安装的步骤都要在走一遍,只是到了编辑配置文件的时候,编辑的是 storage.conf 而已 |
| 125 | + - 复制一份配置文件:`cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf` |
| 126 | + - 编辑:`vim /etc/fdfs/storage.conf`,编辑内容看下面中文注释 |
| 127 | + ``` ini |
| 128 | + disabled=false |
| 129 | + group_name=group1 |
| 130 | + bind_addr= |
| 131 | + client_bind=true |
| 132 | + port=23000 |
| 133 | + connect_timeout=30 |
| 134 | + network_timeout=60 |
| 135 | + heart_beat_interval=30 |
| 136 | + stat_report_interval=60 |
| 137 | + # 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录,创建目录:mkdir -p /opt/fastdfs/storage/data-and-log |
| 138 | + # 我这里习惯的目录是:/opt/fastdfs/storage/data-and-log |
| 139 | + base_path=/opt/fastdfs/storage/data-and-log |
| 140 | + max_connections=256 |
| 141 | + buff_size = 256KB |
| 142 | + accept_threads=1 |
| 143 | + work_threads=4 |
| 144 | + disk_rw_separated = true |
| 145 | + disk_reader_threads = 1 |
| 146 | + disk_writer_threads = 1 |
| 147 | + sync_wait_msec=50 |
| 148 | + sync_interval=0 |
| 149 | + sync_start_time=00:00 |
| 150 | + sync_end_time=23:59 |
| 151 | + write_mark_file_freq=500 |
| 152 | + store_path_count=1 |
| 153 | + # 图片实际存放路径,如果有多个,这里可以有多行: |
| 154 | + # store_path0=/opt/fastdfs/storage/images-data0 |
| 155 | + # store_path1=/opt/fastdfs/storage/images-data1 |
| 156 | + # store_path2=/opt/fastdfs/storage/images-data2 |
| 157 | + # 创建目录:mkdir -p /opt/fastdfs/storage/images-data |
| 158 | + store_path0=/opt/fastdfs/storage/images-data |
| 159 | + subdir_count_per_path=256 |
| 160 | + # 指定 tracker 服务器的 IP 和端口 |
| 161 | + tracker_server=192.168.1.114:22122 |
| 162 | + log_level=info |
| 163 | + run_by_group= |
| 164 | + run_by_user= |
| 165 | + allow_hosts=* |
| 166 | + file_distribute_path_mode=0 |
| 167 | + file_distribute_rotate_count=100 |
| 168 | + fsync_after_written_bytes=0 |
| 169 | + sync_log_buff_interval=10 |
| 170 | + sync_binlog_buff_interval=10 |
| 171 | + sync_stat_file_interval=300 |
| 172 | + thread_stack_size=512KB |
| 173 | + upload_priority=10 |
| 174 | + if_alias_prefix= |
| 175 | + check_file_duplicate=0 |
| 176 | + file_signature_method=hash |
| 177 | + key_namespace=FastDFS |
| 178 | + keep_alive=0 |
| 179 | + use_access_log = false |
| 180 | + rotate_access_log = false |
| 181 | + access_log_rotate_time=00:00 |
| 182 | + rotate_error_log = false |
| 183 | + error_log_rotate_time=00:00 |
| 184 | + rotate_access_log_size = 0 |
| 185 | + rotate_error_log_size = 0 |
| 186 | + log_file_keep_days = 0 |
| 187 | + file_sync_skip_invalid_record=false |
| 188 | + use_connection_pool = false |
| 189 | + connection_pool_max_idle_time = 3600 |
| 190 | + http.domain_name= |
| 191 | + http.server_port=8888 |
| 192 | + ``` |
| 193 | + - 启动 storage 服务:`/usr/bin/fdfs_storaged /etc/fdfs/storage.conf`,首次启动会很慢,因为它在创建预设存储文件的目录 |
| 194 | + - 重启 storage 服务:`/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart` |
| 195 | + - 查看是否有 storage 进程:`ps aux | grep storage` |
| 196 | +- 测试是否部署成功 |
| 197 | + - 利用自带的 client 进行测试 |
| 198 | + - 复制一份配置文件:`cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf` |
| 199 | + - 编辑:`vim /etc/fdfs/client.conf`,编辑内容看下面中文注释 |
| 200 | + ``` ini |
| 201 | + connect_timeout=30 |
| 202 | + network_timeout=60 |
| 203 | + # 下面这个路径是保存 store log 的地方,需要我们改下,指向我们一个存在的目录,创建目录:mkdir -p /opt/fastdfs/client/data-and-log |
| 204 | + base_path=/opt/fastdfs/client/data-and-log |
| 205 | + # 指定 tracker 服务器的 IP 和端口 |
| 206 | + tracker_server=192.168.1.114:22122 |
| 207 | + log_level=info |
| 208 | + use_connection_pool = false |
| 209 | + connection_pool_max_idle_time = 3600 |
| 210 | + load_fdfs_parameters_from_tracker=false |
| 211 | + use_storage_id = false |
| 212 | + storage_ids_filename = storage_ids.conf |
| 213 | + http.tracker_server_port=80 |
| 214 | + ``` |
| 215 | + - 在终端中通过 shell 上传 opt 目录下的一张图片:`/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/test.jpg` |
| 216 | + - 如下图箭头所示,生成的图片地址为:`http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg` |
| 217 | + - 因为我们还没装 FastDFS 的 Nginx 模块,所以现在我们访问不了图片地址 |
| 218 | +- 安装 **fastdfs-nginx-module_v1.16.tar.gz**,安装 Nginx 第三方模块相当于这个 Nginx 都是要重新安装一遍的 |
| 219 | + - 解压 Nginx 模块:`tar zxvf fastdfs-nginx-module_v1.16.tar.gz`,得到目录地址:**/opt/setups/FastDFS/fastdfs-nginx-module** |
| 220 | + - 编辑 Nginx 模块的配置文件:`vim /opt/setups/FastDFS/fastdfs-nginx-module/src/config` |
| 221 | + - 把下面内容的三个路径中包含有 `local` 字眼去掉,因为这三个路径根本不是在 local 下的。 |
| 222 | + ``` nginx |
| 223 | + ngx_addon_name=ngx_http_fastdfs_module |
| 224 | + HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module" |
| 225 | + NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c" |
| 226 | + CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/" |
| 227 | + CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient" |
| 228 | + CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'" |
| 229 | + ``` |
| 230 | + - 解压 Nginx:`tar zxvf /opt/setups/nginx-1.8.1.tar.gz` |
| 231 | + - 进入解压后目录:`cd /opt/setups/nginx-1.8.1/` |
| 232 | + - 编译配置:(注意最后一行) |
| 233 | + ``` ini |
| 234 | + ./configure \ |
| 235 | + --prefix=/usr/local/nginx \ |
| 236 | + --pid-path=/var/local/nginx/nginx.pid \ |
| 237 | + --lock-path=/var/lock/nginx/nginx.lock \ |
| 238 | + --error-log-path=/var/log/nginx/error.log \ |
| 239 | + --http-log-path=/var/log/nginx/access.log \ |
| 240 | + --with-http_gzip_static_module \ |
| 241 | + --http-client-body-temp-path=/var/temp/nginx/client \ |
| 242 | + --http-proxy-temp-path=/var/temp/nginx/proxy \ |
| 243 | + --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ |
| 244 | + --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ |
| 245 | + --http-scgi-temp-path=/var/temp/nginx/scgi \ |
| 246 | + --add-module=/opt/setups/FastDFS/fastdfs-nginx-module/src |
| 247 | + ``` |
| 248 | + - 编译:`make` |
| 249 | + - 安装:`make install` |
| 250 | + - 复制 Nginx 模块的配置文件:`cp /opt/setups/FastDFS/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs` |
| 251 | + - 编辑 Nginx 模块的配置文件:`vim /etc/fdfs/mod_fastdfs.conf`,编辑内容看下面中文注释 |
| 252 | + ``` ini |
| 253 | + connect_timeout=2 |
| 254 | + network_timeout=30 |
| 255 | + # 下面这个路径是保存 log 的地方,需要我们改下,指向我们一个存在的目录,创建目录:mkdir -p /opt/fastdfs/fastdfs-nginx-module/data-and-log |
| 256 | + base_path=/opt/fastdfs/fastdfs-nginx-module/data-and-log |
| 257 | + load_fdfs_parameters_from_tracker=true |
| 258 | + storage_sync_file_max_delay = 86400 |
| 259 | + use_storage_id = false |
| 260 | + storage_ids_filename = storage_ids.conf |
| 261 | + # 指定 tracker 服务器的 IP 和端口 |
| 262 | + tracker_server=192.168.1.114:22122 |
| 263 | + storage_server_port=23000 |
| 264 | + group_name=group1 |
| 265 | + url_have_group_name = false |
| 266 | + store_path_count=1 |
| 267 | + # 图片实际存放路径,如果有多个,这里可以有多行: |
| 268 | + # store_path0=/opt/fastdfs/storage/images-data0 |
| 269 | + # store_path1=/opt/fastdfs/storage/images-data1 |
| 270 | + # store_path2=/opt/fastdfs/storage/images-data2 |
| 271 | + store_path0=/opt/fastdfs/storage/images-data |
| 272 | + log_level=info |
| 273 | + log_filename= |
| 274 | + response_mode=proxy |
| 275 | + if_alias_prefix= |
| 276 | + flv_support = true |
| 277 | + flv_extension = flv |
| 278 | + group_count = 0 |
| 279 | + ``` |
| 280 | + |
| 281 | + - 编辑 Nginx 配置文件 |
| 282 | + |
| 283 | + ``` nginx |
| 284 | + worker_processes 1; |
| 285 | + |
| 286 | + events { |
| 287 | + worker_connections 1024; |
| 288 | + } |
| 289 | + |
| 290 | + http { |
| 291 | + include mime.types; |
| 292 | + default_type application/octet-stream; |
| 293 | + |
| 294 | + sendfile on; |
| 295 | + keepalive_timeout 65; |
| 296 | + |
| 297 | + server { |
| 298 | + listen 80; |
| 299 | + # 访问本机 |
| 300 | + server_name 192.168.1.114; |
| 301 | + |
| 302 | + # 拦截包含 /group1/M00 请求,使用 fastdfs 这个 Nginx 模块进行转发 |
| 303 | + location /group1/M00 { |
| 304 | + ngx_fastdfs_module; |
| 305 | + } |
| 306 | + } |
| 307 | + } |
| 308 | + ``` |
| 309 | + - 启动 Nginx |
| 310 | + - 停掉防火墙:`service iptables stop` |
| 311 | + - 启动:`/usr/local/nginx/sbin/nginx`,启动完成 shell 是不会有输出的 |
| 312 | + - 访问:`192.168.1.114`,如果能看到:`Welcome to nginx!`,即可表示安装成功 |
| 313 | + - 检查 时候有 Nginx 进程:`ps aux | grep nginx`,正常是显示 3 个结果出来 |
| 314 | + - 刷新 Nginx 配置后重启:`/usr/local/nginx/sbin/nginx -s reload` |
| 315 | + - 停止 Nginx:`/usr/local/nginx/sbin/nginx -s stop` |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | +### 资料 |
| 320 | + |
| 321 | + |
| 322 | + |
0 commit comments