2014-11-15 13:37:01
来 源
itjs.cn
Nginx
此文详细介绍fastdfs+nginx安装配置过程,希望对于初学Nginx服务器相关的朋友有帮助,更多Nginx安装、配置、报错处理等资源请本站内搜索。。
1.系统环境

最小化安装的 CentOS 6.2

tracker1:   192.168.68.113

tracker1:   192.168.68.116

storage1:   192.168.68.114

storage1:   192.168.68.115

2.环境准备[所有服务器都需要]

安装EPEL源

rpm -ivh epel-release-6-6.noarch.rpm

安装开发工具和编译nginx所需的开发包

yum groupinstall -y "Development Tools"

yum install -y libevent-devel pcre-devel zlib-devel

3.在tracker上的安装配置

[[email protected]]# wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz

[[email protected]]# tar xvzf FastDFS_v3.06.tar.gz

[[email protected]]# cd FastDFS

[[email protected]]# vi make.sh

#将找到下面两行,将前边的"#"去掉,目的是安装httpd和fdfs_trackerd/fdfs_storaged服务

    WITH_HTTPD=1

    WITH_LINUX_SERVICE=1

[[email protected]]# ./make.sh

[[email protected]]# ./make.sh install

[[email protected]]# vi /etc/fdfs/tracker.conf

修改/etc/fdfs/tracker.conf,主要修改以下两处,如有其他调整,可参考文档自行调整,默认的配置也可以工作。

    # 配置data和log的存放路径,该路径如果不存在,需要自己创建

    base_path=/home/tracker1/fastdfs

    # 找到下面这行包含两个"##"号

    ##include http.conf

    # 去掉一个"#"

    #include http.conf

[[email protected]]# mkdir -p /home/tracker1/fastdfs

启动tracker服务

[[email protected]]# service fdfs_trackerd start

确认8080,22122端口已经监听

[[email protected]]# netstat -ntl

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

tcp        0      0 0.0.0.0:111                 0.0.0.0:* LISTEN

tcp        0      0 0.0.0.0:8080                0.0.0.0:* LISTEN

tcp        0      0 0.0.0.0:22  0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:45372               0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:22122               0.0.0.0:*                   LISTEN

tcp        0      0 :::111    :::*                        LISTEN

tcp        0      0 :::22     :::*                        LISTEN

tcp        0      0 :::45032  :::*                        LISTEN

4.在storage上的安装配置

下载FastDFS,Nginx和fastdfs-nginx-module

[[email protected]]# wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz

[[email protected]]# wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.10.tar.gz

[[email protected]]# wget http://nginx.org/download/nginx-1.0.11.tar.gz

安装FastDFS =>安装方法与tracker1上相同。

安装nginx和fastdfs-nginx-module

[[email protected]]# tar xvzf nginx-1.0.11.tar.gz

[[email protected]]# tar xvzf fastdfs-nginx-module_v1.10.tar.gz

[[email protected]]# cd nginx-1.0.11

[[email protected]]# ./configure --prefix=/usr/local/nginx --add-module=/home/fastdfs-nginx-module/src

[[email protected]]# make

[[email protected]]# make install

[[email protected]]# vi /etc/fdfs/storage.conf

修改/etc/fdfs/storage.conf,主要修改以下几处,如有其他调整,可参考文档自行调整,默认的配置也可以工作。

    

    # HTTP settings

    # 关闭内置的web server

    http.disabled=true

    # the port of the web server on this storage server

    # web server的端口改成80

    http.server_port=80

    # the name of the group this storage server belongs to

    # 此台storage1所属的服务器组名,同组内storage数据完全相同

    group_name=group1

    # the base path to store data and log files

    # 放置data和log的目录

    base_path=/home/storage1/fastdfs

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

    # the paths must be exist

    # 放置文件的目录

    store_path0=/home/storage1/fastdfs

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

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

    # tracker server的ip和端口,此处可以写多个tracker server,每行一个

    tracker_server=192.168.68.113:22122

    tracker_server=192.168.68.116:22122

[[email protected]]# cp /home/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

[[email protected]]# vi /etc/fdfs/mod_fastdfs.conf

    # the base path to store log files

    # 放置log的目录

    base_path=/home/storage1/fastdfs

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

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

    # tracker1的ip和端口,此处可以写多个tracker server,每行一个

    tracker_server=192.168.68.113:22122

    tracker_server=192.168.68.116:22122

    # the group name of storage server

    # 此台storage server所属的服务器组名

    group_name=group1

    # if uri including group name

    # default value is false

    # 在URL中包含group名称

    url_have_group_name = true

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

    # the paths must be exist

    # 放置文件的目录

    store_path0=/home/storage1/fastdfs

[[email protected]]# mkdir -p /home/storage1/fastdfs

在nginx的server配置段中增加M00的location声明

[[email protected]]# vi /usr/local/nginx/conf/nginx.conf

    location /group1/M00 {

            root /home/storage1/fastdfs/data;

            ngx_fastdfs_module;

    }

创建M00目录的软连接

[[email protected]]# ln -s /home/storage1/fastdfs/data  /home/storage1/fastdfs/data/M00

启动storage服务

[[email protected]]# service fdfs_storaged start

启动nginx,启动之前,要确定fdfs_trackerd服务已启动且相关防火墙端口已开放

[[email protected]]# /usr/local/nginx/sbin/nginx

确认80,23000端口已经监听

[[email protected]]# netstat -ntl

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

tcp        0      0 0.0.0.0:111                 0.0.0.0:* LISTEN

tcp        0      0 0.0.0.0:80  0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:22  0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:23000               0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:34169               0.0.0.0:*                   LISTEN

tcp        0      0 :::111    :::*                        LISTEN

tcp        0      0 :::22     :::*                        LISTEN

tcp        0      0 :::60001  :::*                        LISTEN

5.在tracker上的操作[作为client测试]

[[email protected]]# /etc/fdfs/client.conf

    # the base path to store log files

    base_path=/tmp

    # 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.68.113:22122

    tracker_server=192.168.68.116:22122

创建一个用于测试的文件test.txt

[[email protected]]# vi test.txt

输入内容: hello,this is my first fastdfs test

保存。使用自带的fdfs_test上传文件测试

[[email protected]]# /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload test.txt

This is FastDFS client test program v3.06

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.

[2012-06-13 17:58:25] INFO - base_path=/tmp, connect_timeout=30, network_timeout=60, tracker_server_count=2, anti_steal_token=0, anti_steal_secret_key 

length=0

tracker_query_storage_store_list_without_group:

        server 1. group_name=group1, ip_addr=192.168.68.114, port=23000

group_name=group1, ip_addr=192.168.68.114, port=23000

storage_upload_by_filename

group_name=group1, remote_filename=M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607.txt

source ip address: 192.168.68.114

file timestamp=2012-06-13 17:58:25

file size=37

file crc32=3584975788

file url: http://192.168.68.113:8080/group1/M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607.txt

storage_upload_slave_by_filename

group_name=group1, remote_filename=M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607_big.txt

source ip address: 192.168.68.114

file timestamp=2012-06-13 17:58:25

file size=37

file crc32=3584975788

file url: http://192.168.68.113:8080/group1/M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607_big.txt

6.使用浏览器打开上传的文件

http://192.168.68.113:8080/group1/M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607_big.txt

如果看到文件内容,说明配置成功!

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。