FastDFS+Nginx单机部署
admin
2023-03-08 07:22:25
0


一、环境

    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的内容相同。


相关内容

热门资讯

金正恩向俄总统致贺电:平壤始终... 新华社平壤5月9日电(记者王天僚)据朝中社9日报道,朝鲜最高领导人金正恩当天向俄罗斯总统普京致贺电,...
美专家:伊朗扛不住了,或正向波... 据福克斯新闻5月8日报道,卫星图像显示,伊朗主要石油出口枢纽哈尔克岛附近出现大片疑似石油泄漏的浮油带...
黄土塬藏“算力密码”!中国电信... 在陇东黄土塬上,数字浪潮奔涌不息。作为国家 “东数西算” 工程的核心承载地,中国电信庆阳智算产业园正...
科沃斯加入清洁电器行业反虚假测... 【CNMO科技消息】5月8日,科沃斯官方微博宣布,科沃斯加入由中国家用电器协会指导、中国家电网发起成...
东华科技获得发明专利授权:“一... 证券之星消息,根据天眼查APP数据显示东华科技(002140)新获得一项发明专利授权,专利名为“一种...
头部企业扎堆超百场无人机赛事,... 文/陈聆听 2026 年 5 月 4 日,山东诸城,山东天鸟航空负责人丁总与当地多位中小学校长会面,...
重磅签约!华为、中国银联战略合... 快科技5月8日消息,华为和中国银联在深圳正式签约,进一步深化双方的战略合作,还一起发布了自主创新和人...
胡锡进:日本已成中国“头号潜在... 日本高市早苗政府代表了日本政治思维,特别是对华策略最阴暗的一面,这个女人绝对是“政治女巫”级别的。中...
“190元榴莲遭仅退款”商家:... 近日,河南濮阳一冷冻榴莲果肉商家“程大叔”反映,自己遭遇一名买家恶意“仅退款”。为讨回公道,4月28...
新价格项目落地,让医疗真创新更... “让瘫痪的人能动、心衰末期的人能活、万里之外能手术”,这些看似奇迹的变化,背后藏着一个关键支撑—近三...