centos7 安裝FastDFS分布式文件系統


一、版本介紹:

系統:centos7.1

FastDFS:5.08

libfastcommon:1.30 

fastdfs-nginx-module:1.16

nginx:1.10.1

 

二、服務器結構:

 

兩台服務器:172.0.0.190【fastdfs_1】、172.0.0.171【fastdfs_2】

每一台都充當 tracker 與 storage 的角色,配置都一樣

 

三、安裝需要用到的應用與類庫:

[root@fastdfs_1 pangyiguang]# yum install vim wget zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl net-tools unzip

四、配置hosts

[root@fastdfs_1 pangyiguang]# vim /etc/hosts

追加內容(這里的server不能綁定127.0.0.1,否則報錯):

172.0.0.190 fastdfs-server1
172.0.0.171 fastdfs-server2

 

五、添加用戶與組

[root@fastdfs_1 pangyiguang]# groupadd www
[root@fastdfs_1 pangyiguang]# useradd -s /sbin/nologin  -g www www


[root@fastdfs_1 pangyiguang]# groupadd fastdfs
[root@fastdfs_1 pangyiguang]# useradd -s /sbin/nologin  -g fastdfs fastdfs

 

六、創建環境目錄

[root@fastdfs_1 pangyiguang]# mkdir -p /servers/nginx
[root@fastdfs_1 pangyiguang]# mkdir -p /data/fastdfs/storage
[root@fastdfs_1 pangyiguang]# chown -R fastdfs:fastdfs /data/fastdfs

 

七、下載並解壓安裝包

[root@fastdfs_1 pangyiguang]# cd ~
[root@fastdfs_1 ~]# wget http://ncu.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
[root@fastdfs_1 ~]# wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz
[root@fastdfs_1 ~]# wget https://codeload.github.com/happyfish100/libfastcommon/zip/master -O libfastcommon.zip
[root@fastdfs_1 ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz

 

如果下載不了,可以從百度雲這里下載:http://pan.baidu.com/s/1eSeAkZg

 

解壓:

[root@fastdfs_1 ~]# tar zxf fastdfs-nginx-module_v1.16.tar.gz 
[root@fastdfs_1 ~]# tar zxf FastDFS_v5.08.tar.gz 
[root@fastdfs_1 ~]# unzip libfastcommon.zip
[root@fastdfs_1 ~]# tar zxf nginx-1.10.1.tar.gz

 

八、安裝libfastcommon類庫

[root@fastdfs_1 ~]# cd ~/libfastcommon-master/
[root@fastdfs_1 libfastcommon-master]# ./make.sh
[root@fastdfs_1 libfastcommon-master]# ./make.sh install

 

九、安裝與配置FastDFS

[root@fastdfs_1 libfastcommon-master]# cd ~/FastDFS
[root@fastdfs_1 FastDFS]# ./make.sh
[root@fastdfs_1 FastDFS]# ./make.sh install
[root@fastdfs_1 FastDFS]# cp conf/* /etc/fdfs/

編輯:client.conf

[root@fastdfs_1 fdfs]# vim client.conf

更改對應內容:

base_path=/data/fastdfs/storage
tracker_server=fastdfs-server1:22122
tracker_server=fastdfs-server2:22122

 

 

編輯:storage.conf

[root@fastdfs_1 fdfs]# vim storage.conf

更改對應內容:

group_name=group1
base_path=/data/fastdfs/storage
store_path0=/data/fastdfs/storage
tracker_server=fastdfs-server1:22122
tracker_server=fastdfs-server2:22122
http.server_port=80

編輯:tracker.conf

[root@fastdfs_1 fdfs]# vim tracker.conf

更改對應內容:

base_path=/data/fastdfs/storage
run_by_group=fastdfs
run_by_user=fastdfs
use_storage_id = false
http.server_port=80

 

十、安裝配置nginx與fastdfs模塊

[root@fastdfs_1 fdfs]# cd ~/nginx-1.10.1
[root@fastdfs_1 nginx-1.10.1]# ./configure --prefix=/servers/nginx  --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module  --add-module=/root/fastdfs-nginx-module/src/ --user=www --group=www
[root@fastdfs_1 nginx-1.10.1]# make && make install

 

############################如果出現以下這個錯誤:############################

/root/fastdfs-nginx-module/src//common.c:21:25: 致命錯誤:fdfs_define.h:沒有那個文件或目錄
 #include "fdfs_define.h"
                         ^
編譯中斷。
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] 錯誤 1
make[1]: 離開目錄“/root/nginx-1.10.1”
make: *** [build] 錯誤 2

 

說明添加fastdfs模塊出錯,可以更改fastdfs-nginx-module/src/config這個文件

[root@fastdfs_1 nginx-1.10.1]# vim ~/fastdfs-nginx-module/src/config

更改后內容為:

ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

 

然后再進行上面的兩個步驟:

[root@fastdfs_1 nginx-1.10.1]# ./configure --prefix=/servers/nginx  --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module  --add-module=/root/fastdfs-nginx-module/src/ --user=www --group=www
[root@fastdfs_1 nginx-1.10.1]# make && make install

############################如果出現以上這個錯誤:############################

把對應的配置文件拷貝到對應的配置路徑:

[root@fastdfs_1 nginx-1.10.1]# cp ~/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

