Centos7安装FASTDFS整合宝塔Nginx,配合nginx-fastdfs插件,实现文件上传

安装fastdfs需要的环境

首先安装gcc

yum -y install gcc-c++

然后安装libevent库

yum -y install libvent

安装libfastcommon

libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库。先解压安装包

tar -zxvf libfastcommonV1.0.7.tar.gz

进入文件夹

cd libfastcommon-1.0.7

运行

./make.sh
./make.sh install

注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录,所以需要将/usr/lib64下的库文件拷贝至/usr/lib下。

cp /usr/lib64/libfastcommon.so /usr/lib

查看是否拷贝成功

find /usr/lib -name libfastcommon.so

安装FASTDFS

解压安装包

tar -zxf FastDFS_v5.0.5.tar.gz 

然后在FastDFS中运行

./make.sh
./make.sh install

安装成功将安装目录下的conf文件拷贝到/etc/fdfs/下。

cp * /etc/fdfs/

安装tracker服务

修改conf文件

vim /etc/fdfs/tracker.conf

其中base_path改为/usr/local/myapps/fastdfs/FastDFS/tracker

启动tracker

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

安装storage服务

修改conf文件

vim /etc/fdfs/storage.conf

其中base_path改为/usr/local/myapps/fastdfs/FastDFS/storage

store_path0改为/usr/local/myapps/fastdfs/FastDFS/storage

其中tracker_server改为[服务器外网地址]:22122

启动storage

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

此时出现问题,一直没反应,等半天,去看日志有什么问题,发现报错超时,此处若无报错可跳过。

ERROR - file: storage_ip_changed_dealer.c, line: 180, connect to tracker server xxxxxx:22122 fail, errno: 110, error info: Connection timed out

解决方法:
打开防火墙22122端口及云服务器22122端口即可,cento7打开防火墙端口如下

firewall-cmd --zone=public --add-port=22122/tcp --permanent

重启防火墙

systemctl restart firewalld.service

ps:连接超时可以检查防火墙及云服务器安全组。

此时在storge里面的logs文件夹

cp ../../client/libfdfsclient.so /usr/lib

修改配置文件

vim /etc/fdfs/client.conf

其中base_path改为/usr/local/myapps/fastdfs/FastDFS/client

tracker_server改为[服务器外网地址]:22122

测试
新建root目录下一个hi.html文件,随便输点东西

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/hi.html

目前无法访问,FASTDFS需要nginx提供http服务
在这里插入图片描述

安装nginx-fastdfs插件

解压后,在src目录下修改config文件,全局替换local为空

:%s/local\///g

移动文件

cp mod_fastdfs.conf /etc/fdfs/

修改配置文件

vim /etc/fdfs/mod_fastdfs.conf

tracker_server改为[服务器外网地址]:22122

url_have_group_name=true

其中store_path0改为/usr/local/myapps/fastdfs/FastDFS/storage

安装并配置Nginx

可以采用宝塔安装Nginx。
但是注意用宝塔必须编译安装才有src目录,不能极速安装,重新编译安装即可出现src目录。

首先查看之前的安装设置项:

/www/server/nginx/sbin/nginx -v

结果:
configure arguments: --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module

记录configure arguments:后的配置项。然后切换到宝塔nginx安装目录

cd /www/server/nginx/src

输入下列命令(将前面的配置项后面加上-module=/usr/local/myapps/fastdfs/fastdfs-nginx-module/src):

./configure --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module --add-module=/usr/local/myapps/fastdfs/fastdfs-nginx-module/src

然后依次输入:

make
make install

此时发现/www/server/nginx/sbin/目录多了一个nginx.odd文件

重启

/www/server/nginx/sbin/nginx -s stop    #这是停止
/www/server/nginx/sbin/nginx            #这是启动

然后在/www/server/nginx/sbin/nginx目录下

./nginx

结果出现报错,未报错可跳过:

ngx_http_fastdfs_set pid=32496
nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:888 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] still could not bind()

然后查找占用888,443,80端口进程的pid号

lsof -i:[端口号]

杀死端口

kill -9 [端口号]

重新运行

./nginx

查看nginx进程

ps -aux |grep nginx

修改nginx配置:

vim /www/server/nginx/conf/nginx.conf

在server中添加:

location /group1/M00 {
    root /usr/local/myapps/fastdfs/FastDFS/storage/data;
    ngx_fastdfs_module; 
}

测试,新建hi.html,随便写点东西

vim /root/hi.html

上传文件

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/hi.html

然后访问网址,此时注意加端口号进行访问。

http://[服务器外网地址]:[端口号例如888]/group1/M00/00/00/rBbXeGC02HiAXjmRAAAACuoLQFc87.html

成功访问!
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值