在我的生產(chǎn)環(huán)境中利用FastDFS實(shí)現(xiàn)動(dòng)靜分離的方案
?
配置過(guò)程
1.? 系統(tǒng)環(huán)境
CentOS 5.5
Tracker server: 192.168.204.135
Storage server: 192.168.204.136
?
2. 環(huán)境配置
為了速度,配置使用sohu的源
cd /etc/
yum
.repo.d/
wget
http:
//
mirrors.sohu.com/help/CentOS-Base-sohu.repo
裝開(kāi)發(fā)工具和編譯nginx所需的開(kāi)發(fā)包
yum
groupinstall
"
Development Tools
"
yum
install
libevent-devel pcre-devel zlib-devel
?
3.安裝trackerserver
# wget
http:
//
fastdfs.googlecode.com/files/FastDFS_v3.05.tar.gz
#
tar
xvzf FastDFS_v3.
05
.
tar
.gz
# cd FastDFS
#
vi
make
.
sh
將如下兩行前邊的
"
#
"
刪除
WITH_HTTPD
=
1
WITH_LINUX_SERVICE
=
1
# .
/
make
.
sh
# .
/
make
.
sh
install
修改/etc/fdfs/tracker.conf,主要修改以下兩處,如有其他調(diào)整,可參考文檔自行調(diào)整,默認(rèn)的配置也可以工作。
# vi
/etc/fdfs/
tracker.conf
# the base path to store data and log files
base_path
=/fastdfs/tracker ====>
放置data和log的目錄
##include http.conf
====> #include http.conf 這里一定要注意!是 #include,不是include!!!
#
mkdir
-p /fastdfs/
tracker
#
/etc/init.d/
fdfs_trackerd start
# netstat –ntplu
|
grep
-E ‘
8080
|
22122
’
tcp
0
0
0.0
.
0.0
:
22122
0.0
.
0.0
:* LISTEN
5149
/
fdfs_trackerd
tcp
0
0
0.0
.
0.0
:
8080
0.0
.
0.0
:* LISTEN
5149
/fdfs_trackerd
?
4. 在storage上的操作
#
wget
http:
//
fastdfs.googlecode.com/files/FastDFS_v3.05.tar.gz
#
wget
http:
//
fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.10.tar.gz
#
wget
http:
//
nginx.org/download/nginx-1.0.11.tar.gz
#
tar
xvzf FastDFS_v3.
05
.
tar
.gz
# cd FastDFS
#
vi
make
.
sh
將如下兩行前邊的
"
#
"
刪除
WITH_HTTPD
=
1
WITH_LINUX_SERVICE
=
1
# .
/
make
.
sh
# .
/
make
.
sh
install
#
tar
xvzf nginx-
1.0
.
11
.
tar
.gz
#
tar
xvzf fastdfs-nginx-module_v1.
10
.
tar
.gz
# cd nginx
-
1.0
.
11
# .
/configure --prefix=/soft/nginx --add-module=/root/fastdfs-nginx-module/
src
#
make
#
make
install
修改/etc/fdfs/storage.conf,主要修改以下幾處,如有其他調(diào)整,可參考文檔自行調(diào)整,默認(rèn)的配置也可以工作。
#
vi
/etc/fdfs/
storage.conf
# the name of the group this storage server belongs to
group_name
=group1 ====>
此臺(tái)storage server所屬的服務(wù)器組名
# the base path to store data and log files
base_path
=/home/storage ====>
放置data和log的目錄
# store_path#, based
0
,
if
store_path0 not exists, it
'
s value is base_path
# the paths must be exist
store_path0
=/fastdfs/storage ====>
放置文件的目錄
# 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
.
204.135
:
22122
====>
tracker server的ip和端口,此處可以寫多個(gè)tracker server,每行一個(gè)
#HTTP settings
http.disabled
=
true
====>
關(guān)閉內(nèi)置的web server
# the port of the web server on this storage server
http.server_port
=
80
====>
web server的端口改成80
#
cp
/root/fastdfs-nginx-module/mod_fastdfs.conf /etc/fdfs/
#
vi
/etc/fdfs/
mod_fastdfs.conf
# the base path to store log files
base_path
=/fasdfs/storage ====>
放置log的目錄
# FastDFS 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
.
204.135
:
22122
====>
tracker server的ip和端口,此處可以寫多個(gè)tracker server,每行一個(gè)
# the group name of storage server
group_name
=group1 ====>
此臺(tái)storage server所屬的服務(wù)器組名
#
if
uri including group name
# default value is
false
url_have_group_name
=
true
====>
在URL中包含group名稱
# store_path#, based
0
,
if
store_path0 not exists, it
'
s value is base_path
# the paths must be exist
store_path0
=/fastdfs/storage ====>
放置文件的目錄
response_mode
=redirect ====>
對(duì)文件同步延遲的處理方式,通過(guò)redirect跳轉(zhuǎn)和proxy代理兩種方式解決
#
mkdir
-p /fastdfs/storage
啟動(dòng)storage服務(wù)
# /etc/init.d/fdfs_storaged start
啟動(dòng)nginx
# /usr/local/nginx/sbin/nginx
確認(rèn)8080,22122端口已經(jīng)監(jiān)聽(tīng)
# netstat -ntplu|
grep
-E
'
80|23000
'
tcp
0
0
0.0
.
0.0
:
80
0.0
.
0.0
:* LISTEN
2797
/
nginx
tcp
0
0
0.0
.
0.0
:
23000
0.0
.
0.0
:* LISTEN
6524
/fdfs_storaged
?
5. 在tracker上的操作[作為client測(cè)試]
修改/etc/fdfs/client.conf文件,主要修改以下幾處,如有其他調(diào)整,可參考文檔自行調(diào)整,默認(rèn)的配置也可以工作。
# 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
.
204.135
:
22122
創(chuàng)建一個(gè)用于測(cè)試的文件demofile.txt
[root@tracker]#
vi
demofile.txt
內(nèi)容就一行字: dddddddddd
使用自帶的fdfs_test上傳文件測(cè)試。
[root@tracker]# /usr/local/bin/fdfs_test /etc/fdfs/
client.conf upload demofile.txt
This is FastDFS client test program v3.
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.
[
2012
-
01
-
20
14
:
36
:
04
] INFO - base_path=/tmp, connect_timeout=
30
, network_timeout=
60
, tracker_server_count=
1
, 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
.
204.136
, port=
23000
group_name
=group1, ip_addr=
192.168
.
204.136
, port=
23000
storage_upload_by_filename
group_name
=group1, remote_filename=M00/
00
/
00
/wKgD4k8ZC1SNK-
NYAAAAC3lx3Rk484.txt
source ip address:
192.168
.
204.136
file
timestamp=
2012
-
01
-
20
14
:
36
:
04
file
size=
11
file
crc32=
2037505305
file
url: http:
//
192.168.204.135:8080/group1/M00/00/00/wKgD4k8ZC1SNK-NYAAAAC3lx3Rk484.txt
storage_upload_slave_by_filename
group_name
=group1, remote_filename=M00/
00
/
00
/wKgD4k8ZC1SNK-
NYAAAAC3lx3Rk484_big.txt
source ip address:
192.168
.
204.136
file
timestamp=
2012
-
01
-
20
14
:
36
:
04
file
size=
11
file
crc32=
2037505305
file
url: http:
//
192.168.204.135:8080/group1/M00/00/00/wKgD4k8ZC1SNK-NYAAAAC3lx3Rk484_big.txt
?
通過(guò)http://192.168.204.136/group1/M00/00/00/wKgD4k8ZC1SNK-NYAAAAC3lx3Rk484_big.txt 址可以直接訪問(wèn)storage地址。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元

