FastDFS安装部署
选取3台机器
10.20.5.112 trackerServer
10.20.5.113 storageServer (group1)
10.20.5.114 storageServer (group1)
防火墙关闭 selinux关闭
略
访问余大的GitHub网址下载对应的安装包
github网址:(https://github.com/happyfish100)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xVIISmjV-1571383327013)(FastDFS文件安装部署_files/1.jpg)]
下载标红的3处文件。
下载安装libfastCommon(all)
1.新建/opt/fastdfs文件夹,下载libfastCommon文件
[root@master ~]# cd /opt/
[root@master opt]# mkdir -p fastdfs
[root@master opt]# cd fastdfs/
[root@master fastdfs]# ls
[root@master fastdfs]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz
[root@master fastdfs]# tar -zxvf V1.0.39.tar.gz
[root@slave1 fastdfs]# cd libfastcommon-1.0.39/
[root@slave1 libfastcommon-1.0.39]# ./make.sh
[root@master libfastcommon-1.0.39]# ./make.sh install
[root@slave2 libfastcommon-1.0.39]# ln -s /usr/lib64/libfastcommon.so /usr/local/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 (all)
1.下载fastdfs文件:(所有节点)
[root@master fastdfs]# ls
libfastcommon-1.0.39 V1.0.39.tar.gz
[root@master fastdfs]# wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
[root@slave1 fastdfs]# tar -zxvf V5.11.tar.gz
[root@slave1 fastdfs]# cd fastdfs-5.11/
[root@slave1 fastdfs-5.11]# ./make.sh
[root@master fastdfs-5.11]# ./make.sh install
2.修改fastdfs的配置文件:(tracker节点)
[root@master fastdfs-5.11]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
修改tracker.conf
修改basepath:/data/tracker/fastdfs (需要手动创建)
3.修改fastdfs的配置文件(storage节点)
[root@slave3 fastdfs-5.11]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
修改storage.conf
base_path=/data/storage/fastdfs (需要手动创建)
store_path0=/data/storage/fastdfs (需要手动创建)
tracker_server=10.20.5.112:22122
启动fastdfs(all)
[root@master ~]# fdfs_trackerd /etc/fdfs/tracker.conf (tracker节点)
[root@slave1 ~]# fdfs_storaged /etc/fdfs/storage.conf start (storage节点)
****************
如果出现 节点一直存在同步状态
从集群中删除
fdfs_monitor /etc/fdfs/client.conf delete group1 10.20.5.114
删除数据文件夹
rm -rf /home/storage1/fastdfs/data
重启节点
fdfs_storaged /etc/fdfs/storage.con
*****************
安装nginx 和fastdfs-nginx-module(storage)
[root@slave1 fastdfs]# wget http://mirrors.sohu.com/nginx/nginx-1.12.0.tar.gz
[root@slave1 fastdfs]# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
[root@slave2 fastdfs]# tar -zxvf nginx-1.12.0.tar.gz
[root@slave2 fastdfs]# tar -zxvf V1.20.tar.gz
*************************************
ngx_addon_name=ngx_http_fastdfs_module
if test -n "${ngx_module_link}"; then
ngx_module_type=HTTP
ngx_module_name=$ngx_addon_name
ngx_module_libs="-lfastcommon -lfdfsclient"
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
ngx_module_deps=
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi
**********************************
[root@bigdata3 /opt/fastdfs/nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --add-module=../fastdfs-nginx-module-1.20/src/
[root@bigdata3 /opt/fastdfs/nginx-1.12.0]# make && make install
[root@bigdata3 /opt/fastdfs/nginx-1.12.0]# vi /usr/local/nginx/conf/nginx.conf
*************************************
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
*******************************************
[root@bigdata2 /opt/fastdfs/nginx-1.12.0]# cp /opt/fastdfs/fastdfs-5.11/conf/http.conf /opt/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs/
[root@bigdata3 /opt/fastdfs/nginx-1.12.0]# cp /opt/fastdfs/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/
修改 mod_fastdfs.conf(storage)
[root@slave1 conf]# vi /etc/fdfs/mod_fastdfs.conf
*******************************************
# connect timeout in seconds
# default value is 30s
connect_timeout=2
# network recv and send timeout in seconds
# default value is 30s
network_timeout=30
# the base path to store log files
base_path=/tmp
# if load FastDFS parameters from tracker server
# since V1.12
# default value is false
load_fdfs_parameters_from_tracker=true
# storage sync file max delay seconds
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V1.12
# default value is 86400 seconds (one day)
storage_sync_file_max_delay = 86400
# if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
# since V1.13
use_storage_id = false
# specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V1.13
storage_ids_filename = storage_ids.conf
# FastDFS tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=10.9.35.18:22122
# the port of the local storage server
# the default value is 23000
storage_server_port=23000
# the group name of the local storage server
group_name=group1
# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true
# path(disk or mount point) count, default value is 1
# must same as storage.conf
store_path_count=1
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/data/storage/fastdfs
#store_path1=/home/yuqing/fastdfs1
# standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info
# set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log
# empty for output to stderr (apache and nginx error_log file)
log_filename=
# response mode when the file not exist in the local file system
## proxy: get the content from other storage server, then send to client
## redirect: redirect to the original storage server (HTTP Header is Location)
response_mode=proxy
# the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# this paramter used to get all ip address of the local host
# default values is empty
if_alias_prefix=
# use "#include" directive to include HTTP config file
# NOTE: #include is an include directive, do NOT remove the # before include
#include http.conf
# if support flv
# default value is false
# since v1.15
flv_support = true
# flv file extension name
# default value is flv
# since v1.15
flv_extension = flv
# set the group count
# set to none zero to support multi-group on this storage server
# set to 0 for single group only
# groups settings section as [group1], [group2], ..., [groupN]
# default value is 0
# since v1.14
group_count = 1
# group settings for group #1
# since v1.14
# when support multi-group on this storage server, uncomment following section
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/storage/fastdfs
#store_path1=/home/yuqing/fastdfs1
# group settings for group #2
# since v1.14
# when support multi-group, uncomment following section as neccessary
#[group2]
#group_name=group2
#storage_server_port=23000
#store_path_count=1
#store_path0=/home/yuqing/fastdfs
*********************************************************
开启防盗链(stroage)
[root@slave1 conf]# vi /etc/fdfs/http.conf
******************************************************
# HTTP default content type
http.default_content_type = application/octet-stream
# MIME types mapping filename
# MIME types file format: MIME_type extensions
# such as: image/jpeg jpeg jpg jpe
# you can use apache's MIME file: mime.types
http.mime_types_filename=mime.types
# if use token to anti-steal
# default value is false (0)
http.anti_steal.check_token=true
# token TTL (time to live), seconds
# default value is 600
http.anti_steal.token_ttl=900
# secret key to generate anti-steal token
# this parameter must be set when http.anti_steal.check_token set to true
# the length of the secret key should not exceed 128 bytes
http.anti_steal.secret_key=chuang123
# return the content of the file when check token fail
# default value is empty (no file sepecified)
http.anti_steal.token_check_fail=/home/yuqing/fastdfs/conf/anti-steal.jpg
# if support multi regions for HTTP Range
# default value is true
http.multi_range.enabed = true
**********************************************************
启动nginx(storage)
[root@slave1 conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
在tracker上添加安装nginx负载均衡
nginx.config
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream fdfs_group1 {
server xxxx:port weight=1 max_fails=2 fail_timeout=30s;
server xxxx:port weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 开放的端口号;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /group1/M00 {
proxy_pass http://fdfs_group1;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
在storage上的nginx安装imageFilter缩略图插件(nginx已经内置)
./configure --prefix=/usr/local/nginx --add-module=../fastdfs-nginx-module-1.20/src/ --with-http_image_filter_module
nginx.conf内容
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8899;
server_name localhost;
location ~ /group1/M00/(.*)_([0-9]+)x([0-9]+)\.(jpg|JPG|png){
root /home/fdfsdata/data;
ngx_fastdfs_module;
set $w $2;
set $h $3;
if ($h != "0") {
rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|JPG|gif|png)$ group1/M00$1.$4 break;
}
if ($w != "0") {
rewrite /group1/M00/(.+)_(\d+)x(\d+)\.(jpg|JPG|gif|png)$ /group1/M00/$1.$4 break;
}
image_filter resize $w $h;
image_filter_buffer 2M;
}
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}