一、需要的软件包
源码包存放路径: /usr/local/src
- zlib-1.2.8.tar.gz
- pcre-8.34.tar.gz
- openssl-1.0.2g.tar.gz
- ngx_cache_purge-2.3.tar.gz
- nginx-1.8.0.tar.gz
- libfastcommon-1.0.35.tar.gz
- fastdfs-nginx-module_v1.16.tar.gz
- fastdfs-5.09.tar.gz
由于需要编译源码包,需提前安装 pcre-devel gcc* perl-devel
二、安装
1、安装libfastcommon
解压缩libfastcommon-1.0.35.tar.gz:
tar zxf libfastcommon-1.0.35.tar.gz -C /usr/local/
cd /usr/local/libfastcommon-1.0.35/
./make.sh
./make.sh install
2、解压缩fastDFS源码包并安装
(1) 安装
tar zxf fastdfs-5.09.tar.gz -C /usr/local/
cd /usr/local/fastdfs-5.09
./make.sh
./make.sh install
(2)创建存放数据目录
mkdir -pv /data/tracker
mkdir -pv /data/storage
mkdir -pv /data/client
(3)复制配置文件
cd /etc/fdfs/
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
cp client.conf.sample client.conf
(4)修改tracker配置
vim tracker.conf
===============
base_path=/data/tracker
connect_timeout=60
===============
(5)修改storage配置
vim storage.conf
===============
base_path=/data/storage
store_path0=/data/storage
tracker_server=95.169.16.55:22122 #这里填写tracker_server的ip,就是刚才tracker配置文件所在的ip,我的是本机,但是这里不要写127.0.0.1最好写本机内网ip,多个的话就写多个tracker_server
#tracker_server=95.169.16.55:22122 #多个就在写个tracker_server
===============
(6)修改client配置
vim client.conf
==============
base_path=/data/client
tracker_server=95.169.16.55:22122
#tracker_server=192.168.58.132:22122 #如果有多个的话就在写个tracker_server
==============
(7)启动fastdfs服务
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart 先启动tracker服务
netstat -ntpl | grep 22122 查看进程是否存在
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart 启动storaged服务
netstat -ntpl | grep 23000 查看进程是否存在
(8)测试下fastdfs能否正常使用
echo 'this is test' > ~/test.txt 我们写个测试文件
fdfs_upload_file /etc/fdfs/client.conf ~/test.txt #上传这个文本
======================================
group1/M00/00/00/wKg6g1twLQyAQyfKAAAADbk5jjo236.txt #这个是成功后的fastdfs存储路径
=====================================
我们测试下载下这个txt
fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKg6g1twLQyAQyfKAAAADbk5jjo236.txt
成功时,在/data路径下可以看见这个文件
(9)查看集群信息
fdfs_monitor /etc/fdfs/client.conf #这条命令是查询你的fdfs的信息的
在安装完成后查看/usr/bin/目录会多出以fdfs开头的文件
配置文件默认在/etc/fdfs下; 默认脚本在/etc/init.d下
3、安装Nginx的fastdfs模块
(1)Nginx的fastdfs模块安装前准备
tar zxf fastdfs-nginx-module_v1.16.tar.gz #解压缩nginx的fastdfs模块
cd /usr/local/src/fastdfs-nginx-module/src #进入到安装源码包里的src目录
vim config #修改如下配置(把里面的所有/usr/local/改为/usr/)
====================
修改前:
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs
/usr/local/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
修改为:
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
====================
cp mod_fastdfs.conf /etc/fdfs/ #复制模块文件到/etc/fdfs配置文件目录中
cp /usr/local/fastdfs-5.09/conf/http.conf /etc/fdfs/
#将fastDFS源码包里的conf目录下的这个文件复制到/etc/fdfs下
cp /usr/local/fastdfs-5.09/conf/mime.types /etc/fdfs/
#将fastDFS源码包里的conf目录下的这个文件复制到/etc/fdfs下
(2)安装Nginx并添加fastdfs模块
tar zxf ngx_cache_purge-2.3.tar.gz #解压缩nginx的缓存模块
========安装pcre========
tar zxf pcre-8.34.tar.gz
cd pcre-8.34
./configure && make && make install
========安装openssl======
tar zxf openssl-1.0.2g.tar.gz
cd openssl-1.0.2g
./config --prefix=/usr/local/openssl
make && make install
========安装zlib========
tar zxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure && make && make install
========安装nginx========
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --with-openssl=../openssl-1.0.2g --with-pcre=../pcre-8.34 --with-zlib=../zlib-1.2.8 --add-module=../ngx_cache_purge-2.3 --with-http_ssl_module --with-http_stub_status_module --add-module=../fastdfs-nginx-module/src/
make
make install
(3)修改mod_fastdfs.conf配置文件
vim /etc/fdfs/mod_fastdfs.conf
========================
base_path=/data/storage
tracker_server=95.169.16.55:22122
输入tracker的ip,就是本机ip
#tracker_server=192.168.58.132:22122
store_path0=/data/storage
url_have_group_name = true
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/storage
========================
(4)杀掉fdfs的进程并重启服务
ps -ef | grep fdfs | grep -v grep | awk '{print $2}' | xargs kill -9 杀掉进程
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart 一定要先启动track
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart 然后再启动 storaged
ps -ef | grep fdfs 查看进程是否存在
日志存放路径:
/data/tracker/logs/ 存放tracker服务的日志
/data/storage/logs/ 存放storage服务的日志
(5)配置nginx的nginx.conf文件
vim /usr/local/nginx/conf/nginx.conf
===========================
user root;
worker_processes 1;
worker_rlimit_nofile 65535;
events {
worker_connections 65536;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
limit_conn_zone $binary_remote_addr zone=one:15m;
limit_req_zone $binary_remote_addr zone=two:10m rate=10r/s;
client_body_timeout 100;
client_max_body_size 20m;
client_header_buffer_size 32k;
large_client_header_buffers 4 128k;
server_names_hash_bucket_size 128;
open_file_cache max=102400 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
tcp_nopush on;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
keepalive_timeout 120;
server {
listen 80;
server_name 95.169.16.55;
#charset koi8-r;
access_log logs/access.log main;
error_log logs/err.log
location /group1/M00 {
ngx_fastdfs_module;
}
}
}
(6)创建超链接并启动nginx
ln -s /data/storage/data/ /data/storage/data/M00
启动Nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
(7)添加开机启动
vim /etc/rc.local
==================
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
===================
(8)测试nginx是否正常
fdfs_test /etc/fdfs/client.conf upload ~/test.txt
上传成功后会返回http路径地址 example file url
http://10.10.20.3/group1/M00/00/00/CgoUA1wYYsuAKRMKAAAADbk5jjo971_big.txt
浏览器可以访问