Linux + Nginx + FastFDS图片服务器搭载

一、环境准备

  1. libfastcommon
  2. FastDFS
  3. fastdfs-nginx-module
  4. nginx

二、安装libfastcommon工具包以及安装

  1. 下载libevent依赖包:yum install -y libevent;
  2. 进入到一个安装的文件:cd /usr/local
  3. 创建一个存放接下来安装应用的文件夹:mkdir fastdfs
  4. 下载libfastcommon:wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
  5. 解压文件:tar -zxvf libfastcommon-1.0.7.tar.gz
  6. 进入解压文件夹编译安装:执行./make.sh 后执行./make.sh install
  7. 设置软连接:
  8. ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
  9. ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
  10. ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
  11. ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

三、安装配置Tracker(跟踪器)服务

  1. 下载安装包:wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
  2. 解压安装包:tar -zxvf FastDFS_v5.05.tar.gz
  3. 进入解压目录,执行./make.sh后执行./make.sh install
  4. 修改配置文件,复制配置文件:cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf后使用vim /etc/fdfs/tracker.conf修改配置文件。并且创建一个文件夹用于存放文件以及日志,mkdir -p /../...
  5. 启动服务:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf 
  6. 重启服务:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

四、配置Storage服务

  1. 复制配置文件,并且修改步骤类似配置stracker服务:cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf,使用vim /etc/fdfs/storage.conf修改配置文件,创建一个存放文件以及日志的文件夹以及上传文件所在的目录,但是我在上传文件的时候并没有保存在store_path所在目录,而是存在于base_path所在的目录
  2. 启动服务:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
  3. 重启服务:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

五、测试文件上传

1.类似以上配置tracker操作,复制文件并且修改配置文件,路径/etc/fdfs/client.conf,这里简略说明。

进入到照片所在的文件夹 ,执行命令:/usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg

上传成功

七、安装配置Nginx

1.解压fastdfs-nginx-module安装包,修改配置文件

2.重新编译nginx,其中add-module设置fastdfs-nginx-module解压包的位置

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/root/fastdfs-nginx-module/src

3.编译make,安装make install:

4.修改nginx.conf配置文件,路径在nginx安装路径的conf文件内。其中alias设置为你图片所在的文件夹路径,location设置的路径是图片访问的路径。

server {
        listen       80;
        server_name  localhost;

	location /group1/M00{
		alias /data/fastdfs/storage/data-and-log/data;
		index  index.html index.htm;
		autoindex on;

	}

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

5.进入nginx的sbin文件夹,启动nginx:./nginx  重启nginx:./nginx -s reload 。停止nginx:./nginx -s stop

六、参考资料

https://www.jianshu.com/p/b56e84912825

https://blog.csdn.net/Code_shadow/article/details/80814383

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值