在集群环境下,图片存放在本地存在诸多限制,一般采用单独的图片服务器进行管理。FastDFS就是这样一个图片管理服务器。
环境需求,CentOS7下
一.先下载三件套,并上传到服务器中(Nginx自行下载),地址如下
1:libfastcommon https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
2:fastdfs https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
3:fastdfs-nginx-module http://jaist.dl.sourceforge.NET/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
二.安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++
三.安装FastDFS之前,先安装libevent工具包。yum -y install libevent
四.安装libfastcommonV1.0.7工具包。
1、解压缩
2、./make.sh //先编译
3、./make.sh install
五.安装tracker和storage(如果正式开发环境一般是安装在多台服务器上,需要多次重新安装)
1、解压缩
2、./make.sh
3、./make.sh install。安装后在/usr/bin/目录下有以fdfs开头的文件都是编译出来的。配置文件都放到/etc/fdfs文件夹
4、把/root/FastDFS/conf目录下的所有的配置文件都复制到/etc/fdfs下。
5、配置tracker服务。修改/root/FastDFS/conf/tracker.conf文件。
base_path=/home/fastdfs/tracker
6、配置storage服务。修改/root/FastDFS/conf/storage.conf文件。
base_path=/home/fastdfs/storage
store_path0=/home/fastdfs/storage
tracker_server=192.168.10.134:22122
7、配置client服务。修改/root/FastDFS/conf/client.conf文件。
base_path=/home/fastdfs/client
8、测试是否成功
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/anti-steal.jpg
如果正常输出路径如:example file url: http://192.168.10.134/group1/M00/00/00/wKgKhlmVwZSAZYk5AABdrZgsqUU888_big.jpg
则表示配置成功!
六.安装nginx并添加fastdfs模块插件
可以使用官方提供的nginx插件。要使用nginx插件需要重新编译。fastdfs-nginx-module_v1.16.tar.gz
1、解压插件压缩包
修改/root/fastdfs-nginx-module/src/config文件,把其中的local去掉
2 .先在centOS上配置好对应的依赖关系,免得麻烦
yum install gcc-c++(之前装过的可以省略)
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel、
3.对nginx重新config
./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
4.make install.
5.把/root/fastdfs-nginx-module/src/mod_fastdfs.conf文件复制到/etc/fdfs目录下。编辑:、
load_fdfs_parameters_from_tracker=true
tracker_server=192.168.10.134:22122
url_have_group_name = true
store_path0=/home/fastdfs/storage
6.安装完成后在var文件夹下新建temp/nginx文件夹。不然无法启动nginx。
7.配置nginx的配置文件,在/usr/local/nginx/conf下的nginx.conf文件,在底部新增一个server
server {
listen 80;
server_name 192.168.10.134;
location /group1/M00/{
ngx_fastdfs_module;
}
}
8.启动nginx并测试上次文件,记下文件路径名
访问路径:http://192.168.10.134/group1/M00/00/00/wKgKhlmVwZSAZYk5AABdrZgsqUU888_big.jpg
能正常显示表示配置一切正常!
其中centOS7默认是不打开80端口的,这点很坑,需要自行打开
firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl stop firewalld.service
systemctl start firewalld.service