Fastdfs安装
下载 FastDFS_v5.05.tar.gz、fastdfs-nginx-module_v1.16.tar.gz、libfastcommonV1.0.7.tar.gz以及nginx-1.12.1.tar.gz(注意FastDFS的版本和fastdfs-nginx-module的版本兼容问题,fastdfs-nginx-module v1.2x以上需要FastDFS v6.0以上)
安装tracker
(1)安装gcc
yum install gcc-c++
(2)安装libevent
yum -y install libevent
(3)安装libfastcommon
将libfastcommonV1.0.7.tar.gz拷贝至/usr/local/下
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install
注意如果./make.sh失败,报perl未找到,执行下方的方法。
yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl
openssl-devel libevent libevent-devel perl unzip net-tools wget
(4)将/usr/lib64下的库文件libfastcommon.so拷贝至/usr/lib下
(5)将FastDFS_v5.05.tar.gz拷贝至/usr/local/下
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
安装成功将安装目录下的conf下的文件拷贝到/etc/fdfs/下。
client,http,mime,storage,storage_ids,tracker
(6)安装成功后进入/etc/fdfs目录:
拷贝一份新的tracker配置文件:
cp tracker.conf.sample tracker.conf
修改tracker.conf
vi tracker.conf
base_path=/home/yuqing/FastDFS
改为:
base_path=/home/FastDFS
(7)启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
(8)设置开机自动启动
vim /etc/rc.d/rc.local
将运行命令行添加进文件:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
安装 Storage
(0)如果在一台服务器上,之前的tracker,libevent,libfastcommon
解压 fastdfs,这些步骤可以不用进行,如果两台的话,需要进行。
(1)安装成功后进入/etc/fdfs目录
拷贝一份新的storage配置文件:
cp storage.conf.sample storage.conf
(2)修改storage.conf
vi storage.conf
group_name=group1
base_path=/home/yuqing/FastDFS改为:base_path=/home/FastDFS
store_path0=/home/yuqing/FastDFS改为:store_path0=/home/FastDFS/fdfs_storage
/#如果有多个挂载磁盘则定义多个store_path,如下
/#store_path1=.....
/#store_path2=......tracker_server=xxx.xxx.xxx.xxx:20799 #配置tracker服务器:IP
/#如果有多个则配置多个tracker
tracker_server=xxx.xxx.xxx.xxx:20799
上面的地址写你自己的详细地址。
(3)启动
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
(4)设置开机启动
vim /etc/rc.d/rc.local
将运行命令行添加进文件
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
上传测试
修改/etc/fdfs/client.conf
base_path=/home/fastdfs
tracker_server=xxx.xxx.xxx.xxx:20799
使用格式:
/usr/bin/fdfs_test 客户端配置文件地址 upload 上传文件
比如将/home下的图片上传到FastDFS中:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/1.png
下载配置nginx
fastdfs从4.0版本后就取消http协议的监听,需要配置nginx
解压nginx和fastdfs-nginx-module
进入fastdfs-nginx-module解压目录
vi src/mod_fastdfs.conf
配置fastdfs相关配置
base_path=/home/FastDFS/fdfs_storage
tracker_server=xxx.xxx.xxx.xxx:20799
group_name=group1
url_have_group_name = true
修改fsatdfs的安装路径
vi src/config
修改CORE_INCS参数
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
主要是看看fastdfs的文件在/usr/local/include还是在/usr/include
进入nginx解压目录,执行
./configure --prefix=/home/xx/nginx-1.12.1/nginx-fast --conf-path=/home/xx/nginx-1.12.1/nginx-fast/nginx.conf --add-module=/home/xx/fastdfs-nginx-module/src
make
make install
vi /home/xx/nginx-1.12.1/nginx-fast/nginx.conf
添加以下配置
server {
listen 30080;
server_name xxx.xxx.xxx.xxx;
location / {
root html;
index index.html index.htm;
}
location /group1/M00 {
root /home/FastDFS/fdfs_storage/data;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
启动nginx
./sbin/nginx -p /usr/local/nginx/ -c /usr/local/nginx/nginx.conf
访问浏览器
http://xxx.xxx.xxx.xxx:30080/group1/M00/00/00/wKgB8F5wnw-AHhryAAAQslDi-iU002.png
显示刚刚测试上传的图片