本篇初步介绍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
- 登录TrackerServer,下载各个安装包:
下载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
-
安装C语言的编译环境:
yum -y install gcc gcc+ gcc-c++ openssl openssl-devel pcre pcre-deve
-
创建系统用户:
useradd fastdfs -M -s /sbin/nologin useradd nginx -M -s /sbin/nologin
-
安装FastDFS:
tar -zxvf FastDFS_v5.01.tar.gz cd FastDFS ./make.sh ./make.sh install
-
安装Nginx
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
-
Tracker Server的配置
-
创建数据以及日志存放目录:
mkdir -p /data/fastdfs/tracker
-
修改tracker.conf配置
vim /etc/fdfs/tracker.conf 修改: base_path=/data/fastdfs/tracker group_name=group1
-
修改nginx.conf配置
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; }
-
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
-
进行StorageServer的配置。
-
首先创建数据以及日志的保存目录:
mkdir -p /data/fastdfs/storage/data
-
修改storage.conf配置:
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
-
修改mod_fastdfs.conf配置。
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
-
配置nginx.conf
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; #} }
-
# 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
-
启动TrackerServer:
service fdfs_trackerd start
-
启动StorageServer:
service fdfs_storaged start
-
启动Tracker和StorageServer的nginx服务器:
./usr/local/nginx/sbin/nginx
-
在TrackerServer中配置一个客户端:
vim /etc/fdfs/client.conf 其中: base_path=/data/fastdfs tracker_server=192.168.33.3:22122
-
进行文件上传:
fdfs_upload_file /etc/fdfs/client.conf iPhoneX.jpg
今天的文章FastDFS的介绍与安装配置分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/20466.html