由該圖可知,上傳、修改、刪除是經過tracker的api進行的,訪問、下載操做是經過nginx進行的html
服務器,使用的系統爲centos7.1,libfastcommon1.07,fastdfs版本爲5.05穩定版nginx
服務器ip分別是1八、50、51git
18做爲tracker機器,50做爲group1的storage,51做爲group2的storagegithub
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
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip unzip fastdfs-nginx-module-master.zipwget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz tar -zxvf ngx_openresty-1.7.10.1.tar.gz
sudo yum -y groupinstall 'Development Tools'vim
cd libfastcommon-master centos
./make.sh api
sudo ./make.sh install服務器
cd fastdfs-5.05/ 架構
./make.sh app
sudo ./make.sh install
sudo useradd fastdfs -M -s /sbin/nologin
sudo mkdir -p /data/fdfs/
sudo chown -R fastdfs:fastdfs /data/fdfs
sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
sudo vim /etc/fdfs/tracker.conf
# the base path to store data and log files
base_path=/data/fdfs
run_by_group=fastdfs
run_by_user=fastdfs
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
cd /etc/fdfs
sudo cp storage.conf.sample storage.conf
修改group1的storage配置文件
group_name=group1
run_by_group=fastdfs
run_by_user=fastdfs
# the base path to store data and log files
base_path=/data/fdfs
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.50:22122
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/data/fdfs
#store_path1=/home/yuqing/fastdfs2
修改group2的storage的配置文件
run_by_group=fastdfs
run_by_user=fastdfs
group_name=group2
base_path=/data/fdfs
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.51:22122
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/data/fdfs
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
下載fastdfs-nginx-module
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip unzip fastdfs-nginx-module-master.zip
下載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
sudo yum install
pcre-devel openssl openssl-devel
編譯安裝ngx_openresty
cd ngx_openresty-1.7.10.1sudo ./configure --with-luajit --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/usr/yKF6600/fdfs/fastdfs-nginx-module-master/srcsudo gmake
sudo gmake install
爲50機器添加client配置文件
cd /etc/fdfs sudo cp client.conf.sample client.conf修改client.conf文件的以下內容# the base path to store log files base_path=/data/fdfs# tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=192.168.1.50:22122
51配置相似
sudo mkdir /data/ngxsudo chown -R fastdfs:fastdfs /data
sudo cp /usr/yKF6600/fdfs/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
修改group1的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=/var/log/ngx-fdfs.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
修改group2的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=/var/log/ngx-fdfs.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
cd /usr/yKF6600/fdfs/fastdfs-5.05/confsudo cp http.conf mime.types /etc/fdfs/
修改group1的nginx的/usr/local/openresty/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;
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 logs/access.log main;
sendfile on;
#tcp_nopush on;#keepalive_timeout 0;
keepalive_timeout 65;#gzip on;
server {
listen 80;
server_name localhost;#charset koi8-r;
charset utf8;#access_log logs/host.access.log main;
location /group1/M00 {
alias /data/fdfs/data;
ngx_fastdfs_module;
}location / {
root html;
index index.html index.htm;
}#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
修改group2的nginx的/usr/local/openresty/nginx/conf/nginx.conf
#user nobody;
user fastdfs;
worker_processes 1;error_log /data/ngx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;
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 koi8-r;
charset utf8;location /group2/M00 {
alias /data/fdfs/data;
#root /data/fdfs/data;
ngx_fastdfs_module;
}#access_log logs/host.access.log main;
}
}
sudo ln -s /data/fdfs/data /data/fdfs/data/M00
sudo /usr/local/openresty/nginx/sbin/nginx或者sudo /usr/local/openresty/nginx/sbin/nginx -s reload
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
建立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.16.4.97, port=23000group_name=group1, ip_addr=172.16.4.97, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/rBAEYVcpWTqAWVsvAAAADcvBslg32.html
source ip address: 172.16.4.97
file timestamp=2016-05-04 02:06:50
file size=13
file crc32=3418468952
example file url: http://172.16.4.97/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.16.4.97
file timestamp=2016-05-04 02:06:50
file size=13
file crc32=3418468952
example file url: http://172.16.4.97/group1/M00/00/00/rBAEYVcpWTqAWVsvAAAADcvBslg32_big.html
訪問頁面
curl http://172.16.4.97/group1/M00/00/00/rBAEYVcpWTqAWVsvAAAADcvBslg32_big.html
獲得結果爲
test fdfs
執行fdfs_monitor /etc/fdfs/storage.conf,配置正確顯示以下信息:
[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 = 0Storage 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:00Group 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 = 0Storage 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
在50服務器執行刪除命令:
sudo rm /usr/bin/fdfs_*
sudo rm -R /usr/local/openrestysudo rm -R /etc/fdfs
sudo rm -R /data
sudo chkconfig --del fdfs_trackerd有些lib庫刪不掉 - -!!
http://www.centoscn.com/image-text/install/2015/0429/5298.html