【FastDFS】图片服务器的搭建

使用一台虚拟机来模拟,只有一个Tracker、一个Storage服务,配置nginx访问图片。

一、安装依赖包:libevent等依赖包

yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget

二、软件下载

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz

三、安装libfastcommon-1.0.7

  •     解压缩:tar -zxvf V1.0.7.tar.gz
  •     cd libfastcommon-1.0.7
  •     ./make.sh
  •     ./make.sh install

四、安装Tracker服务

  •     解压缩:tar -zxvf V5.05.tar.gz
  •     cd fastdfs-5.05
  •     ./make.sh
  •     ./make.sh install

    安装之后会在/usr/bin目录下看到fdfs开头的文件

   

创建文件夹:

  •     mkdir -p /data/fdfs/
  •     mkdir -p /data/nginx
  •     mkdir -p /data/nginx/logs

拷贝配置文件:

  •     cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
  •     cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
  •     cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

配置tracker服务:

    修改/etc/fdfs/tracker.conf文件:    vi /etc/fdfs/tracker.conf

    修改内容:

  •        日志文件路径为/data/fdfs
  •        执行权限:root

            base_path=/data/fdfs

            run_by_group=root

           run_by_user=root

启动tracker:

  •     /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

    可以查看是否启动: ps aux|grep tracker

五、安装storage服务

配置storage服务:

    修改/etc/fdfs/storage.conf文件:vi /etc/fdfs/storage.conf

    修改内容:

  •         组名
  •         执行权限
  •         日志文件存储路径
  •         tracker服务器地址
  •         存储文件路径

        group_name=group1

       run_by_group=root

       run_by_user=root

       base_path=/data/fdfs

       tracker_server=192.168.25.62:22122

       store_path0=/data/fdfs

启动storage:

  •     /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start

       可以查看是否启动: ps aux|grep storage

六、配置storage测试

 修改配置文件/etc/fdfs/client.conf文件:vi /etc/fdfs/client.conf

   修改内容:

  •         日志文件存储路径
  •         tracker服务器地址        

             base_path=/data/fdfs

            tracker_server=192.168.25.62:22122

本地测试上传

        首先在/etc/fdfs下放上tupian.jpg这张图片

        上传图片:

  •         /usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/tupian.jpg

   

七、搭建nginx_openresty

 解压fastdfs-nginx-module_v1.16.tar.gz

    修改/root/fastdfs-nginx-module/src/config文件,把其中的local去掉(总共有3个)

   

安装nginx_openresty包:

 

  •         yum install pcre-devel openssl openssl-devel(安装编译环境)
  •         解压:tar -zxvf ngx_openresty-1.7.10.1.tar.gz
  •        cd ngx_openresty-1.7.10.1
  • ./configure --with-luajit --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=../fastdfs-nginx-module/src
  •         gmake
  •         gmake install

       说明:

                  --with***                安装一些内置/集成的模块

                  --with-http_realip_module  取用户真实ip模块

                  -with-pcre               Perl兼容的达式模块

                  --with-luajit              集成luajit模块

                  --add-module            添加自定义的第三方模块,如此次的fastdfs-nginx-module

 配置mode_fastdfs.conf

         将mode_fastdfs.conf复制到/etc/fdfs目录下

  •                cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

编辑配置文件

  •         vim /etc/fdfs/mod_fastdfs.conf

        修改内容:这里注意要将[group1]下面的内容解放

                             

复制http.conf和mime.types文件到/etc/fdfd/

  •             cd /root/fastdfs-5.05/conf
  •             cp http.conf mime.types /etc/fdfs/

编辑配置文件:

  •      vi /usr/local/openresty/nginx/conf/nginx.conf
#user  nobody;
user root;
worker_processes  1;

error_log logs/error.log;

events {
    worker_connections  1024;
}

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  data/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        charset utf8;

        #access_log  logs/host.access.log  main;

        location /group1/M00 {
            alias   /data/fdfs/data;
            ngx_fastdfs_module;
        }

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

     }     
    }

启动:

  •         /usr/local/openresty/nginx/sbin/nginx

八、配置FastDFS开机自启

  开机启动需要启动fastdfs和nginx,在centos中,在/etc/rc.local文件中,就是配置开机启动项的,我们在这个文件中添加下面的配置:

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/usr/local/openresty/nginx/sbin/nginx

这次在浏览器的地址栏中输入一下网址,就可以看到我们上传的图片了

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值