- 安装依赖环境
yum install make cmake gcc gcc-c++ pcre-devel zlib-devel perl-devel - 安装libfastcommon-master.zip依赖
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.36.tar.gz -O libfastcommon-master.tar.gz
mkdir -p /usr/local/fast/
tar -xf libfastcommon-master.tar.gz -C /usr/local/fast/
cd libfastcommon-1.0.36
./make.sh
./make.sh install
libfastcommon.so默认安装到了/usr/lib64/libfastcommon.so
而FastDFS主程序设置的lib目录是/usr/local/lib/
设置软连接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so - 安装Fastdfs
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz -O FastDFS-5.1.1.tar.gz
tar -xf FastDFS-5.1.1.tar.gz -C /usr/local/fast/
cd fastdfs-5.11
./make.sh
./make.sh install - storage服务器配置(默认监听端口23000)
安装fastdfs-nginx-module
cd /usr/local/fast/
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
通过nginx或openresty的安装包源目录编译安装
./configure --user=www --group=www --with-http_stub_status_module --with-http_flv_module --with-http_gzip_static_module --add-module=/usr/local/fast/fastdfs-nginx-module/src
./configure --add-module=/usr/local/fast/fastdfs-nginx-module/src
make
make install
### 报错处理
修改 fastdfs-nginx-module-1.20/src/config 文件,修改如下:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
然后重新 configure make make install,就可以了
storage配置文件修改
cd /etc/fdfs/
cp storage.conf.sample storage.conf
#### base_path=/fastdfs/FastDFSdata (这里的文件目录如果没有,要自己新建,不然会报错)
#### store_path0=/fastdfs/FastDFSdata (建议与bast_path一样)
#### tracker_server要改为自己的trakcer_server的ip
vim storage.confdisabled=false
group_name=group1
bind_addr=
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/fastdfs/FastDFSdata
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1
store_path0=/fastdfs/FastDFSdata
subdir_count_per_path=2
tracker_server=10.10.24.237:22122
#tracker_server=10.10.24.238:22122
log_level=info
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=80storage.conf
复制配置文件
cp /usr/local/fast/fastdfs-nginx-module/src/mod_fastdfs.conf ./
cp /usr/local/fast/fastdfs-5.11/conf/http.conf ./
cp /usr/local/fast/fastdfs-5.11/conf/mime.types ./
mod_fastdfs.conf 配置
更改/etc/fdfs/mod_fastdfs.conf,增加"#include http.conf",必须加#号
vim /etc/fdfs/mod_fastdfs.confconnect_timeout=2
network_timeout=30
base_path=/fastdfs/FastDFSdata
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=10.10.24.237:22122
#tracker_server=10.10.24.238:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path_count=1
store_path0=/fastdfs/FastDFSdata
log_level=info
log_filename=/fastdfs/FastDFSdata/mod_fdfs.log
response_mode=proxy
if_alias_prefix=
#include http.conf
flv_support = true
flv_extension = flv
group_count = 0mod_fastdfs.conf
- tracker服务器配置(默认监听端口22122)
tracker配置文件修改
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
cp /usr/local/fast/fastdfs-5.11/conf/storage_ids.conf ./
vim tracker.confdisabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/fastdfs/FastDFSdata
max_connections=256
accept_threads=1
work_threads=4
store_lookup=2
store_group=group2
store_server=0
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 0
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.htmltracker.conf
storage_ids.conf 配置
vi storage_ids.conf
100001 group1 10.10.24.237
#100002 group1 10.10.24.238 - storage服务器nginx配置
touch /fastdfs/FastDFSdata/mod_fdfs.log
chmod 777 /fastdfs/FastDFSdata/mod_fdfs.log
添加nginx虚拟主机配置文件server {
listen 80;
server_name fastcdn.test.com;
access_log /data/logs/nginx/access_fastcdn.test.com_80.log main buffer=10k flush=5s;
error_log /data/logs/nginx/error_fastcdn.test.com_80.log crit;
location /group1/M00 {
alias /fastdfs/FastDFSdata/data;
ngx_fastdfs_module;
}
} - 启停服务
tracker: fdfs_trackerd /etc/fdfs/tracker.conf restart
tracker: fdfs_trackerd /etc/fdfs/tracker.conf stop
storage: fdfs_storaged /etc/fdfs/storage.conf restart
storage: fdfs_storaged /etc/fdfs/storage.conf stop
(storage机器) nginx: /etc/init.d/nginx restart - 功能测试
tracker 服务器
client.conf客户端配置:
cd /etc/fdfs/
cp client.conf.sample client.conf
vim client.confconnect_timeout=30
network_timeout=60
base_path=/fastdfs/FastDFSdata
tracker_server=10.10.24.237:22122
#tracker_server=10.10.24.238:22122
log_level=info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker=false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port=80client.conf
文件上传:
cd /usr/local/fast
echo "fdfs">fdfs.txt
执行上传:
fdfs_test /etc/fdfs/client.conf upload fdfs.txt
文件下载:
通过提示的URL,打开网页直接下载 - 集群说明
节点增加
tracker :可以动态扩容增加,需要配置storage 配置中增加tracker IP及端口,并重载配置
storage : 动态添加,tracker 自动发现,文件会自动进行多节点同步
节点删除
tracker : 删除节点,需要同步修改storage配置
storage: 删除节点,tracker 会自动同步
备份策略
tracker:无数据,程序部分可通过多台实现互备
storage: 数据存储,有多台相互之间自动实现同步
分布式方案
tracker: 多台部署,避免单点故障
storage: 多台部署能够自动实现互备
- 安装php拓展
cd /usr/local/fast/fastdfs-5.11/php_client/
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
/usr/local/php7/bin/php -m | grep fastdfs - 查看配置
fdfs_monitor /etc/fdfs/storage.conf
fdfs_monitor /etc/fdfs/client.conf
fdfs_file_info /etc/fdfs/client.conf group1/M00/01/01/rBLin109O96AewiGAADJ2ivPi74763.jpg