1 版本信息
服务器使用的系统为centos7.1, fastdfs版本为5.05稳定版
服务器ip分别是:
172.27.12.65,作为tracker机器
172.27.12.61,作为group1的storage
172.27.12.67,作为group2的storage
2 FastDFS安装配置
2.1 FastDFS安装
2.1.1 下载FastDFS及相关
下载fastdfs-5.05:
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
下载libfastcommon-master:
wget https://github.com/happyfish100/libfastcommon/archive/master.zip
下载fastdfs module:
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip
下载nginx lua:
wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
2.1.2 安装FastDFS依赖
安装编译环境,执行命令:
sudo yum -y groupinstall ‘Development Tools‘
安装libfastcommon,执行命令:
cd libfastcommon-master
./make.sh
sudo ./make.sh install
2.1.3 安装FastDFS
cd fastdfs-5.05/
./make.sh
sudo ./make.sh install
2.2 FastDFS配置
添加用户
sudo useradd fastdfs -M -s /sbin/nologin
创建文件夹
sudo mkdir -p /data/fdfs/
sudo chown -R fastdfs:fastdfs /data/fdfs
2.2.1 配置tracker服务器
在65服务器上配置tracker服务器,只列出修改的内容,未列出内容无需修改。添加配置文件:
sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
修改tracker配置文件:
base_path=/data/fdfs
run_by_group=fastdfs
run_by_user=fastdfs
2.2.2 启动tracker
执行启动命令:
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
2.2.3 配置storage服务器
分别在61和67服务器,修改storage.conf文件,只列出修改的内容,未列出内容无需修改。添加storage配置文件:
cd /etc/fdfs
sudo cp storage.conf.sample storage.conf
修改group1的storage配置文件
group_name=group1
run_by_group=fastdfs
run_by_user=fastdfs
base_path=/data/fdfs
tracker_server=192.168.1.50:22122
store_path0=/data/fdfs
修改group2的storage的配置文件
run_by_group=fastdfs
run_by_user=fastdfs
group_name=group2
base_path=/data/fdfs
tracker_server=192.168.1.51:22122
store_path0=/data/fdfs
2.2.4 启动storage
分别在61和67服务器执行启动storage命令:
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
storage正确启动后,需要创建连接。分别在61和67服务器,执行命令:
sudo ln -s /data/fdfs/data /data/fdfs/data/M00
2.2.5 配置storage的测试客户端
为storage服务器添加配置客户端文件
cd /etc/fdfs
sudo cp client.conf.sample client.conf
修改client.conf文件,未列出内容无需修改,修改项如下:
base_path=/data/fdfs
tracker_server=192.168.1.50:22122
3 Openresty Nginx Lua安装和配置
3.1 Openresty Nginx Lua安装
在/usr/yKF6600/fdfs目录,下载并解压fastdfs-nginx-module,执行命令:
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip
unzip fastdfs-nginx-module-master.zip
在/usr/yKF6600/fdfs目录,下载并解压openresty nginx lua,执行命令:
wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
tar -zxvf ngx_openresty-1.7.10.1.tar.gz
3.1.1 安装ngx_openresty
安装编译环境
sudo yum install pcre-devel openssl openssl-devel
安装ngx_openresty,在ngx_openresty目录,执行
sudo ./configure --with-luajit --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/usr/yKF6600/fastdfs/fastdfs-nginx-module-master/src
sudo gmake
sudo gmake install
创建nginx使用的目录
sudo mkdir /data/ngx
sudo chown -R fastdfs:fastdfs /data
创建mod_fastdfs.conf文件
sudo cp /usr/yKF6600/fdfs/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
3.2 配置ngx_openresty
3.2.1 修改mod_fastdfs.conf文件
分别咋61和67机器执行
sudo touch /data/ngx/mod_nginx.log
sudo chown –R fastdfs:fastdfs /data
61机器为group1的storage服务器,修改/etc/fdfs/mod_fastdfs.conf文件(未列出内容无需修改),修改的内容如下:
base_path=/data/ngx
tracker_server=192.168.1.36:22122
group_name=group1
store_path0=/data/fdfs
url_have_group_name = true
log_filename=/data/ngx/mod_nginx.log
group_count = 2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fdfs
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/data/fdfs
67服务器为group2的storage服务器,修改/etc/fdfs/mod_fastdfs.conf(未列出内容无需修改),修改的内容如下:
base_path=/data/ngx
tracker_server=192.168.1.36:22122
group_name=group2
store_path0=/data/fdfs
url_have_group_name = true
log_filename=/data/ngx/mod_nginx.log
group_count = 2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fdfs
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/data/fdfs
3.2.2 添加http.conf和mine.types文件
分别在61和67服务器复制http.conf和mime.types到/etc/fdfs目录
cd /usr/yKF6600/fdfs/fastdfs-5.05/conf
sudo cp http.conf mime.types /etc/fdfs/
3.2.3 配置nginx.conf文件
在61服务器上,修改group1的nginx的/usr/local/openresty/nginx/conf/nginx.conf
#user nobody;
user fastdfs;
worker_processes 1;
error_log /data/ngx/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log /data/ngx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
charset utf8;
location /group1/M00 {
alias /data/fdfs/data;
ngx_fastdfs_module;
}
}
}
在67服务器上,修改nginx.conf,因为group2的nginx.conf文件内容只有如下内容和group1的nginx.conf内容不一致,其他按照group1的nginx.conf配置修改:
location /group2/M00 {
alias /data/fdfs/data;
ngx_fastdfs_module;
}
3.2.4 启动或者重载入nginx配置文件
启动nginx命令:
sudo /usr/local/openresty/nginx/sbin/nginx
重新载入nginx配置:
sudo /usr/local/openresty/nginx/sbin/nginx -s reload
4 上传测试
创建test.html页面,输入如下内容
test fastdfs
上传测试文件,命令为:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.html
返回结果类似为为:
[2016-05-04 02:06:56] DEBUG - base_path=/data/fdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=172.27.12.61, port=23000
group_name=group1, ip_addr=172.27.12.61, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/rBAEYVcpWTqAWVsvAAAADcvBslg32.html
source ip address: 172.27.12.61
file timestamp=2016-05-04 02:06:50
file size=13
file crc32=3418468952
example file url: http://172.27.12.61/group1/M00/00/00/rBAEYVcpWTqAWVsvAAAADcvBslg32.html
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/rBAEYVcpWTqAWVsvAAAADcvBslg32_big.html
source ip address: 172.27.12.61
file timestamp=2016-05-04 02:06:50
file size=13
file crc32=3418468952
example file url: http://172.27.12.61/group1/M00/00/00/rBAEYVcpWTqAWVsvAAAADcvBslg32_big.html
访问上传的页面,执行命令:
curl http://172.27.12.61/group1/M00/00/00/rBAEYVcpWTqAWVsvAAAADcvBslg32_big.html
得到结果为:
test fdfs
如果无法成功上传误,可以在storage服务器上使用fdfs_monitor检测是否有错误。命令为fdfs_monitor /etc/fdfs/storage.conf
以下是使用fdfs_monitor检测为运行正常的结果:
[2016-05-04 17:36:37] DEBUG - base_path=/data/fdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
server_count=1, server_index=0
tracker server is 172.27.12.65:22122
group count: 2
Group 1:
group name = group1
disk total space = 36426 MB
disk free space = 31228 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage 1:
id = 172.27.12.61
ip_addr = 172.27.12.61 ACTIVE
http domain =
version = 5.05
join time = 2016-05-04 17:05:01
up time = 2016-05-04 17:05:01
total storage = 36426 MB
free storage = 31228 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 8888
current_write_path = 0
source storage id =
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 0
connection.max_count = 0
total_upload_count = 0
success_upload_count = 0
total_append_count = 0
success_append_count = 0
total_modify_count = 0
success_modify_count = 0
total_truncate_count = 0
success_truncate_count = 0
total_set_meta_count = 0
success_set_meta_count = 0
total_delete_count = 0
success_delete_count = 0
total_download_count = 0
success_download_count = 0
total_get_meta_count = 0
success_get_meta_count = 0
total_create_link_count = 0
success_create_link_count = 0
total_delete_link_count = 0
success_delete_link_count = 0
total_upload_bytes = 0
success_upload_bytes = 0
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 0
success_download_bytes = 0
total_sync_in_bytes = 0
success_sync_in_bytes = 0
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 0
success_file_open_count = 0
total_file_read_count = 0
success_file_read_count = 0
total_file_write_count = 0
success_file_write_count = 0
last_heart_beat_time = 2016-05-04 17:31:37
last_source_update = 1970-01-01 08:00:00
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
Group 2:
group name = group2
disk total space = 36426 MB
disk free space = 32921 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage 1:
id = 172.27.12.67
ip_addr = 172.27.12.67 (ci-dmz-c03) ACTIVE
http domain =
version = 5.05
join time = 2016-05-04 17:33:01
up time = 2016-05-04 17:33:01
total storage = 36426 MB
free storage = 32921 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 8888
current_write_path = 0
source storage id =
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 0
connection.max_count = 0
total_upload_count = 0
success_upload_count = 0
total_append_count = 0
success_append_count = 0
total_modify_count = 0
success_modify_count = 0
total_truncate_count = 0
success_truncate_count = 0
total_set_meta_count = 0
success_set_meta_count = 0
total_delete_count = 0
success_delete_count = 0
total_download_count = 0
success_download_count = 0
total_get_meta_count = 0
success_get_meta_count = 0
total_create_link_count = 0
success_create_link_count = 0
total_delete_link_count = 0
success_delete_link_count = 0
total_upload_bytes = 0
success_upload_bytes = 0
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 0
success_download_bytes = 0
total_sync_in_bytes = 0
success_sync_in_bytes = 0
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 0
success_file_open_count = 0
total_file_read_count = 0
success_file_read_count = 0
total_file_write_count = 0
success_file_write_count = 0
last_heart_beat_time = 2016-05-04 17:31:45
last_source_update = 1970-01-01 08:00:00
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00