編輯模塊配置文件:
[root@fastdfs_1 nginx-1.10.1]# vim /etc/fdfs/mod_fastdfs.conf

更改以下對應內容:

base_path=/data/fastdfs/storage
use_storage_id = false
tracker_server=fastdfs-server1:22122
tracker_server=fastdfs-server2:22122
group_name=group1
url_have_group_name = true
store_path0=/data/fastdfs/storage

 

 

接着更改nginx的配置文件:

[root@fastdfs_1 nginx-1.10.1]# vim /servers/nginx/conf/nginx.conf

把 sever指令段內容改為:

server {
listen       80;
server_name  localhost;


location / {
root   html;
index  index.html index.htm;
}


location /group1/M00 {
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}


error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}


}

 

十一、授權對應的端口開放:

[root@fastdfs_1 nginx-1.10.1]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@fastdfs_1 nginx-1.10.1]# firewall-cmd --zone=public --add-port=22122/tcp --permanent
[root@fastdfs_1 nginx-1.10.1]# firewall-cmd --zone=public --add-port=23000/tcp --permanent
[root@fastdfs_1 nginx-1.10.1]# firewall-cmd --reload
[root@fastdfs_1 nginx-1.10.1]# firewall-cmd --list-all

 

 

 

上面的配置過程就是其中一台主機的配置,因為兩台主機的配置時一樣的,重復上面的 【三  ~ 十一】的流程就可以了,如果是虛擬機,直接clone剛才那個鏡像就可以了。假如上面的這台ip是172.0.0.190 ,那么另外一台ip就是172.0.0.171。

 

好了下面就是使用的過程了:

啟動:

[root@fastdfs_1 pangyiguang]# /etc/init.d/fdfs_storaged start
[root@fastdfs_1 pangyiguang]# /etc/init.d/fdfs_trackerd start
[root@fastdfs_1 pangyiguang]# /servers/nginx/sbin/nginx 


[root@fastdfs_2 pangyiguang]# netstat -lpna | grep -E "nginx|fdfs"

 

查看faskFDS的運行狀態信息:

[root@fastdfs_1 pangyiguang]# fdfs_monitor /etc/fdfs/storage.conf


[2016-08-16 16:34:05] DEBUG - base_path=/data/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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=2, server_index=1


tracker server is 172.0.0.190:22122


group count: 1


Group 1:
group name = group1
disk total space = 17878 MB
disk free space = 16622 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
storage server port = 23000
storage HTTP port = 80
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0


Storage 1:
id = 172.0.0.171
ip_addr = 172.0.0.171 (fastdfs-server2)  ACTIVE
http domain = 
version = 5.08
join time = 2016-08-16 16:32:00
up time = 2016-08-16 16:32:00
total storage = 17878 MB
free storage = 16622 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 80
current_write_path = 0
source storage id = 
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 1
connection.max_count = 1
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-08-16 16:33:36
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 
Storage 2:
id = 172.0.0.190
ip_addr = 172.0.0.190 (fastdfs-server1)  ACTIVE
http domain = 
version = 5.08
join time = 2016-08-16 16:30:51
up time = 2016-08-16 16:30:51
total storage = 17878 MB
free storage = 16622 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 80
current_write_path = 0
source storage id = 172.0.0.171
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 1
connection.max_count = 1
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-08-16 16:33:40
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

 

上傳一個文件:

[root@fastdfs_1 fdfs]# fdfs_test /etc/fdfs/client.conf upload /root/libfastcommon.zip

This is FastDFS client test program v5.08


Copyright (C) 2008, Happy Fish / YuQing


FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.


[2016-08-16 16:57:25] DEBUG - base_path=/data/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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.0.0.171, port=23000
server 2. group_name=, ip_addr=172.0.0.190, port=23000


group_name=group1, ip_addr=172.0.0.190, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/rAAAvley1XWAWtVPAAJ3f72gVQQ365.zip
source ip address: 172.0.0.190
file timestamp=2016-08-16 16:57:25
file size=161663
file crc32=3181401348
example file url: http://172.0.0.190/group1/M00/00/00/rAAAvley1XWAWtVPAAJ3f72gVQQ365.zip
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/rAAAvley1XWAWtVPAAJ3f72gVQQ365_big.zip
source ip address: 172.0.0.190
file timestamp=2016-08-16 16:57:25
file size=161663
file crc32=3181401348
example file url: http://172.0.0.190/group1/M00/00/00/rAAAvley1XWAWtVPAAJ3f72gVQQ365_big.zip

 

然后可以直接用 http://172.0.0.190/group1/M00/00/00/rAAAvley1XWAWtVPAAJ3f72gVQQ365.zip 來 訪問下載了。

 

通過另外一台主機查看該文件信息:

[root@fastdfs_2 libfastcommon-master]# fdfs_test /etc/fdfs/client.conf getmeta group1 M00/00/00/rAAAvley1XWAWtVPAAJ3f72gVQQ365.zip

This is FastDFS client test program v5.08


Copyright (C) 2008, Happy Fish / YuQing


FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.


[2016-08-16 17:54:41] DEBUG - base_path=/data/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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


storage=172.0.0.171:23000
get meta data success, meta count=4
ext_name=jpg
file_size=115120
height=80
width=160

 

查看也成功,兩台主機也是互相通信的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM