1.先安装 libfastcommon
##download libfastcommon source package and install it
tar xzf libfastcommon_v1.23.tar.gz
cd libfastcommon
./make.sh
./make.sh install
2.安装 fastdfs
##download FastDFS source package and unpack it
tar xzf FastDFS_v5.08.tar.gz
cd FastDFS
./make.sh
./make.sh install
## 修改配置文件,安装后配置文件在 /etc/fdfs 目录下,重点修改以下参数:
base_path=/homr/fdfs/storage #日志存放路径
tracker_server=xxx:22122 #tracker服务器IP地址和端口号(不能是127.0.0.1)
http.tracker_server_port=8080 #tracker服务器的http端口号
## 启动 tracker server:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
## or
service fdfs_trackerd restart
## 启动 the storage server:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
## or
service fdfs_storaged restart
##可添加成开机启动
echo "/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart" >> /etc/rc.local
echo "/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart" >> /etc/rc.local
## 客户端测试:
/usr/bin/fdfs_test <client_conf_filename> <operation>
##for example, upload a file:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/vfsroot/sherlocky.jpg
## 监控程序:
/usr/bin/fdfs_monitor <client_conf_filename>
3.安装 fastdfs-nginx-module
##step 1. first install the FastDFS storage server and client library, the FastDFS version should >= 2.09.
##step 2. FastDFS nginx module test passed with nginx 0.8.53,
my nginx installed in /opt/nginx
##step 3. download FastDFS nginx module source package and unpack it
tar xzf fastdfs_nginx_module_v1.16.tar.gz
cd nginx-1.12.0
./configure --prefix=/opt/nginx --add-module=/opt/fastdfs/fastdfs-nginx-module-master/src/
make && make install
Notice:
before compile, you can change FDFS_OUTPUT_CHUNK_SIZE
and
FDFS_MOD_CONF_FILENAME
macro in the config file as:
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
## nginx配置文件 (详细的配置可见第4节)
location /M00 {
root /home/fdfs/storage;
ngx_fastdfs_module;
}
## 配置软连接 ${fastdfs_base_path}/storage/M00 to ${fastdfs_base_path}/storage
ln -s /home/fdfs/storage/data /home/fdfs/storage/data/M00
## 修改配置文件 /etc/fdfs/mod_fastdfs.conf (先复制到/etc/fdfs,目录)
cp /opt/fastdfs/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
## 启动nginx
/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
有可能会报错:
ERROR - file: ini_file_reader.c, line: 631, include file "http.conf" not exists, line: "#include http.conf"
这个是由于缺少 http.conf
在 FastDFS/conf/
目录下有, 复制到 fastdfs-nginx-module/src/
目录, 重新编译并安装 nginx 即可。
4.Nginx 进阶配置
在 http {}
中添加以下配置
sendfile on;
tcp_nopush on;
### fastdfs 文件访问
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
#设置缓存存储路径、存储方式、分配内存大小、磁盘最大空间、缓存期限 (可能需要手动创建目录)
proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d;
proxy_temp_path /var/cache/nginx/proxy_cache/tmp;
upstream 配置 (暂时没用上)
#fastdfs 设置group1的服务器
upstream fdfs_group1 {
server 127.0.0.1:8888 weight=1 max_fails=2 fail_timeout=30s;
}
#fastdfs 设置group2的服务器
upstream fdfs_group2 {
server 127.0.0.1:8888 weight=1 max_fails=2 fail_timeout=30s;
#server 172.16.1.205:8080 weight=1 max_fails=2 fail_timeout=30s;
#server 172.16.1.206:8080 weight=1 max_fails=2 fail_timeout=30s;
}
#fastdfs 设置group3的服务器
upstream fdfs_group3 {
server 127.0.0.1:8888 weight=1 max_fails=2 fail_timeout=30s;
}
server配置 (负载部分:暂未配置多机负载环境,先忽略)
### fastdfs
server {
listen 80;
server_name fdfs.sherlocky.com;
location ~ /group[1-3]/M00 {
root /home/fdfs/storage/data;
ngx_fastdfs_module;
}
### 多group 负载服务配置
#设置group1的负载均衡参数
#location /group1/M00 {
# proxy_next_upstream http_502 http_504 error timeout invalid_header;
# proxy_cache http-cache;
# proxy_cache_valid 200 304 12h;
# proxy_cache_key $uri$is_args$args;
# proxy_pass http://fdfs_group1;
# expires 30d;
#}
#设置group2的负载均衡参数
#location /group2/M00 {
# proxy_next_upstream http_502 http_504 error timeout invalid_header;
# proxy_cache http-cache;
# proxy_cache_valid 200 304 12h;
# proxy_cache_key $uri$is_args$args;
# proxy_pass http://fdfs_group2;
# expires 30d;
#}
#设置group3的负载均衡参数
#location /group3/M00 {
# proxy_next_upstream http_502 http_504 error timeout invalid_header;
# proxy_cache http-cache;
# proxy_cache_valid 200 304 12h;
# proxy_cache_key $uri$is_args$args;
# proxy_pass http://fdfs_group3;
# expires 30d;
#}
#设置 Nginx Purge 清除缓存的访问权限(需要安装Purge模块)
#location ~ /purge(/.*) {
# allow 127.0.0.1;
# allow 103.74.175.172;
# allow 103.74.175.174;
# #allow 172.16.1.0/24;
# deny all;
# proxy_cache_purge http-cache $1$is_args$args;
#}
}
评论区