FastDFS+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上的安裝配置

[root@tracker1]# wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz
[root@tracker1]# tar xvzf FastDFS_v3.06.tar.gz
[root@tracker1]# cd FastDFS
[root@tracker1]# vi make.sh
#將找到下面兩行,將前邊的"#"去掉,目的是安裝httpd和fdfs_trackerd/fdfs_storaged服務

WITH_HTTPD=1
WITH_LINUX_SERVICE=1

[root@tracker1]# ./make.sh
[root@tracker1]# ./make.sh install
[root@tracker1]# vi /etc/fdfs/tracker.conf

修改/etc/fdfs/tracker.conf,主要修改以下兩處,如有其他調整,可參考文檔自行調整,默認的配置也可以工作。

# 配置data和log的存放路徑,該路徑如果不存在,需要自己創建
base_path=/home/tracker1/fastdfs

# 找到下面這行包含兩個"##"號
##include http.conf
# 去掉一個"#"
#include http.conf

[root@tracker1]# mkdir -p /home/tracker1/fastdfs

啓動tracker服務
[root@tracker1]# service fdfs_trackerd start

確認8080,22122端口已經監聽
[root@tracker1]# 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
[root@storage1]# wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz
[root@storage1]# wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.10.tar.gz
[root@storage1]# wget http://nginx.org/download/nginx-1.0.11.tar.gz

安裝FastDFS =>安裝方法與tracker1上相同。

安裝nginx和fastdfs-nginx-module
[root@storage1]# tar xvzf nginx-1.0.11.tar.gz
[root@storage1]# tar xvzf fastdfs-nginx-module_v1.10.tar.gz
[root@storage1]# cd nginx-1.0.11
[root@storage1]# ./configure --prefix=/usr/local/nginx --add-module=/home/fastdfs-nginx-module/src
[root@storage1]# make
[root@storage1]# make install

[root@storage1]# 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

[root@storage1]# cp /home/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@storage1]# 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

[root@storage1]# mkdir -p /home/storage1/fastdfs

在nginx的server配置段中增加M00的location聲明
[root@storage1]# vi /usr/local/nginx/conf/nginx.conf
location /group1/M00 {
root /home/storage1/fastdfs/data;
ngx_fastdfs_module;
}

創建M00目錄的軟連接
[root@storage1]# ln -s /home/storage1/fastdfs/data /home/storage1/fastdfs/data/M00

啓動storage服務
[root@storage1]# service fdfs_storaged start

啓動nginx,啓動之前,要確定fdfs_trackerd服務已啓動且相關防火牆端口已開放
[root@storage1]# /usr/local/nginx/sbin/nginx

確認80,23000端口已經監聽
[root@storage1]# 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測試]

[root@tracker1]# /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
[root@tracker1]# vi test.txt
輸入內容: hello,this is my first fastdfs test

保存。使用自帶的fdfs_test上傳文件測試

[root@tracker1]# /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

如果看到文件內容,說明配置成功!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章