fastdfs配置
伺服器環境
fastdfs-trackerd 192.168.32.128
fastdfs-storage 192.168.32.129
分别在兩個伺服器上面安裝好fastdfs服務
1.安裝依賴
yum install openssl* -y
yum install gd-devel -y
yum install pcre-devel -y
2.安裝lbevent
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure --prefix=/usr/local/libevent
make
make install
export LD_LIBRARY_PATH=/usr/local/libevent/lib
3..安裝fastdfs
tar zxvf FastDFS_v4.07.tar.gz
cd FastDFS
./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
./make.sh install
4.建立fastdfs存儲目錄
mkdir /data/fastDFS
5.在tracker修改配置檔案
vim /etc/fdfs/tracker.conf
bind_addr=192.168.32.128 綁定tracker伺服器ip
base_path=/data/fastDFS 存放資料和日志的根目錄位址(這個目錄必須存在,其下的子目錄自動生成
max_connections=256 系統提供服務時最大連接配接數
work_threads=4工作顯成熟,通常設定為cpu數,預設為4
store_lookup=2上傳檔案到組的方式,
0:輪詢 1:制定組 2:平均負載(選擇最大剩餘空間的組上傳)。
store_group=group2當store_lookup設定為1時。必須設定本參數為系統存在的一個組名
store_server=0選擇哪個storage server進行上傳
0:輪詢(預設方式)1:根據ip位址進行排序(選擇ip位址最小的) 2:根據優先級進行排序(上傳優先級由storage_server來設定,參數名為upload_priority)
store_path=0 選擇storage server中的那個目錄進行上傳,storage server可以有多個存放檔案的base_path,可以了解為多個磁盤。
0:輪流方式,多個目錄一次存放檔案 2:選擇生育空間最大的目錄存放檔案
download_Server=0 選擇哪個storage server作為下載下傳伺服器
0:輪詢方式,可以下載下傳目前檔案的任一storage server
1:哪個為源storage server就用哪一個,就是之前上傳到那個storage server伺服器就是哪個!
reserved_storage_space=10%storage server上的保留白間,保證系統或其他應用需求空間。
run_by_user=從作業系統運作FDFS的使用者(不填,就是目前使用者)
allow_hosts=*可以連接配接到此tracker server的ip範圍。可以配置多行
sync_log_buff_interval=10 同步或重新整理日志資訊到硬碟的時間間隔,預設為秒
check_active_interval=120檢測storage server存活的時間間隔,以秒為機關
thread_stack_size=64KB線程棧的大小,線程越大,占用資源越大。此值必須大于64KB
storeage_ip_changed_auto_adjust=true 這個參數控制當storage server ip改變時,叢集是否自動調整。注:隻有在storage server程序重新開機時才完成自動調整
storage_sync_file_max_delay=86400 storage server之間同步檔案的最大延遲時間,以秒為機關,預設為1天
storage_sync_file_max_time=300同步一個檔案需要消耗的最大時間,以秒為機關
use_trunk_file=fakse是否使用trunk file來合并小檔案,預設是關閉的
slot_min_size=256trunk file配置設定的最小位元組數,比如檔案隻有16個位元組,系統也會配置設定slot_min_size個位元組
slot_max_size=16MB隻有檔案大小<=這個參數值得檔案,才會合并存儲,如果檔案大小大于這個值,将直接儲存到一個檔案中(不采用合并存儲)
trunk_file_size=64MB合并存儲的trunk file大小,至少4MB.預設值為64MB,不建議設定過大
use_storage_id=false是否使用server id作為storage server辨別
storage_ids_filename=storage_ids.conf在檔案中設定組名。server id和對用的ip位址
id_type_in_filename=ip 設定檔案名中的storage server的辨別
ip:storage server的ip位址
id:storage server的server id
rotate_error_log=flase是夠定期輪轉error log,目前僅支援一天輪轉一次,建議設定為true!
error_log_rotate_time=00:00設定error log定期輪轉的時間點。當rotate_error_log為true時有效
connection_poll_max_idle_time=3600最大連接配接等待時間,以秒為機關
http.server_port=80 (http服務端口,可以不設定)
http.check_alive_interval=30 檢測storage http server存活的時間間隔, 以秒為機關
http.check_alive_type=tcp檢測storage http server存活的方式,預設為tcp
http.check_alive_url=/status.html檢測storage http server是否存活的url
#include http.conf
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf 啟動服務
修改client.conf
vim /etc/fdfs/client.conf
base_path=/data/fastDFS
tracker_server=192.168.32.128:22122
http.tracker_server_port=80
在storage伺服器安裝nginx。用來上傳和下載下傳檔案
#1.下載下傳fastdfs-nginx-module_v1.15.tar.gz
tar -zxvf fastdfs-nginx-module_v1.15.tar.gz -C /usr/local
#2.安裝nginx
tar zxvf nginx-1.6.0.tar.gz
cd nginx-1.6.0
cd /usr/local
tar zxvf fastdfs-nginx-module_v1.15.tar.gz
yum -y install pcre openssl gd*
./configure --prefix=/usr/local/nginx \
--with-file-aio \
--with-http_ssl_module \
--with-http_p_w_picpath_filter_module \
--with-http_sub_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-pcre \
--with-cc-opt='-O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' \
--with-ld-opt=-Wl,-E \
--with-http_realip_module \
--with-http_gzip_static_module \
--add-module=/usr/local/fastdfs-nginx-module/src
export LD_LIBRARY_PATH=/usr/local/libevent/lib/
cp mod_fastdfs.conf /etc/fdfs/
make && make install
修改mod_fastdfs.conf
vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=20
store_path0=/data/fastDFS
url_have_group_name = true
修改nginx.conf
vim /usr/local/nginx/conf/nginx.conf
在server段添加以下内容
location /group1/M00/
{
alias /www/fastDFS/data/;
ngx_fastdfs_module;
}
/usr/local/nginx/sbin/nginx -t檢查配置檔案參數
/usr/local/nginx/sbin/nginx 啟動nginx
在storage修改配置檔案
vim /etc/storage.conf
bind_addr=192.168.32.129
http.server_port=80
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf 啟動服務
測試:上傳檔案
cat ./.bash_profile >> 2.txt
/usr/local/bin/fdfs_test /etc/fdfs/client.conf upload 2.txt
This is FastDFS client test program v4.07
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.
[2014-12-31 09:20:40] DEBUG - base_path=/data/fastDFS, 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.32.129, port=23000
group_name=group1, ip_addr=192.168.32.129, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgggVSjQ-iAJxtqAAAAsFQ-X38886.txt
source ip address: 192.168.32.129
file timestamp=2014-12-31 08:31:36
file size=176
file crc32=1413373823
example file url: http://192.168.32.129/group1/M00/00/00/wKgggVSjQ-iAJxtqAAAAsFQ-X38886.txt
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgggVSjQ-iAJxtqAAAAsFQ-X38886_big.txt
example file url: http://192.168.32.129/group1/M00/00/00/wKgggVSjQ-iAJxtqAAAAsFQ-X38886_big.txt
用浏覽器通路 http://192.168.32.129/group1/M00/00/00/wKgggVSjQ-iAJxtqAAAAsFQ-X38886_big.txt 就能看到上傳的檔案了
上傳的檔案放在/data/fastDFS/data/00/00中
檢視端口
netstat -tunpl
配置fastdfs支援php
yum -y install php*
cd /root/FastDFS/php-client
phpize 用來準備php擴充庫的編譯環境
./configure
make
cat fastdfs_client.ini >> /etc/php.ini
/usr/bin/php -m | grep fastdfs
service php-fpm start
修改/etc/fdfs/client.conf
echo 'php_upload_test' > /tmp/upload.txt
vim test.php
<?php
var_dump(function_exists('fastdfs_storage_upload_by_filename'));
$ret = fastdfs_storage_upload_by_filename('
/tmp/upload.txt
');
var_dump($ret);
?>
/usr/bin/php test.php
bool(true)
成功
array(2) {
["group_name"]=>
string(6) "group1"
["filename"]=>
string(44) "M00/00/00/wKgggVSjbDaATlrAAAAAEIxdRHw661.txt"
}