温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

FastDFS+Nginx单机部署

发布时间:2020-07-11 21:31:10 来源:网络 阅读:1282 作者:Rangers_ 栏目:建站服务器


一、环境

    Ubuntu 18.04.1 LTS

二、资源准备

1.  nginx-1.14.0

2.  FastDFS-5.11

3.  fastdfs-nginx-module

4.  libfastcommon

三、安装

    1.安装libfastcommon

       1>解压libfastcommon

       2>make命令编译

       3>make install命令安装

       4>设置软链接

       ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
       ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
       ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
       ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

    2.安装FastDFS

       1>解压

       2>make命令编译,make install命令安装

       3>将安装到/etc/fdfs/下的三个示例配置文件复制一份,去掉.sample后缀

    3.配置Tracker

       1>在/opt/下建立f_tracker目录

       2>修改2.3>中的tracker.conf文件

           disabled=false#启用配置文件(false为启用)
           port=22122#设置tracker的端口号,通常采用22122这个默认端口
           base_path=/opt/f_tracker#设置tracker的数据文件和日志目录
           http.server_port=6666#设置http端口号,默认为8080

3>为启动脚本创建软引用,因为fdfs_trackerd等命令在/usr/local/bin中并没有,而是在/usr/bin路径下

           ln -s /usr/bin/fdfs_trackerd /usr/local/bin
           ln -s /usr/bin/stop.sh /usr/local/bin
           ln -s /usr/bin/restart.sh /usr/local/bin

4>service fdfs_trackerd start 启动Tracker服务器(通过netstat -unltp|grep fdfs 命令查看tracker服务的监听情况)

    4.配置Storage

       1>在/opt/下建立f_storage和f_storage_data目录

       2>修改2.3>中的storage.conf文件

       disabled=false#启用配置文件(false为启用)
       group_name=group1#组名,根据实际情况修改
       port=23000 #设置storage的端口号,默认是23000,同一个组的storage端口号必须  一致
       base_path=/opt/f_storage#设置storage数据文件和日志目录
       store_path_count=1 #存储路径个数,需要和store_path个数匹配
       store_path0=/opt/f_storage_data #实际文件存储路径
       tracker_server=192.168.43.45:22122 #tracker 服务器的 IP地址和端口号,因为本次是单机搭建,所以此处为本机ip,集群搭建的话即填写tracker服务器所在的ip
       http.server_port=8888#设置 http 端口号

       3>为Storage服务器的启动脚本设置软引用

         ln -s /usr/bin/fdfs_storaged /usr/local/bin

       4>service fdfs_storaged start 命令启动Storage服务器,文件存储路径下会生成多级存储目录即为成功

       5>查看storage是否登记在tracker上。命令/usr/bin/fdfs_monitor /etc/fdfs/storage.conf 有图中Active字样为成功

FastDFS+Nginx单机部署


    5.配置client.conf

       1>修改2.3>中的storage.conf文件

         base_path=/opt/fastdfs_tracker#tracker服务器文件路径
         tracker_server=192.168.43.45:22122#tracker服务器IP地址和端口号
       http.tracker_server_port=6666# tracker 服务器的 http 端口号,必须和tracker的设置对应起来

       2>通过命令上传1.txt

         /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/2.jpg

       3>成功则返回id为group1/M00/00/00/wKgrLVu5nQ6ADqBpAAB92gKP0_o908.jpg

    6.安装Nginx

       1>解压nginx-1.14.0和fastdfs-nginx-module

       2>为nginx添加fastdfs-nginx-module模块。在nginx-1.14.0目录下输入命令./configure --prefix=/usr/share/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --add-module=/home/jobs/fastdfs/moudle1/src

--prefix为安装目录,/home/jobs/fastdfs/moudle1/src为模块所在目录

       3>make命令编译

       4>make install命令安装

       5>我安装时编译一直不通过,弄了大半天也没通过,最后我是先通过apt-get install nginx安装nginx,然后nognx -V命令查看安装信息,得知--prefix=/usr/share/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module,然后在nginx-1.14.0目录下输入命令./configure加以上信息加--add-module=/home/jobs/fastdfs/moudle1/src  最终编译成功。

    7.配置fastdfs-nginx-module模块和nginx

       1>修改/usr/share/nginx/nginx.conf

           server {

        listen       8888;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   html;

            index  index.html index.htm;

        }

    location ~/group1/M00 {

           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;

        #}

    }

       2>进入FastDFS安装包的目录下的conf目录,将http.conf和mime.types拷贝到/etc/fdfs目录下,接下来还需要把fastdfs-nginx-module安装目录中src目录下的mod_fastdfs.conf也拷贝到/etc/fdfs目录下:

       3>mod_fastdfs.conf修改如下配置,其它默认

# 连接超时时间

connect_timeout=10

# Tracker Server

tracker_server=file.ljzsg.com:22122

# StorageServer 默认端口

storage_server_port=23000

# 如果文件ID的uri中包含/group**,则要设置为true

url_have_group_name = true

# Storage 配置的store_path0路径,必须和storage.conf中的一致

store_path0=/opt/f_storage_data

       4>启动Nginx 命令service nginx start,打印出pid信息为成功

       5>浏览器访问http://192.168.43.45:8888/group1/M00/00/00/wKgrLVu5nQ6ADqBpAAB92gKP0_o908.jpg

 FastDFS+Nginx单机部署

 

四、集群安装

    集群安装只需要在每台机器上安装fastdfs和nginx,如果是一台tracker,多台storage,只要在一台机器上配置tracker,其他机器上配置storage和nginx即可。Fastdfs也可以有多台tracker组成,每台tracker地位相同,轮查使用,storage可以按组划分,每个group内的storage的内容相同。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI