一 1.下载FastDFS搭建所需安装包
libfastcommon安装包:
wget https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.43
fastdfs安装包:
wget https://codeload.github.com/happyfish100/fastdfs/tar.gz/V6.06
fastdfs-nginx-module安装包:
wget https://codeload.github.com/happyfish100/fastdfs-nginx-module/tar.gz/V1.2
nginx安装包:
wget http://nginx.org/download/nginx-1.9.9.tar.gz
2.安装依赖和插件
yum -y install gcc-c++
yum -y install libevent
yum install -y pcre pcre-devel # pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库
yum -y install zlib zlib-devel # zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装
yum -y install openssl open-devel #openssl是web安全通信的基石
二 、安装(按照顺序安装)
1.解压缩安装libfastcommon
# 进入下载安装包路径解压缩,编译安装
cd /usr/local/FastDFS #我这里下载路径是到/usr/local/FastDFS下
tar -zxvf libfastcommon.tar.gz
./make.sh //编译
./make.sh install //安装
# 因为编译安装的路劲在usr/local下,所以需要确保libfastcommon.so文件在/usr/lib目录下
################################################################
2.解压缩安装fastdfs
cd /usr/local/FastDFS
tar -zxvf fastdfs-6.06
./make.sh
./make.sh install
2.1
# 进入/etc/fdfs目录,修改tracker.conf文件
vim tracker.conf
找到base_path
base_path=这里是存储路径自己自定义 我的是/usr/local/FastDFS/fastdfs-6.06/tracker
Esc :wq 退出保存
# 启动tracker跟踪器
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
2.2
# 进入/etc/fdfs目录,修改storage.conf文件
cd /etc/fdfs
vim storage.conf
找到base_path
base_path=这里是存储路径自己自定义 我的是/opt/fastdfs/storage
找到base_path0
store_path0=这里是默认的存储路径自己自定义 我的是/opt/fastdfs/storage
找到tracker_server
tracker_server=你的服务器的ip:22122
Esc :wq 退出保存
# 启动storage存储器
/etc/init.d/fdfs_storaged start #/usr/bin/fdfs_storaged /etc/fdfs/tracker.conf (配置文件启动)
2.3
# 进入/etc/fdfs目录,修改client.conf文件
cd /etc/fdfs
vim client.conf
找到base_path
base_path=这里是存储路径自己自定义 我的是/usr/local/FastDFS/fastdfs-6.06/client
找到tracker_server
tracker_server=你的服务器的ip:22122
Esc :wq 退出保存
####################################################################
3.安装fastdfs-nginx-module插件
cd /usr/local/FastDFS
tar -zxvf fastdfs-nginx-module.tar.gz
# 进入解压目录修改配置文件
cd fastdfs-nginx-module/src
vim config
#修改以下配置内容
ngx_addon_name=ngx_http_fastdfs_module
if test -n "${ngx_module_link}"; then
ngx_module_type=HTTP
ngx_module_name=$ngx_addon_name
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
ngx_module_libs="-lfastcommon -lfdfsclient"
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
ngx_module_deps=
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='2561024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"'"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='2561024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"'"
fi
3.1
配置nginx,添加fastdfs-nginx-module模块
### 如果已经安装nginx,先停掉nginx服务 则使用 # /usr/local/nginx/sbin/nginx -s stop#####
cd /usr/local/FastDFS
tar -zxvf nginx-1.9.9.tar.gz
cd /usr/local/FastDFS/nginx-1.9.9
配置了ssl的配置方法:./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/fastdfs/fastdfs-nginx-module-1.22/src(后面路径是你的插件安装地址)
没有配置ssl的配置方法:./configure --add-module=/usr/local/fastdfs/fastdfs-nginx-module-1.22/src(后面路径是你的插件安装地址)
make //编译
make install
cp ./objs/nginx /usr/local/nginx/sbin 如果之前安装过nginx 把编译后的nginx替换你安装的nginx
# 验证是否加载fastdfs-nginx-module模块是否成功
/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.9.9
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --add-module=/usr/local/FastDFS/fastdfs-nginx-module-1.22/src
3.2
# 修改配置文件并复制/usr/local/FastDFS/fastdfs-nginx-module-1.22/src中的配置文件 mod_fastdfs.conf到/etc/fdfs
vim /usr/local/FastDFS/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf
连接超时时间
connect_timeout=10
Tracker Server
tracker_server=172.16.137.187:22122
StorageServer 默认端口
storage_server_port=23000
如果文件ID的uri中包含/group**,则要设置为true
#url_have_group_name = true
Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0=/opt/fastdfs/storage
esc:wq
cp /usr/local/FastDFS/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs
# 复制部分FastDFS的部分文件到/etc/fdfs目录
cd /usr/local/FastDFS/fastdfs-6.06/conf
cp anti-steal.jpg http.conf mime.types /etc/fdfs/
3.3
# 配置nginx,修改nginx.conf
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80 ;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~/group[0-9]/M00/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
最后启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf