在我的生產環境中利用FastDFS實現動靜分離的方案
?
配置過程
1.? 系統環境
CentOS 5.5
Tracker server: 192.168.204.135
Storage server: 192.168.204.136
?
2. 環境配置
為了速度,配置使用sohu的源
cd /etc/ yum .repo.d/ wget http: // mirrors.sohu.com/help/CentOS-Base-sohu.repo
裝開發工具和編譯nginx所需的開發包
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,主要修改以下兩處,如有其他調整,可參考文檔自行調整,默認的配置也可以工作。
# 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,主要修改以下幾處,如有其他調整,可參考文檔自行調整,默認的配置也可以工作。
# vi /etc/fdfs/ storage.conf # the name of the group this storage server belongs to group_name =group1 ====> 此臺storage server所屬的服務器組名 # 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和端口,此處可以寫多個tracker server,每行一個 #HTTP settings http.disabled = true ====> 關閉內置的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和端口,此處可以寫多個tracker server,每行一個 # the group name of storage server group_name =group1 ====> 此臺storage server所屬的服務器組名 # 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 ====> 對文件同步延遲的處理方式,通過redirect跳轉和proxy代理兩種方式解決 # mkdir -p /fastdfs/storage
啟動storage服務
# /etc/init.d/fdfs_storaged start
啟動nginx
# /usr/local/nginx/sbin/nginx
確認8080,22122端口已經監聽
# 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測試]
修改/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 . 204.135 : 22122
創建一個用于測試的文件demofile.txt
[root@tracker]# vi demofile.txt 內容就一行字: dddddddddd
使用自帶的fdfs_test上傳文件測試。
[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
?
通過http://192.168.204.136/group1/M00/00/00/wKgD4k8ZC1SNK-NYAAAAC3lx3Rk484_big.txt 址可以直接訪問storage地址。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
