- libfastcommonV1.0.7.tar.gz
- FastDFS_v5.05.tar.gz
- nginx-1.8.0.tar.gz
- fastdfs-nginx-module_v1.16.tar.gz
说明: FastDFS 5.05版本不再依赖libevent,而依赖于libfastcommon,因此在安装FastDFS前需要先安装libfastcommon。
安装环境为VMware安装的CentOS7虚拟机,并提前安装好编译器和一些依赖的软件.
1. gcc编译器 # yum -y install gcc gcc-c++
2. 解压缩软件
# yum -y install unzip zip
3. wget
# yum -y install wget
4. perl
# wget http://www.cpan.org/src/5.0/perl-5.20.2.tar.gz
# tar zxvf perl-5.20.2.tar.gz
# mkdir /usr/local/perl
# ./Configure -des -Dprefix=/usr/local/perl -Dusethreads -Uversiononly
# make
# make install
# perl -version
# other
# yum -y install pcre-devel openssl openssl-devel
# tar -zxvf libfastcommonV1.0.7.tar.gz # cd libfastcommonV1.0.7 # ./make.sh # ./make.sh installlibfastcommon.so 默认安装到了/usr/lib64/libfastcommon.so,而FastDFS主程序设置的lib目录是/usr/local/lib,因此需要设置软链接(如果已存在,可以忽略)
# 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
# tar -zxvf FastDFS_v5.05.tar.gz
# cd FastDFS
# ./make.sh
# ./make.sh install
安装完成后/etc/fdfs目录下生成了3个文件:
- client.conf.sample
- storage.conf.sample
- tracker.conf.sample
# mkdir /opt/fastdfs/tracker# 创建tracker的数据文件和日志存储目录
# cd /etc/fdfs
# cp tracker.conf.sample tracker.conf
# vi tracker.conf
修改如下配置:
base_path=/opt/fastdfs/tracker#设置tracker的数据文件和日志目录
http.server_port=9090
启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
启动过程会在/opt/fastdfs/tracker目录下生成data和logs两个目录
启动完成后查看tracker是否启动成功:
1> netstat -unltp|grep fdfs#查看22122端口监听情况
2> tail -100f /opt/fastdfs/tracker/logs/trackerd.log # 查看启动日志,看是否报错
如果启动没有问题,将tracker添加到开机启动项
1>vi /etc/rc.d/rc.local
2> 添加/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
# mkdir /opt/fastdfs/storage
# cd /etc/fdfs
# mv storage.conf.sample storage.conf
# vi storage.conf
修改如下配置:
group_name=group1#组名
base_path=/opt/fastdfs/storage#设置storage数据和日志目录,需预先创建
store_path_count=1#存储路径个数,需要和 store_path 个数匹配、
store_path0=/opt/fastdfs/storage#存储路径
tracker_server=192.168.234.128:22122#tracker服务器的IP地址和端口号(单机搭建时,IP不能写127.0.0.1,否则启动失败)
http.server_port=8888#设置 http 端口号
启动storage:
usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
启动后会在/opt/fastdfs/storage目录下生成data目录,里面生成有两级目录
查看storage是否启动成功:
1> netstat -unltp|grep fdfs# 查看端口23000是否被监听
2> tail -100f /opt/fastdfs/storage/logs/storage.log# 查看启动日志
启动成功后,可以运行fdfs_monitor查看storage服务器是否已经登记到 tracker服务器
# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
看到"ipaddr = 192.168.234.128 ACTIVE"即可确认storage正常启动
把storage添加到开机启动项:
1>vi /etc/rc.d/rc.local
2> 添加/usr/bin/fdfs_storage /etc/fdfs/storage.conf restart
安装nginx主要目的是为了提供http的访问服务,同时解决group中storage服务器的同步延迟问题
nginx需要添加fastdfs-nginx-module模块
# tar -zxvf nginx-1.8.0.tar.gz
# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
# cd nginx-1.8.0
# ./configure --prefix=/usr/local/nginx --add-module=/opt/dev/fastdfs-nginx-module/src
# make
# make install
make前需要执行以下操作:
进入fastdfs-nginx-module/src目录,编辑config文件,找到包含CORE_INCS的这一行,把其中的local全部去掉,变为
CORE_INCS="$CORE_INCS/usr/include/fastdfs /usr/include/fastcommon/"
进入/usr/local/nginx目录,修改nginx.conf配置文件:
upstream fdfs_group1 {
server 127.0.0.1:9999;
}
在server下添加如下配置:
location ~/group[1-3]/M00 {
root /opt/fastdfs/storage/data;
ngx_fastdfs_module;
}
location /group1/M00 {
proxy_pass http://fdfs_group1;
}
修改FastDFS配置文件:
# cp /opt/dev/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
# cp /opt/dev/FastDFS/conf/mime.types /etc/fdfs/
# cp /opt/dev/soft/FastDFS/conf/http.conf /etc/fdfs/
# cp /opt/dev/FastDFS/conf/anti-steal.jpg /etc/fdfs/
修改/etc/fdfs/mod_fastdfs.conf配置:
base_path=/opt/fastdfs/storage # 保存日志目录 tracker_server=192.168.116.145:22122 # tracker服务器的IP地址以及端口号 url_have_group_name=true # 文件url中是否有group名 store_path0=/opt/fastdfs/storage # 存储路径 http.need_find_content_type=true # 从文件扩展名查找文件类型 (nginxs为true) group_count = 3 # 设置组的个数,事实上这次只使用了group1 在文件末添加如下内容: [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/opt/fastdfs/storage [group2] group_name=group2 storage_server_port=23000 store_path_count=1 store_path0=/opt/fastdfs/storage [group3] group_name=group3 storage_server_port=23000 store_path_count=1 store_path0=/opt/fastdfs/storage
http.need_find_content_type=true # 根据文件扩展名查找文件类型(nginx时为true)
建立M00至存储目录的软连接:
# ln -s /opt/fastdfs/storage/data /opt/fastdfs/storage/data/M00
启动nginx:
# /data/nginx/sbin/nginx
# cd /etc/fdfs/
# cp client.conf.sample client.conf
修改如下:
base_path=/opt/fastdfs/storage
tracker_server=192.168.234.128:22122# tracker服务器IP和端口号
http.tracker_server_port=9090# tracker服务器的http端口号,必须和tracker的设置对应起来
# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /opt/dev/xxx.jpg
返回 group1/M00/00/00/wKjqgFou0tGALOlbABwUdloTHZw999.jpg文件id
通过浏览器访问192.168.234.128/group1/M00/00/00/wKjqgFou0tGALOlbABwUdloTHZw999.jpg可以查看到图片