fastdfs(檔案伺服器)安裝教程及php擴充安裝

來源:互聯網
上載者:User

標籤:1.4   mod   主伺服器   next   ati   add   openssl   conf   install   

在安裝fastdfs之前已經安裝了lnmp整合套件,所以直接安裝fastdfs,之後再安裝fastdfs_nginx_model(nginx的擴充)準備工作:下載fastdif安裝包到 /home/soft 目錄 ,:http://pan.baidu.com/s/1jH59oO21、安裝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 配置tracker2.1 建立與配置tracker資料目錄# mkdir -p /home/fastdfs/tracker# vi /etc/fdfs/tracker.confbase_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_model4.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、啟動nginxlnmp 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擴充安裝

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.