FastDFS的介绍与安装配置

本篇初步介绍FastDFS,并且在CentOS上安装FastDFS。

基本介绍:

FastDFS是比较优秀的分布式文件系统。它分为服务端和客户端API两个部分,服务端又分成了跟踪器(Tracker)和服务节点(Storage)两个角色。跟踪器主要负责服务调度,起着负载均衡的作用;存储节点主要负责文件的存储、读取和同步等功能;客户端API来提供文件的上传与下载和删除的功能。

实际使用中,我们往往是使用客户端来连接跟踪器服务器集群,跟踪器管理存储节点集群,存储节点集群来为客户端提供可用的存储节点。存储节点的文件使用了分卷或者分组的组织方式,在FastDFS上一个文件的标识由卷名(或者是组名)、路径和文件名等部分组成。FastDFS支持动态扩展,我们可以通过增加新卷或者新组的方式来增加更多的存储节点。

安装步骤:

我们要安装FastDFS需要3台主机,这里我使用3台模拟器来模拟。其中的ip地址分别为:192.168.33.3 192.168.33.4 192.168.33.5,其中将192.168.33.3来作为TrackerServer,其他的两台主机作为StorageServer

  1. 登录TrackerServer,下载各个安装包:
1
2
3
4
5
6
复制代码下载FastDFS
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.01/FastDFS_v5.01.tar.gz
下载Nginx
wget http://nginx.org/download/nginx-1.7.0.tar.gz
下载FastDFS-Nginx-Module
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
  1. 安装C语言的编译环境:
1
复制代码yum -y install gcc gcc+ gcc-c++ openssl openssl-devel pcre pcre-deve
  1. 创建系统用户:
1
2
复制代码useradd fastdfs -M -s /sbin/nologin
useradd nginx -M -s /sbin/nologin
  1. 安装FastDFS:
1
2
3
4
复制代码tar -zxvf FastDFS_v5.01.tar.gz
cd FastDFS
./make.sh
./make.sh install
  1. 安装Nginx
1
2
3
4
5
6
7
复制代码tar -zxvf fast-nginx-module_v1.16.tar.gz
tar -zxvf nginx-1.7.0.tar.gz
cd nginx-1.7.0
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --add-module=../fastdfs-nginx-module/src
注意--add-module=../fastdfs-nginx-module/src这个配置项只在两个StorageServer上添加
make
make install
  1. Tracker Server的配置
1. 创建数据以及日志存放目录:



1
复制代码mkdir -p /data/fastdfs/tracker
2. 修改tracker.conf配置
1
2
3
4
复制代码vim /etc/fdfs/tracker.conf
修改:
base_path=/data/fastdfs/tracker
group_name=group1
3. 修改nginx.conf配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
复制代码vim /usr/local/nginx/conf/nginx.conf
配置为:

user nginx nginx;
worker_processes 4;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 51200;

events {
use epoll;
worker_connections 20480;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
复制代码                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 /usr/local/nginx/logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

upstream server_group1{
server 192.168.33.4;
server 192.168.33.5;
}
server {
listen 80;
server_name 192.168.33.3;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}
location /group1{
include proxy.conf;
proxy_pass http://server.group1;
}

}



4. 配置TrackerServer的启动程序:

cp /usr/local/app/fastdfs/FastDFS/init.d/fdfs_trackerd /etc/init.d/
chkconfig --add fdfs_trackerd
chkconfig fdfs_trackerd on
  1. 进行StorageServer的配置。
1. 首先创建数据以及日志的保存目录:



1
复制代码mkdir -p /data/fastdfs/storage/data
2. 修改storage.conf配置:
1
2
3
4
5
6
7
8
9
10
复制代码vim /etc/fdfs/storage.conf
其中:
group_name=group1
base_path=/data/fastdfs
store_path0=/data/fastdfs/storage
tracker_server=192.168.33.3:22122
run_by_group=fastdfs
run_by_user=fastdfs
file_distribute_path_mode=1
rotate_error_log=true
3. 修改mod\_fastdfs.conf配置。
1
2
3
4
5
6
7
8
9
复制代码cp /usr/local/app/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
vim /etc/fdfs/mod_fastdfs.conf
其中:
connect_timeout=10
tracker_server=192.168.33.3:22122
group_name=group1
url_have_group_name = true
store_path_count=1
store_path0=/data/fastdfs/storage
4. 配置nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
复制代码    access_log  /usr/local/nginx/logs/access.log  main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 88;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

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

"/usr/local/nginx/conf/nginx.conf" 128L, 2960C 43,9 29%

http {
include mime.types;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 20m;
limit_rate 1024k;

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 /usr/local/nginx/logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 88;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

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

location /group1/M00{
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}
#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;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#\}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#\}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#\}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
复制代码                    # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

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


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

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

}
创建软连接:
ln -s /data/fastdfs/storage/data /data/fastdfs/storage/data/M00
5. 配置Storage的启动程序:

cp /usr/local/app/fastdfs/FastDFS/init.d/fdfs_storaged /etc/init.d/
chkconfig --add fdfs_storaged
chkconfig fdfs_storaged on
  1. 启动TrackerServer:
1
复制代码service fdfs_trackerd start
  1. 启动StorageServer:
1
复制代码service fdfs_storaged start
  1. 启动Tracker和StorageServer的nginx服务器:
1
复制代码./usr/local/nginx/sbin/nginx
  1. 在TrackerServer中配置一个客户端:
1
2
3
4
复制代码vim /etc/fdfs/client.conf
其中:
base_path=/data/fastdfs
tracker_server=192.168.33.3:22122
  1. 进行文件上传:

fdfs_upload_file /etc/fdfs/client.conf iPhoneX.jpg

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%