10

FastDFS学习使用(一)--安装

 3 years ago
source link: http://timebusker.top/2019/12/31/FastDFS%E5%AD%A6%E4%B9%A0%E4%BD%BF%E7%94%A8-%E4%B8%80-%E5%AE%89%E8%A3%85/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
timebusker的博客|BY Blog

启动storage时,要先启动tracker,不然无法启动监视

Fastdfs单节点安装包集合

fastdfs 5.11版本对照:Version 5.11对应的fastdfs-nginx-module的Version 1.20 fastdfs 5.10版本对照:Version 5.10对应的fastdfs-nginx-module的Version 1.19

详细操作

FastDFS原理

手把手教你搭建FastDFS集群

FastDFS服务操作

# tracker
service fdfs_trackerd start/restart/stop 

# storage
service fdfs_storaged start/restart/stop 

# nginx
/usr/local/nginx/sbin/nginx (启动)
/usr/local/nginx/sbin/nginx -s reload/stop 

安装fastdfs-nginx-module

nginx默认安装路径:/usr/local/nginx/

需要分别两个nginx实例进行端口转发 : storage nginx 、tracker nginx

FastDFS 通过 Tracker 服务器,将文件放在 Storage 服务器存储,但是同组存储服务器之间需要进入文件复制,有同步延迟的问题。 假Tracker 服务器将文件上传到了 192.168.64.32,上传成功后文件ID已经返回给客户端。此时 FastDFS 存储集群机制会将这个文件同步到同组存储 192.168.64.33, 在文件还没有复制完成的情况下,客户端如果用这个文件 ID 在 192.168.64.33 上取文件,就会出现文件无法访问的错误。而 fastdfs-nginx-module 可以重定向文件连接到源服务器取文件, 避免客户端由于复制延迟导致的文件无法访问错误。

提前Nginx依赖包:

yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel

./configure --user=root --group=root --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/root/fastdfs/fastdfs-nginx-module-master/src/
./configure --user=root --group=root --add-module=/root/fastdfs/fastdfs-nginx-module-master/src/

make && make install

# 拷贝fastdfs-5.11中的、fastdfs-nginx-module中的配置文件到/etc/fdfs/
cp -r fastdfs-5.11/conf/http.conf /etc/fdfs/
cp -r fastdfs-5.11/conf/mime.types /etc/fdfs/
cp -r fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/

# 指定配置文件启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

nginx实例配置信息:

image


#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
	// 该实例直联storage服务端
    server {
	    // 监听storage服务端口响应请求。
	    // listen端口对应到/etc/fdfs/storage.conf中的http.server_port
        listen       8888;
        server_name  localhost;
		// 拦截带有(组名/磁盘名)的URL请求,转发到storage解析实际路径
        location ~/mine/M00 {
            root   /fastdfs/storage-data/data/;
            ngx_fastdfs_module;
        }

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

    // 配置storage服务负载均衡,集群环境下有用
    upstream fdfs_tracker {
             server 127.0.0.1:8888;
    }
	
    server {
	    // 监听tracker服务端口,进行请求转发。
		// listen端口和tracker.conf的http.server_port一致
        listen       8080;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location ~/mine/M00 {
            proxy_pass http://fdfs_tracker;
        }

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

文件操作测试

# 上传文件
/usr/bin/fdfs_upload_file  /etc/fdfs/client.conf 404.png 



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK