FastDFS 安装和配置
单机安装部署(CentOS 6.7 环境)
yum install -y libevent
tar zxvf libfastcommon-1.0.7.tar.gz
cd libfastcommon-1.0.7/
./make.sh
./make.sh install
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
tar zxvf FastDFS_v5.05.tar.gz
cd FastDFS/
./make.sh
./make.sh install
/usr/bin 存放有编译出来的文件
/etc/fdfs 存放有配置文件
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim /etc/fdfs/tracker.conf
,编辑内容看下面中文注释disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/tracker/data-and-log
base_path=/opt/fastdfs/tracker/data-and-log
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
run_by_group=
run_by_user=
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.html
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
ps aux | grep tracker
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim /etc/fdfs/storage.conf
,编辑内容看下面中文注释disabled=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
# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/storage/data-and-log
base_path=/opt/fastdfs/storage/data-and-log
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=/opt/fastdfs/storage/images-data0
# store_path1=/opt/fastdfs/storage/images-data1
# store_path2=/opt/fastdfs/storage/images-data2
# 创建目录:mkdir -p /opt/fastdfs/storage/images-data
store_path0=/opt/fastdfs/storage/images-data
subdir_count_per_path=256
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114:22122
log_level=info
run_by_group=
run_by_user=
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=8888
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
,首次启动会很慢,因为它在创建预设存储文件的目录/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
ps aux | grep storage
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/client.conf
,编辑内容看下面中文注释connect_timeout=30
network_timeout=60
# 下面这个路径是保存 store log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/client/data-and-log
base_path=/opt/fastdfs/client/data-and-log
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114: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=80
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/test.jpg
http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg
tar zxvf fastdfs-nginx-module_v1.16.tar.gz
,得到目录地址:/opt/setups/FastDFS/fastdfs-nginx-modulevim /opt/setups/FastDFS/fastdfs-nginx-module/src/config
local
字眼去掉,因为这三个路径根本不是在 local 目录下的。CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
cp /opt/setups/FastDFS/FastDFS/conf/http.conf /etc/fdfs
cp /opt/setups/FastDFS/FastDFS/conf/mime.types /etc/fdfs
安装 Nginx 和 Nginx 第三方模块
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
mkdir -p /usr/local/nginx /var/log/nginx /var/temp/nginx /var/lock/nginx
tar zxvf /opt/setups/nginx-1.8.1.tar.gz
cd /opt/setups/nginx-1.8.1/
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/local/nginx/nginx.pid \
--lock-path=/var/lock/nginx/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/opt/setups/FastDFS/fastdfs-nginx-module/src
make
make install
cp /opt/setups/FastDFS/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
vim /etc/fdfs/mod_fastdfs.conf
,编辑内容看下面中文注释connect_timeout=2
network_timeout=30
# 下面这个路径是保存 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/fastdfs-nginx-module/data-and-log
base_path=/opt/fastdfs/fastdfs-nginx-module/data-and-log
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114:22122
storage_server_port=23000
group_name=group1
# 因为我们访问图片的地址是:http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg
# 该地址前面是带有 /group1/M00,所以我们这里要使用 true,不然访问不到(原值是 false)
url_have_group_name = true
store_path_count=1
# 图片实际存放路径,如果有多个,这里可以有多行:
# store_path0=/opt/fastdfs/storage/images-data0
# store_path1=/opt/fastdfs/storage/images-data1
# store_path2=/opt/fastdfs/storage/images-data2
store_path0=/opt/fastdfs/storage/images-data
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 0
# 注意这一行行,我特别加上了使用 root 用户去执行,不然有些日记目录没有权限访问
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 8080;
# 访问本机
server_name 192.168.1.114;
# 拦截包含 /group1/M00 请求,使用 fastdfs 这个 Nginx 模块进行转发
location ~/group[0-9]/M00 {
ngx_fastdfs_module;
}
location = /favicon.ico { log_not_found off; access_log off; } } }
一、复制一份storage.conf并修改文件名storage_aaa.conf
二、修改storage_aaa.conf相关配置
1、修改组名:group_name=group4
2、修改端口:port=23004
3、修改日志文件目录:base_path=/fastdfs/aaa/data-and-log
4、修改资源保存路径:store_path0=/fastdfs/aaa/aaa-data
三、修改mod_fastdfs.conf配置文件
1、修改组名:group_name=group1/group2/group3/group4 多个用/区分开
2、设置组个数:group_count = 4
3、设置每一组信息:
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage/images-data
[group2]
group_name=group2
storage_server_port=23001
store_path_count=1
store_path0=/fastdfs/storage_voice/voice-data
等以此类推
nginx日志报错ERROR - file: ../common/fdfs_global.c, line: 52, the format of filename
解决办法:
vi /etc/fdfs/mod_fastdfs.conf
将
url_have_group_name=false
改为
url_have_group_name=true
四、重启相关服务,可以访问到相关图片、语音等信息
本人在码云上提交了关于阅读spring源码之后编写的一些基础模块的实现,https://git.oschina.net/73hulu/spring.git 望大家不吝给颗星star,谢谢大家