码迷,mamicode.com
首页 > 其他好文 > 详细

FastDFS和nginx安装

时间:2016-04-26 09:27:35      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:

介绍

两台服务器,使用的系统为centos7.1,libfastcommon1.07,fastdfs版本为5.05稳定版

两台服务器ip分别是18和50,18作为tracker机器,50作为storage。

安装依赖

sudo yum -y groupinstall ‘Development Tools‘

安装libfastcommon

cd libfastcommon-master

./make.sh

sudo ./make.sh install

安装fastdfs

cd fastdfs-5.05/

./make.sh

sudo ./make.sh install

添加用户

useradd fastdfs -M -s /sbin/nologin

useradd nginx -M -s /sbin/nologin

创建文件夹

sudo mkdir -p /data/fdfs/

sudo chown -R fastdfs:fastdfs /data/fdfs

在18机器上

修改tracker配置文件

sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

sudo vim /etc/fdfs/tracker.conf

修改base_path

# the base path to store data and log files

base_path=/data/fdfs

配置run-user,run group为fastdfs,fastdfs

启动tracker

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

在50机器上

修改storage配置文件

cd /etc/fdfs

sudo cp tracker.conf.sample tracker.conf

#编辑文件tracker.conf

sudo vim tracker.conf

 

run_by_group=fastdfs

run_by_user=fastdfs

 

# the base path to store data and log files

base_path=/data/fdfs

# tracker_server can ocur more than once, and tracker_server format is

# "host:port", host can be hostname or ip address

tracker_server=192.168.1.36:22122

# store_path#, based 0, if store_path0 not exists, it‘s value is base_path

# the paths must be exist

store_path0=/data/fdfs

#store_path1=/home/yuqing/fastdfs2

启动storage

sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start

配置测试客户端

为50机器添加client配置文件
cd /etc/fdfs
sudo cp client.conf.sample client.conf
 
修改client.conf文件的如下内容
# the base path to store log files
base_path=/data/fdfs
# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=192.168.1.50:22122

创建nginx使用的目录

sudo mkdir /data/ngx
sudo chown –R fastdfs:fastdfs /data

创建mod_fastdfs.conf文件

sudo cp /root/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/

修改mod_fastdfs.conf

# the base path to store log files
base_path=/data/ngx
# FastDFS tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=192.168.1.36:22122
# store_path#, based 0, if store_path0 not exists, it‘s value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/data/fdfs

复制文件http.conf和mime.types到/etc/fdfs目录

cp /usr/yKF6600/fastdfs-master/conf/http.conf /usr/yKF6600/fastdfs-master/conf/mime.types  /etc/fdfs

配置nginx配置

修改vi /usr/local/openresty/nginx/conf/nginx.conf

 server {
        listen       80;
        server_name  localhost;

        charset utf8;

        location /M00 {
                alias /data/fdfs/data;
                ngx_fastdfs_module;
        }
   ......

创建连接

sudo ln -s /data/fdfs/data /data/fdfs/data/M00

重启nginx

sudo /usr/local/openresty/nginx/sbin/nginx -s reload
 

创建并上传测试文件

创建test.html,输入如下内容

test fastdfs

上传测试文件,命令为

/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.html

结果类似为为

This is FastDFS client test program v5.05

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.

[2015-04-25 18:06:09] DEBUG - base_path=/data/fdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

tracker_query_storage_store_list_without_group:
        server 1. group_name=, ip_addr=192.168.1.36, port=23000

group_name=group1, ip_addr=192.168.1.36, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01.html
source ip address: 192.168.1.36
file timestamp=2015-04-25 18:06:09
file size=13
file crc32=3418468952
example file url: http://192.168.1.36/group1/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01.html
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html
source ip address: 192.168.1.36
file timestamp=2015-04-25 18:06:09
file size=13
file crc32=3418468952
example file url: http://192.168.1.36/group1/M00/00/00/wKgC1FU7ZxGAF19vAAAADcvBslg01_big.html

技术分享

访问上传的页面

curl http://172.16.4.50/M00/00/00/rBAEMlcersyAT4p8AAAADcvBslg24_big.html

得到结果为

test fdfs

 

参考

http://www.centoscn.com/image-text/install/2015/0429/5298.html

FastDFS和nginx安装

标签:

原文地址:http://www.cnblogs.com/Yin-BloodMage/p/5433629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!