1. 程式人生 > >fastdfs(文件服務器)安裝教程及php擴展安裝

fastdfs(文件服務器)安裝教程及php擴展安裝

ofa cbc install host block lan 玩耍 lena ffi

在安裝fastdfs之前已經安裝了lnmp集成包,所以直接安裝fastdfs,之後再安裝fastdfs_nginx_model(nginx的擴展) 準備工作:下載fastdif安裝包到 /home/soft 目錄 ,下載地址:http://pan.baidu.com/s/1jH59oO2 1、安裝fastdfs # cd /home/softs/fastdfs # tar xzf FastDFS_v4.06.tar.gz # cd FastDFS # vi make.sh 去掉註釋 WITH_LINUX_SERVICE=1 # ./make.sh # ./make.sh install 2 配置tracker 2.1 創建與配置tracker數據目錄 # mkdir -p /home/fastdfs/tracker # vi /etc/fdfs/tracker.conf base_path=/home/fastdfs/tracker 2.2 啟動tracker # service fdfs_trackerd start 2.3 查看啟動 # netstat -anp | grep 22122 技術分享
3 配置storage 3.1 創建與配置storage目錄 # mkdir -p /home/fastdfs/storage/storage0 # vi /etc/fdfs/storage.conf 需要修改的部分:
http.server_port=80
group_name=group1
base_path=/home/fastdfs
store_path0=/home/fastdfs/storage/storage0
tracker_server=175.22.14.205:22122
3.2 啟動storage # service fdfs_storaged start 3.3 查看啟動 # netstat -anp | grep 23000 技術分享
4 安裝fastdfs_nginx_model 4.1、首先下載好fastdfs_nginx_model擴展 4.2 配置mod_fastdfs.conf # cp /home/softs/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ # vi /etc/fdfs/mod_fastdfs.conf 修改:
base_path=/home/fastdfs
tracker_server=175.22.14.205:22122
group_name=group1
url_have_group_name = true
store_path0=/home/fastdfs/storage/storage0
4.3、更新nginx
cd /home/softs/lnmp1.4
vi lnmp.conf (主要修改加黑的行就可以了)
Download_Mirror=‘https://soft.vpser.net‘
Nginx_Modules_Options=‘--add-module=/home/softs/fastdfs/fastdfs-nginx-module/src‘
PHP_Modules_Options=‘‘
##MySQL/MariaDB database directory##
MySQL_Data_Dir=‘/usr/local/mysql/var‘
MariaDB_Data_Dir=‘/usr/local/mariadb/var‘
##Default website home directory##
Default_Website_Dir=‘/home/wwwroot/default‘
Enable_Nginx_Openssl=‘y‘
~
更新一下nginx
cd /home/softs/lnmp1.4
./upgrade.sh nginx 【運行之後會要求輸入一個nginx版本,當前版本是1.12.1】
4.5 配置nginx.conf
# vi /usr/local/nginx/conf/nginx.conf
location /group2/M00 {
root /home/fastdfs/storage/storage0/data;
ngx_fastdfs_module;
}
4.6、啟動nginx lnmp nginx reload 5、 配置client.conf
# vi /etc/fdfs/client.conf
base_path=/home/tmp
tracker_server=175.22.14.205:22122
http.tracker_server_port=80
6、測試 /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload test.txt 技術分享 技術分享 上傳圖片 /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload 111.png 技術分享 技術分享 上傳mp3 /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload 123.mp3 技術分享 第二部分,php擴展fastdfs_client安裝 1、安裝,進入/home/softs/fastdfs/FastDFS/php_client目錄 技術分享 執行:
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
執行完之後文件變化 技術分享 2、測試
cp ../conf/client.conf /etc/fdfs/
cat fastdfs_client.ini >> /usr/local/php/etc/php.ini
cp fastdfs_test.php /home/wwwroot/default/ (測試php擴展是否安裝成功)
技術分享 技術分享 至此php擴展fastdfs_client安裝完畢 可以盡情的玩耍了..... php測試fastdfs上傳 附帶php上傳代碼 表單提交html
<html>
<body>
<form action="upload.php" method="post" target="_blank" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="upFile" id="upFile" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
upload.php文件代碼 <?php //上傳附件
function uploadAttach() {/* {{{ */
$ret = array();
$ret[‘errorcode‘] = 0;
$ret[‘errormsg‘] = ‘‘;
if (!$_FILES || false == isset($_FILES["upFile"])) {
$ret[‘errorcode‘] = 1;
$ret[‘errormsg‘] = "ERROR:upFile is not set";
return $ret;
}
$file = $_FILES["upFile"];
if (false == isset($file[‘tmp_name‘]) || false == is_file($file[‘tmp_name‘])) {
$ret[‘errorcode‘] = 2;
$ret[‘errormsg‘] = "tmp_name is not file";
return $ret;
}
if (0 == filesize($file[‘tmp_name‘])) {
$ret[‘errorcode‘] = 3;
$ret[‘errormsg‘] = "tmp_name filesize is 0";
return $ret;
}
$curlFile = new CurlFile($file[‘tmp_name‘], $file[‘type‘], $file[‘name‘]);
$fileSuffix = getSuffix($curlFile->getPostFilename());
$ret[‘file‘] = $file;
$ret[‘fileId‘] = uploadToFastdfs($curlFile, $fileSuffix);
return $ret;
}
/* }}} */
//獲取後綴
function getSuffix($fileName) {/* {{{ */
preg_match(‘/\.(\w+)?$/‘, $fileName, $matchs);
return isset($matchs[1]) ? $matchs[1] : ‘‘;
}
/* }}} */
//上傳文件到fastdfs
function uploadToFastdfs(CurlFile $file, $fileSuffix) {/* {{{ */
$fdfs = new FastDFS();
$tracker = $fdfs->tracker_get_connection();
$fileId = $fdfs->storage_upload_by_filebuff1(file_get_contents($file->getFilename()), $fileSuffix);
$fdfs->tracker_close_all_connections();
return $fileId;
}
/* }}} */
function start() {
$ret = uploadAttach();
if (!empty($ret[‘fileId‘])) {
$host_file = ‘http://175.22.14.205/‘ . $ret[‘fileId‘];
header(‘location:‘ . $host_file);
}
print_r($ret);
}
start();
?>
fastdfs文件服務器集群配置(簡版配置) 文件服務器: 主:175.22.14.205 【group1】 從:175.22.14.208 【group2】 從:175.22.14.211 【group3】 主服務器nginx配置 nginx.cof文件中http區域中加入如下代碼 技術分享 upstream fdfs_group2 { server 175.22.14.208; } server配置項增加: 技術分享 location /group2/M00 { proxy_next_upstream http_502 http_504 error timeout invalid_header; #proxy_cache http-cache; #proxy_cache_valid 200 304 12h; #proxy_cache_key $uri$is_args$args; proxy_pass http://fdfs_group2; expires 30d; } 從服務器配置,增加一個server配置即可 技術分享 測試 技術分享 技術分享 技術分享

fastdfs(文件服務器)安裝教程及php擴展安裝