FastDFS 安装实战教程
实战教程
环境检查
检查 GCC
[root@10 local]# gcc --version
安装 GCC
如果已经安装可跳过此步
[root@10 local]# yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
[root@10 local]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@10 local]#
下载 libfastcommon
# 下载 libfastcommon_V1.0.43.tar.gz
[root@10 local]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
# 重命名
[root@10 local]# mv V1.0.43.tar.gz libfastcommon_V1.0.43.tar.gz
# 解压 libfastcommon_V1.0.43.tar.gz
[root@10 local]# tar zxf libfastcommon_V1.0.43.tar.gz
# 目录结构
[root@10 local]# ll libfastcommon-1.0.43/
total 32
drwxrwxr-x. 2 root root 114 Dec 25 2019 doc
-rw-rw-r--. 1 root root 10301 Dec 25 2019 HISTORY
-rw-rw-r--. 1 root root 674 Dec 25 2019 INSTALL
-rw-rw-r--. 1 root root 1607 Dec 25 2019 libfastcommon.spec
-rwxrwxr-x. 1 root root 3253 Dec 25 2019 make.sh
drwxrwxr-x. 2 root root 191 Dec 25 2019 php-fastcommon
-rw-rw-r--. 1 root root 2776 Dec 25 2019 README
drwxrwxr-x. 3 root root 4096 Dec 25 2019 src
# 编译安装
[root@10 libfastcommon-1.0.43]# ./make.sh clean && ./make.sh && ./make.sh install
......
......
......
mkdir -p /usr/lib64
mkdir -p /usr/lib
mkdir -p /usr/include/fastcommon
install -m 755 libfastcommon.so /usr/lib64
install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_define.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h fast_mpool.h fast_allocator.h fast_buffer.h skiplist.h multi_skiplist.h flat_skiplist.h skiplist_common.h system_info.h fast_blocked_queue.h php7_ext_wrapper.h id_generator.h char_converter.h char_convert_loader.h common_blocked_queue.h multi_socket_client.h skiplist_set.h fc_list.h json_parser.h buffered_file_writer.h /usr/include/fastcommon
if [ ! -e /usr/lib/libfastcommon.so ]; then ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so; fi
[root@10 libfastcommon-1.0.43]#
下载 FastDFS
# 下载
[root@10 local]# wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz
# 重命名
[root@10 local]# mv V6.06.tar.gz FastDFS_V6.06.tar.gz
# 解压
[root@10 local]# tar zxf FastDFS_V6.06.tar.gz
[root@10 local]# ll
# 目录结构
[root@10 local]# ll fastdfs-6.06/
total 140
drwxrwxr-x. 3 root root 4096 Dec 30 2019 client
drwxrwxr-x. 2 root root 189 Dec 30 2019 common
drwxrwxr-x. 2 root root 146 Dec 30 2019 conf
-rw-rw-r--. 1 root root 35067 Dec 30 2019 COPYING-3_0.txt
drwxrwxr-x. 4 root root 56 Dec 30 2019 docker
-rw-rw-r--. 1 root root 3170 Dec 30 2019 fastdfs.spec
-rw-rw-r--. 1 root root 36881 Dec 30 2019 HISTORY
drwxrwxr-x. 2 root root 27 Dec 30 2019 images
drwxrwxr-x. 2 root root 48 Dec 30 2019 init.d
-rw-rw-r--. 1 root root 8344 Dec 30 2019 INSTALL
-rwxrwxr-x. 1 root root 5517 Dec 30 2019 make.sh
drwxrwxr-x. 2 root root 4096 Dec 30 2019 php_client
-rw-rw-r--. 1 root root 2448 Dec 30 2019 README.md
-rw-rw-r--. 1 root root 1700 Dec 30 2019 README_zh.md
-rwxrwxr-x. 1 root root 1768 Dec 30 2019 restart.sh
-rwxrwxr-x. 1 root root 763 Dec 30 2019 setup.sh
-rwxrwxr-x. 1 root root 1680 Dec 30 2019 stop.sh
drwxrwxr-x. 4 root root 4096 Dec 30 2019 storage
drwxrwxr-x. 2 root root 4096 Dec 30 2019 test
drwxrwxr-x. 2 root root 4096 Dec 30 2019 tracker
[root@10 local]#
# 编译安装
[root@10 fastdfs-6.06]# ./make.sh clean && ./make.sh && ./make.sh install
......
......
mkdir -p /usr/bin
mkdir -p /etc/fdfs
cp -f fdfs_storaged /usr/bin
if [ ! -f /etc/fdfs/storage.conf.sample ]; then cp -f ../conf/storage.conf /etc/fdfs/storage.conf.sample; fi
mkdir -p /usr/bin
mkdir -p /etc/fdfs
mkdir -p /usr/lib64
mkdir -p /usr/lib
cp -f fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file fdfs_download_file fdfs_delete_file fdfs_file_info fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_upload_appender fdfs_regenerate_filename /usr/bin
if [ 0 -eq 1 ]; then cp -f libfdfsclient.a /usr/lib64; cp -f libfdfsclient.a /usr/lib/;fi
if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; cp -f libfdfsclient.so /usr/lib/;fi
mkdir -p /usr/include/fastdfs
cp -f ../common/fdfs_define.h ../common/fdfs_global.h ../common/mime_file_parser.h ../common/fdfs_http_shared.h ../tracker/tracker_types.h ../tracker/tracker_proto.h ../tracker/fdfs_shared_func.h ../tracker/fdfs_server_id_func.h ../storage/trunk_mgr/trunk_shared.h tracker_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h /usr/include/fastdfs
if [ ! -f /etc/fdfs/client.conf.sample ]; then cp -f ../conf/client.conf /etc/fdfs/client.conf.sample; fi
[root@10 fastdfs-6.06]#
重要日志打印信息:
mkdir -p /usr/bin
mkdir -p /etc/fdfs
mkdir -p /usr/lib64
mkdir -p /usr/lib
下载 fastdfs-nginx-module
[root@10 local]# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz
[root@10 local]#
# 目录结构
openresty 添加 fastdfs-nginx-module
[root@localhost local]# cd openresty-1.19.3.1/
[root@localhost openresty-1.19.3.1]# ./configure --add-module=/usr/local/fastdfs-nginx-module-1.22/src
platform: linux (linux)
cp -rp bundle/ build
cd build
cd LuaJIT-2.1-20201027
gmake TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_ENA
......
......
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/openresty/nginx"
nginx binary file: "/usr/local/openresty/nginx/sbin/nginx"
nginx modules path: "/usr/local/openresty/nginx/modules"
nginx configuration prefix: "/usr/local/openresty/nginx/conf"
nginx configuration file: "/usr/local/openresty/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/openresty/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/openresty/nginx/logs/error.log"
nginx http access log file: "/usr/local/openresty/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
cd ../..
Type the following commands to build and install:
gmake
gmake install
[root@localhost openresty-1.19.3.1]#
# 编译
[root@localhost openresty-1.19.3.1]# make
cd /usr/local/openresty-1.19.3.1/build/LuaJIT-2.1-20201027 && make TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_ENABLE_LUA52COMPAT' CC=cc PREFIX=/usr/local/openresty/luajit
make[1]: Entering directory `/usr/local/openresty-1.19.3.1/build/LuaJIT-2.1-20201027'
......
......
......
-L/usr/local/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib -L/usr/local/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,--require-defined=pcre_version -Wl,-E -Wl,-E -ldl -lpthread -lcrypt -L/usr/local/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl -L/usr/local/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl -lfastcommon -lfdfsclient -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/openresty/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/openresty/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/openresty/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/openresty/nginx/logs/error.log|" \
< docs/man/nginx.8 > objs/nginx.8
make[2]: Leaving directory `/usr/local/openresty-1.19.3.1/build/nginx-1.19.3'
make[1]: Leaving directory `/usr/local/openresty-1.19.3.1/build/nginx-1.19.3'
[root@localhost openresty-1.19.3.1]#
# 验证是否安装成功
# 进入目录
[root@localhost objs]# pwd
/usr/local/openresty-1.19.3.1/build/nginx-1.19.3/objs
# 执行 `nginx -V`
[root@localhost objs]# nginx -V
nginx version: openresty/1.19.3.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.19 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.9 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-http_stub_status_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --add-module=/usr/local/ngx_cache_purge-2.3 --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module
[root@localhost objs]#
1、备份原来的 nginx 可执行二进制文件
cd /usr/local/openresty/nginx/sbin
cp nginx nginx.old
2、将编译好的 nginx 可执行二进制文件复制到原始 nginx 的 sbin 目录
cp -r /openresty-1.19.3.1/build/nginx-1.19.3/objs/nginx /usr/local/openresty/nginx/sbin/ -f
3、验证是否成功安装 fastdfs-nginx-module
cd /usr/local/openresty/nginx/sbin
./nginx -V
[root@localhost ~]# cd /usr/local/openresty/nginx/sbin
[root@localhost sbin]#
[root@localhost sbin]# cp nginx nginx.old
[root@localhost sbin]# ll
total 33984
-rwxr-xr-x. 1 root root 17399344 Dec 5 15:27 nginx
-rwxr-xr-x. 1 root root 17399344 Dec 8 02:54 nginx.old
[root@localhost sbin]# cp -r /openresty-1.19.3.1/build/nginx-1.19.3/objs/nginx /usr/local/openresty/nginx/sbin/ -f
cp: cannot stat ‘/openresty-1.19.3.1/build/nginx-1.19.3/objs/nginx’: No such file or directory
[root@localhost sbin]# cp -r /usr/local/openresty-1.19.3.1/build/nginx-1.19.3/objs/nginx /usr/local/openresty/nginx/sbin/ -f
cp: overwrite ‘/usr/local/openresty/nginx/sbin/nginx’? y
[root@localhost sbin]# pwd
/usr/local/openresty/nginx/sbin
[root@localhost sbin]# nginx -V
nginx version: openresty/1.19.3.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.19 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.9 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --add-module=/usr/local/fastdfs-nginx-module-1.22/src --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module
[root@localhost sbin]#
启动
启动 openresty
[root@localhost init.d]# systemctl start nginx
启动 tracker
#启动tracker服务
/etc/init.d/fdfs_trackerd start
#重启动tracker服务
/etc/init.d/fdfs_trackerd restart
#停止tracker服务
/etc/init.d/fdfs_trackerd stop
#自启动tracker服务
chkconfig fdfs_trackerd on
启动 storage
#启动storage服务
/etc/init.d/fdfs_storaged start
#重动storage服务
/etc/init.d/fdfs_storaged restart
#停止动storage服务
/etc/init.d/fdfs_storaged stop
#自启动storage服务
chkconfig fdfs_storaged on
上传测试
[root@localhost fastdfs-6.06]# client/fdfs_upload_file /etc/fdfs/client.conf /usr/local/001.png
group1/M00/00/00/wKghCl_PFGaAeg3SAAESTxub-Qk993.png
[root@localhost fastdfs-6.06]# pwd
/usr/local/fastdfs-6.06
[root@localhost fastdfs-6.06]#
浏览器访问
http://192168.33.10/group1/M00/00/00/wKghCl_PFGaAeg3SAAESTxub-Qk993.png
参考文档
FastDFS INSTALL 文档
文档路径:/usr/local/fastdfs-6.06/INSTALL
Copy right 2009 Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page for more detail.
Chinese language: http://www.fastken.com/
# step 1. download libfastcommon source codes and install it,
# github address: https://github.com/happyfish100/libfastcommon.git
# gitee address: https://gitee.com/fastdfs100/libfastcommon.git
# command lines as:
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon; git checkout V1.0.43
./make.sh clean && ./make.sh && ./make.sh install
# step 2. download fastdfs source codes and install it,
# github address: https://github.com/happyfish100/fastdfs.git
# gitee address: https://gitee.com/fastdfs100/fastdfs.git
# command lines as:
git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs; git checkout V6.06
./make.sh clean && ./make.sh && ./make.sh install
# step 3. setup the config files
# the setup script does NOT overwrite existing config files,
# please feel free to execute this script (take easy :)
./setup.sh /etc/fdfs
# step 4. edit or modify the config files of tracker, storage and client
such as:
vi /etc/fdfs/tracker.conf
vi /etc/fdfs/storage.conf
vi /etc/fdfs/client.conf
and so on ...
# step 5. run the server programs
# start the tracker server:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
# start the storage server:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
# (optional) in Linux, you can start fdfs_trackerd and fdfs_storaged as a service:
/sbin/service fdfs_trackerd restart
/sbin/service fdfs_storaged restart
# step 6. (optional) run monitor program
# such as:
/usr/bin/fdfs_monitor /etc/fdfs/client.conf
# step 7. (optional) run the test program
# such as:
/usr/bin/fdfs_test <client_conf_filename> <operation>
/usr/bin/fdfs_test1 <client_conf_filename> <operation>
# for example, upload a file for test:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h
tracker server config file sample please see conf/tracker.conf
storage server config file sample please see conf/storage.conf
client config file sample please see conf/client.conf
Item detail
1. server common items
---------------------------------------------------
| item name | type | default | Must |
---------------------------------------------------
| base_path | string | | Y |
---------------------------------------------------
| disabled | boolean| false | N |
---------------------------------------------------
| bind_addr | string | | N |
---------------------------------------------------
| network_timeout | int | 30(s) | N |
---------------------------------------------------
| max_connections | int | 256 | N |
---------------------------------------------------
| log_level | string | info | N |
---------------------------------------------------
| run_by_group | string | | N |
---------------------------------------------------
| run_by_user | string | | N |
---------------------------------------------------
| allow_hosts | string | * | N |
---------------------------------------------------
| sync_log_buff_interval| int | 10(s) | N |
---------------------------------------------------
| thread_stack_size | string | 1M | N |
---------------------------------------------------
memo:
* base_path is the base path of sub dirs:
data and logs. base_path must exist and it's sub dirs will
be automatically created if not exist.
$base_path/data: store data files
$base_path/logs: store log files
* log_level is the standard log level as syslog, case insensitive
# emerg: for emergency
# alert
# crit: for critical
# error
# warn: for warning
# notice
# info
# debug
* allow_hosts can ocur more than once, host can be hostname or ip address,
"*" means match all ip addresses, can use range like this: 10.0.1.[1-15,20]
or host[01-08,20-25].domain.com, for example:
allow_hosts=10.0.1.[1-15,20]
allow_hosts=host[01-08,20-25].domain.com
2. tracker server items
---------------------------------------------------
| item name | type | default | Must |
---------------------------------------------------
| port | int | 22000 | N |
---------------------------------------------------
| store_lookup | int | 0 | N |
---------------------------------------------------
| store_group | string | | N |
---------------------------------------------------
| store_server | int | 0 | N |
---------------------------------------------------
| store_path | int | 0 | N |
---------------------------------------------------
| download_server | int | 0 | N |
---------------------------------------------------
| reserved_storage_space| string | 1GB | N |
---------------------------------------------------
memo:
* the value of store_lookup is:
0: round robin (default)
1: specify group
2: load balance (supported since V1.1)
* store_group is the name of group to store files.
when store_lookup set to 1(specify group),
store_group must be set to a specified group name.
* reserved_storage_space is the reserved storage space for system
or other applications. if the free(available) space of any stoarge
server in a group <= reserved_storage_space, no file can be uploaded
to this group (since V1.1)
bytes unit can be one of follows:
# G or g for gigabyte(GB)
# M or m for megabyte(MB)
# K or k for kilobyte(KB)
# no unit for byte(B)
3. storage server items
-------------------------------------------------
| item name | type | default | Must |
-------------------------------------------------
| group_name | string | | Y |
-------------------------------------------------
| tracker_server | string | | Y |
-------------------------------------------------
| port | int | 23000 | N |
-------------------------------------------------
| heart_beat_interval | int | 30(s) | N |
-------------------------------------------------
| stat_report_interval| int | 300(s) | N |
-------------------------------------------------
| sync_wait_msec | int | 100(ms) | N |
-------------------------------------------------
| sync_interval | int | 0(ms) | N |
-------------------------------------------------
| sync_start_time | string | 00:00 | N |
-------------------------------------------------
| sync_end_time | string | 23:59 | N |
-------------------------------------------------
| store_path_count | int | 1 | N |
-------------------------------------------------
| store_path0 | string |base_path| N |
-------------------------------------------------
| store_path# | string | | N |
-------------------------------------------------
|subdir_count_per_path| int | 256 | N |
-------------------------------------------------
|check_file_duplicate | boolean| 0 | N |
-------------------------------------------------
| key_namespace | string | | N |
-------------------------------------------------
| keep_alive | boolean| 0 | N |
-------------------------------------------------
| sync_binlog_buff_interval| int | 60s | N |
-------------------------------------------------
memo:
* tracker_server can ocur more than once, and tracker_server format is
"host:port", host can be hostname or ip address.
* store_path#, # for digital, based 0
* check_file_duplicate: when set to true, must work with FastDHT server,
more detail please see INSTALL of FastDHT. FastDHT download page:
http://code.google.com/p/fastdht/downloads/list
* key_namespace: FastDHT key namespace, can't be empty when
check_file_duplicate is true. the key namespace should short as possible