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

 

查看也成功,两台主机也是互相通信的。

posted on 2017-10-26 17:33  Jt00  阅读(1676)  评论(0编辑  收藏  举报

导航